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