Add more bits for native 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}/..
984263bc
MD
14
15# A value of 0x80 enables LBA support.
16B1FLAGS= 0x80
17
18BOOT_COMCONSOLE_PORT?= 0x3f8
19BOOT_COMCONSOLE_SPEED?= 9600
20B2SIOFMT?= 0x3
21
22.if exists(${.OBJDIR}/../btx)
23BTX= ${.OBJDIR}/../btx
24.else
25BTX= ${.CURDIR}/../btx
26.endif
27
cacaceec 28# These origins are taken from bootasm.h.
04144d62 29#
cacaceec
MD
30REL1 = `${.OBJDIR}/bootasmdef.nx BOOT1_ORIGIN`
31REL1D = `${.OBJDIR}/bootasmdef.nx -d BOOT1_ORIGIN`
32ORG1 = `${.OBJDIR}/bootasmdef.nx MEM_BIOS_LADDR`
33ORG1D = `${.OBJDIR}/bootasmdef.nx -d MEM_BIOS_LADDR`
04144d62
MD
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#
4e06dda7 39ORG2= `${.OBJDIR}/bootasmdef.nx BOOT2_VORIGIN`
984263bc 40
5ee58eed
MD
41# gcc3.x
42# -fno-guess-branch-probability
43# -mno-align-long-strings
0e24d183 44CFLAGS= -elf -ffreestanding -Os -fno-builtin \
5ee58eed 45 -fomit-frame-pointer \
7580e818
SS
46 -std=c99 \
47 -DBOOT2 \
5ee58eed 48 -I${.CURDIR}/../../common \
7580e818 49 -I${.CURDIR}/../../../../lib/libstand \
5ee58eed 50 -I${.CURDIR}/../btx/lib -I. \
984263bc
MD
51 -Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
52 -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
f91a71dd
JS
53 -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings \
54 -D__BOOT2_HACK
984263bc 55
d90d8005 56# Unfortunately, unit-at-a-time creates issues as yet
3d310902
MD
57# not tracked down, in boot2, so we have to turn it off. Note that
58# the problem has been narrowed down to the 'boot2' code. The /boot/loader
59# doesn't seem to have a problem.
60#
3d310902 61CFLAGS+= -fno-unit-at-a-time
3d310902 62
d90d8005
SW
63# Disable propolice on gcc that supports it
64.if ${CCVER} == "gcc34"
0e24d183
SS
65CFLAGS+= -fno-stack-protector
66.endif
67
6080181b
SS
68NSECT_32?= 16
69NSECT_64?= 18
5ee58eed 70LDFLAGS=-nostdlib -static -N --gc-sections
984263bc 71
6080181b
SS
72all: boot
73
74boot: boot1_32 boot2_32
75 cat ${.ALLSRC} > boot
76
77.for s in _32 _64
78
79_ADDCFLAGS$s:= -DNSECT=${NSECT$s}
80_ts= $s
81.if ${_ts} == "_64"
82_ADDCFLAGS$s+= -DDISKLABEL64
83_ADDCFLAGS$s+= -DHAMMERFS
84.else
85_ADDCFLAGS$s+= -DUFS1_ONLY
86.endif
5ee58eed 87
6080181b 88all: boot1$s boot2$s
984263bc 89
6080181b
SS
90boot1$s: boot1$s.out
91 objcopy -S -O binary boot1$s.out ${.TARGET}
984263bc 92
6080181b
SS
93boot1$s.out: boot1$s.o bootasmdef.nx
94 ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} ${.ALLSRC:M*.o}
984263bc 95
6080181b
SS
96boot1$s.o: boot1.S
97 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -DFLAGS=${B1FLAGS} \
98 ${.ALLSRC} -o ${.TARGET} -c
5ee58eed 99
6080181b
SS
100boot2$s.o: boot2.c ${.CURDIR}/../../common/ufsread.c ${.CURDIR}/../../../../lib/libstand/hammerread.c
101 ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -S -o boot2$s.s.tmp boot2.c
102 sed -e '/align/d' -e '/nop/d' < boot2$s.s.tmp > boot2$s.s
103 rm -f boot2$s.s.tmp
104 ${AS} ${AFLAGS} -o boot2$s.o boot2$s.s
984263bc 105
6080181b 106boot2$s.h: boot1$s.out bootasmdef.nx
cacaceec 107 @echo "NOTE: boot2 using xread from boot1 at ${REL1}"
984263bc 108 ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
5ee58eed
MD
109 { x = $$1 - ORG1; \
110 printf("#define XREADORG %#x\n", REL1 + x) }' \
6080181b 111 ORG1=${ORG1D} REL1=${REL1D} > boot2$s.h
984263bc 112
6080181b
SS
113boot2$s: boot2$s.ldr boot2$s.bin ${BTX}/btx/btx
114 btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2$s.ldr \
115 -o boot2$s.ld -P 1 boot2$s.bin
116 stat boot2$s.ld | awk '{ x = (${NSECT$s} - 1) * 512 - $$8; \
984263bc 117 print x " bytes available"; if (x < 0) exit 1 }'
6080181b 118 dd if=boot2$s.ld of=${.TARGET} obs=$$(( (${NSECT$s} - 1) * 512)) conv=osync 2>/dev/null
984263bc 119
6080181b 120boot2$s.ldr:
2d7f6790 121 dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
984263bc 122
6080181b
SS
123boot2$s.bin: boot2$s.out
124 objcopy -S -O binary boot2$s.out ${.TARGET}
984263bc 125
6080181b 126boot2$s.out: boot2$s.o sio.o
984263bc 127 ${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
5ee58eed 128 ${BTX}/lib/crt0.o ${.ALLSRC}
984263bc 129
6080181b
SS
130boot2$s.o: boot2$s.h
131
132CLEANFILES+= boot1$s boot1$s.out boot1$s.o \
133 boot2$s boot2$s.ldr boot2$s.bin boot2$s.ld boot2$s.out boot2$s.o boot2$s.h boot2$s.s
134
135.endfor
984263bc 136
409cbc03
MD
137sio.o: sio.S
138 ${CC} -DSIOPRT=${BOOT_COMCONSOLE_PORT} -DSIOFMT=${B2SIOFMT} \
aec2661d 139 -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
6080181b 140 ${.ALLSRC} -o ${.TARGET} -c
984263bc
MD
141
142install:
143 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
5ee58eed
MD
144 boot ${DESTDIR}${BINDIR}/boot
145 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
6080181b
SS
146 boot1_32 ${DESTDIR}${BINDIR}/boot1
147 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
148 boot2_32 ${DESTDIR}${BINDIR}/boot2
149 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
150 boot1_64 ${DESTDIR}${BINDIR}/boot1_64
984263bc 151 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
6080181b 152 boot2_64 ${DESTDIR}${BINDIR}/boot2_64
984263bc
MD
153
154.include <bsd.prog.mk>
5ee58eed
MD
155
156.if defined(REALLY_AMD64)
157boot2.o: machine
158
159beforedepend ${OBJS}: machine
160
161machine:
062db326 162 ${LN} -sf ${.CURDIR}/../../../i386/include machine
5ee58eed
MD
163
164CLEANFILES+= machine
165.endif
166
cacaceec
MD
167CLEANFILES+= bootasmdef.nx
168