1 # $FreeBSD: src/sys/boot/i386/boot2/Makefile,v 1.47 2003/06/26 03:51:57 peter Exp $
2 # $DragonFly: src/sys/boot/pc32/boot2/Makefile,v 1.18 2008/09/13 11:45:45 corecode Exp $
15 # A value of 0x80 enables LBA support.
18 BOOT_COMCONSOLE_PORT?= 0x3f8
19 BOOT_COMCONSOLE_SPEED?= 9600
22 .if exists(${.OBJDIR}/../btx)
23 BTX= ${.OBJDIR}/../btx
25 BTX= ${.CURDIR}/../btx
28 # These origins are taken from bootasm.h.
30 REL1 = `${.OBJDIR}/bootasmdef.nx BOOT1_ORIGIN`
31 REL1D = `${.OBJDIR}/bootasmdef.nx -d BOOT1_ORIGIN`
32 ORG1 = `${.OBJDIR}/bootasmdef.nx MEM_BIOS_LADDR`
33 ORG1D = `${.OBJDIR}/bootasmdef.nx -d MEM_BIOS_LADDR`
35 # WARNING! The ORG2 calculation is the origin of boot2.bin relative to
36 # the start of the BTX *USER* address space, not the start of physical
39 ORG2= `${.OBJDIR}/bootasmdef.nx BOOT2_VORIGIN`
42 # -fno-guess-branch-probability
43 # -mno-align-long-strings
44 CFLAGS= -elf -ffreestanding -Os -fno-builtin \
45 -fomit-frame-pointer \
48 -I${.CURDIR}/../../common \
49 -I${.CURDIR}/../../../../lib/libstand \
50 -I${.CURDIR}/../btx/lib -I. \
51 -Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
52 -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
53 -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings \
56 # Tell gcc that it shouldn't do fancy optimizations for newer processors.
57 # Otherwise it winds up creating larger code and we won't be able to fit boot2.
60 # Unfortunately, unit-at-a-time creates issues as yet
61 # not tracked down, in boot2, so we have to turn it off. Note that
62 # the problem has been narrowed down to the 'boot2' code. The /boot/loader
63 # doesn't seem to have a problem.
65 CFLAGS+= -fno-unit-at-a-time
67 # Disable propolice on gcc that supports it
68 .if ${CCVER} == "gcc34"
69 CFLAGS+= -fno-stack-protector
74 LDFLAGS=-nostdlib -static -N --gc-sections
78 boot: boot1_32 boot2_32
83 _ADDCFLAGS$s:= -DNSECT=${NSECT$s}
86 _ADDCFLAGS$s+= -DDISKLABEL64
87 _ADDCFLAGS$s+= -DHAMMERFS
89 _ADDCFLAGS$s+= -DUFS1_ONLY
95 objcopy -S -O binary boot1$s.out ${.TARGET}
97 boot1$s.out: boot1$s.o bootasmdef.nx
98 ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} ${.ALLSRC:M*.o}
101 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -DFLAGS=${B1FLAGS} \
102 ${.ALLSRC} -o ${.TARGET} -c
104 boot2$s.o: boot2.c ${.CURDIR}/../../common/ufsread.c ${.CURDIR}/../../../../lib/libstand/hammerread.c
105 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -S -o boot2$s.s.tmp ${.CURDIR}/boot2.c
106 sed -e '/align/d' -e '/nop/d' < boot2$s.s.tmp > boot2$s.s
108 ${AS} ${AFLAGS} -o boot2$s.o boot2$s.s
110 boot2$s.h: boot1$s.out bootasmdef.nx
111 @echo "NOTE: boot2 using xread from boot1 at ${REL1}"
112 ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
114 printf("#define XREADORG %#x\n", REL1 + x) }' \
115 ORG1=${ORG1D} REL1=${REL1D} > boot2$s.h
117 boot2$s: boot2$s.ldr boot2$s.bin ${BTX}/btx/btx
118 btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2$s.ldr \
119 -o boot2$s.ld -P 1 boot2$s.bin
120 stat boot2$s.ld | awk '{ x = (${NSECT$s} - 1) * 512 - $$8; \
121 print x " bytes available"; if (x < 0) exit 1 }'
122 dd if=boot2$s.ld of=${.TARGET} obs=$$(( (${NSECT$s} - 1) * 512)) conv=osync 2>/dev/null
125 dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
127 boot2$s.bin: boot2$s.out
128 objcopy -S -O binary boot2$s.out ${.TARGET}
130 boot2$s.out: boot2$s.o sio.o
131 ${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
132 ${BTX}/lib/crt0.o ${.ALLSRC}
136 CLEANFILES+= boot1$s boot1$s.out boot1$s.o \
137 boot2$s boot2$s.ldr boot2$s.bin boot2$s.ld boot2$s.out boot2$s.o boot2$s.h boot2$s.s
142 ${CC} ${CFLAGS} -DSIOPRT=${BOOT_COMCONSOLE_PORT} -DSIOFMT=${B2SIOFMT} \
143 -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
144 ${.ALLSRC} -o ${.TARGET} -c
147 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
148 boot ${DESTDIR}${BINDIR}/boot
149 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
150 boot1_32 ${DESTDIR}${BINDIR}/boot1
151 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
152 boot2_32 ${DESTDIR}${BINDIR}/boot2
153 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
154 boot1_64 ${DESTDIR}${BINDIR}/boot1_64
155 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
156 boot2_64 ${DESTDIR}${BINDIR}/boot2_64
158 .include <bsd.prog.mk>
160 .if defined(REALLY_AMD64)
161 # For amd64, we need to fake up a complete machine/ tree
162 # so that types for -m32 appear correctly.
166 beforedepend ${OBJS}: machine cpu
170 ${LN} -sf ${.CURDIR}/../../../cpu/i386/include/* machine
171 ${LN} -sf ${.CURDIR}/../../../platform/pc32/include/* machine
174 ${LN} -sf ${.CURDIR}/../../../cpu/i386/include cpu
176 CLEANDIRS+= machine cpu
179 CLEANFILES+= bootasmdef.nx