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 $
14 .PATH: ${.CURDIR}/../../common
15 .PATH: ${.CURDIR}/../../../../lib/libstand
17 # A value of 0x80 enables LBA support.
20 BOOT_COMCONSOLE_PORT?= 0x3f8
21 BOOT_COMCONSOLE_SPEED?= 9600
24 .if exists(${.OBJDIR}/../btx)
25 BTX= ${.OBJDIR}/../btx
27 BTX= ${.CURDIR}/../btx
30 # These origins are taken from bootasm.h.
32 REL1 = `${.OBJDIR}/bootasmdef.nx BOOT1_ORIGIN`
33 REL1D = `${.OBJDIR}/bootasmdef.nx -d BOOT1_ORIGIN`
34 ORG1 = `${.OBJDIR}/bootasmdef.nx MEM_BIOS_LADDR`
35 ORG1D = `${.OBJDIR}/bootasmdef.nx -d MEM_BIOS_LADDR`
37 # WARNING! The ORG2 calculation is the origin of boot2.bin relative to
38 # the start of the BTX *USER* address space, not the start of physical
41 ORG2= `${.OBJDIR}/bootasmdef.nx BOOT2_VORIGIN`
44 # -fno-guess-branch-probability
45 # -mno-align-long-strings
46 CFLAGS= -elf -ffreestanding -Os -fno-builtin \
47 -fomit-frame-pointer \
50 -I${.CURDIR}/../../common \
51 -I${.CURDIR}/../../../../lib/libstand \
52 -I${.CURDIR}/../btx/lib -I. \
53 -Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
54 -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
55 -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings
57 # Tell gcc that it shouldn't do fancy optimizations for newer processors.
58 # Otherwise it winds up creating larger code and we won't be able to fit boot2.
61 # Unfortunately, unit-at-a-time creates issues as yet
62 # not tracked down, in boot2, so we have to turn it off. Note that
63 # the problem has been narrowed down to the 'boot2' code. The /boot/loader
64 # doesn't seem to have a problem.
66 CFLAGS+= -fno-unit-at-a-time
68 # Disable propolice on gcc that supports it
69 .if ${CCVER} == "gcc34"
70 CFLAGS+= -fno-stack-protector
73 # boot2 area in 32 bit disklabel is 16 sectors (8K)
75 # boot2 area in 64 bit disklabel is 64 sectors (32K).
76 # However, the boot1 btx loader puts boot2 at a physical address
77 # of MEM_BTX_USR+BOOT2_VORIGIN which is typically 0xC000, so we
78 # cannot make boot2 any larger then 16KB or we overflow the segment.
82 LDFLAGS=-nostdlib -static -N --gc-sections
86 boot: boot1_32 boot2_32
91 _ADDCFLAGS$s:= -DNSECT=${NSECT$s}
94 _ADDCFLAGS$s+= -DDISKLABEL64
95 _ADDCFLAGS$s+= -DHAMMERFS -DUFS
96 _ADDOBJS$s+= hammerread$s.o ufsread$s.o
98 _ADDCFLAGS$s+= -DUFS -DUFS1_ONLY
99 _ADDOBJS$s+= ufsread$s.o
105 objcopy -S -O binary boot1$s.out ${.TARGET}
107 boot1$s.out: boot1$s.o bootasmdef.nx
108 ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} ${.ALLSRC:M*.o}
111 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -DFLAGS=${B1FLAGS} \
112 ${.ALLSRC} -o ${.TARGET} -c
114 boot2$s.o: boot2.c ${.CURDIR}/../../common/ufsread.c ${.CURDIR}/../../../../lib/libstand/hammerread.c
115 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -S -o boot2$s.s.tmp ${.CURDIR}/boot2.c
116 sed -e '/align/d' -e '/nop/d' < boot2$s.s.tmp > boot2$s.s
118 ${AS} ${AFLAGS} -o boot2$s.o boot2$s.s
120 boot2$s.h: boot1$s.out bootasmdef.nx
121 @echo "NOTE: boot2 using xread from boot1 at ${REL1}"
122 ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
124 printf("#define XREADORG %#x\n", REL1 + x) }' \
125 ORG1=${ORG1D} REL1=${REL1D} > boot2$s.h
127 boot2$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; \
131 print x " bytes available"; if (x < 0) exit 1 }'
132 dd if=boot2$s.ld of=${.TARGET} obs=$$(( (${NSECT$s} - 1) * 512)) conv=osync 2>/dev/null
135 dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
137 boot2$s.bin: boot2$s.out
138 objcopy -S -O binary boot2$s.out ${.TARGET}
140 boot2$s.out: boot2$s.o sio.o ${_ADDOBJS$s}
141 ${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
142 ${BTX}/lib/crt0.o ${.ALLSRC}
146 CLEANFILES+= boot1$s boot1$s.out boot1$s.o \
147 boot2$s boot2$s.ldr boot2$s.bin \
148 boot2$s.ld boot2$s.out boot2$s.o boot2$s.h boot2$s.s \
151 hammerread$s.o: hammerread.c
152 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} ${.ALLSRC} -o ${.TARGET} -c
154 ufsread$s.o: ufsread.c
155 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} ${.ALLSRC} -o ${.TARGET} -c
160 ${CC} ${CFLAGS} -DSIOPRT=${BOOT_COMCONSOLE_PORT} -DSIOFMT=${B2SIOFMT} \
161 -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
162 ${.ALLSRC} -o ${.TARGET} -c
165 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
166 boot ${DESTDIR}${BINDIR}/boot
167 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
168 boot1_32 ${DESTDIR}${BINDIR}/boot1
169 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
170 boot2_32 ${DESTDIR}${BINDIR}/boot2
171 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
172 boot1_64 ${DESTDIR}${BINDIR}/boot1_64
173 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
174 boot2_64 ${DESTDIR}${BINDIR}/boot2_64
176 .include <bsd.prog.mk>
178 .if defined(REALLY_AMD64)
179 # For amd64, we need to fake up a complete machine/ tree
180 # so that types for -m32 appear correctly.
184 beforedepend ${OBJS}: machine cpu
188 ${LN} -sf ${.CURDIR}/../../../cpu/i386/include/* machine
189 ${LN} -sf ${.CURDIR}/../../../platform/pc32/include/* machine
192 ${LN} -hsf ${.CURDIR}/../../../cpu/i386/include cpu
194 CLEANDIRS+= machine cpu
197 CLEANFILES+= bootasmdef.nx