Tweak some makefiles to prepare for bmake
[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 $
984263bc 2
984263bc
MD
3BINDIR?= /boot
4BINMODE= 444
6080181b
SS
5CLEANFILES= boot \
6 sio.o
984263bc 7
2983445f
SW
8CSTD?= c99
9
984263bc 10NM?= nm
cacaceec
MD
11NXCFLAGS=
12NXLDFLAGS=
13
14.PATH: ${.CURDIR}/..
d64b2e33
MD
15.PATH: ${.CURDIR}/../../common
16.PATH: ${.CURDIR}/../../../../lib/libstand
984263bc
MD
17
18# A value of 0x80 enables LBA support.
19B1FLAGS= 0x80
20
21BOOT_COMCONSOLE_PORT?= 0x3f8
22BOOT_COMCONSOLE_SPEED?= 9600
23B2SIOFMT?= 0x3
24
25.if exists(${.OBJDIR}/../btx)
26BTX= ${.OBJDIR}/../btx
27.else
28BTX= ${.CURDIR}/../btx
29.endif
30
cacaceec 31# These origins are taken from bootasm.h.
04144d62 32#
cacaceec
MD
33REL1 = `${.OBJDIR}/bootasmdef.nx BOOT1_ORIGIN`
34REL1D = `${.OBJDIR}/bootasmdef.nx -d BOOT1_ORIGIN`
35ORG1 = `${.OBJDIR}/bootasmdef.nx MEM_BIOS_LADDR`
36ORG1D = `${.OBJDIR}/bootasmdef.nx -d MEM_BIOS_LADDR`
04144d62
MD
37
38# WARNING! The ORG2 calculation is the origin of boot2.bin relative to
39# the start of the BTX *USER* address space, not the start of physical
40# memory.
41#
4e06dda7 42ORG2= `${.OBJDIR}/bootasmdef.nx BOOT2_VORIGIN`
984263bc 43
64005844
JM
44CFLAGS= -Os \
45 -fno-guess-branch-probability \
5ee58eed 46 -fomit-frame-pointer \
64005844
JM
47 -fno-unwind-tables \
48 -fno-asynchronous-unwind-tables \
7580e818 49 -DBOOT2 \
5ee58eed 50 -I${.CURDIR}/../../common \
7580e818 51 -I${.CURDIR}/../../../../lib/libstand \
5ee58eed 52 -I${.CURDIR}/../btx/lib -I. \
984263bc
MD
53 -Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
54 -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
d64b2e33 55 -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings
984263bc 56
2b4e55a0
SW
57DEBUG_FLAGS=
58
63a12d94
SS
59# Tell gcc that it shouldn't do fancy optimizations for newer processors.
60# Otherwise it winds up creating larger code and we won't be able to fit boot2.
61CFLAGS+= -march=i386
62
d90d8005 63# Unfortunately, unit-at-a-time creates issues as yet
3d310902
MD
64# not tracked down, in boot2, so we have to turn it off. Note that
65# the problem has been narrowed down to the 'boot2' code. The /boot/loader
66# doesn't seem to have a problem.
67#
3d310902 68CFLAGS+= -fno-unit-at-a-time
3d310902 69
d64b2e33
MD
70# boot2 area in 32 bit disklabel is 16 sectors (8K)
71#
72# boot2 area in 64 bit disklabel is 64 sectors (32K).
73# However, the boot1 btx loader puts boot2 at a physical address
74# of MEM_BTX_USR+BOOT2_VORIGIN which is typically 0xC000, so we
75# cannot make boot2 any larger then 16KB or we overflow the segment.
76#
6080181b 77NSECT_32?= 16
d64b2e33 78NSECT_64?= 30
044f3f17
JM
79LDFLAGS= -nostdlib -static -N --gc-sections
80LINKSCRIPT= --script ${.CURDIR}/boot2.ldscript
984263bc 81
6080181b
SS
82all: boot
83
84boot: boot1_32 boot2_32
85 cat ${.ALLSRC} > boot
86
87.for s in _32 _64
88
89_ADDCFLAGS$s:= -DNSECT=${NSECT$s}
90_ts= $s
91.if ${_ts} == "_64"
92_ADDCFLAGS$s+= -DDISKLABEL64
d64b2e33
MD
93_ADDCFLAGS$s+= -DHAMMERFS -DUFS
94_ADDOBJS$s+= hammerread$s.o ufsread$s.o
6080181b 95.else
d64b2e33
MD
96_ADDCFLAGS$s+= -DUFS -DUFS1_ONLY
97_ADDOBJS$s+= ufsread$s.o
6080181b 98.endif
5ee58eed 99
6080181b 100all: boot1$s boot2$s
984263bc 101
6080181b
SS
102boot1$s: boot1$s.out
103 objcopy -S -O binary boot1$s.out ${.TARGET}
984263bc 104
6080181b
SS
105boot1$s.out: boot1$s.o bootasmdef.nx
106 ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} ${.ALLSRC:M*.o}
984263bc 107
6080181b
SS
108boot1$s.o: boot1.S
109 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -DFLAGS=${B1FLAGS} \
110 ${.ALLSRC} -o ${.TARGET} -c
5ee58eed 111
a8a5ffd4 112boot2$s.s: boot2.c boot2$s.h ${.CURDIR}/../../common/ufsread.c ${.CURDIR}/../../../../lib/libstand/hammerread.c
ec1618fb 113 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -S -o boot2$s.s.tmp ${.CURDIR}/boot2.c
a8a5ffd4
JM
114 sed -e '/align/d' -e '/nop/d' < ${.TARGET}.tmp > ${.TARGET}
115 rm -f ${.TARGET}.tmp
116
117boot2$s.o: boot2$s.s
118 ${AS} ${AFLAGS} -o ${.TARGET} boot2$s.s
984263bc 119
6080181b 120boot2$s.h: boot1$s.out bootasmdef.nx
cacaceec 121 @echo "NOTE: boot2 using xread from boot1 at ${REL1}"
984263bc 122 ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
5ee58eed
MD
123 { x = $$1 - ORG1; \
124 printf("#define XREADORG %#x\n", REL1 + x) }' \
6080181b 125 ORG1=${ORG1D} REL1=${REL1D} > boot2$s.h
984263bc 126
6080181b
SS
127boot2$s: boot2$s.ldr boot2$s.bin ${BTX}/btx/btx
128 btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2$s.ldr \
129 -o boot2$s.ld -P 1 boot2$s.bin
130 stat boot2$s.ld | awk '{ x = (${NSECT$s} - 1) * 512 - $$8; \
984263bc 131 print x " bytes available"; if (x < 0) exit 1 }'
6080181b 132 dd if=boot2$s.ld of=${.TARGET} obs=$$(( (${NSECT$s} - 1) * 512)) conv=osync 2>/dev/null
984263bc 133
6080181b 134boot2$s.ldr:
2d7f6790 135 dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
984263bc 136
6080181b
SS
137boot2$s.bin: boot2$s.out
138 objcopy -S -O binary boot2$s.out ${.TARGET}
984263bc 139
d64b2e33 140boot2$s.out: boot2$s.o sio.o ${_ADDOBJS$s}
044f3f17 141 ${LD} ${LDFLAGS} -Ttext ${ORG2} ${LINKSCRIPT} -o ${.TARGET} \
5ee58eed 142 ${BTX}/lib/crt0.o ${.ALLSRC}
984263bc 143
6080181b 144CLEANFILES+= boot1$s boot1$s.out boot1$s.o \
d64b2e33
MD
145 boot2$s boot2$s.ldr boot2$s.bin \
146 boot2$s.ld boot2$s.out boot2$s.o boot2$s.h boot2$s.s \
147 ${_ADDOBJS$s}
148
149hammerread$s.o: hammerread.c
150 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} ${.ALLSRC} -o ${.TARGET} -c
151
152ufsread$s.o: ufsread.c
153 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} ${.ALLSRC} -o ${.TARGET} -c
6080181b
SS
154
155.endfor
984263bc 156
409cbc03 157sio.o: sio.S
72f919a1 158 ${CC} ${CFLAGS} -DSIOPRT=${BOOT_COMCONSOLE_PORT} -DSIOFMT=${B2SIOFMT} \
aec2661d 159 -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
6080181b 160 ${.ALLSRC} -o ${.TARGET} -c
984263bc
MD
161
162install:
163 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
5ee58eed
MD
164 boot ${DESTDIR}${BINDIR}/boot
165 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
6080181b
SS
166 boot1_32 ${DESTDIR}${BINDIR}/boot1
167 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
168 boot2_32 ${DESTDIR}${BINDIR}/boot2
169 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
170 boot1_64 ${DESTDIR}${BINDIR}/boot1_64
984263bc 171 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
6080181b 172 boot2_64 ${DESTDIR}${BINDIR}/boot2_64
984263bc
MD
173
174.include <bsd.prog.mk>
5ee58eed 175
b2b3ffcd
SS
176.if defined(REALLY_X86_64)
177# For x86_64, we need to fake up a complete machine/ tree
3d801ff7
SS
178# so that types for -m32 appear correctly.
179
5ee58eed
MD
180boot2.o: machine
181
3d801ff7
SS
182beforedepend ${OBJS}: machine cpu
183
184machine::
185 mkdir -p machine
186 ${LN} -sf ${.CURDIR}/../../../cpu/i386/include/* machine
187 ${LN} -sf ${.CURDIR}/../../../platform/pc32/include/* machine
5ee58eed 188
3d801ff7 189cpu::
9115b425 190 ${LN} -hsf ${.CURDIR}/../../../cpu/i386/include cpu
5ee58eed 191
3d801ff7 192CLEANDIRS+= machine cpu
5ee58eed
MD
193.endif
194
cacaceec
MD
195CLEANFILES+= bootasmdef.nx
196