Commit | Line | Data |
---|---|---|
5ee58eed | 1 | # $FreeBSD: src/sys/boot/i386/boot2/Makefile,v 1.47 2003/06/26 03:51:57 peter Exp $ |
984263bc | 2 | |
984263bc MD |
3 | BINDIR?= /boot |
4 | BINMODE= 444 | |
6080181b SS |
5 | CLEANFILES= boot \ |
6 | sio.o | |
984263bc | 7 | |
2983445f SW |
8 | CSTD?= c99 |
9 | ||
984263bc | 10 | NM?= nm |
cacaceec MD |
11 | NXCFLAGS= |
12 | NXLDFLAGS= | |
13 | ||
14 | .PATH: ${.CURDIR}/.. | |
d64b2e33 MD |
15 | .PATH: ${.CURDIR}/../../common |
16 | .PATH: ${.CURDIR}/../../../../lib/libstand | |
cdfd0a3e | 17 | .PATH: ${.CURDIR}/../../../libkern |
984263bc MD |
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 | ||
cacaceec | 32 | # These origins are taken from bootasm.h. |
04144d62 | 33 | # |
cacaceec MD |
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` | |
04144d62 MD |
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 | # | |
4e06dda7 | 43 | ORG2= `${.OBJDIR}/bootasmdef.nx BOOT2_VORIGIN` |
984263bc | 44 | |
64005844 | 45 | CFLAGS= -Os \ |
5ee58eed | 46 | -fomit-frame-pointer \ |
64005844 JM |
47 | -fno-unwind-tables \ |
48 | -fno-asynchronous-unwind-tables \ | |
7580e818 | 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 | |
2b4e55a0 SW |
57 | DEBUG_FLAGS= |
58 | ||
63a12d94 SS |
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 | ||
d90d8005 | 63 | # Unfortunately, unit-at-a-time creates issues as yet |
3d310902 MD |
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 | |
00a3729f JM |
66 | # doesn't seem to have a problem. Added to BOOT2_GCC_FLAGS since clang |
67 | # doesn't recognize this flag. The no-guess-branch-probability flag is also | |
68 | # gcc-specific so it was moved to BOOT2_GCC_FLAGS as well. | |
3d310902 | 69 | # |
00a3729f | 70 | CFLAGS+= ${BOOT2_GCC_FLAGS} |
3d310902 | 71 | |
d64b2e33 MD |
72 | # boot2 area in 32 bit disklabel is 16 sectors (8K) |
73 | # | |
74 | # boot2 area in 64 bit disklabel is 64 sectors (32K). | |
75 | # However, the boot1 btx loader puts boot2 at a physical address | |
76 | # of MEM_BTX_USR+BOOT2_VORIGIN which is typically 0xC000, so we | |
77 | # cannot make boot2 any larger then 16KB or we overflow the segment. | |
78 | # | |
6080181b | 79 | NSECT_32?= 16 |
d64b2e33 | 80 | NSECT_64?= 30 |
044f3f17 JM |
81 | LDFLAGS= -nostdlib -static -N --gc-sections |
82 | LINKSCRIPT= --script ${.CURDIR}/boot2.ldscript | |
984263bc | 83 | |
6080181b SS |
84 | all: boot |
85 | ||
86 | boot: 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 | |
cdfd0a3e | 95 | _ADDCFLAGS$s+= -DHAMMER2FS -DUFS |
2ff972f5 | 96 | _ADDOBJS$s+= hammer2$s.o ufsread$s.o scrc32$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 | 102 | all: boot1$s boot2$s |
984263bc | 103 | |
6080181b SS |
104 | boot1$s: boot1$s.out |
105 | objcopy -S -O binary boot1$s.out ${.TARGET} | |
984263bc | 106 | |
6080181b SS |
107 | boot1$s.out: boot1$s.o bootasmdef.nx |
108 | ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} ${.ALLSRC:M*.o} | |
984263bc | 109 | |
6080181b SS |
110 | boot1$s.o: boot1.S |
111 | ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -DFLAGS=${B1FLAGS} \ | |
00a3729f | 112 | ${ASSEMBLER_FLAGS} ${.ALLSRC} -o ${.TARGET} -c |
5ee58eed | 113 | |
cdfd0a3e MD |
114 | #${.CURDIR}/../../common/ufsread.c ${.CURDIR}/../../../../lib/libstand/hammer2.c |
115 | ||
2ff972f5 | 116 | boot2$s.s: boot2.c boot2$s.h ufsread.c hammer2.c scrc32.c |
ec1618fb | 117 | ${CC} ${CFLAGS} ${_ADDCFLAGS$s} -S -o boot2$s.s.tmp ${.CURDIR}/boot2.c |
692786ae JM |
118 | sed -e '/align/d' -e '/nop/d' < ${.TARGET}.tmp > ${.TARGET} |
119 | rm -f ${.TARGET}.tmp | |
120 | ||
121 | boot2$s.o: boot2$s.s | |
122 | ${AS} ${AFLAGS} -o ${.TARGET} boot2$s.s | |
984263bc | 123 | |
6080181b | 124 | boot2$s.h: boot1$s.out bootasmdef.nx |
cacaceec | 125 | @echo "NOTE: boot2 using xread from boot1 at ${REL1}" |
984263bc | 126 | ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \ |
5ee58eed MD |
127 | { x = $$1 - ORG1; \ |
128 | printf("#define XREADORG %#x\n", REL1 + x) }' \ | |
6080181b | 129 | ORG1=${ORG1D} REL1=${REL1D} > boot2$s.h |
984263bc | 130 | |
6080181b SS |
131 | boot2$s: boot2$s.ldr boot2$s.bin ${BTX}/btx/btx |
132 | btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2$s.ldr \ | |
133 | -o boot2$s.ld -P 1 boot2$s.bin | |
134 | stat boot2$s.ld | awk '{ x = (${NSECT$s} - 1) * 512 - $$8; \ | |
984263bc | 135 | print x " bytes available"; if (x < 0) exit 1 }' |
6080181b | 136 | dd if=boot2$s.ld of=${.TARGET} obs=$$(( (${NSECT$s} - 1) * 512)) conv=osync 2>/dev/null |
984263bc | 137 | |
6080181b | 138 | boot2$s.ldr: |
2d7f6790 | 139 | dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null |
984263bc | 140 | |
6080181b SS |
141 | boot2$s.bin: boot2$s.out |
142 | objcopy -S -O binary boot2$s.out ${.TARGET} | |
984263bc | 143 | |
d64b2e33 | 144 | boot2$s.out: boot2$s.o sio.o ${_ADDOBJS$s} |
044f3f17 | 145 | ${LD} ${LDFLAGS} -Ttext ${ORG2} ${LINKSCRIPT} -o ${.TARGET} \ |
5ee58eed | 146 | ${BTX}/lib/crt0.o ${.ALLSRC} |
984263bc | 147 | |
6080181b | 148 | CLEANFILES+= boot1$s boot1$s.out boot1$s.o \ |
d64b2e33 MD |
149 | boot2$s boot2$s.ldr boot2$s.bin \ |
150 | boot2$s.ld boot2$s.out boot2$s.o boot2$s.h boot2$s.s \ | |
07065cf7 | 151 | bootasmdef.nx \ |
d64b2e33 MD |
152 | ${_ADDOBJS$s} |
153 | ||
cdfd0a3e | 154 | hammer2$s.o: hammer2.c |
d64b2e33 MD |
155 | ${CC} ${CFLAGS} ${_ADDCFLAGS$s} ${.ALLSRC} -o ${.TARGET} -c |
156 | ||
157 | ufsread$s.o: ufsread.c | |
158 | ${CC} ${CFLAGS} ${_ADDCFLAGS$s} ${.ALLSRC} -o ${.TARGET} -c | |
6080181b | 159 | |
2ff972f5 | 160 | scrc32$s.o: scrc32.c |
cdfd0a3e MD |
161 | ${CC} ${CFLAGS} ${_ADDCFLAGS$s} ${.ALLSRC} -o ${.TARGET} -c |
162 | ||
6080181b | 163 | .endfor |
984263bc | 164 | |
409cbc03 | 165 | sio.o: sio.S |
72f919a1 | 166 | ${CC} ${CFLAGS} -DSIOPRT=${BOOT_COMCONSOLE_PORT} -DSIOFMT=${B2SIOFMT} \ |
aec2661d | 167 | -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \ |
6080181b | 168 | ${.ALLSRC} -o ${.TARGET} -c |
984263bc MD |
169 | |
170 | install: | |
5ee58eed MD |
171 | ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ |
172 | boot ${DESTDIR}${BINDIR}/boot | |
984263bc | 173 | ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ |
6080181b SS |
174 | boot1_32 ${DESTDIR}${BINDIR}/boot1 |
175 | ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ | |
176 | boot2_32 ${DESTDIR}${BINDIR}/boot2 | |
177 | ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ | |
178 | boot1_64 ${DESTDIR}${BINDIR}/boot1_64 | |
984263bc | 179 | ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ |
6080181b | 180 | boot2_64 ${DESTDIR}${BINDIR}/boot2_64 |
984263bc MD |
181 | |
182 | .include <bsd.prog.mk> |