xref: /titanic_52/usr/src/boot/sys/boot/i386/boot2/Makefile (revision 071ca66ea5e45078699d3a2ade8c6ca5c00bba2c)
1# $FreeBSD$
2
3.include <bsd.own.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	-DUSE_XREAD \
29	-D${BOOT2_UFS} \
30	-DFLAGS=${BOOT_BOOT1_FLAGS} \
31	-DSIOPRT=${BOOT_COMCONSOLE_PORT} \
32	-DSIOFMT=${B2SIOFMT} \
33	-DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
34	-I${.CURDIR}/../../common \
35	-I${.CURDIR}/../btx/lib -I. \
36	-Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
37	-Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
38	-Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings \
39	-Winline
40
41CFLAGS.gcc+=	-Os \
42		-fno-guess-branch-probability \
43		-fno-unit-at-a-time \
44		--param max-inline-insns-single=100
45.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} <= 40201
46CFLAGS.gcc+=   -mno-align-long-strings
47.endif
48
49CFLAGS.clang+=	-Oz ${CLANG_OPT_SMALL}
50
51LD_FLAGS=-static -N --gc-sections
52
53# Pick up ../Makefile.inc early.
54.include <bsd.init.mk>
55
56CLEANFILES=	boot
57
58boot: boot1 boot2
59	cat boot1 boot2 > boot
60
61CLEANFILES+=	boot1 boot1.out boot1.o
62
63boot1: boot1.out
64	${OBJCOPY} -S -O binary boot1.out ${.TARGET}
65
66boot1.out: boot1.o
67	${LD} ${LD_FLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
68
69CLEANFILES+=	boot2 boot2.ld boot2.ldr boot2.bin boot2.out boot2.o \
70		boot2.s boot2.s.tmp boot2.h sio.o
71
72boot2: boot2.ld
73	@set -- `ls -l boot2.ld`; x=$$((7680-$$5)); \
74	    echo "$$x bytes available"; test $$x -ge 0
75	dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync status=none
76
77boot2.ld: boot2.ldr boot2.bin ${BTXKERN}
78	btxld -v -E ${ORG2} -f bin -b ${BTXKERN} -l boot2.ldr \
79	    -o ${.TARGET} -P 1 boot2.bin
80
81boot2.ldr:
82	dd if=/dev/zero of=${.TARGET} bs=512 count=1 status=none
83
84boot2.bin: boot2.out
85	${OBJCOPY} -S -O binary boot2.out ${.TARGET}
86
87boot2.out: ${BTXCRT} boot2.o sio.o
88	${LD} ${LD_FLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC}
89
90boot2.o: boot2.s
91	${CC} ${ACFLAGS} -c boot2.s
92
93SRCS=	boot2.c boot2.h
94
95boot2.s: boot2.c boot2.h ${.CURDIR}/../../common/ufsread.c
96	${CC} ${CFLAGS} -S -o boot2.s.tmp ${.CURDIR}/boot2.c
97	sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
98	rm -f boot2.s.tmp
99
100boot2.h: boot1.out
101	${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
102	    { x = $$1 - ORG1; \
103	    printf("#define XREADORG %#x\n", REL1 + x) }' \
104	    ORG1=`printf "%d" ${ORG1}` \
105	    REL1=`printf "%d" ${REL1}` > ${.TARGET}
106
107.if ${MACHINE_CPUARCH} == "amd64"
108beforedepend boot2.s: machine
109CLEANFILES+=	machine
110machine: ${.CURDIR}/../../../i386/include .NOMETA
111	ln -sf ${.ALLSRC} ${.TARGET}
112.endif
113
114.include <bsd.prog.mk>
115
116# XXX: clang integrated-as doesn't grok .codeNN directives yet
117CFLAGS.boot1.S=		${CLANG_NO_IAS}
118CFLAGS+=		${CFLAGS.${.IMPSRC:T}}
119