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