199767f8919635c4928607450d9e0abb932109ceToomas Soome# $FreeBSD$
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome.include <bsd.own.mk>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeFILES= boot boot1 boot2
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeNM?= nm
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome# A value of 0x80 enables LBA support.
199767f8919635c4928607450d9e0abb932109ceToomas SoomeBOOT_BOOT1_FLAGS?= 0x80
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeBOOT_COMCONSOLE_PORT?= 0x3f8
199767f8919635c4928607450d9e0abb932109ceToomas SoomeBOOT_COMCONSOLE_SPEED?= 9600
199767f8919635c4928607450d9e0abb932109ceToomas SoomeB2SIOFMT?= 0x3
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeREL1= 0x700
199767f8919635c4928607450d9e0abb932109ceToomas SoomeORG1= 0x7c00
199767f8919635c4928607450d9e0abb932109ceToomas SoomeORG2= 0x2000
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome# Decide level of UFS support.
199767f8919635c4928607450d9e0abb932109ceToomas SoomeBOOT2_UFS?= UFS1_AND_UFS2
199767f8919635c4928607450d9e0abb932109ceToomas Soome#BOOT2_UFS?= UFS2_ONLY
199767f8919635c4928607450d9e0abb932109ceToomas Soome#BOOT2_UFS?= UFS1_ONLY
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCFLAGS= -fomit-frame-pointer \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -mrtd \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -mregparm=3 \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -DUSE_XREAD \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -D${BOOT2_UFS} \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -DFLAGS=${BOOT_BOOT1_FLAGS} \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -DSIOPRT=${BOOT_COMCONSOLE_PORT} \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -DSIOFMT=${B2SIOFMT} \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -I${.CURDIR}/../../common \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -I${.CURDIR}/../btx/lib -I. \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -Winline
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCFLAGS.gcc+= -Os \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -fno-guess-branch-probability \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -fno-unit-at-a-time \
199767f8919635c4928607450d9e0abb932109ceToomas Soome --param max-inline-insns-single=100
199767f8919635c4928607450d9e0abb932109ceToomas Soome.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} <= 40201
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCFLAGS.gcc+= -mno-align-long-strings
199767f8919635c4928607450d9e0abb932109ceToomas Soome.endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCFLAGS.clang+= -Oz ${CLANG_OPT_SMALL}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeLD_FLAGS=-static -N --gc-sections
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome# Pick up ../Makefile.inc early.
199767f8919635c4928607450d9e0abb932109ceToomas Soome.include <bsd.init.mk>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCLEANFILES= boot
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeboot: boot1 boot2
199767f8919635c4928607450d9e0abb932109ceToomas Soome cat boot1 boot2 > boot
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCLEANFILES+= boot1 boot1.out boot1.o
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeboot1: boot1.out
199767f8919635c4928607450d9e0abb932109ceToomas Soome ${OBJCOPY} -S -O binary boot1.out ${.TARGET}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeboot1.out: boot1.o
199767f8919635c4928607450d9e0abb932109ceToomas Soome ${LD} ${LD_FLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCLEANFILES+= boot2 boot2.ld boot2.ldr boot2.bin boot2.out boot2.o \
199767f8919635c4928607450d9e0abb932109ceToomas Soome boot2.s boot2.s.tmp boot2.h sio.o
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeboot2: boot2.ld
199767f8919635c4928607450d9e0abb932109ceToomas Soome @set -- `ls -l boot2.ld`; x=$$((7680-$$5)); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome echo "$$x bytes available"; test $$x -ge 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync status=none
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeboot2.ld: boot2.ldr boot2.bin ${BTXKERN}
199767f8919635c4928607450d9e0abb932109ceToomas Soome btxld -v -E ${ORG2} -f bin -b ${BTXKERN} -l boot2.ldr \
199767f8919635c4928607450d9e0abb932109ceToomas Soome -o ${.TARGET} -P 1 boot2.bin
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeboot2.ldr:
199767f8919635c4928607450d9e0abb932109ceToomas Soome dd if=/dev/zero of=${.TARGET} bs=512 count=1 status=none
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeboot2.bin: boot2.out
199767f8919635c4928607450d9e0abb932109ceToomas Soome ${OBJCOPY} -S -O binary boot2.out ${.TARGET}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeboot2.out: ${BTXCRT} boot2.o sio.o
199767f8919635c4928607450d9e0abb932109ceToomas Soome ${LD} ${LD_FLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeboot2.o: boot2.s
199767f8919635c4928607450d9e0abb932109ceToomas Soome ${CC} ${ACFLAGS} -c boot2.s
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeSRCS= boot2.c boot2.h
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeboot2.s: boot2.c boot2.h ${.CURDIR}/../../common/ufsread.c
199767f8919635c4928607450d9e0abb932109ceToomas Soome ${CC} ${CFLAGS} -S -o boot2.s.tmp ${.CURDIR}/boot2.c
199767f8919635c4928607450d9e0abb932109ceToomas Soome sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
199767f8919635c4928607450d9e0abb932109ceToomas Soome rm -f boot2.s.tmp
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeboot2.h: boot1.out
199767f8919635c4928607450d9e0abb932109ceToomas Soome ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
199767f8919635c4928607450d9e0abb932109ceToomas Soome { x = $$1 - ORG1; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("#define XREADORG %#x\n", REL1 + x) }' \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ORG1=`printf "%d" ${ORG1}` \
199767f8919635c4928607450d9e0abb932109ceToomas Soome REL1=`printf "%d" ${REL1}` > ${.TARGET}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome.if ${MACHINE_CPUARCH} == "amd64"
199767f8919635c4928607450d9e0abb932109ceToomas Soomebeforedepend boot2.s: machine
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCLEANFILES+= machine
199767f8919635c4928607450d9e0abb932109ceToomas Soomemachine: ${.CURDIR}/../../../i386/include .NOMETA
199767f8919635c4928607450d9e0abb932109ceToomas Soome ln -sf ${.ALLSRC} ${.TARGET}
199767f8919635c4928607450d9e0abb932109ceToomas Soome.endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome.include <bsd.prog.mk>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome# XXX: clang integrated-as doesn't grok .codeNN directives yet
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCFLAGS.boot1.S= ${CLANG_NO_IAS}
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCFLAGS+= ${CFLAGS.${.IMPSRC:T}}