Makefile revision 226440
150477Speter# $FreeBSD: head/sys/boot/i386/boot2/Makefile 224131 2011-07-17 13:50:21Z dim $
240269Srnordier
3211571Srpaulo.include <bsd.own.mk>
4211571Srpaulo
5125537SruFILES=		boot boot1 boot2
640326Srnordier
780751SjhbNM?=		nm
880751Sjhb
948919Srnordier# A value of 0x80 enables LBA support.
10134382SyarBOOT_BOOT1_FLAGS?=	0x80
1148919Srnordier
1242480SrnordierBOOT_COMCONSOLE_PORT?= 0x3f8
1342480SrnordierBOOT_COMCONSOLE_SPEED?= 9600
1440541SrnordierB2SIOFMT?=	0x3
1540541Srnordier
16104673SgreenREL1=	0x700
1740269SrnordierORG1=	0x7c00
18104683SjhbORG2=	0x2000
1940269Srnordier
20125537Sru# Decide level of UFS support.
21108000SimpBOOT2_UFS?=	UFS1_AND_UFS2
22125537Sru#BOOT2_UFS?=	UFS2_ONLY
23125537Sru#BOOT2_UFS?=	UFS1_ONLY
24104635Sphk
25125566SruCFLAGS=	-Os \
26132870Skan	-fno-guess-branch-probability \
27132870Skan	-fomit-frame-pointer \
28132870Skan	-fno-unit-at-a-time \
29108149Sobrien	-mno-align-long-strings \
3096327Sjhb	-mrtd \
31220337Srdivacky	-mregparm=3 \
32221177Sjhb	-DUSE_XREAD \
33107879Sphk	-D${BOOT2_UFS} \
34134382Syar	-DFLAGS=${BOOT_BOOT1_FLAGS} \
35125932Sru	-DSIOPRT=${BOOT_COMCONSOLE_PORT} \
36125932Sru	-DSIOFMT=${B2SIOFMT} \
37125932Sru	-DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
3897860Sphk	-I${.CURDIR}/../../common \
3996306Sobrien	-I${.CURDIR}/../btx/lib -I. \
4040269Srnordier	-Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
4140269Srnordier	-Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
42169732Skan	-Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings \
43169732Skan	-Winline --param max-inline-insns-single=100
4440269Srnordier
45221348Sdim.if ${CC:T:Mclang} == "clang"
46221506SdimCFLAGS+=	-mllvm -stack-alignment=8 -mllvm -inline-threshold=3 \
47221506Sdim		-mllvm -enable-load-pre=false
48221348Sdim# XXX: clang integrated-as doesn't grok .codeNN directives yet
49221348SdimCFLAGS+=	${.IMPSRC:T:Mboot1.S:C/^.+$/-no-integrated-as/}
50221348Sdim.endif
51221348Sdim
52125621SruLDFLAGS=-static -N --gc-sections
5340269Srnordier
54125537Sru# Pick up ../Makefile.inc early.
55125537Sru.include <bsd.init.mk>
5640269Srnordier
57125537SruCLEANFILES=	boot
58125537Sru
59109886Sphkboot: boot1 boot2
60109886Sphk	cat boot1 boot2 > boot
61109886Sphk
62125537SruCLEANFILES+=	boot1 boot1.out boot1.o
63125537Sru
6440269Srnordierboot1: boot1.out
6540308Srnordier	objcopy -S -O binary boot1.out ${.TARGET}
6640269Srnordier
6740269Srnordierboot1.out: boot1.o
6840269Srnordier	${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
6940269Srnordier
70125537SruCLEANFILES+=	boot2 boot2.ld boot2.ldr boot2.bin boot2.out boot2.o \
71125537Sru		boot2.s boot2.s.tmp boot2.h sio.o
7296424Speter
73125537Sruboot2: boot2.ld
74125537Sru	@set -- `ls -l boot2.ld`; x=$$((7680-$$5)); \
75125537Sru	    echo "$$x bytes available"; test $$x -ge 0
76125537Sru	dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync
7780751Sjhb
78125537Sruboot2.ld: boot2.ldr boot2.bin ${BTXKERN}
79125537Sru	btxld -v -E ${ORG2} -f bin -b ${BTXKERN} -l boot2.ldr \
80125537Sru	    -o ${.TARGET} -P 1 boot2.bin
8140269Srnordier
8240269Srnordierboot2.ldr:
83189500Smarcel	dd if=/dev/zero of=${.TARGET} bs=512 count=1
8440269Srnordier
8540269Srnordierboot2.bin: boot2.out
8640308Srnordier	objcopy -S -O binary boot2.out ${.TARGET}
8740269Srnordier
88125537Sruboot2.out: ${BTXCRT} boot2.o sio.o
89125537Sru	${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC}
9040269Srnordier
91125537Sruboot2.o: boot2.s
92224131Sdim.if ${CC:T:Mclang} == "clang"
93224131Sdim	${CC} ${ACFLAGS} -c boot2.s
94224131Sdim.endif
9580751Sjhb
96125564SruSRCS=	boot2.c boot2.h
97125564Sru
98125537Sruboot2.s: boot2.c boot2.h ${.CURDIR}/../../common/ufsread.c
99125537Sru	${CC} ${CFLAGS} -S -o boot2.s.tmp ${.CURDIR}/boot2.c
100125537Sru	sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
101125537Sru	rm -f boot2.s.tmp
10240404Srnordier
103125537Sruboot2.h: boot1.out
104125537Sru	${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
105125537Sru	    { x = $$1 - ORG1; \
106125537Sru	    printf("#define XREADORG %#x\n", REL1 + x) }' \
107125537Sru	    ORG1=`printf "%d" ${ORG1}` \
108125537Sru	    REL1=`printf "%d" ${REL1}` > ${.TARGET}
10940326Srnordier
110211677Simp.if ${MACHINE_CPUARCH} == "amd64"
111125581Srubeforedepend boot2.s: machine
112125556SruCLEANFILES+=	machine
113116864Spetermachine:
114116864Speter	ln -sf ${.CURDIR}/../../../i386/include machine
115116864Speter.endif
116116864Speter
117125537Sru.include <bsd.prog.mk>
118