Add usr.bin/stat to bootstrap-tools:
[dragonfly.git] / sys / boot / i386 / boot2 / Makefile
... / ...
CommitLineData
1# $FreeBSD: src/sys/boot/i386/boot2/Makefile,v 1.47 2003/06/26 03:51:57 peter Exp $
2# $DragonFly: src/sys/boot/i386/boot2/Attic/Makefile,v 1.16 2005/09/25 12:43:58 asmodai Exp $
3
4PROG= boot2
5NOMAN=
6STRIP=
7BINDIR?= /boot
8BINMODE= 444
9CLEANFILES= boot boot1 boot1.out boot1.o \
10 boot2.ldr boot2.bin boot2.ld boot2.out boot2.o boot2.h \
11 boot2.s sio.o
12
13NM?= nm
14NXCFLAGS=
15NXLDFLAGS=
16
17.PATH: ${.CURDIR}/..
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
32# These origins are taken from bootasm.h.
33#
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`
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#
43ORG2= `${.OBJDIR}/bootasmdef.nx BOOT2_VORIGIN`
44
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
54CFLAGS= -elf -ffreestanding -Os -fno-builtin \
55 -fomit-frame-pointer \
56 -D${BOOT2_UFS} \
57 -I${.CURDIR}/../../common \
58 -I${.CURDIR}/../btx/lib -I. \
59 -Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
60 -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
61 -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings \
62 -D__BOOT2_HACK
63
64# -mrtd will produce bad code (missing stack pops) when combined with
65# gcc-3.4's (default on) unit-at-a-time optimization. See the code
66# generated for 'xputc' as an example.
67#
68# __USING_MRTD__ is used to conditionalize any assembly modules
69# (aka sio_putc())
70#
71.if ${CCVER} == "gcc2"
72CFLAGS+= -mrtd
73MRTDFLAGS=-D__USING_MRTD__
74.else
75MRTDFLAGS=
76.endif
77
78# Unfortunately, unit-at-a-time creates other issues as well, as yet
79# not tracked down, in boot2, so we have to turn it off. Note that
80# the problem has been narrowed down to the 'boot2' code. The /boot/loader
81# doesn't seem to have a problem.
82#
83.if ${CCVER} != "gcc2"
84CFLAGS+= -fno-unit-at-a-time
85.endif
86
87# Disable propolice on gcc that support it
88.if ${CCVER} == "gcc2" || ${CCVER} == "gcc34"
89CFLAGS+= -fno-stack-protector
90.endif
91
92LDFLAGS=-nostdlib -static -N --gc-sections
93
94all: boot1 boot2 boot
95
96boot: boot1 boot2
97 cat boot1 boot2 > boot
98
99boot1: boot1.out
100 objcopy -S -O binary boot1.out ${.TARGET}
101
102boot1.out: boot1.o bootasmdef.nx
103 ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
104
105boot1.o: boot1.S
106 ${CC} ${CFLAGS} -DFLAGS=${B1FLAGS} ${AFLAGS} \
107 ${.IMPSRC} -o ${.TARGET} -c
108
109boot2.o: boot2.c ${.CURDIR}/../../common/ufsread.c
110 ${CC} ${CFLAGS} -S -o boot2.s.tmp ${.IMPSRC}
111 sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
112 rm -f boot2.s.tmp
113 ${AS} ${AFLAGS} -o boot2.o boot2.s
114
115boot2.h: boot1.out bootasmdef.nx
116 @echo "NOTE: boot2 using xread from boot1 at ${REL1}"
117 ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
118 { x = $$1 - ORG1; \
119 printf("#define XREADORG %#x\n", REL1 + x) }' \
120 ORG1=${ORG1D} REL1=${REL1D} > boot2.h
121
122boot2: boot2.ldr boot2.bin ${BTX}/btx/btx
123 btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2.ldr \
124 -o boot2.ld -P 1 boot2.bin
125 @stat boot2.ld | awk '{ x = 7680 - $$8; \
126 print x " bytes available"; if (x < 0) exit 1 }'
127 dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync 2>/dev/null
128
129boot2.ldr:
130 dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
131
132boot2.bin: boot2.out
133 objcopy -S -O binary boot2.out ${.TARGET}
134
135boot2.out: boot2.o sio.o
136 ${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
137 ${BTX}/lib/crt0.o ${.ALLSRC}
138
139boot2.o: boot2.h
140
141sio.o: sio.S
142 ${CC} -DSIOPRT=${BOOT_COMCONSOLE_PORT} -DSIOFMT=${B2SIOFMT} \
143 -DSIOSPD=${BOOT_COMCONSOLE_SPEED} ${MRTDFLAGS} \
144 ${AFLAGS} ${.IMPSRC} -o ${.TARGET} -c
145
146install:
147 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
148 boot ${DESTDIR}${BINDIR}/boot
149 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
150 boot1 ${DESTDIR}${BINDIR}/boot1
151 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
152 boot2 ${DESTDIR}${BINDIR}/boot2
153
154.include <bsd.prog.mk>
155
156.if defined(REALLY_AMD64)
157boot2.o: machine
158
159beforedepend ${OBJS}: machine
160
161machine:
162 ${LN} -sf ${.CURDIR}/../../../i386/include machine
163
164CLEANFILES+= machine
165.endif
166
167CLEANFILES+= bootasmdef.nx
168