Makefile revision 221506
1139823Simp# $FreeBSD: head/sys/boot/i386/boot2/Makefile 221506 2011-05-05 18:47:24Z dim $
2133920Sandre
3133920Sandre.include <bsd.own.mk>
4133920Sandre
5133920SandreFILES=		boot boot1 boot2
6133920Sandre
7133920SandreNM?=		nm
8133920Sandre
9133920Sandre# A value of 0x80 enables LBA support.
10133920SandreBOOT_BOOT1_FLAGS?=	0x80
11133920Sandre
12133920SandreBOOT_COMCONSOLE_PORT?= 0x3f8
13133920SandreBOOT_COMCONSOLE_SPEED?= 9600
14133920SandreB2SIOFMT?=	0x3
15133920Sandre
16133920SandreREL1=	0x700
17133920SandreORG1=	0x7c00
18133920SandreORG2=	0x2000
19133920Sandre
20133920Sandre# Decide level of UFS support.
21133920SandreBOOT2_UFS?=	UFS1_AND_UFS2
22133920Sandre#BOOT2_UFS?=	UFS2_ONLY
23133920Sandre#BOOT2_UFS?=	UFS1_ONLY
24133920Sandre
25133920SandreCFLAGS=	-Os \
26133920Sandre	-fno-guess-branch-probability \
27172467Ssilby	-fomit-frame-pointer \
28172467Ssilby	-fno-unit-at-a-time \
29172467Ssilby	-mno-align-long-strings \
30134346Sru	-mrtd \
31133920Sandre	-mregparm=3 \
32133920Sandre	-DUSE_XREAD \
33133920Sandre	-D${BOOT2_UFS} \
34133920Sandre	-DFLAGS=${BOOT_BOOT1_FLAGS} \
35133920Sandre	-DSIOPRT=${BOOT_COMCONSOLE_PORT} \
36133920Sandre	-DSIOFMT=${B2SIOFMT} \
37134383Sandre	-DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
38152928Sume	-I${.CURDIR}/../../common \
39133920Sandre	-I${.CURDIR}/../btx/lib -I. \
40133920Sandre	-Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
41133920Sandre	-Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
42133920Sandre	-Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings \
43133920Sandre	-Winline --param max-inline-insns-single=100
44133920Sandre
45133920Sandre.if ${CC:T:Mclang} == "clang"
46185895SzecCFLAGS+=	-mllvm -stack-alignment=8 -mllvm -inline-threshold=3 \
47185895Szec		-mllvm -enable-load-pre=false
48133920Sandre# XXX: clang integrated-as doesn't grok .codeNN directives yet
49133920SandreCFLAGS+=	${.IMPSRC:T:Mboot1.S:C/^.+$/-no-integrated-as/}
50133920Sandre.endif
51133920Sandre
52133920SandreLDFLAGS=-static -N --gc-sections
53133920Sandre
54196423Sjulian# Pick up ../Makefile.inc early.
55133920Sandre.include <bsd.init.mk>
56133920Sandre
57133920SandreCLEANFILES=	boot
58133920Sandre
59133920Sandreboot: boot1 boot2
60133920Sandre	cat boot1 boot2 > boot
61200580Sluigi
62201124SluigiCLEANFILES+=	boot1 boot1.out boot1.o
63133920Sandre
64133920Sandreboot1: boot1.out
65133920Sandre	objcopy -S -O binary boot1.out ${.TARGET}
66200601Sluigi
67200601Sluigiboot1.out: boot1.o
68200601Sluigi	${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
69158470Smlaier
70200601SluigiCLEANFILES+=	boot2 boot2.ld boot2.ldr boot2.bin boot2.out boot2.o \
71200601Sluigi		boot2.s boot2.s.tmp boot2.h sio.o
72158470Smlaier
73133920Sandreboot2: boot2.ld
74158470Smlaier	@set -- `ls -l boot2.ld`; x=$$((7680-$$5)); \
75158470Smlaier	    echo "$$x bytes available"; test $$x -ge 0
76136714Sandre	dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync
77201527Sluigi
78133920Sandreboot2.ld: boot2.ldr boot2.bin ${BTXKERN}
79200601Sluigi	btxld -v -E ${ORG2} -f bin -b ${BTXKERN} -l boot2.ldr \
80204591Sluigi	    -o ${.TARGET} -P 1 boot2.bin
81204591Sluigi
82204591Sluigiboot2.ldr:
83200601Sluigi	dd if=/dev/zero of=${.TARGET} bs=512 count=1
84200601Sluigi
85200601Sluigiboot2.bin: boot2.out
86200601Sluigi	objcopy -S -O binary boot2.out ${.TARGET}
87200601Sluigi
88200601Sluigiboot2.out: ${BTXCRT} boot2.o sio.o
89200601Sluigi	${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC}
90200601Sluigi
91200601Sluigiboot2.o: boot2.s
92200601Sluigi
93204591SluigiSRCS=	boot2.c boot2.h
94204591Sluigi
95204591Sluigiboot2.s: boot2.c boot2.h ${.CURDIR}/../../common/ufsread.c
96200601Sluigi	${CC} ${CFLAGS} -S -o boot2.s.tmp ${.CURDIR}/boot2.c
97200601Sluigi	sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
98201122Sluigi	rm -f boot2.s.tmp
99201122Sluigi
100201122Sluigiboot2.h: boot1.out
101201122Sluigi	${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
102201122Sluigi	    { x = $$1 - ORG1; \
103204591Sluigi	    printf("#define XREADORG %#x\n", REL1 + x) }' \
104201122Sluigi	    ORG1=`printf "%d" ${ORG1}` \
105135920Smlaier	    REL1=`printf "%d" ${REL1}` > ${.TARGET}
106133920Sandre
107133920Sandre.if ${MACHINE_CPUARCH} == "amd64"
108201527Sluigibeforedepend boot2.s: machine
109201122SluigiCLEANFILES+=	machine
110201122Sluigimachine:
111133920Sandre	ln -sf ${.CURDIR}/../../../i386/include machine
112201527Sluigi.endif
113201740Sluigi
114201740Sluigi.include <bsd.prog.mk>
115201527Sluigi