Makefile revision 97860
150477Speter# $FreeBSD: head/sys/boot/i386/gptboot/Makefile 97860 2002-06-05 11:10:38Z phk $
240269Srnordier
340326SrnordierPROG=		boot2
440326SrnordierNOMAN=
540326SrnordierSTRIP=
640326SrnordierBINDIR?=	/boot
740326SrnordierBINMODE=	444
840326SrnordierCLEANFILES+=	boot1 boot1.out boot1.o \
980751Sjhb		boot2.ldr boot2.bin boot2.ld boot2.out boot2.o boot2.h \
1096533Sru		boot2.s sio.o
1140326Srnordier
1280751SjhbNM?=		nm
1380751Sjhb
1448919Srnordier# A value of 0x80 enables LBA support.
1562138SjhbB1FLAGS=	0x80
1648919Srnordier
1742480SrnordierBOOT_COMCONSOLE_PORT?= 0x3f8
1842480SrnordierBOOT_COMCONSOLE_SPEED?= 9600
1940541SrnordierB2SIOFMT?=	0x3
2040541Srnordier
2140269Srnordier.if exists(${.OBJDIR}/../btx)
2240269SrnordierBTX=	${.OBJDIR}/../btx
2340269Srnordier.else
2440269SrnordierBTX=	${.CURDIR}/../btx
2540269Srnordier.endif
2640269Srnordier
2740269SrnordierORG1=	0x7c00
2840269SrnordierORG2=	0x1000
2940269Srnordier
3096327SjhbCFLAGS=	-elf -ffreestanding -Os -fno-builtin \
3196460Sbde	-fno-guess-branch-probability \
3296327Sjhb	-mrtd \
3397860Sphk	-I${.CURDIR}/../../common \
3496306Sobrien	-I${.CURDIR}/../btx/lib -I. \
3540269Srnordier	-Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
3640269Srnordier	-Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
3740269Srnordier	-Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings
3840269Srnordier
3940269SrnordierLDFLAGS=-nostdlib -static -N
4040269Srnordier
4140269Srnordierall: boot1 boot2
4240269Srnordier
4340269Srnordierboot1: boot1.out
4440308Srnordier	objcopy -S -O binary boot1.out ${.TARGET}
4540269Srnordier
4640269Srnordierboot1.out: boot1.o
4740269Srnordier	${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
4840269Srnordier
4960821Sjhbboot1.o: boot1.s
5060821Sjhb	${AS} ${AFLAGS} --defsym FLAGS=${B1FLAGS} ${.IMPSRC} -o ${.TARGET}
5140269Srnordier
5296424Speterboot2.o: boot2.c
5396424Speter	${CC} ${CFLAGS} -S -o boot2.s.tmp ${.IMPSRC}
5496424Speter	sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
5596424Speter	rm -f boot2.s.tmp
5696424Speter	${AS} ${AFLAGS} -o boot2.o boot2.s
5796424Speter
5880751Sjhbboot2.h: boot1.out
5980751Sjhb	${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
6080751Sjhb	 	{ x = $$1 - ORG1; printf("#define XREADORG 0x7%x\n", x) }' \
6180751Sjhb	 	ORG1=`printf "%d" ${ORG1}` > boot2.h
6280751Sjhb
6359150Sjhbboot2: boot2.ldr boot2.bin ${BTX}/btx/btx
6440269Srnordier	btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2.ldr \
6540314Srnordier		-o boot2.ld -P 1 boot2.bin
6640314Srnordier	@ls -l boot2.ld | awk '{ x = 7680 - $$5; \
6740314Srnordier		print x " bytes available"; if (x < 0) exit 1 }'
6840314Srnordier	dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync 2>/dev/null
6940269Srnordier
7040269Srnordierboot2.ldr:
7140269Srnordier	dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
7240269Srnordier
7340269Srnordierboot2.bin: boot2.out
7440308Srnordier	objcopy -S -O binary boot2.out ${.TARGET}
7540269Srnordier
7640404Srnordierboot2.out: boot2.o sio.o
7740269Srnordier	${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
7840404Srnordier		${BTX}/lib/crt0.o boot2.o sio.o
7940269Srnordier
8080751Sjhbboot2.o: boot2.h
8180751Sjhb
8240404Srnordiersio.o: sio.s
8360821Sjhb	${AS} ${AFLAGS} --defsym SIOPRT=${BOOT_COMCONSOLE_PORT} \
8460821Sjhb		--defsym SIOFMT=${B2SIOFMT} \
8560821Sjhb		--defsym SIOSPD=${BOOT_COMCONSOLE_SPEED} \
8660821Sjhb		${.IMPSRC} -o ${.TARGET}
8740404Srnordier
8840326Srnordierinstall:
8940326Srnordier	${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
9040326Srnordier		boot1 ${DESTDIR}${BINDIR}/boot1
9140326Srnordier	${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
9240326Srnordier		boot2 ${DESTDIR}${BINDIR}/boot2
9340326Srnordier
9440326Srnordier.include <bsd.prog.mk>
95