Makefile revision 211725
1# $FreeBSD: head/sys/boot/i386/boot2/Makefile 211677 2010-08-23 01:42:09Z imp $
2
3.include <bsd.own.mk>
4
5# XXX: clang can compile the boot code just fine, but boot2 gets too big
6CC:=${CC:C/^cc|^clang/gcc/}
7
8FILES=		boot boot1 boot2
9
10NM?=		nm
11
12# A value of 0x80 enables LBA support.
13BOOT_BOOT1_FLAGS?=	0x80
14
15BOOT_COMCONSOLE_PORT?= 0x3f8
16BOOT_COMCONSOLE_SPEED?= 9600
17B2SIOFMT?=	0x3
18
19REL1=	0x700
20ORG1=	0x7c00
21ORG2=	0x2000
22
23# Decide level of UFS support.
24BOOT2_UFS?=	UFS1_AND_UFS2
25#BOOT2_UFS?=	UFS2_ONLY
26#BOOT2_UFS?=	UFS1_ONLY
27
28CFLAGS=	-Os \
29	-fno-guess-branch-probability \
30	-fomit-frame-pointer \
31	-fno-unit-at-a-time \
32	-mno-align-long-strings \
33	-mrtd \
34	-mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 \
35	-D${BOOT2_UFS} \
36	-DFLAGS=${BOOT_BOOT1_FLAGS} \
37	-DSIOPRT=${BOOT_COMCONSOLE_PORT} \
38	-DSIOFMT=${B2SIOFMT} \
39	-DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
40	-I${.CURDIR}/../../common \
41	-I${.CURDIR}/../btx/lib -I. \
42	-Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
43	-Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
44	-Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings \
45	-Winline --param max-inline-insns-single=100
46
47LDFLAGS=-static -N --gc-sections
48
49# Pick up ../Makefile.inc early.
50.include <bsd.init.mk>
51
52CLEANFILES=	boot
53
54boot: boot1 boot2
55	cat boot1 boot2 > boot
56
57CLEANFILES+=	boot1 boot1.out boot1.o
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
65CLEANFILES+=	boot2 boot2.ld boot2.ldr boot2.bin boot2.out boot2.o \
66		boot2.s boot2.s.tmp boot2.h sio.o
67
68boot2: boot2.ld
69	@set -- `ls -l boot2.ld`; x=$$((7680-$$5)); \
70	    echo "$$x bytes available"; test $$x -ge 0
71	dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync
72
73boot2.ld: boot2.ldr boot2.bin ${BTXKERN}
74	btxld -v -E ${ORG2} -f bin -b ${BTXKERN} -l boot2.ldr \
75	    -o ${.TARGET} -P 1 boot2.bin
76
77boot2.ldr:
78	dd if=/dev/zero of=${.TARGET} bs=512 count=1
79
80boot2.bin: boot2.out
81	objcopy -S -O binary boot2.out ${.TARGET}
82
83boot2.out: ${BTXCRT} boot2.o sio.o
84	${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC}
85
86boot2.o: boot2.s
87
88SRCS=	boot2.c boot2.h
89
90boot2.s: boot2.c boot2.h ${.CURDIR}/../../common/ufsread.c
91	${CC} ${CFLAGS} -S -o boot2.s.tmp ${.CURDIR}/boot2.c
92	sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
93	rm -f boot2.s.tmp
94
95boot2.h: boot1.out
96	${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
97	    { x = $$1 - ORG1; \
98	    printf("#define XREADORG %#x\n", REL1 + x) }' \
99	    ORG1=`printf "%d" ${ORG1}` \
100	    REL1=`printf "%d" ${REL1}` > ${.TARGET}
101
102.if ${MACHINE_CPUARCH} == "amd64"
103beforedepend boot2.s: machine
104CLEANFILES+=	machine
105machine:
106	ln -sf ${.CURDIR}/../../../i386/include machine
107.endif
108
109.include <bsd.prog.mk>
110