freebsd-dev/sys/boot/i386/boot2/Makefile
Bruce Evans e754a32842 Saved 176 bytes by compiling with -fno-guess-branch-probability. The
default of -fguess-branch-probablility causes time optimizations (?)
like rewriting `if (foo) x++;' as
`if (!foo) goto forth; back: ; ...; forth: x++; goto back;".  This is
pessimizes space especially well on i386's because one short branch
gets converted to 2 long ones.

Removed -fno-align-foo since it is implied by -Os.  Previous commit
messages seem to have overstated the new alignment bugs in gcc.  The
only case that affects boot2 is that -fno-align-functions (or
equivalently -falign-functions=1) actually gives -falign-functions=2.
This is caused by FUNCTION_BOUNDARY being 2 (bytes) instead of 1.
The default case where the optimization level is 1 and no alignment
options are given is more broken.  All alignments are minimal, modulo
the bug in FUNCTION_BOUNDARY.  This is caused by toplev.c setting
defaults too early.

Some hacks in previous commits ar not needed now, but may as well be
kept until gcc is fixed.  The previous on in the Makefile saved 96
bytes of text due to the wrong FUNCTION_BOUNDARY and 32 bytes of data
due to unrelated bloat in the alignment of large objects.  There aren't
even any options to control alignment of data.
2002-05-12 15:45:28 +00:00

94 lines
2.3 KiB
Makefile

# $FreeBSD$
PROG= boot2
NOMAN=
STRIP=
BINDIR?= /boot
BINMODE= 444
CLEANFILES+= boot1 boot1.out boot1.o \
boot2.ldr boot2.bin boot2.ld boot2.out boot2.o boot2.h \
sio.o
NM?= nm
# A value of 0x80 enables LBA support.
B1FLAGS= 0x80
BOOT_COMCONSOLE_PORT?= 0x3f8
BOOT_COMCONSOLE_SPEED?= 9600
B2SIOFMT?= 0x3
.if exists(${.OBJDIR}/../btx)
BTX= ${.OBJDIR}/../btx
.else
BTX= ${.CURDIR}/../btx
.endif
ORG1= 0x7c00
ORG2= 0x1000
CFLAGS= -elf -ffreestanding -Os -fno-builtin \
-fno-guess-branch-probability \
-mrtd \
-I${.CURDIR}/../btx/lib -I. \
-Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
-Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
-Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings
LDFLAGS=-nostdlib -static -N
all: boot1 boot2
boot1: boot1.out
objcopy -S -O binary boot1.out ${.TARGET}
boot1.out: boot1.o
${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
boot1.o: boot1.s
${AS} ${AFLAGS} --defsym FLAGS=${B1FLAGS} ${.IMPSRC} -o ${.TARGET}
boot2.o: boot2.c
${CC} ${CFLAGS} -S -o boot2.s.tmp ${.IMPSRC}
sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
rm -f boot2.s.tmp
${AS} ${AFLAGS} -o boot2.o boot2.s
boot2.h: boot1.out
${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
{ x = $$1 - ORG1; printf("#define XREADORG 0x7%x\n", x) }' \
ORG1=`printf "%d" ${ORG1}` > boot2.h
boot2: boot2.ldr boot2.bin ${BTX}/btx/btx
btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2.ldr \
-o boot2.ld -P 1 boot2.bin
@ls -l boot2.ld | awk '{ x = 7680 - $$5; \
print x " bytes available"; if (x < 0) exit 1 }'
dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync 2>/dev/null
boot2.ldr:
dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
boot2.bin: boot2.out
objcopy -S -O binary boot2.out ${.TARGET}
boot2.out: boot2.o sio.o
${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
${BTX}/lib/crt0.o boot2.o sio.o
boot2.o: boot2.h
sio.o: sio.s
${AS} ${AFLAGS} --defsym SIOPRT=${BOOT_COMCONSOLE_PORT} \
--defsym SIOFMT=${B2SIOFMT} \
--defsym SIOSPD=${BOOT_COMCONSOLE_SPEED} \
${.IMPSRC} -o ${.TARGET}
install:
${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
boot1 ${DESTDIR}${BINDIR}/boot1
${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
boot2 ${DESTDIR}${BINDIR}/boot2
.include <bsd.prog.mk>