Merge branch 'vendor/NCURSES'
[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
3 BINDIR?=        /boot
4 BINMODE=        444
5 CLEANFILES=     boot \
6                 sio.o
7
8 CSTD?=          c99
9
10 NM?=            nm
11 NXCFLAGS=
12 NXLDFLAGS=
13
14 .PATH: ${.CURDIR}/..
15 .PATH: ${.CURDIR}/../../common
16 .PATH: ${.CURDIR}/../../../../lib/libstand
17
18 # A value of 0x80 enables LBA support.
19 B1FLAGS=        0x80
20
21 BOOT_COMCONSOLE_PORT?= 0x3f8
22 BOOT_COMCONSOLE_SPEED?= 9600
23 B2SIOFMT?=      0x3
24
25 .if exists(${.OBJDIR}/../btx)
26 BTX=    ${.OBJDIR}/../btx
27 .else
28 BTX=    ${.CURDIR}/../btx
29 .endif
30
31 # These origins are taken from bootasm.h.
32 #
33 REL1 = `${.OBJDIR}/bootasmdef.nx BOOT1_ORIGIN`
34 REL1D = `${.OBJDIR}/bootasmdef.nx -d BOOT1_ORIGIN`
35 ORG1 = `${.OBJDIR}/bootasmdef.nx MEM_BIOS_LADDR`
36 ORG1D = `${.OBJDIR}/bootasmdef.nx -d MEM_BIOS_LADDR`
37
38 # WARNING!  The ORG2 calculation is the origin of boot2.bin relative to 
39 # the start of the BTX *USER* address space, not the start of physical 
40 # memory.
41 #
42 ORG2=   `${.OBJDIR}/bootasmdef.nx BOOT2_VORIGIN`
43
44 CFLAGS= -Os \
45         -fno-guess-branch-probability \
46         -fomit-frame-pointer \
47         -fno-unwind-tables \
48         -fno-asynchronous-unwind-tables \
49         -DBOOT2 \
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
56
57 DEBUG_FLAGS=
58
59 # Tell gcc that it shouldn't do fancy optimizations for newer processors.
60 # Otherwise it winds up creating larger code and we won't be able to fit boot2.
61 CFLAGS+= -march=i386
62
63 # Unfortunately, unit-at-a-time creates issues as yet
64 # not tracked down, in boot2, so we have to turn it off.  Note that
65 # the problem has been narrowed down to the 'boot2' code.  The /boot/loader
66 # doesn't seem to have a problem.
67 #
68 CFLAGS+= -fno-unit-at-a-time
69
70 # boot2 area in 32 bit disklabel is 16 sectors (8K)
71 #
72 # boot2 area in 64 bit disklabel is 64 sectors (32K).
73 # However, the boot1 btx loader puts boot2 at a physical address
74 # of MEM_BTX_USR+BOOT2_VORIGIN which is typically 0xC000, so we
75 # cannot make boot2 any larger then 16KB or we overflow the segment.
76 #
77 NSECT_32?=      16
78 NSECT_64?=      30
79 LDFLAGS=        -nostdlib -static -N --gc-sections
80 LINKSCRIPT=     --script ${.CURDIR}/boot2.ldscript
81
82 all: boot
83
84 boot: boot1_32 boot2_32
85         cat ${.ALLSRC} > boot
86
87 .for s in _32 _64
88
89 _ADDCFLAGS$s:= -DNSECT=${NSECT$s}
90 _ts=    $s
91 .if ${_ts} == "_64"
92 _ADDCFLAGS$s+= -DDISKLABEL64
93 _ADDCFLAGS$s+= -DHAMMERFS -DUFS
94 _ADDOBJS$s+= hammerread$s.o ufsread$s.o
95 .else
96 _ADDCFLAGS$s+= -DUFS -DUFS1_ONLY
97 _ADDOBJS$s+= ufsread$s.o
98 .endif
99
100 all: boot1$s boot2$s
101
102 boot1$s: boot1$s.out
103         objcopy -S -O binary boot1$s.out ${.TARGET}
104
105 boot1$s.out: boot1$s.o bootasmdef.nx
106         ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} ${.ALLSRC:M*.o}
107
108 boot1$s.o: boot1.S
109         ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -DFLAGS=${B1FLAGS} \
110                 ${.ALLSRC} -o ${.TARGET} -c
111
112 boot2$s.o: boot2.c ${.CURDIR}/../../common/ufsread.c ${.CURDIR}/../../../../lib/libstand/hammerread.c
113         ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -S -o boot2$s.s.tmp ${.CURDIR}/boot2.c
114         sed -e '/align/d' -e '/nop/d' < boot2$s.s.tmp > boot2$s.s
115         rm -f boot2$s.s.tmp
116         ${AS} ${AFLAGS} -o boot2$s.o boot2$s.s
117
118 boot2$s.h: boot1$s.out bootasmdef.nx
119         @echo "NOTE: boot2 using xread from boot1 at ${REL1}"
120         ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
121                 { x = $$1 - ORG1; \
122                 printf("#define XREADORG %#x\n", REL1 + x) }' \
123                 ORG1=${ORG1D} REL1=${REL1D} > boot2$s.h
124
125 boot2$s: boot2$s.ldr boot2$s.bin ${BTX}/btx/btx
126         btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2$s.ldr \
127                 -o boot2$s.ld -P 1 boot2$s.bin
128         stat boot2$s.ld | awk '{ x = (${NSECT$s} - 1) * 512 - $$8; \
129                 print x " bytes available"; if (x < 0) exit 1 }'
130         dd if=boot2$s.ld of=${.TARGET} obs=$$(( (${NSECT$s} - 1) * 512)) conv=osync 2>/dev/null
131
132 boot2$s.ldr:
133         dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
134
135 boot2$s.bin: boot2$s.out
136         objcopy -S -O binary boot2$s.out ${.TARGET}
137
138 boot2$s.out: boot2$s.o sio.o ${_ADDOBJS$s}
139         ${LD} ${LDFLAGS} -Ttext ${ORG2} ${LINKSCRIPT} -o ${.TARGET} \
140                 ${BTX}/lib/crt0.o ${.ALLSRC}
141
142 boot2$s.o: boot2$s.h
143
144 CLEANFILES+=    boot1$s boot1$s.out boot1$s.o \
145                 boot2$s boot2$s.ldr boot2$s.bin \
146                 boot2$s.ld boot2$s.out boot2$s.o boot2$s.h boot2$s.s \
147                 ${_ADDOBJS$s}
148
149 hammerread$s.o: hammerread.c
150         ${CC} ${CFLAGS} ${_ADDCFLAGS$s} ${.ALLSRC} -o ${.TARGET} -c
151
152 ufsread$s.o: ufsread.c
153         ${CC} ${CFLAGS} ${_ADDCFLAGS$s} ${.ALLSRC} -o ${.TARGET} -c
154
155 .endfor
156
157 sio.o: sio.S
158         ${CC} ${CFLAGS} -DSIOPRT=${BOOT_COMCONSOLE_PORT} -DSIOFMT=${B2SIOFMT} \
159                 -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
160                 ${.ALLSRC} -o ${.TARGET} -c
161
162 install:
163         ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
164                 boot ${DESTDIR}${BINDIR}/boot
165         ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
166                 boot1_32 ${DESTDIR}${BINDIR}/boot1
167         ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
168                 boot2_32 ${DESTDIR}${BINDIR}/boot2
169         ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
170                 boot1_64 ${DESTDIR}${BINDIR}/boot1_64
171         ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
172                 boot2_64 ${DESTDIR}${BINDIR}/boot2_64
173
174 .include <bsd.prog.mk>
175
176 .if defined(REALLY_X86_64)
177 # For x86_64, we need to fake up a complete machine/ tree
178 # so that types for -m32 appear correctly.
179
180 boot2.o: machine
181
182 beforedepend ${OBJS}: machine cpu
183
184 machine::
185         mkdir -p machine
186         ${LN} -sf ${.CURDIR}/../../../cpu/i386/include/* machine
187         ${LN} -sf ${.CURDIR}/../../../platform/pc32/include/* machine
188
189 cpu::
190         ${LN} -hsf ${.CURDIR}/../../../cpu/i386/include cpu
191
192 CLEANDIRS+=     machine cpu
193 .endif
194
195 CLEANFILES+=    bootasmdef.nx
196