Merge from vendor branch NTPD:
[dragonfly.git] / sys / boot / pc32 / boot2 / Makefile
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.12 2004/09/12 18:37:15 dillon Exp $
3
4 PROG=           boot2
5 NOMAN=
6 STRIP=
7 BINDIR?=        /boot
8 BINMODE=        444
9 CLEANFILES=     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
13 NM?=            nm
14 NXCFLAGS=
15 NXLDFLAGS=
16
17 .PATH: ${.CURDIR}/..
18
19 # A value of 0x80 enables LBA support.
20 B1FLAGS=        0x80
21
22 BOOT_COMCONSOLE_PORT?= 0x3f8
23 BOOT_COMCONSOLE_SPEED?= 9600
24 B2SIOFMT?=      0x3
25
26 .if exists(${.OBJDIR}/../btx)
27 BTX=    ${.OBJDIR}/../btx
28 .else
29 BTX=    ${.CURDIR}/../btx
30 .endif
31
32 # These origins are taken from bootasm.h.
33 #
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`
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 #
43 ORG2=   `${.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
49 BOOT2_UFS?=     UFS1_ONLY
50
51 # gcc3.x
52 #       -fno-guess-branch-probability
53 #       -mno-align-long-strings
54 CFLAGS= -elf -ffreestanding -Os -fno-builtin -fno-stack-protector \
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
63 # -mrtd will produce bad code (missing stack pops) when combined with
64 # gcc-3.4's (default on) unit-at-a-time optimization.  See the code
65 # generated for 'xputc' as an example.
66 #
67 # __USING_MRTD__ is used to conditionalize any assembly modules
68 # (aka sio_putc())
69 #
70 .if ${CCVER} == "gcc2"
71 CFLAGS+= -mrtd
72 MRTDFLAGS=-D__USING_MRTD__
73 .else
74 MRTDFLAGS=
75 .endif
76
77 # Unfortunately, unit-at-a-time creates other issues as well, as yet
78 # not tracked down, in boot2, so we have to turn it off.  Note that
79 # the problem has been narrowed down to the 'boot2' code.  The /boot/loader
80 # doesn't seem to have a problem.
81 #
82 .if ${CCVER} != "gcc2"
83 CFLAGS+= -fno-unit-at-a-time
84 .endif
85
86 LDFLAGS=-nostdlib -static -N --gc-sections
87
88 all: boot1 boot2 boot
89
90 boot: boot1 boot2
91         cat boot1 boot2 > boot
92
93 boot1: boot1.out
94         objcopy -S -O binary boot1.out ${.TARGET}
95
96 boot1.out: boot1.o bootasmdef.nx
97         ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
98
99 boot1.o: boot1.S
100         ${CC} ${CFLAGS} -DFLAGS=${B1FLAGS} ${AFLAGS} \
101                 ${.IMPSRC} -o ${.TARGET} -c
102
103 boot2.o: boot2.c ${.CURDIR}/../../common/ufsread.c
104         ${CC} ${CFLAGS} -S -o boot2.s.tmp ${.IMPSRC}
105         sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
106         rm -f boot2.s.tmp
107         ${AS} ${AFLAGS} -o boot2.o boot2.s
108
109 boot2.h: boot1.out bootasmdef.nx
110         @echo "NOTE: boot2 using xread from boot1 at ${REL1}"
111         ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
112                 { x = $$1 - ORG1; \
113                 printf("#define XREADORG %#x\n", REL1 + x) }' \
114                 ORG1=${ORG1D} REL1=${REL1D} > boot2.h
115
116 boot2: boot2.ldr boot2.bin ${BTX}/btx/btx
117         btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2.ldr \
118                 -o boot2.ld -P 1 boot2.bin
119         @ls -l boot2.ld | awk '{ x = 7680 - $$5; \
120                 print x " bytes available"; if (x < 0) exit 1 }'
121         dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync 2>/dev/null
122
123 boot2.ldr:
124         dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
125
126 boot2.bin: boot2.out
127         objcopy -S -O binary boot2.out ${.TARGET}
128
129 boot2.out: boot2.o sio.o
130         ${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
131                 ${BTX}/lib/crt0.o ${.ALLSRC}
132
133 boot2.o: boot2.h
134
135 sio.o: sio.S
136         ${CC} -DSIOPRT=${BOOT_COMCONSOLE_PORT} -DSIOFMT=${B2SIOFMT} \
137                 -DSIOSPD=${BOOT_COMCONSOLE_SPEED} ${MRTDFLAGS} \
138                 ${AFLAGS} ${.IMPSRC} -o ${.TARGET} -c
139
140 install:
141         ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
142                 boot ${DESTDIR}${BINDIR}/boot
143         ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
144                 boot1 ${DESTDIR}${BINDIR}/boot1
145         ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
146                 boot2 ${DESTDIR}${BINDIR}/boot2
147
148 .include <bsd.prog.mk>
149
150 .if defined(REALLY_AMD64)
151 boot2.o: machine
152
153 beforedepend ${OBJS}: machine
154
155 machine:
156         ln -sf ${.CURDIR}/../../../i386/include machine
157
158 CLEANFILES+=    machine
159 .endif
160
161 CLEANFILES+=    bootasmdef.nx
162