1 # $FreeBSD: src/sys/boot/i386/boot2/Makefile,v 1.47 2003/06/26 03:51:57 peter Exp $
15 .PATH: ${.CURDIR}/../../common
16 .PATH: ${.CURDIR}/../../../../lib/libstand
17 .PATH: ${.CURDIR}/../../../libkern
19 # A value of 0x80 enables LBA support.
22 BOOT_COMCONSOLE_PORT?= 0x3f8
23 BOOT_COMCONSOLE_SPEED?= 9600
26 .if exists(${.OBJDIR}/../btx)
27 BTX= ${.OBJDIR}/../btx
29 BTX= ${.CURDIR}/../btx
32 # These origins are taken from bootasm.h.
34 REL1 = `${.OBJDIR}/bootasmdef.nx BOOT1_ORIGIN`
35 REL1D = `${.OBJDIR}/bootasmdef.nx -d BOOT1_ORIGIN`
36 ORG1 = `${.OBJDIR}/bootasmdef.nx MEM_BIOS_LADDR`
37 ORG1D = `${.OBJDIR}/bootasmdef.nx -d MEM_BIOS_LADDR`
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
43 ORG2= `${.OBJDIR}/bootasmdef.nx BOOT2_VORIGIN`
46 -fno-guess-branch-probability \
47 -fomit-frame-pointer \
49 -fno-asynchronous-unwind-tables \
51 -I${.CURDIR}/../../common \
52 -I${.CURDIR}/../../../../lib/libstand \
53 -I${.CURDIR}/../btx/lib -I. \
54 -Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
55 -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
56 -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings
60 # Tell gcc that it shouldn't do fancy optimizations for newer processors.
61 # Otherwise it winds up creating larger code and we won't be able to fit boot2.
64 # Unfortunately, unit-at-a-time creates issues as yet
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.
69 CFLAGS+= -fno-unit-at-a-time
71 # boot2 area in 32 bit disklabel is 16 sectors (8K)
73 # boot2 area in 64 bit disklabel is 64 sectors (32K).
74 # However, the boot1 btx loader puts boot2 at a physical address
75 # of MEM_BTX_USR+BOOT2_VORIGIN which is typically 0xC000, so we
76 # cannot make boot2 any larger then 16KB or we overflow the segment.
80 LDFLAGS= -nostdlib -static -N --gc-sections
81 LINKSCRIPT= --script ${.CURDIR}/boot2.ldscript
85 boot: boot1_32 boot2_32
90 _ADDCFLAGS$s:= -DNSECT=${NSECT$s}
93 _ADDCFLAGS$s+= -DDISKLABEL64
94 _ADDCFLAGS$s+= -DHAMMER2FS -DUFS
95 _ADDOBJS$s+= hammer2$s.o ufsread$s.o icrc32$s.o
97 _ADDCFLAGS$s+= -DUFS -DUFS1_ONLY
98 _ADDOBJS$s+= ufsread$s.o
104 objcopy -S -O binary boot1$s.out ${.TARGET}
106 boot1$s.out: boot1$s.o bootasmdef.nx
107 ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} ${.ALLSRC:M*.o}
110 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -DFLAGS=${B1FLAGS} \
111 ${.ALLSRC} -o ${.TARGET} -c
113 #${.CURDIR}/../../common/ufsread.c ${.CURDIR}/../../../../lib/libstand/hammer2.c
115 boot2$s.s: boot2.c boot2$s.h ufsread.c hammer2.c icrc32.c
116 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -S -o boot2$s.s.tmp ${.CURDIR}/boot2.c
117 sed -e '/align/d' -e '/nop/d' < ${.TARGET}.tmp > ${.TARGET}
121 ${AS} ${AFLAGS} -o ${.TARGET} boot2$s.s
123 boot2$s.h: boot1$s.out bootasmdef.nx
124 @echo "NOTE: boot2 using xread from boot1 at ${REL1}"
125 ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
127 printf("#define XREADORG %#x\n", REL1 + x) }' \
128 ORG1=${ORG1D} REL1=${REL1D} > boot2$s.h
130 boot2$s: boot2$s.ldr boot2$s.bin ${BTX}/btx/btx
131 btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2$s.ldr \
132 -o boot2$s.ld -P 1 boot2$s.bin
133 stat boot2$s.ld | awk '{ x = (${NSECT$s} - 1) * 512 - $$8; \
134 print x " bytes available"; if (x < 0) exit 1 }'
135 dd if=boot2$s.ld of=${.TARGET} obs=$$(( (${NSECT$s} - 1) * 512)) conv=osync 2>/dev/null
138 dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
140 boot2$s.bin: boot2$s.out
141 objcopy -S -O binary boot2$s.out ${.TARGET}
143 boot2$s.out: boot2$s.o sio.o ${_ADDOBJS$s}
144 ${LD} ${LDFLAGS} -Ttext ${ORG2} ${LINKSCRIPT} -o ${.TARGET} \
145 ${BTX}/lib/crt0.o ${.ALLSRC}
147 CLEANFILES+= boot1$s boot1$s.out boot1$s.o \
148 boot2$s boot2$s.ldr boot2$s.bin \
149 boot2$s.ld boot2$s.out boot2$s.o boot2$s.h boot2$s.s \
152 hammer2$s.o: hammer2.c
153 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} ${.ALLSRC} -o ${.TARGET} -c
155 ufsread$s.o: ufsread.c
156 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} ${.ALLSRC} -o ${.TARGET} -c
159 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} ${.ALLSRC} -o ${.TARGET} -c
164 ${CC} ${CFLAGS} -DSIOPRT=${BOOT_COMCONSOLE_PORT} -DSIOFMT=${B2SIOFMT} \
165 -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
166 ${.ALLSRC} -o ${.TARGET} -c
169 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
170 boot ${DESTDIR}${BINDIR}/boot
171 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
172 boot1_32 ${DESTDIR}${BINDIR}/boot1
173 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
174 boot2_32 ${DESTDIR}${BINDIR}/boot2
175 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
176 boot1_64 ${DESTDIR}${BINDIR}/boot1_64
177 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
178 boot2_64 ${DESTDIR}${BINDIR}/boot2_64
180 .include <bsd.prog.mk>
182 .if defined(REALLY_X86_64)
183 # For x86_64, we need to fake up a complete machine/ tree
184 # so that types for -m32 appear correctly.
188 beforedepend ${OBJS}: machine cpu
192 ${LN} -sf ${.CURDIR}/../../../cpu/i386/include/* machine
193 ${LN} -sf ${.CURDIR}/../../../platform/pc32/include/* machine
196 ${LN} -hsf ${.CURDIR}/../../../cpu/i386/include cpu
198 CLEANDIRS+= machine cpu
201 CLEANFILES+= bootasmdef.nx