150477Speter# $FreeBSD$
243561Skato
3212062Sdim.include <bsd.own.mk>
4212062Sdim
5212062Sdim# XXX: clang can compile the boot code just fine, but boot2 gets too big
6242706SdimCC:=		gcc
7260096SdimCOMPILER_TYPE:=	gcc
8212062Sdim
9201342SnyanFILES=		boot boot1 boot2
1043561Skato
11201342SnyanNM?=		nm
1243561Skato
13201342SnyanBOOT_COMCONSOLE_PORT?= 0x238
14201342SnyanBOOT_COMCONSOLE_SPEED?= 9600
15201342SnyanB2SIOFMT?=	0x3
1643561Skato
17201342SnyanREL1=	0x700
18201342SnyanORG1=	0
19201342SnyanORG2=	0x2000
2043561Skato
21201342Snyan# Decide level of UFS support.
22201342SnyanBOOT2_UFS?=	UFS1_AND_UFS2
23201342Snyan#BOOT2_UFS?=	UFS2_ONLY
24201342Snyan#BOOT2_UFS?=	UFS1_ONLY
25201342Snyan
26201342SnyanCFLAGS=	-Os \
27201342Snyan	-fno-guess-branch-probability \
28201342Snyan	-fomit-frame-pointer \
29201342Snyan	-fno-unit-at-a-time \
30201342Snyan	-mno-align-long-strings \
31201342Snyan	-mrtd \
32220361Snyan	-mregparm=3 \
33201342Snyan	-D${BOOT2_UFS} \
34201342Snyan	-DFLAGS=${BOOT_BOOT1_FLAGS} \
35201342Snyan	-DSIOPRT=${BOOT_COMCONSOLE_PORT} \
36201342Snyan	-DSIOFMT=${B2SIOFMT} \
37201342Snyan	-DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
38201342Snyan	-I${.CURDIR}/../../.. \
39201342Snyan	-I${.CURDIR}/../../i386/boot2 \
40201342Snyan	-I${.CURDIR}/../../common \
41201342Snyan	-I${.CURDIR}/../btx/lib -I. \
42201342Snyan	-Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
43201342Snyan	-Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
44201342Snyan	-Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings \
45260497Sdim	-Winline
46201342Snyan
47260497SdimCFLAGS.gcc+=	--param max-inline-insns-single=100
48260497Sdim
49200407Snyan# Set machine type to PC98_SYSTEM_PARAMETER
50201342Snyan#CFLAGS+=	-DSET_MACHINE_TYPE
51200407Snyan
52200407Snyan# Initialize the bi_bios_geom using the BIOS geometry
53201342Snyan#CFLAGS+=	-DGET_BIOSGEOM
54200407Snyan
55260291SdimLD_FLAGS=-static -N --gc-sections
5643561Skato
57201342Snyan# Pick up ../Makefile.inc early.
58201342Snyan.include <bsd.init.mk>
5943561Skato
60201342Snyan.PATH:	${.CURDIR}/../../i386/boot2
6143561Skato
62201342SnyanCLEANFILES=	boot
6343561Skato
64201342Snyanboot: boot1 boot2
65201342Snyan	cat boot1 boot2 > boot
6643561Skato
67201342SnyanCLEANFILES+=	boot1 boot1.out boot1.o
6843561Skato
69201342Snyanboot1: boot1.out
70201342Snyan	objcopy -S -O binary boot1.out ${.TARGET}
7143561Skato
72201342Snyanboot1.out: boot1.o
73260291Sdim	${LD} ${LD_FLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
74110102Snyan
75201342SnyanCLEANFILES+=	boot2 boot2.ld boot2.ldr boot2.bin boot2.out boot2.o \
76201342Snyan		boot2.s boot2.s.tmp boot2.h sio.o
7743561Skato
78201342Snyanboot2: boot2.ld
79201342Snyan	@set -- `ls -l boot2.ld`; x=$$((7680-$$5)); \
80201342Snyan	    echo "$$x bytes available"; test $$x -ge 0
81201342Snyan	dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync
8243561Skato
83201342Snyanboot2.ld: boot2.ldr boot2.bin ${BTXKERN}
84201342Snyan	btxld -v -E ${ORG2} -f bin -b ${BTXKERN} -l boot2.ldr \
85201342Snyan	    -o ${.TARGET} -P 1 boot2.bin
8643561Skato
87201342Snyanboot2.ldr:
88201342Snyan	dd if=/dev/zero of=${.TARGET} bs=276 count=1
8943561Skato
90201342Snyanboot2.bin: boot2.out
91201342Snyan	objcopy -S -O binary boot2.out ${.TARGET}
92104412Snyan
93201342Snyanboot2.out: ${BTXCRT} boot2.o sio.o
94260291Sdim	${LD} ${LD_FLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC}
95104412Snyan
96201342Snyanboot2.o: boot2.s
97104412Snyan
98201342SnyanSRCS=	boot2.c boot2.h
99104412Snyan
100201342Snyanboot2.s: boot2.c boot2.h ${.CURDIR}/../../common/ufsread.c
101201342Snyan	${CC} ${CFLAGS} -S -o boot2.s.tmp ${.CURDIR}/boot2.c
102201342Snyan	sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
103201342Snyan	rm -f boot2.s.tmp
104144563Simp
105201342Snyanboot2.h: boot1.out
106201342Snyan	${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T (read|putc)/ \
107201342Snyan	    { x = $$1 - ORG1; \
108201342Snyan	    printf("#define %sORG %#x\n", toupper($$3), REL1 + x) }' \
109201342Snyan	    ORG1=`printf "%d" ${ORG1}` \
110201342Snyan	    REL1=`printf "%d" ${REL1}` > ${.TARGET}
111144563Simp
11243561Skato.include <bsd.prog.mk>
113