xref: /freebsd/stand/i386/boot2/Makefile (revision 56b17de1e8360fe131d425de20b5e75ff3ea897c)
1.include <bsd.init.mk>
2
3FILES=		boot boot1 boot2
4
5# A value of 0x80 enables LBA support.
6BOOT_BOOT1_FLAGS?=	0x80
7
8BOOT_COMCONSOLE_PORT?= 0x3f8
9BOOT_COMCONSOLE_SPEED?= 115200
10B2SIOFMT?=	0x3
11
12REL1=	0x700
13ORG1=	0x7c00
14ORG2=	0x2000
15
16# Decide level of UFS support.
17BOOT2_UFS?=	UFS1_AND_UFS2
18#BOOT2_UFS?=	UFS2_ONLY
19#BOOT2_UFS?=	UFS1_ONLY
20
21CFLAGS+=-fomit-frame-pointer \
22	-mrtd \
23	-mregparm=3 \
24	-D${BOOT2_UFS} \
25	-DFLAGS=${BOOT_BOOT1_FLAGS} \
26	-DSIOPRT=${BOOT_COMCONSOLE_PORT} \
27	-DSIOFMT=${B2SIOFMT} \
28	-DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
29	-I${LDRSRC} \
30	-Wall -Waggregate-return -Wbad-function-cast -Wno-cast-align \
31	-Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
32	-Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings
33
34CFLAGS.gcc+=	-Os \
35		-fno-asynchronous-unwind-tables \
36		--param max-inline-insns-single=100
37
38CFLAGS.clang+=	-Oz ${CLANG_OPT_SMALL}
39
40LD_FLAGS+=${LD_FLAGS_BIN}
41
42CLEANFILES+=	boot
43
44boot: boot1 boot2
45	cat boot1 boot2 > boot
46
47CLEANFILES+=	boot1 boot1.out boot1.o
48
49boot1: boot1.out
50	${OBJCOPY} -S -O binary boot1.out ${.TARGET}
51
52boot1.out: boot1.o
53	${LD} ${LD_FLAGS} -e start --defsym ORG=${ORG1} -T ${LDSCRIPT} -o ${.TARGET} boot1.o
54
55CLEANFILES+=	boot2 boot2.ld boot2.ldr boot2.bin boot2.out boot2.o \
56		boot2.h sio.o
57
58BOOT2SIZE=	7680
59
60boot2: boot2.ld
61	@set -- `ls -l ${.ALLSRC}`; x=$$((${BOOT2SIZE}-$$5)); \
62	    echo "$$x bytes available"; test $$x -ge 0
63	${DD} if=${.ALLSRC} of=${.TARGET} bs=${BOOT2SIZE} conv=sync
64
65boot2.ld: boot2.ldr boot2.bin ${BTXKERN}
66	btxld -v -E ${ORG2} -f bin -b ${BTXKERN} -l boot2.ldr \
67	    -o ${.TARGET} -P 1 boot2.bin
68
69boot2.ldr:
70	${DD} if=/dev/zero of=${.TARGET} bs=512 count=1
71
72boot2.bin: boot2.out
73	${OBJCOPY} -S -O binary boot2.out ${.TARGET}
74
75# For __ashldi3
76.PATH: ${SRCTOP}/contrib/llvm-project/compiler-rt/lib/builtins
77CFLAGS.ashldi3.c=	-Wno-missing-prototypes -Wno-missing-declarations
78CLEANFILES+=	ashldi3.o
79
80boot2.out: ${BTXCRT} boot2.o sio.o ashldi3.o
81	${LD} ${LD_FLAGS} --defsym ORG=${ORG2} -T ${LDSCRIPT} -o ${.TARGET} ${.ALLSRC}
82
83SRCS=	boot2.c boot2.h
84
85boot2.h: boot1.out
86	${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
87	    { x = $$1 - ORG1; \
88	    printf("#define XREADORG %#x\n", REL1 + x) }' \
89	    ORG1=`printf "%d" ${ORG1}` \
90	    REL1=`printf "%d" ${REL1}` > ${.TARGET}
91
92.include <bsd.prog.mk>
93