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