disklabel64 UFS+HAMMER boot support (was previously just HAMMER boot support)
[dragonfly.git] / sys / boot / pc32 / boot2 / Makefile
CommitLineData
5ee58eed 1# $FreeBSD: src/sys/boot/i386/boot2/Makefile,v 1.47 2003/06/26 03:51:57 peter Exp $
7580e818 2# $DragonFly: src/sys/boot/pc32/boot2/Makefile,v 1.18 2008/09/13 11:45:45 corecode Exp $
984263bc 3
984263bc
MD
4BINDIR?= /boot
5BINMODE= 444
6080181b
SS
6CLEANFILES= boot \
7 sio.o
984263bc
MD
8
9NM?= nm
cacaceec
MD
10NXCFLAGS=
11NXLDFLAGS=
12
13.PATH: ${.CURDIR}/..
d64b2e33
MD
14.PATH: ${.CURDIR}/../../common
15.PATH: ${.CURDIR}/../../../../lib/libstand
984263bc
MD
16
17# A value of 0x80 enables LBA support.
18B1FLAGS= 0x80
19
20BOOT_COMCONSOLE_PORT?= 0x3f8
21BOOT_COMCONSOLE_SPEED?= 9600
22B2SIOFMT?= 0x3
23
24.if exists(${.OBJDIR}/../btx)
25BTX= ${.OBJDIR}/../btx
26.else
27BTX= ${.CURDIR}/../btx
28.endif
29
cacaceec 30# These origins are taken from bootasm.h.
04144d62 31#
cacaceec
MD
32REL1 = `${.OBJDIR}/bootasmdef.nx BOOT1_ORIGIN`
33REL1D = `${.OBJDIR}/bootasmdef.nx -d BOOT1_ORIGIN`
34ORG1 = `${.OBJDIR}/bootasmdef.nx MEM_BIOS_LADDR`
35ORG1D = `${.OBJDIR}/bootasmdef.nx -d MEM_BIOS_LADDR`
04144d62
MD
36
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
39# memory.
40#
4e06dda7 41ORG2= `${.OBJDIR}/bootasmdef.nx BOOT2_VORIGIN`
984263bc 42
5ee58eed
MD
43# gcc3.x
44# -fno-guess-branch-probability
45# -mno-align-long-strings
0e24d183 46CFLAGS= -elf -ffreestanding -Os -fno-builtin \
5ee58eed 47 -fomit-frame-pointer \
7580e818
SS
48 -std=c99 \
49 -DBOOT2 \
5ee58eed 50 -I${.CURDIR}/../../common \
7580e818 51 -I${.CURDIR}/../../../../lib/libstand \
5ee58eed 52 -I${.CURDIR}/../btx/lib -I. \
984263bc
MD
53 -Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
54 -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
d64b2e33 55 -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings
984263bc 56
63a12d94
SS
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.
59CFLAGS+= -march=i386
60
d90d8005 61# Unfortunately, unit-at-a-time creates issues as yet
3d310902
MD
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.
65#
3d310902 66CFLAGS+= -fno-unit-at-a-time
3d310902 67
d90d8005
SW
68# Disable propolice on gcc that supports it
69.if ${CCVER} == "gcc34"
0e24d183
SS
70CFLAGS+= -fno-stack-protector
71.endif
72
d64b2e33
MD
73# boot2 area in 32 bit disklabel is 16 sectors (8K)
74#
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.
79#
6080181b 80NSECT_32?= 16
d64b2e33 81NSECT_64?= 30
5ee58eed 82LDFLAGS=-nostdlib -static -N --gc-sections
984263bc 83
6080181b
SS
84all: boot
85
86boot: boot1_32 boot2_32
87 cat ${.ALLSRC} > boot
88
89.for s in _32 _64
90
91_ADDCFLAGS$s:= -DNSECT=${NSECT$s}
92_ts= $s
93.if ${_ts} == "_64"
94_ADDCFLAGS$s+= -DDISKLABEL64
d64b2e33
MD
95_ADDCFLAGS$s+= -DHAMMERFS -DUFS
96_ADDOBJS$s+= hammerread$s.o ufsread$s.o
6080181b 97.else
d64b2e33
MD
98_ADDCFLAGS$s+= -DUFS -DUFS1_ONLY
99_ADDOBJS$s+= ufsread$s.o
6080181b 100.endif
5ee58eed 101
6080181b 102all: boot1$s boot2$s
984263bc 103
6080181b
SS
104boot1$s: boot1$s.out
105 objcopy -S -O binary boot1$s.out ${.TARGET}
984263bc 106
6080181b
SS
107boot1$s.out: boot1$s.o bootasmdef.nx
108 ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} ${.ALLSRC:M*.o}
984263bc 109
6080181b
SS
110boot1$s.o: boot1.S
111 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -DFLAGS=${B1FLAGS} \
112 ${.ALLSRC} -o ${.TARGET} -c
5ee58eed 113
6080181b 114boot2$s.o: boot2.c ${.CURDIR}/../../common/ufsread.c ${.CURDIR}/../../../../lib/libstand/hammerread.c
ec1618fb 115 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -S -o boot2$s.s.tmp ${.CURDIR}/boot2.c
6080181b
SS
116 sed -e '/align/d' -e '/nop/d' < boot2$s.s.tmp > boot2$s.s
117 rm -f boot2$s.s.tmp
118 ${AS} ${AFLAGS} -o boot2$s.o boot2$s.s
984263bc 119
6080181b 120boot2$s.h: boot1$s.out bootasmdef.nx
cacaceec 121 @echo "NOTE: boot2 using xread from boot1 at ${REL1}"
984263bc 122 ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
5ee58eed
MD
123 { x = $$1 - ORG1; \
124 printf("#define XREADORG %#x\n", REL1 + x) }' \
6080181b 125 ORG1=${ORG1D} REL1=${REL1D} > boot2$s.h
984263bc 126
6080181b
SS
127boot2$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; \
984263bc 131 print x " bytes available"; if (x < 0) exit 1 }'
6080181b 132 dd if=boot2$s.ld of=${.TARGET} obs=$$(( (${NSECT$s} - 1) * 512)) conv=osync 2>/dev/null
984263bc 133
6080181b 134boot2$s.ldr:
2d7f6790 135 dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
984263bc 136
6080181b
SS
137boot2$s.bin: boot2$s.out
138 objcopy -S -O binary boot2$s.out ${.TARGET}
984263bc 139
d64b2e33 140boot2$s.out: boot2$s.o sio.o ${_ADDOBJS$s}
984263bc 141 ${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
5ee58eed 142 ${BTX}/lib/crt0.o ${.ALLSRC}
984263bc 143
6080181b
SS
144boot2$s.o: boot2$s.h
145
146CLEANFILES+= boot1$s boot1$s.out boot1$s.o \
d64b2e33
MD
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 \
149 ${_ADDOBJS$s}
150
151hammerread$s.o: hammerread.c
152 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} ${.ALLSRC} -o ${.TARGET} -c
153
154ufsread$s.o: ufsread.c
155 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} ${.ALLSRC} -o ${.TARGET} -c
6080181b
SS
156
157.endfor
984263bc 158
409cbc03 159sio.o: sio.S
72f919a1 160 ${CC} ${CFLAGS} -DSIOPRT=${BOOT_COMCONSOLE_PORT} -DSIOFMT=${B2SIOFMT} \
aec2661d 161 -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
6080181b 162 ${.ALLSRC} -o ${.TARGET} -c
984263bc
MD
163
164install:
165 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
5ee58eed
MD
166 boot ${DESTDIR}${BINDIR}/boot
167 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
6080181b
SS
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
984263bc 173 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
6080181b 174 boot2_64 ${DESTDIR}${BINDIR}/boot2_64
984263bc
MD
175
176.include <bsd.prog.mk>
5ee58eed
MD
177
178.if defined(REALLY_AMD64)
3d801ff7
SS
179# For amd64, we need to fake up a complete machine/ tree
180# so that types for -m32 appear correctly.
181
5ee58eed
MD
182boot2.o: machine
183
3d801ff7
SS
184beforedepend ${OBJS}: machine cpu
185
186machine::
187 mkdir -p machine
188 ${LN} -sf ${.CURDIR}/../../../cpu/i386/include/* machine
189 ${LN} -sf ${.CURDIR}/../../../platform/pc32/include/* machine
5ee58eed 190
3d801ff7
SS
191cpu::
192 ${LN} -sf ${.CURDIR}/../../../cpu/i386/include cpu
5ee58eed 193
3d801ff7 194CLEANDIRS+= machine cpu
5ee58eed
MD
195.endif
196
cacaceec
MD
197CLEANFILES+= bootasmdef.nx
198