1 2.if !defined(__BOOT_DEFS_MK__) 3__BOOT_DEFS_MK__=${MFILE} 4 5FORTIFY_SOURCE= 0 6 7# We need to define all the MK_ options before including src.opts.mk 8# because it includes bsd.own.mk which needs the right MK_ values, 9# espeically MK_CTF. 10 11MK_CTF= no 12MK_SSP= no 13MK_PIE= no 14MK_ZEROREGS= no 15MAN= 16.if !defined(PIC) 17NO_PIC= 18INTERNALLIB= 19.endif 20# Should be NO_CPU_FLAGS, but bsd.cpu.mk is included too early in bsd.init.mk 21# via the early include of bsd.opts.mk. Moving Makefile.inc include earlier in 22# that file causes weirdness, so this is the next best thing. We need to do this 23# because the loader needs very specific flags to work right, and things like 24# CPUTYPE?=native prevent that, and introduce an endless game of whack-a-mole 25# to disable more and more features. Boot loader performance is never improved 26# enough to make that hassle worth chasing. 27_CPUCFLAGS= 28 29.if ${LDFLAGS:M-nostdlib} 30# Sanitizers won't work unless we link against libc (e.g. in userboot/test). 31MK_ASAN:= no 32MK_UBSAN:= no 33.endif 34 35.include <src.opts.mk> 36.include <bsd.linker.mk> 37 38WARNS?= 1 39 40BOOTSRC= ${SRCTOP}/stand 41EDK2INC= ${SYSDIR}/contrib/edk2/Include 42EFISRC= ${BOOTSRC}/efi 43EFIINC= ${EFISRC}/include 44# For amd64, there's a bit of mixed bag. Some of the tree (i386, lib*32) is 45# built 32-bit and some 64-bit (lib*, efi). Centralize all the 32-bit magic here 46# and activate it when DO32 is explicitly defined to be 1. 47.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1 48EFIINCMD= ${EFIINC}/i386 49.else 50EFIINCMD= ${EFIINC}/${MACHINE} 51.endif 52FDTSRC= ${BOOTSRC}/fdt 53FICLSRC= ${BOOTSRC}/ficl 54LDRSRC= ${BOOTSRC}/common 55LIBLUASRC= ${BOOTSRC}/liblua 56LIBOFWSRC= ${BOOTSRC}/libofw 57LUASRC= ${SRCTOP}/contrib/lua/src 58SASRC= ${BOOTSRC}/libsa 59SYSDIR= ${SRCTOP}/sys 60UBOOTSRC= ${BOOTSRC}/uboot 61ZFSSRC= ${SASRC}/zfs 62OZFS= ${SRCTOP}/sys/contrib/openzfs 63ZFSOSSRC= ${OZFS}/module/os/freebsd/ 64ZFSOSINC= ${OZFS}/include/os/freebsd 65LIBCSRC= ${SRCTOP}/lib/libc 66 67BOOTOBJ= ${OBJTOP}/stand 68 69# BINDIR is where we install 70BINDIR?= /boot 71 72# LUAPATH is where we search for and install lua scripts. 73LUAPATH?= /boot/lua 74FLUASRC?= ${SRCTOP}/libexec/flua 75FLUALIB?= ${SRCTOP}/libexec/flua 76 77LIBSA= ${BOOTOBJ}/libsa/libsa.a 78.if ${MACHINE} == "i386" 79LIBSA32= ${LIBSA} 80.else 81LIBSA32= ${BOOTOBJ}/libsa32/libsa32.a 82.endif 83 84# Standard options: 85CFLAGS+= -nostdinc 86# Allow CFLAGS_EARLY.file/target so that code that needs specific stack 87# of include paths can set them up before our include paths. Normally 88# the only thing that should be there are -I directives, and as few of 89# those as possible. 90CFLAGS+= ${CFLAGS_EARLY} ${CFLAGS_EARLY.${.IMPSRC:T}} ${CFLAGS_EARLY.${.TARGET:T}} 91.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1 92CFLAGS+= -I${BOOTOBJ}/libsa32 93.else 94CFLAGS+= -I${BOOTOBJ}/libsa 95.endif 96CFLAGS+= -I${SASRC} -D_STANDALONE 97CFLAGS+= -I${SYSDIR} 98# Spike the floating point interfaces 99CFLAGS+= -Ddouble=jagged-little-pill -Dfloat=floaty-mcfloatface 100.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "amd64" 101# Slim down the image. This saves about 15% in size with clang 6 on x86 102# Our most constrained /boot/loader env is BIOS booting on x86, where 103# our text + data + BTX have to fit into 640k below the ISA hole. 104# Experience has shown that problems arise between ~520k to ~530k. 105CFLAGS.clang+= -Oz 106CFLAGS.gcc+= -Os 107CFLAGS+= -ffunction-sections -fdata-sections 108.endif 109 110# GELI Support, with backward compat hooks (mostly) 111.if defined(LOADER_NO_GELI_SUPPORT) 112MK_LOADER_GELI=no 113.warning "Please move from LOADER_NO_GELI_SUPPORT to WITHOUT_LOADER_GELI" 114.endif 115.if defined(LOADER_GELI_SUPPORT) 116MK_LOADER_GELI=yes 117.warning "Please move from LOADER_GELI_SUPPORT to WITH_LOADER_GELI" 118.endif 119.if ${MK_LOADER_GELI} == "yes" 120CFLAGS+= -DLOADER_GELI_SUPPORT 121CFLAGS+= -I${SASRC}/geli 122.endif # MK_LOADER_GELI 123 124# These should be confined to loader.mk, but can't because uboot/lib 125# also uses it. It's part of loader, but isn't a loader so we can't 126# just include loader.mk 127.if ${LOADER_DISK_SUPPORT:Uyes} == "yes" 128CFLAGS+= -DLOADER_DISK_SUPPORT 129.endif 130 131# Machine specific flags for all builds here 132 133# Ensure PowerPC64 and PowerPC64LE boot loaders are compiled as 32 bit. 134# PowerPC64LE boot loaders are 32-bit little-endian. 135.if ${MACHINE_ARCH} == "powerpc64" 136CFLAGS+= -m32 -mcpu=powerpc -mbig-endian 137.elif ${MACHINE_ARCH} == "powerpc64le" 138CFLAGS+= -m32 -mcpu=powerpc -mlittle-endian 139.endif 140 141.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1 142CFLAGS+= -m32 143# LD_FLAGS is passed directly to ${LD}, not via ${CC}: 144LD_FLAGS+= -m elf_i386_fbsd 145AFLAGS+= --32 146.endif 147 148# Add in the no float / no SIMD stuff and announce we're freestanding 149# aarch64 and riscv don't have -msoft-float, but all others do. 150CFLAGS+= -ffreestanding ${CFLAGS_NO_SIMD} 151.if ${MACHINE_CPUARCH} == "aarch64" 152CFLAGS+= -mgeneral-regs-only -ffixed-x18 -fPIC 153.elif ${MACHINE_CPUARCH} == "riscv" 154CFLAGS+= -march=rv64imac -mabi=lp64 -fPIC 155CFLAGS.clang+= -mcmodel=medium 156CFLAGS.gcc+= -mcmodel=medany 157.else 158CFLAGS+= -msoft-float 159.endif 160 161# -msoft-float seems to be insufficient for powerpcspe 162.if ${MACHINE_ARCH} == "powerpcspe" 163CFLAGS+= -mno-spe 164.endif 165 166.if ${MACHINE_CPUARCH} == "i386" || (${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 1) 167CFLAGS+= -march=i386 168CFLAGS.gcc+= -mpreferred-stack-boundary=2 169.endif 170.if ${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 0 171CFLAGS+= -fPIC -mno-red-zone 172.endif 173 174.if ${MACHINE_CPUARCH} == "arm" 175# Do not generate movt/movw, because the relocation fixup for them does not 176# translate to the -Bsymbolic -pie format required by self_reloc() in loader(8). 177# Also, the fpu is not available in a standalone environment. 178CFLAGS.clang+= -mno-movt 179CFLAGS.clang+= -mfpu=none 180CFLAGS+= -fPIC 181.endif 182 183# Some RISC-V linkers have support for relaxations, while some (lld) do not 184# yet. If this is the case we inhibit the compiler from emitting relaxations. 185.if ${LINKER_FEATURES:Mriscv-relaxations} == "" 186CFLAGS+= -mno-relax 187.endif 188 189# The boot loader build uses dd status=none, where possible, for reproducible 190# build output (since performance varies from run to run). Trouble is that 191# option was recently (10.3) added to FreeBSD and is non-standard. Only use it 192# when this test succeeds rather than require dd to be a bootstrap tool. 193DD_NOSTATUS!=(dd status=none count=0 2> /dev/null && echo status=none) || true 194DD=dd ${DD_NOSTATUS} 195 196# 197# Have a sensible default 198# 199.if ${MK_LOADER_LUA} == "yes" 200LOADER_DEFAULT_INTERP?=lua 201.elif ${MK_FORTH} == "yes" 202LOADER_DEFAULT_INTERP?=4th 203.else 204LOADER_DEFAULT_INTERP?=simp 205.endif 206LOADER_INTERP?=${LOADER_DEFAULT_INTERP} 207 208# Make sure we use the machine link we're about to create 209CFLAGS+=-I. 210 211.include "${BOOTSRC}/veriexec.mk" 212 213all: ${PROG} 214 215CLEANFILES+= teken_state.h 216teken.c: teken_state.h 217 218teken_state.h: ${SYSDIR}/teken/sequences 219 awk -f ${SYSDIR}/teken/gensequences \ 220 ${SYSDIR}/teken/sequences > teken_state.h 221 222.if !defined(NO_OBJ) 223_ILINKS=include/machine 224.if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64" 225_ILINKS+=include/${MACHINE_CPUARCH} 226.endif 227.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" 228_ILINKS+=include/x86 229.endif 230CFLAGS+= -Iinclude 231CLEANDIRS+= include 232 233beforedepend: ${_ILINKS} 234beforebuild: ${_ILINKS} 235 236# Ensure that the links exist without depending on it when it exists which 237# causes all the modules to be rebuilt when the directory pointed to changes. 238.for _link in ${_ILINKS} 239.if !exists(${.OBJDIR}/${_link}) 240${OBJS}: ${_link} 241.endif # _link exists 242.endfor 243 244.NOPATH: ${_ILINKS} 245 246${_ILINKS}: .NOMETA 247 @case ${.TARGET:T} in \ 248 machine) \ 249 if [ ${DO32:U0} -eq 0 ]; then \ 250 path=${SYSDIR}/${MACHINE}/include ; \ 251 else \ 252 path=${SYSDIR}/${MACHINE:C/amd64/i386/}/include ; \ 253 fi ;; \ 254 *) \ 255 path=${SYSDIR}/${.TARGET:T}/include ;; \ 256 esac ; \ 257 case ${.TARGET} in \ 258 */*) mkdir -p ${.TARGET:H};; \ 259 esac ; \ 260 path=`(cd $$path && /bin/pwd)` ; \ 261 ${ECHO} ${.TARGET} "->" $$path ; \ 262 ln -fns $$path ${.TARGET} 263.endif # !NO_OBJ 264 265.-include "local.defs.mk" 266.endif # __BOOT_DEFS_MK__ 267