Merge branch 'vendor/OPENSSL'
[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.18 2008/09/13 11:45:45 corecode Exp $
3
4 BINDIR?=        /boot
5 BINMODE=        444
6 CLEANFILES=     boot \
7                 sio.o
8
9 NM?=            nm
10 NXCFLAGS=
11 NXLDFLAGS=
12
13 .PATH: ${.CURDIR}/..
14
15 # A value of 0x80 enables LBA support.
16 B1FLAGS=        0x80
17
18 BOOT_COMCONSOLE_PORT?= 0x3f8
19 BOOT_COMCONSOLE_SPEED?= 9600
20 B2SIOFMT?=      0x3
21
22 .if exists(${.OBJDIR}/../btx)
23 BTX=    ${.OBJDIR}/../btx
24 .else
25 BTX=    ${.CURDIR}/../btx
26 .endif
27
28 # These origins are taken from bootasm.h.
29 #
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`
34
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 
37 # memory.
38 #
39 ORG2=   `${.OBJDIR}/bootasmdef.nx BOOT2_VORIGIN`
40
41 # gcc3.x
42 #       -fno-guess-branch-probability
43 #       -mno-align-long-strings
44 CFLAGS= -elf -ffreestanding -Os -fno-builtin \
45         -fomit-frame-pointer \
46         -std=c99 \
47         -DBOOT2 \
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 \
54         -D__BOOT2_HACK
55
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.
58 CFLAGS+= -march=i386
59
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.
64 #
65 CFLAGS+= -fno-unit-at-a-time
66
67 # Disable propolice on gcc that supports it
68 .if ${CCVER} == "gcc34"
69 CFLAGS+= -fno-stack-protector
70 .endif
71
72 NSECT_32?=      16
73 NSECT_64?=      18
74 LDFLAGS=-nostdlib -static -N --gc-sections
75
76 all: boot
77
78 boot: boot1_32 boot2_32
79         cat ${.ALLSRC} > boot
80
81 .for s in _32 _64
82
83 _ADDCFLAGS$s:= -DNSECT=${NSECT$s}
84 _ts=    $s
85 .if ${_ts} == "_64"
86 _ADDCFLAGS$s+= -DDISKLABEL64
87 _ADDCFLAGS$s+= -DHAMMERFS
88 .else
89 _ADDCFLAGS$s+= -DUFS1_ONLY
90 .endif
91
92 all: boot1$s boot2$s
93
94 boot1$s: boot1$s.out
95         objcopy -S -O binary boot1$s.out ${.TARGET}
96
97 boot1$s.out: boot1$s.o bootasmdef.nx
98         ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} ${.ALLSRC:M*.o}
99
100 boot1$s.o: boot1.S
101         ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -DFLAGS=${B1FLAGS} \
102                 ${.ALLSRC} -o ${.TARGET} -c
103
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
107         rm -f boot2$s.s.tmp
108         ${AS} ${AFLAGS} -o boot2$s.o boot2$s.s
109
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/ \
113                 { x = $$1 - ORG1; \
114                 printf("#define XREADORG %#x\n", REL1 + x) }' \
115                 ORG1=${ORG1D} REL1=${REL1D} > boot2$s.h
116
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
123
124 boot2$s.ldr:
125         dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
126
127 boot2$s.bin: boot2$s.out
128         objcopy -S -O binary boot2$s.out ${.TARGET}
129
130 boot2$s.out: boot2$s.o sio.o
131         ${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
132                 ${BTX}/lib/crt0.o ${.ALLSRC}
133
134 boot2$s.o: boot2$s.h
135
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
138
139 .endfor
140
141 sio.o: sio.S
142         ${CC} ${CFLAGS} -DSIOPRT=${BOOT_COMCONSOLE_PORT} -DSIOFMT=${B2SIOFMT} \
143                 -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
144                 ${.ALLSRC} -o ${.TARGET} -c
145
146 install:
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
157
158 .include <bsd.prog.mk>
159
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.
163
164 boot2.o: machine
165
166 beforedepend ${OBJS}: machine cpu
167
168 machine::
169         mkdir -p machine
170         ${LN} -sf ${.CURDIR}/../../../cpu/i386/include/* machine
171         ${LN} -sf ${.CURDIR}/../../../platform/pc32/include/* machine
172
173 cpu::
174         ${LN} -sf ${.CURDIR}/../../../cpu/i386/include cpu
175
176 CLEANDIRS+=     machine cpu
177 .endif
178
179 CLEANFILES+=    bootasmdef.nx
180