1fbeb31a2SMatt MacyHAVE_ZFS= ${MK_LOADER_ZFS} 2060679efSWarner Losh 3ca987d46SWarner LoshLOADER_NET_SUPPORT?= yes 4ca987d46SWarner LoshLOADER_NFS_SUPPORT?= yes 5ca987d46SWarner LoshLOADER_TFTP_SUPPORT?= yes 68f46043bSWarner LoshLOADER_CD9660_SUPPORT?= yes 7195a96f0SWarner LoshLOADER_EXT2FS_SUPPORT?= no 8195a96f0SWarner LoshLOADER_MSDOS_SUPPORT?= no 9ca987d46SWarner LoshLOADER_UFS_SUPPORT?= yes 1023dee252SWarner LoshLOADER_GZIP_SUPPORT?= yes 1123dee252SWarner LoshLOADER_BZIP2_SUPPORT?= yes 12ca987d46SWarner Losh 13ca987d46SWarner Losh.include <bsd.init.mk> 14ca987d46SWarner Losh 159d45c24cSWarner LoshLOADER?= loader_${LOADER_INTERP} 16ca987d46SWarner LoshPROG= ${LOADER}.sym 17ca987d46SWarner LoshINTERNALPROG= 18ca987d46SWarner LoshNEWVERSWHAT?= "bootstrap loader" x86 19*2982c708SSimon J. GerratyVERSION_FILE?= ${.CURDIR}/../loader/version 20f8a199f2SWarner Losh# 21f8a199f2SWarner Losh# There's 640k - 40k maximum space, less however much memory the BIOS uses. A 22f8a199f2SWarner Losh# non-random survey suggests that 20k-25k is a good value for 'most' machines. 23f8a199f2SWarner Losh# We also need to subtract maximum stack usage (20-25k). 24f8a199f2SWarner Losh# 25e5d1a21eSWarner Losh# So 640k - 40k - 25k - 25k = 550k = 563,200 bytes, but use 560,000 below for 26f8a199f2SWarner Losh# some extra buffer for more complex setups and/or wider BIOS lomem variation. 27f8a199f2SWarner Losh# 283179bb27SJessica Clarke# Some systems use more stack or have BIOS reserve more RAM (or both), and will 293179bb27SJessica Clarke# need to set this lower in /etc/src.conf if the above buffer is too small. 30f8a199f2SWarner Losh# 31f8a199f2SWarner Losh# sudo dd if=/dev/mem bs=1 iseek=0x413 count=2 | hd -d 32f8a199f2SWarner Losh# 33f8a199f2SWarner Losh# will tell you how many kiB of lomem are available. 34f8a199f2SWarner Losh# 3546ea2ffcSWarner Losh# We further reduce this to 500k, though, to give PXE an additional 64k of space 3646ea2ffcSWarner Losh# so pxeloader will fit. If you have special needs that do not include pxeboot, 3746ea2ffcSWarner Losh# you can safely set this as high as 560000 generally, or a bit higher if you 3846ea2ffcSWarner Losh# have tight control over the machines you are booting on. 3946ea2ffcSWarner Losh# 4046ea2ffcSWarner LoshLOADERSIZE?= 500000 # Largest known safe size for loader.bin 41ca987d46SWarner Losh 42ca987d46SWarner Losh.PATH: ${BOOTSRC}/i386/loader 43ca987d46SWarner Losh 44ca987d46SWarner Losh# architecture-specific loader code 45bbfc01c2SWarner LoshSRCS+= chain.c 46bbfc01c2SWarner LoshSRCS+= conf.c 47bbfc01c2SWarner LoshSRCS+= gfx_bios.c 48bbfc01c2SWarner LoshSRCS+= main.c 49bbfc01c2SWarner LoshSRCS+= vers.c 50bbfc01c2SWarner Losh 51bbfc01c2SWarner Losh.if ${MK_LOADER_BIOS_TEXTONLY} == "no" 52bbfc01c2SWarner LoshSRCS+= gfx_fb.c 53bbfc01c2SWarner LoshSRCS+= 8x16.c 543630506bSToomas Soome 553630506bSToomas SoomeCFLAGS.gfx_fb.c += -I${.CURDIR}/../libi386 563630506bSToomas SoomeCFLAGS.gfx_fb.c += -I$(SRCTOP)/sys/teken 573630506bSToomas SoomeCFLAGS.gfx_fb.c += -I${SRCTOP}/sys/cddl/contrib/opensolaris/common/lz4 583630506bSToomas SoomeCFLAGS.gfx_fb.c += -I${SRCTOP}/contrib/pnglite 593630506bSToomas SoomeCFLAGS.gfx_fb.c += -DHAVE_MEMCPY -I${SRCTOP}/sys/contrib/zlib 60bbfc01c2SWarner LoshCFLAGS.gfx_bios.c += -I$(SRCTOP)/sys/teken 61bbfc01c2SWarner LoshCFLAGS.gfx_bios.c += -I${SRCTOP}/contrib/pnglite 62bbfc01c2SWarner Losh.else 63bbfc01c2SWarner LoshCFLAGS.gfx_bios.c += -DBIOS_TEXT_ONLY 64bbfc01c2SWarner LoshCFLAGS.conf.c += -DBIOS_TEXT_ONLY 65bbfc01c2SWarner Losh.endif 66ca987d46SWarner Losh 67ca987d46SWarner Losh# Include bcache code. 68ca987d46SWarner LoshHAVE_BCACHE= yes 69ca987d46SWarner Losh 70ca987d46SWarner Losh# Enable PnP and ISA-PnP code. 71ca987d46SWarner LoshHAVE_PNP= yes 72ca987d46SWarner LoshHAVE_ISABUS= yes 73ca987d46SWarner Losh 74e307eb94SToomas Soome.if ${MK_LOADER_ZFS} == "yes" 75e307eb94SToomas SoomeCFLAGS.main.c+= -I${SYSDIR}/contrib/openzfs/include 76e307eb94SToomas SoomeCFLAGS.main.c+= -I${SYSDIR}/contrib/openzfs/include/os/freebsd/zfs 77e307eb94SToomas Soome.endif 78e307eb94SToomas Soome 79ca987d46SWarner Losh.if exists(${.CURDIR}/help.i386) 8025c2f4cbSWarner LoshHELP_FILES= ${.CURDIR}/help.i386 81ca987d46SWarner Losh.endif 8288599604SMitchell HorneHELP_FILENAME= loader.help.bios 83ca987d46SWarner Losh 84ca987d46SWarner Losh# Always add MI sources 85ca987d46SWarner Losh.include "${BOOTSRC}/loader.mk" 86ca987d46SWarner Losh 873630506bSToomas SoomeCLEANFILES+= ${LOADER} ${LOADER}.bin 8x16.c 88ca987d46SWarner Losh 89a2037dbaSDimitry AndricORG= 0x0 90a2037dbaSDimitry Andric 91ca987d46SWarner LoshCFLAGS+= -Wall 92a2037dbaSDimitry AndricLDFLAGS+= -static ${LDFLAGS_ORG} -Wl,--gc-sections 9378661696SKyle Evans.if (${LINKER_TYPE} == "lld" && ${LINKER_VERSION} >= 130000) || \ 9478661696SKyle Evans (${LINKER_TYPE} == "bfd" && ${LINKER_VERSION} >= 23700) 95c90cab0dSDimitry Andric# lld 13 and higher default to garbage collecting start/stop symbols, 96c90cab0dSDimitry Andric# completely ruining our linker sets. For now, work around it by 97c90cab0dSDimitry Andric# disabling this un-feature. 98c90cab0dSDimitry AndricLDFLAGS+= -Wl,-z,nostart-stop-gc 99c90cab0dSDimitry Andric.endif 100ca987d46SWarner Losh 101ca987d46SWarner Losh# i386 standalone support library 102ca987d46SWarner LoshLIBI386= ${BOOTOBJ}/i386/libi386/libi386.a 103ca987d46SWarner LoshCFLAGS+= -I${BOOTSRC}/i386 104ca987d46SWarner Losh 105ca987d46SWarner Losh# Debug me! 106f2be828fSSimon J. Gerraty#CFLAGS+= -g 107f2be828fSSimon J. Gerraty#LDFLAGS+= -g 108ca987d46SWarner Losh 1096c789c55SToomas Soome8x16.c: ${SRCTOP}/contrib/terminus/ter-u16b.bdf 1103630506bSToomas Soome vtfontcvt -f compressed-source -o ${.TARGET} ${.ALLSRC} 1113630506bSToomas Soome 11239fdad34SWarner Losh 113ca987d46SWarner Losh${LOADER}: ${LOADER}.bin ${BTXLDR} ${BTXKERN} 1144c8ea3efSWarner Losh btxld -v -f aout -e ${LOADER_ADDRESS} -o ${.TARGET} -l ${BTXLDR} \ 115ca987d46SWarner Losh -b ${BTXKERN} ${LOADER}.bin 116ca987d46SWarner Losh 117ca987d46SWarner Losh${LOADER}.bin: ${LOADER}.sym 1181a18ab42SAlex Richardson ${STRIPBIN} -R .comment -R .note -o ${.TARGET} ${.ALLSRC} 1194c8ea3efSWarner Losh @set -- `ls -l ${.TARGET}` ; x=$$((${LOADERSIZE}-$$5)); \ 1204c8ea3efSWarner Losh echo "$$x bytes available"; test $$x -ge 0 121ca987d46SWarner Losh 122fbeb31a2SMatt Macy.if ${MK_LOADER_ZFS} == "yes" && ${LOADER_INTERP} == ${LOADER_DEFAULT_INTERP} 1239d45c24cSWarner LoshLINKS+= ${BINDIR}/${LOADER} ${BINDIR}/zfsloader 1249d45c24cSWarner Losh.endif 1259d45c24cSWarner Losh.if ${LOADER_INTERP} == ${LOADER_DEFAULT_INTERP} 1269d45c24cSWarner LoshLINKS+= ${BINDIR}/${LOADER} ${BINDIR}/loader 127060679efSWarner Losh.endif 128ca987d46SWarner LoshFILES+= ${LOADER} 129ca987d46SWarner LoshFILESMODE_${LOADER}= ${BINMODE} -b 130ca987d46SWarner Losh 131e713d3a0SWarner Losh# Note: crt0.o needs to be first for pxeboot(8) to work. It assumes that the 132e713d3a0SWarner Losh# startup code is located at the start of the loader and will jump 133e713d3a0SWarner Losh# there. Although btx is more flexible than this, the emulated boot2 environment 134b45d64fdSWarner Losh# that pxeldr provides has none of that flexibility and assumes the entry point 135b45d64fdSWarner Losh# is 0. Finally, both pxeldr and cdboot assume they are loading an a.out file. 136e713d3a0SWarner Losh# 1372b720db8SWarner Losh# We must add it to the LDFLAGS instead of the OBJS because the former won't try 138e713d3a0SWarner Losh# to clean it. When it is in OBJS, this cleaning can lead to races where 139e713d3a0SWarner Losh# btxcrt.o is rebuilt, but boot2 isn't, leading to errors at installation time. 140e713d3a0SWarner Losh# LDFLAGS does not have this baggage and will be included first in the list of 141e713d3a0SWarner Losh# files. 142e713d3a0SWarner LoshLDFLAGS+= ${BTXCRT} 143ca987d46SWarner Losh 14491d8ee35SChuck Silvers# Force the linker max page size to 4k so that we fit in the limited space even 14591d8ee35SChuck Silvers# if someone has set a larger default linker max page size via /etc/src.conf. 14691d8ee35SChuck SilversLDFLAGS+= -Wl,-z,max-page-size=0x1000 14791d8ee35SChuck Silvers 1488a744de2SWarner LoshDPADD= ${LDR_INTERP32} ${LIBI386} ${LIBSA32} 1498a744de2SWarner LoshLDADD= ${LDR_INTERP32} ${LIBI386} ${LIBSA32} 150ca987d46SWarner Losh 151ca987d46SWarner Losh.if ${MACHINE_CPUARCH} == "amd64" 152ca987d46SWarner LoshCFLAGS+= -DLOADER_PREFER_AMD64 153ca987d46SWarner Losh.endif 154ca987d46SWarner Losh 155ca987d46SWarner Losh.include <bsd.prog.mk> 156