Makefile revision 360660
1221828Sgrehan# $FreeBSD: stable/11/stand/i386/boot2/Makefile 360660 2020-05-05 17:10:49Z dim $
2221828Sgrehan
3221828Sgrehan.include <bsd.init.mk>
4221828Sgrehan
5221828SgrehanFILES=		boot boot1 boot2
6221828Sgrehan
7221828Sgrehan# A value of 0x80 enables LBA support.
8221828SgrehanBOOT_BOOT1_FLAGS?=	0x80
9221828Sgrehan
10221828SgrehanBOOT_COMCONSOLE_PORT?= 0x3f8
11221828SgrehanBOOT_COMCONSOLE_SPEED?= 9600
12221828SgrehanB2SIOFMT?=	0x3
13221828Sgrehan
14221828SgrehanREL1=	0x700
15221828SgrehanORG1=	0x7c00
16221828SgrehanORG2=	0x2000
17221828Sgrehan
18221828Sgrehan# Decide level of UFS support.
19221828SgrehanBOOT2_UFS?=	UFS1_AND_UFS2
20221828Sgrehan#BOOT2_UFS?=	UFS2_ONLY
21221828Sgrehan#BOOT2_UFS?=	UFS1_ONLY
22221828Sgrehan
23221828SgrehanCFLAGS+=-fomit-frame-pointer \
24221828Sgrehan	-mrtd \
25221828Sgrehan	-mregparm=3 \
26221828Sgrehan	-D${BOOT2_UFS} \
27221828Sgrehan	-DFLAGS=${BOOT_BOOT1_FLAGS} \
28221828Sgrehan	-DSIOPRT=${BOOT_COMCONSOLE_PORT} \
29221828Sgrehan	-DSIOFMT=${B2SIOFMT} \
30221828Sgrehan	-DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
31221828Sgrehan	-I${LDRSRC} \
32221828Sgrehan	-Wall -Waggregate-return -Wbad-function-cast -Wno-cast-align \
33221828Sgrehan	-Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
34351753Semaste	-Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings \
35351753Semaste	-Winline
36351753Semaste
37221828SgrehanCFLAGS.gcc+=	-Os \
38221828Sgrehan		-fno-asynchronous-unwind-tables \
39221828Sgrehan		--param max-inline-insns-single=100
40221828Sgrehan.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} <= 40201
41CFLAGS.gcc+=   -mno-align-long-strings
42.endif
43
44CFLAGS.clang+=	-Oz ${CLANG_OPT_SMALL}
45
46LD_FLAGS+=${LD_FLAGS_BIN}
47
48CLEANFILES+=	boot
49
50boot: boot1 boot2
51	cat boot1 boot2 > boot
52
53CLEANFILES+=	boot1 boot1.out boot1.o
54
55boot1: boot1.out
56	${OBJCOPY} -S -O binary boot1.out ${.TARGET}
57
58boot1.out: boot1.o
59	${LD} ${LD_FLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
60
61CLEANFILES+=	boot2 boot2.ld boot2.ldr boot2.bin boot2.out boot2.o \
62		boot2.h sio.o
63
64BOOT2SIZE=	7680
65
66boot2: boot2.ld
67	@set -- `ls -l ${.ALLSRC}`; x=$$((${BOOT2SIZE}-$$5)); \
68	    echo "$$x bytes available"; test $$x -ge 0
69	${DD} if=${.ALLSRC} of=${.TARGET} obs=${BOOT2SIZE} conv=osync
70
71boot2.ld: boot2.ldr boot2.bin ${BTXKERN}
72	btxld -v -E ${ORG2} -f bin -b ${BTXKERN} -l boot2.ldr \
73	    -o ${.TARGET} -P 1 boot2.bin
74
75boot2.ldr:
76	${DD} if=/dev/zero of=${.TARGET} bs=512 count=1
77
78boot2.bin: boot2.out
79	${OBJCOPY} -S -O binary boot2.out ${.TARGET}
80
81# For __ashldi3
82.PATH: ${SRCTOP}/contrib/llvm-project/compiler-rt/lib/builtins
83CFLAGS.ashldi3.c=	-Wno-missing-prototypes -Wno-missing-declarations
84CLEANFILES+=	ashldi3.o
85
86boot2.out: ${BTXCRT} boot2.o sio.o ashldi3.o
87	${LD} ${LD_FLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC}
88
89SRCS=	boot2.c boot2.h
90
91boot2.h: boot1.out
92	${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
93	    { x = $$1 - ORG1; \
94	    printf("#define XREADORG %#x\n", REL1 + x) }' \
95	    ORG1=`printf "%d" ${ORG1}` \
96	    REL1=`printf "%d" ${REL1}` > ${.TARGET}
97
98.include <bsd.prog.mk>
99
100# XXX: clang integrated-as doesn't grok .codeNN directives yet
101CFLAGS.boot1.S=		${CLANG_NO_IAS}
102