1ca987d46SWarner Losh 2ca987d46SWarner Losh.if !defined(__BOOT_DEFS_MK__) 3ca987d46SWarner Losh__BOOT_DEFS_MK__=${MFILE} 4ca987d46SWarner Losh 541c233deSKyle EvansFORTIFY_SOURCE= 0 641c233deSKyle Evans 7991699dbSWarner Losh# We need to define all the MK_ options before including src.opts.mk 8991699dbSWarner Losh# because it includes bsd.own.mk which needs the right MK_ values, 9991699dbSWarner Losh# espeically MK_CTF. 10991699dbSWarner Losh 118299b37fSWarner LoshMK_CTF= no 128299b37fSWarner LoshMK_SSP= no 138299b37fSWarner LoshMK_PROFILE= no 14879675e9SWarner LoshMK_PIE= no 158299b37fSWarner LoshMAN= 1611421c37SWarner Losh.if !defined(PIC) 1711421c37SWarner LoshNO_PIC= 188299b37fSWarner LoshINTERNALLIB= 1911421c37SWarner Losh.endif 207a0c0ff7SWarner Losh# Should be NO_CPU_FLAGS, but bsd.cpu.mk is included too early in bsd.init.mk 217a0c0ff7SWarner Losh# via the early include of bsd.opts.mk. Moving Makefile.inc include earlier in 227a0c0ff7SWarner Losh# that file causes weirdness, so this is the next best thing. We need to do this 237a0c0ff7SWarner Losh# because the loader needs very specific flags to work right, and things like 247a0c0ff7SWarner Losh# CPUTYPE?=native prevent that, and introduce an endless game of whack-a-mole 257a0c0ff7SWarner Losh# to disable more and more features. Boot loader performance is never improved 267a0c0ff7SWarner Losh# enough to make that hassle worth chasing. 277a0c0ff7SWarner Losh_CPUCFLAGS= 288299b37fSWarner Losh 295e9226f0SAlex Richardson.if ${LDFLAGS:M-nostdlib} 305e9226f0SAlex Richardson# Sanitizers won't work unless we link against libc (e.g. in userboot/test). 315e9226f0SAlex RichardsonMK_ASAN:= no 325e9226f0SAlex RichardsonMK_UBSAN:= no 335e9226f0SAlex Richardson.endif 345e9226f0SAlex Richardson 35991699dbSWarner Losh.include <src.opts.mk> 365e697f5fSMitchell Horne.include <bsd.linker.mk> 37991699dbSWarner Losh 38991699dbSWarner LoshWARNS?= 1 39991699dbSWarner Losh 40ca987d46SWarner LoshBOOTSRC= ${SRCTOP}/stand 41ca987d46SWarner LoshEFISRC= ${BOOTSRC}/efi 42ca987d46SWarner LoshEFIINC= ${EFISRC}/include 43*f0d5b1bdSAhmad Khalifa# For amd64, there's a bit of mixed bag. Some of the tree (i386, lib*32) is 44*f0d5b1bdSAhmad Khalifa# built 32-bit and some 64-bit (lib*, efi). Centralize all the 32-bit magic here 45*f0d5b1bdSAhmad Khalifa# and activate it when DO32 is explicitly defined to be 1. 46*f0d5b1bdSAhmad Khalifa.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1 47*f0d5b1bdSAhmad KhalifaEFIINCMD= ${EFIINC}/i386 48*f0d5b1bdSAhmad Khalifa.else 49ca987d46SWarner LoshEFIINCMD= ${EFIINC}/${MACHINE} 50*f0d5b1bdSAhmad Khalifa.endif 51ca987d46SWarner LoshFDTSRC= ${BOOTSRC}/fdt 52ca987d46SWarner LoshFICLSRC= ${BOOTSRC}/ficl 53ca987d46SWarner LoshLDRSRC= ${BOOTSRC}/common 547cafeaa1SWarner LoshLIBLUASRC= ${BOOTSRC}/liblua 55475008d6SBrandon BergrenLIBOFWSRC= ${BOOTSRC}/libofw 567cafeaa1SWarner LoshLUASRC= ${SRCTOP}/contrib/lua/src 57ca987d46SWarner LoshSASRC= ${BOOTSRC}/libsa 58ca987d46SWarner LoshSYSDIR= ${SRCTOP}/sys 59ca987d46SWarner LoshUBOOTSRC= ${BOOTSRC}/uboot 60b8902de1SWarner LoshZFSSRC= ${SASRC}/zfs 614c570f61SWarner LoshOZFS= ${SRCTOP}/sys/contrib/openzfs 624c570f61SWarner LoshZFSOSSRC= ${OZFS}/module/os/freebsd/ 634c570f61SWarner LoshZFSOSINC= ${OZFS}/include/os/freebsd 6480335781SKyle EvansLIBCSRC= ${SRCTOP}/lib/libc 65ca987d46SWarner Losh 66ca987d46SWarner LoshBOOTOBJ= ${OBJTOP}/stand 67ca987d46SWarner Losh 68ca987d46SWarner Losh# BINDIR is where we install 69ca987d46SWarner LoshBINDIR?= /boot 70ca987d46SWarner Losh 71ee74c236SKyle Evans# LUAPATH is where we search for and install lua scripts. 72ee74c236SKyle EvansLUAPATH?= /boot/lua 73506f3640SKyle EvansFLUASRC?= ${SRCTOP}/libexec/flua 747899f917SBaptiste DaroussinFLUALIB?= ${SRCTOP}/libexec/flua 75ee74c236SKyle Evans 76ca987d46SWarner LoshLIBSA= ${BOOTOBJ}/libsa/libsa.a 77ca987d46SWarner Losh.if ${MACHINE} == "i386" 78ca987d46SWarner LoshLIBSA32= ${LIBSA} 79ca987d46SWarner Losh.else 80ca987d46SWarner LoshLIBSA32= ${BOOTOBJ}/libsa32/libsa32.a 81ca987d46SWarner Losh.endif 82ca987d46SWarner Losh 83ca987d46SWarner Losh# Standard options: 8405f37f4dSWarner LoshCFLAGS+= -nostdinc 85f9553770SWarner Losh# Allow CFLAGS_EARLY.file/target so that code that needs specific stack 86f9553770SWarner Losh# of include paths can set them up before our include paths. Normally 87f9553770SWarner Losh# the only thing that should be there are -I directives, and as few of 88f9553770SWarner Losh# those as possible. 89f9553770SWarner LoshCFLAGS+= ${CFLAGS_EARLY} ${CFLAGS_EARLY.${.IMPSRC:T}} ${CFLAGS_EARLY.${.TARGET:T}} 9005f37f4dSWarner Losh.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1 9105f37f4dSWarner LoshCFLAGS+= -I${BOOTOBJ}/libsa32 9205f37f4dSWarner Losh.else 9305f37f4dSWarner LoshCFLAGS+= -I${BOOTOBJ}/libsa 9405f37f4dSWarner Losh.endif 95b65d7763SWarner LoshCFLAGS+= -I${SASRC} -D_STANDALONE 964f6b2874SWarner LoshCFLAGS+= -I${SYSDIR} 97ef1fcaf0SWarner Losh# Spike the floating point interfaces 98e52cfb3eSWarner LoshCFLAGS+= -Ddouble=jagged-little-pill -Dfloat=floaty-mcfloatface 990125fb63SWarner Losh.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "amd64" 100f835d609SWarner Losh# Slim down the image. This saves about 15% in size with clang 6 on x86 101f835d609SWarner Losh# Our most constrained /boot/loader env is BIOS booting on x86, where 102f835d609SWarner Losh# our text + data + BTX have to fit into 640k below the ISA hole. 103f835d609SWarner Losh# Experience has shown that problems arise between ~520k to ~530k. 104f835d609SWarner LoshCFLAGS.clang+= -Oz 105f835d609SWarner LoshCFLAGS.gcc+= -Os 106094b4065SToomas SoomeCFLAGS+= -ffunction-sections -fdata-sections 1070125fb63SWarner Losh.endif 108ca987d46SWarner Losh 1095ba722feSWarner Losh# GELI Support, with backward compat hooks (mostly) 110ca987d46SWarner Losh.if defined(LOADER_NO_GELI_SUPPORT) 111ca987d46SWarner LoshMK_LOADER_GELI=no 112ca987d46SWarner Losh.warning "Please move from LOADER_NO_GELI_SUPPORT to WITHOUT_LOADER_GELI" 113ca987d46SWarner Losh.endif 114ca987d46SWarner Losh.if defined(LOADER_GELI_SUPPORT) 115ca987d46SWarner LoshMK_LOADER_GELI=yes 116ca987d46SWarner Losh.warning "Please move from LOADER_GELI_SUPPORT to WITH_LOADER_GELI" 117ca987d46SWarner Losh.endif 118ca987d46SWarner Losh.if ${MK_LOADER_GELI} == "yes" 119ca987d46SWarner LoshCFLAGS+= -DLOADER_GELI_SUPPORT 12062bd02ceSWarner LoshCFLAGS+= -I${SASRC}/geli 1214927bbceSWarner Losh.endif # MK_LOADER_GELI 122ca987d46SWarner Losh 1238701bb8fSWarner Losh# These should be confined to loader.mk, but can't because uboot/lib 1248701bb8fSWarner Losh# also uses it. It's part of loader, but isn't a loader so we can't 1258701bb8fSWarner Losh# just include loader.mk 1268701bb8fSWarner Losh.if ${LOADER_DISK_SUPPORT:Uyes} == "yes" 1278701bb8fSWarner LoshCFLAGS+= -DLOADER_DISK_SUPPORT 1288701bb8fSWarner Losh.endif 1298701bb8fSWarner Losh 1304f6b2874SWarner Losh# Machine specific flags for all builds here 131ca987d46SWarner Losh 132f8328864SLeandro Lupori# Ensure PowerPC64 and PowerPC64LE boot loaders are compiled as 32 bit. 133f8328864SLeandro Lupori# PowerPC64LE boot loaders are 32-bit little-endian. 134f8328864SLeandro Lupori.if ${MACHINE_ARCH} == "powerpc64" 135b75abea4SBrandon BergrenCFLAGS+= -m32 -mcpu=powerpc -mbig-endian 136f8328864SLeandro Lupori.elif ${MACHINE_ARCH} == "powerpc64le" 137f8328864SLeandro LuporiCFLAGS+= -m32 -mcpu=powerpc -mlittle-endian 138ca987d46SWarner Losh.endif 139ca987d46SWarner Losh 140ca987d46SWarner Losh.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1 141073193edSDimitry AndricCFLAGS+= -m32 142ca987d46SWarner Losh# LD_FLAGS is passed directly to ${LD}, not via ${CC}: 143ca987d46SWarner LoshLD_FLAGS+= -m elf_i386_fbsd 144ca987d46SWarner LoshAFLAGS+= --32 145ca987d46SWarner Losh.endif 146ca987d46SWarner Losh 1474f6b2874SWarner Losh# Add in the no float / no SIMD stuff and announce we're freestanding 1482192efc0SMitchell Horne# aarch64 and riscv don't have -msoft-float, but all others do. 1494f6b2874SWarner LoshCFLAGS+= -ffreestanding ${CFLAGS_NO_SIMD} 1504f6b2874SWarner Losh.if ${MACHINE_CPUARCH} == "aarch64" 151a2e2311aSAndrew TurnerCFLAGS+= -mgeneral-regs-only -ffixed-x18 -fPIC 152fcdb1f03SWarner Losh.elif ${MACHINE_CPUARCH} == "riscv" 1532192efc0SMitchell HorneCFLAGS+= -march=rv64imac -mabi=lp64 -fPIC 1542192efc0SMitchell HorneCFLAGS.clang+= -mcmodel=medium 1552192efc0SMitchell HorneCFLAGS.gcc+= -mcmodel=medany 156fcdb1f03SWarner Losh.else 1574f6b2874SWarner LoshCFLAGS+= -msoft-float 1584f6b2874SWarner Losh.endif 1594f6b2874SWarner Losh 16089797c88SJustin Hibbits# -msoft-float seems to be insufficient for powerpcspe 16189797c88SJustin Hibbits.if ${MACHINE_ARCH} == "powerpcspe" 16289797c88SJustin HibbitsCFLAGS+= -mno-spe 16389797c88SJustin Hibbits.endif 16489797c88SJustin Hibbits 1654f6b2874SWarner Losh.if ${MACHINE_CPUARCH} == "i386" || (${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 1) 1664f6b2874SWarner LoshCFLAGS+= -march=i386 1674f6b2874SWarner LoshCFLAGS.gcc+= -mpreferred-stack-boundary=2 1684f6b2874SWarner Losh.endif 169fcdb1f03SWarner Losh.if ${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 0 170fcdb1f03SWarner LoshCFLAGS+= -fPIC -mno-red-zone 171fcdb1f03SWarner Losh.endif 1724f6b2874SWarner Losh 1734f6b2874SWarner Losh.if ${MACHINE_CPUARCH} == "arm" 1744f6b2874SWarner Losh# Do not generate movt/movw, because the relocation fixup for them does not 1754f6b2874SWarner Losh# translate to the -Bsymbolic -pie format required by self_reloc() in loader(8). 1764f6b2874SWarner Losh# Also, the fpu is not available in a standalone environment. 1774f6b2874SWarner LoshCFLAGS.clang+= -mno-movt 1784f6b2874SWarner LoshCFLAGS.clang+= -mfpu=none 179fcdb1f03SWarner LoshCFLAGS+= -fPIC 1804f6b2874SWarner Losh.endif 1814f6b2874SWarner Losh 1822192efc0SMitchell Horne# Some RISC-V linkers have support for relaxations, while some (lld) do not 1832192efc0SMitchell Horne# yet. If this is the case we inhibit the compiler from emitting relaxations. 1845e697f5fSMitchell Horne.if ${LINKER_FEATURES:Mriscv-relaxations} == "" 1852192efc0SMitchell HorneCFLAGS+= -mno-relax 1862192efc0SMitchell Horne.endif 1872192efc0SMitchell Horne 1884f6b2874SWarner Losh# The boot loader build uses dd status=none, where possible, for reproducible 1894f6b2874SWarner Losh# build output (since performance varies from run to run). Trouble is that 1904f6b2874SWarner Losh# option was recently (10.3) added to FreeBSD and is non-standard. Only use it 1914f6b2874SWarner Losh# when this test succeeds rather than require dd to be a bootstrap tool. 1924f6b2874SWarner LoshDD_NOSTATUS!=(dd status=none count=0 2> /dev/null && echo status=none) || true 1934f6b2874SWarner LoshDD=dd ${DD_NOSTATUS} 1944f6b2874SWarner Losh 1959d45c24cSWarner Losh# 1969d45c24cSWarner Losh# Have a sensible default 1979d45c24cSWarner Losh# 198f9f8ac94SKyle Evans.if ${MK_LOADER_LUA} == "yes" 1999d45c24cSWarner LoshLOADER_DEFAULT_INTERP?=lua 200f9f8ac94SKyle Evans.elif ${MK_FORTH} == "yes" 201f9f8ac94SKyle EvansLOADER_DEFAULT_INTERP?=4th 2029d45c24cSWarner Losh.else 2039d45c24cSWarner LoshLOADER_DEFAULT_INTERP?=simp 2049d45c24cSWarner Losh.endif 2059d45c24cSWarner LoshLOADER_INTERP?=${LOADER_DEFAULT_INTERP} 2069d45c24cSWarner Losh 207ca987d46SWarner Losh# Make sure we use the machine link we're about to create 208ca987d46SWarner LoshCFLAGS+=-I. 209ca987d46SWarner Losh 210a0139c46SWarner Loshall: ${PROG} 211a0139c46SWarner Losh 21256758831SToomas SoomeCLEANFILES+= teken_state.h 21356758831SToomas Soometeken.c: teken_state.h 21456758831SToomas Soome 21556758831SToomas Soometeken_state.h: ${SYSDIR}/teken/sequences 21656758831SToomas Soome awk -f ${SYSDIR}/teken/gensequences \ 21756758831SToomas Soome ${SYSDIR}/teken/sequences > teken_state.h 21856758831SToomas Soome 219a0139c46SWarner Losh.if !defined(NO_OBJ) 220e9b148a3SSimon J. Gerraty_ILINKS=include/machine 221ca987d46SWarner Losh.if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64" 222e9b148a3SSimon J. Gerraty_ILINKS+=include/${MACHINE_CPUARCH} 223ca987d46SWarner Losh.endif 224ca987d46SWarner Losh.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" 225e9b148a3SSimon J. Gerraty_ILINKS+=include/x86 226ca987d46SWarner Losh.endif 227e9b148a3SSimon J. GerratyCFLAGS+= -Iinclude 228e9b148a3SSimon J. GerratyCLEANDIRS+= include 229ca987d46SWarner Losh 230ca987d46SWarner Loshbeforedepend: ${_ILINKS} 231ca987d46SWarner Loshbeforebuild: ${_ILINKS} 232ca987d46SWarner Losh 233ca987d46SWarner Losh# Ensure that the links exist without depending on it when it exists which 234ca987d46SWarner Losh# causes all the modules to be rebuilt when the directory pointed to changes. 235ca987d46SWarner Losh.for _link in ${_ILINKS} 236ca987d46SWarner Losh.if !exists(${.OBJDIR}/${_link}) 237ca987d46SWarner Losh${OBJS}: ${_link} 238a0139c46SWarner Losh.endif # _link exists 239ca987d46SWarner Losh.endfor 240ca987d46SWarner Losh 241ca987d46SWarner Losh.NOPATH: ${_ILINKS} 242ca987d46SWarner Losh 243e9b148a3SSimon J. Gerraty${_ILINKS}: .NOMETA 244e9b148a3SSimon J. Gerraty @case ${.TARGET:T} in \ 245ca987d46SWarner Losh machine) \ 246ca987d46SWarner Losh if [ ${DO32:U0} -eq 0 ]; then \ 247ca987d46SWarner Losh path=${SYSDIR}/${MACHINE}/include ; \ 248ca987d46SWarner Losh else \ 249ca987d46SWarner Losh path=${SYSDIR}/${MACHINE:C/amd64/i386/}/include ; \ 250ca987d46SWarner Losh fi ;; \ 251ca987d46SWarner Losh *) \ 252ca987d46SWarner Losh path=${SYSDIR}/${.TARGET:T}/include ;; \ 253ca987d46SWarner Losh esac ; \ 254e9b148a3SSimon J. Gerraty case ${.TARGET} in \ 255e9b148a3SSimon J. Gerraty */*) mkdir -p ${.TARGET:H};; \ 256e9b148a3SSimon J. Gerraty esac ; \ 257ca987d46SWarner Losh path=`(cd $$path && /bin/pwd)` ; \ 258e9b148a3SSimon J. Gerraty ${ECHO} ${.TARGET} "->" $$path ; \ 259d8e1e85cSAlex Richardson ln -fns $$path ${.TARGET} 260a0139c46SWarner Losh.endif # !NO_OBJ 261ca987d46SWarner Losh.endif # __BOOT_DEFS_MK__ 262