Partitions>8: Leave a whole 512 bytes for the disklabel and squeeze code
[dragonfly.git] / sys / boot / i386 / boot2 / Makefile
CommitLineData
5ee58eed 1# $FreeBSD: src/sys/boot/i386/boot2/Makefile,v 1.47 2003/06/26 03:51:57 peter Exp $
2d7f6790 2# $DragonFly: src/sys/boot/i386/boot2/Attic/Makefile,v 1.5 2004/03/04 00:06:58 dillon Exp $
984263bc
MD
3
4PROG= boot2
5NOMAN=
6STRIP=
7BINDIR?= /boot
8BINMODE= 444
5ee58eed 9CLEANFILES= boot boot1 boot1.out boot1.o \
984263bc 10 boot2.ldr boot2.bin boot2.ld boot2.out boot2.o boot2.h \
5ee58eed 11 boot2.s sio.o
984263bc
MD
12
13NM?= nm
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
5ee58eed 28REL1= 0x700
984263bc 29ORG1= 0x7c00
5ee58eed 30ORG2= 0x2000
984263bc 31
5ee58eed
MD
32# Decide Level of UFS support. UFS1_AND_UFS2 doesn't fit.
33
34# BOOT2_UFS?= UFS2_ONLY
35#BOOT2_UFS?= UFS1_AND_UFS2
36BOOT2_UFS?= UFS1_ONLY
37
38# gcc3.x
39# -fno-guess-branch-probability
40# -mno-align-long-strings
41
42CFLAGS= -elf -ffreestanding -Os -fno-builtin \
43 -fomit-frame-pointer \
44 -mrtd \
45 -D${BOOT2_UFS} \
46 -I${.CURDIR}/../../common \
47 -I${.CURDIR}/../btx/lib -I. \
984263bc
MD
48 -Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
49 -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
50 -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings
51
5ee58eed 52LDFLAGS=-nostdlib -static -N --gc-sections
984263bc 53
5ee58eed
MD
54all: boot1 boot2 boot
55
56boot: boot1 boot2
57 cat boot1 boot2 > boot
984263bc
MD
58
59boot1: boot1.out
60 objcopy -S -O binary boot1.out ${.TARGET}
61
62boot1.out: boot1.o
63 ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
64
65boot1.o: boot1.s
5ee58eed
MD
66 ${CPP} ${CFLAGS} ${.IMPSRC} | \
67 ${AS} ${AFLAGS} --defsym FLAGS=${B1FLAGS} -o ${.TARGET}
68
69boot2.o: boot2.c ${.CURDIR}/../../common/ufsread.c
70 ${CC} ${CFLAGS} -S -o boot2.s.tmp ${.IMPSRC}
71 sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
72 rm -f boot2.s.tmp
73 ${AS} ${AFLAGS} -o boot2.o boot2.s
984263bc
MD
74
75boot2.h: boot1.out
76 ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
5ee58eed
MD
77 { x = $$1 - ORG1; \
78 printf("#define XREADORG %#x\n", REL1 + x) }' \
79 ORG1=`printf "%d" ${ORG1}` \
80 REL1=`printf "%d" ${REL1}` > boot2.h
984263bc
MD
81
82boot2: boot2.ldr boot2.bin ${BTX}/btx/btx
83 btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2.ldr \
84 -o boot2.ld -P 1 boot2.bin
85 @ls -l boot2.ld | awk '{ x = 7680 - $$5; \
86 print x " bytes available"; if (x < 0) exit 1 }'
87 dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync 2>/dev/null
88
89boot2.ldr:
2d7f6790 90 dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
984263bc
MD
91
92boot2.bin: boot2.out
93 objcopy -S -O binary boot2.out ${.TARGET}
94
95boot2.out: boot2.o sio.o
96 ${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
5ee58eed 97 ${BTX}/lib/crt0.o ${.ALLSRC}
984263bc
MD
98
99boot2.o: boot2.h
100
101sio.o: sio.s
102 ${AS} ${AFLAGS} --defsym SIOPRT=${BOOT_COMCONSOLE_PORT} \
103 --defsym SIOFMT=${B2SIOFMT} \
104 --defsym SIOSPD=${BOOT_COMCONSOLE_SPEED} \
105 ${.IMPSRC} -o ${.TARGET}
106
107install:
5ee58eed
MD
108 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
109 boot ${DESTDIR}${BINDIR}/boot
984263bc
MD
110 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
111 boot1 ${DESTDIR}${BINDIR}/boot1
112 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
113 boot2 ${DESTDIR}${BINDIR}/boot2
114
115.include <bsd.prog.mk>
5ee58eed
MD
116
117.if defined(REALLY_AMD64)
118boot2.o: machine
119
120beforedepend ${OBJS}: machine
121
122machine:
123 ln -sf ${.CURDIR}/../../../i386/include machine
124
125CLEANFILES+= machine
126.endif
127