6b9183d27f87fc80f7d8b21398a9d338eafc68aa
[dragonfly.git] / sys / boot / i386 / boot2 / Makefile
1 # $FreeBSD: src/sys/boot/i386/boot2/Makefile,v 1.16.2.5 2002/08/07 16:31:53 ru Exp $
2 # $DragonFly: src/sys/boot/i386/boot2/Attic/Makefile,v 1.2 2003/06/17 04:28:18 dillon Exp $
3
4 PROG=           boot2
5 NOMAN=
6 STRIP=
7 BINDIR?=        /boot
8 BINMODE=        444
9 CLEANFILES+=    boot1 boot1.out boot1.o \
10                 boot2.ldr boot2.bin boot2.ld boot2.out boot2.o boot2.h \
11                 sio.o
12
13 NM?=            nm
14
15 # A value of 0x80 enables LBA support.
16 B1FLAGS=        0x80
17
18 BOOT_COMCONSOLE_PORT?= 0x3f8
19 BOOT_COMCONSOLE_SPEED?= 9600
20 B2SIOFMT?=      0x3
21
22 .if exists(${.OBJDIR}/../btx)
23 BTX=    ${.OBJDIR}/../btx
24 .else
25 BTX=    ${.CURDIR}/../btx
26 .endif
27
28 ORG1=   0x7c00
29 ORG2=   0x1000
30
31 CFLAGS= -elf -I${.CURDIR}/../btx/lib -I. \
32         -Os -fno-builtin -fforce-addr -fdata-sections \
33         -malign-functions=0 -malign-jumps=0 -malign-loops=0 -mrtd \
34         -mpreferred-stack-boundary=2 \
35         -Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
36         -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
37         -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings
38
39 LDFLAGS=-nostdlib -static -N
40
41 all: boot1 boot2
42
43 boot1: boot1.out
44         objcopy -S -O binary boot1.out ${.TARGET}
45
46 boot1.out: boot1.o
47         ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
48
49 boot1.o: boot1.s
50         ${AS} ${AFLAGS} --defsym FLAGS=${B1FLAGS} ${.IMPSRC} -o ${.TARGET}
51
52 boot2.h: boot1.out
53         ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
54                 { x = $$1 - ORG1; printf("#define XREADORG 0x7%x\n", x) }' \
55                 ORG1=`printf "%d" ${ORG1}` > boot2.h
56
57 boot2: boot2.ldr boot2.bin ${BTX}/btx/btx
58         btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2.ldr \
59                 -o boot2.ld -P 1 boot2.bin
60         @ls -l boot2.ld | awk '{ x = 7680 - $$5; \
61                 print x " bytes available"; if (x < 0) exit 1 }'
62         dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync 2>/dev/null
63
64 boot2.ldr:
65         dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
66
67 boot2.bin: boot2.out
68         objcopy -S -O binary boot2.out ${.TARGET}
69
70 boot2.out: boot2.o sio.o
71         ${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
72                 ${BTX}/lib/crt0.o boot2.o sio.o
73
74 boot2.o: boot2.h
75
76 sio.o: sio.s
77         ${AS} ${AFLAGS} --defsym SIOPRT=${BOOT_COMCONSOLE_PORT} \
78                 --defsym SIOFMT=${B2SIOFMT} \
79                 --defsym SIOSPD=${BOOT_COMCONSOLE_SPEED} \
80                 ${.IMPSRC} -o ${.TARGET}
81
82 install:
83         ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
84                 boot1 ${DESTDIR}${BINDIR}/boot1
85         ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
86                 boot2 ${DESTDIR}${BINDIR}/boot2
87
88 .include <bsd.prog.mk>