Add hammer read support for loader.
[dragonfly.git] / sys / boot / pc32 / boot2 / Makefile
CommitLineData
5ee58eed 1# $FreeBSD: src/sys/boot/i386/boot2/Makefile,v 1.47 2003/06/26 03:51:57 peter Exp $
d90d8005 2# $DragonFly: src/sys/boot/pc32/boot2/Makefile,v 1.17 2006/08/12 05:42:26 swildner Exp $
984263bc
MD
3
4PROG= boot2
5NOMAN=
6STRIP=
7BINDIR?= /boot
8BINMODE= 444
5ee58eed 9CLEANFILES= boot boot1 boot1.out boot1.o \
984263bc 10 boot2.ldr boot2.bin boot2.ld boot2.out boot2.o boot2.h \
5ee58eed 11 boot2.s sio.o
984263bc
MD
12
13NM?= nm
cacaceec
MD
14NXCFLAGS=
15NXLDFLAGS=
16
17.PATH: ${.CURDIR}/..
984263bc
MD
18
19# A value of 0x80 enables LBA support.
20B1FLAGS= 0x80
21
22BOOT_COMCONSOLE_PORT?= 0x3f8
23BOOT_COMCONSOLE_SPEED?= 9600
24B2SIOFMT?= 0x3
25
26.if exists(${.OBJDIR}/../btx)
27BTX= ${.OBJDIR}/../btx
28.else
29BTX= ${.CURDIR}/../btx
30.endif
31
cacaceec 32# These origins are taken from bootasm.h.
04144d62 33#
cacaceec
MD
34REL1 = `${.OBJDIR}/bootasmdef.nx BOOT1_ORIGIN`
35REL1D = `${.OBJDIR}/bootasmdef.nx -d BOOT1_ORIGIN`
36ORG1 = `${.OBJDIR}/bootasmdef.nx MEM_BIOS_LADDR`
37ORG1D = `${.OBJDIR}/bootasmdef.nx -d MEM_BIOS_LADDR`
04144d62
MD
38
39# WARNING! The ORG2 calculation is the origin of boot2.bin relative to
40# the start of the BTX *USER* address space, not the start of physical
41# memory.
42#
4e06dda7 43ORG2= `${.OBJDIR}/bootasmdef.nx BOOT2_VORIGIN`
984263bc 44
5ee58eed
MD
45# Decide Level of UFS support. UFS1_AND_UFS2 doesn't fit.
46
47# BOOT2_UFS?= UFS2_ONLY
48#BOOT2_UFS?= UFS1_AND_UFS2
49BOOT2_UFS?= UFS1_ONLY
50
51# gcc3.x
52# -fno-guess-branch-probability
53# -mno-align-long-strings
0e24d183 54CFLAGS= -elf -ffreestanding -Os -fno-builtin \
5ee58eed 55 -fomit-frame-pointer \
5ee58eed
MD
56 -D${BOOT2_UFS} \
57 -I${.CURDIR}/../../common \
58 -I${.CURDIR}/../btx/lib -I. \
984263bc
MD
59 -Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
60 -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
f91a71dd
JS
61 -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings \
62 -D__BOOT2_HACK
984263bc 63
d90d8005 64# Unfortunately, unit-at-a-time creates issues as yet
3d310902
MD
65# not tracked down, in boot2, so we have to turn it off. Note that
66# the problem has been narrowed down to the 'boot2' code. The /boot/loader
67# doesn't seem to have a problem.
68#
3d310902 69CFLAGS+= -fno-unit-at-a-time
3d310902 70
d90d8005
SW
71# Disable propolice on gcc that supports it
72.if ${CCVER} == "gcc34"
0e24d183
SS
73CFLAGS+= -fno-stack-protector
74.endif
75
5ee58eed 76LDFLAGS=-nostdlib -static -N --gc-sections
984263bc 77
5ee58eed
MD
78all: boot1 boot2 boot
79
80boot: boot1 boot2
81 cat boot1 boot2 > boot
984263bc
MD
82
83boot1: boot1.out
84 objcopy -S -O binary boot1.out ${.TARGET}
85
cacaceec 86boot1.out: boot1.o bootasmdef.nx
984263bc
MD
87 ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
88
409cbc03
MD
89boot1.o: boot1.S
90 ${CC} ${CFLAGS} -DFLAGS=${B1FLAGS} ${AFLAGS} \
91 ${.IMPSRC} -o ${.TARGET} -c
5ee58eed
MD
92
93boot2.o: boot2.c ${.CURDIR}/../../common/ufsread.c
94 ${CC} ${CFLAGS} -S -o boot2.s.tmp ${.IMPSRC}
95 sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
96 rm -f boot2.s.tmp
97 ${AS} ${AFLAGS} -o boot2.o boot2.s
984263bc 98
cacaceec
MD
99boot2.h: boot1.out bootasmdef.nx
100 @echo "NOTE: boot2 using xread from boot1 at ${REL1}"
984263bc 101 ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
5ee58eed
MD
102 { x = $$1 - ORG1; \
103 printf("#define XREADORG %#x\n", REL1 + x) }' \
cacaceec 104 ORG1=${ORG1D} REL1=${REL1D} > boot2.h
984263bc
MD
105
106boot2: boot2.ldr boot2.bin ${BTX}/btx/btx
107 btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2.ldr \
108 -o boot2.ld -P 1 boot2.bin
1320c43d 109 @stat boot2.ld | awk '{ x = 7680 - $$8; \
984263bc
MD
110 print x " bytes available"; if (x < 0) exit 1 }'
111 dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync 2>/dev/null
112
113boot2.ldr:
2d7f6790 114 dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
984263bc
MD
115
116boot2.bin: boot2.out
117 objcopy -S -O binary boot2.out ${.TARGET}
118
119boot2.out: boot2.o sio.o
120 ${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
5ee58eed 121 ${BTX}/lib/crt0.o ${.ALLSRC}
984263bc
MD
122
123boot2.o: boot2.h
124
409cbc03
MD
125sio.o: sio.S
126 ${CC} -DSIOPRT=${BOOT_COMCONSOLE_PORT} -DSIOFMT=${B2SIOFMT} \
d90d8005
SW
127 -DSIOSPD=${BOOT_COMCONSOLE_SPEED} ${AFLAGS} \
128 ${.IMPSRC} -o ${.TARGET} -c
984263bc
MD
129
130install:
5ee58eed
MD
131 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
132 boot ${DESTDIR}${BINDIR}/boot
984263bc
MD
133 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
134 boot1 ${DESTDIR}${BINDIR}/boot1
135 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
136 boot2 ${DESTDIR}${BINDIR}/boot2
137
138.include <bsd.prog.mk>
5ee58eed
MD
139
140.if defined(REALLY_AMD64)
141boot2.o: machine
142
143beforedepend ${OBJS}: machine
144
145machine:
062db326 146 ${LN} -sf ${.CURDIR}/../../../i386/include machine
5ee58eed
MD
147
148CLEANFILES+= machine
149.endif
150
cacaceec
MD
151CLEANFILES+= bootasmdef.nx
152