11.86Schristos#	$NetBSD: Makefile.amd64,v 1.86 2023/01/06 15:35:06 christos Exp $
21.1Sfvdl
31.1Sfvdl# Makefile for NetBSD
41.1Sfvdl#
51.1Sfvdl# This makefile is constructed from a machine description:
61.1Sfvdl#	config machineid
71.1Sfvdl# Most changes should be made in the machine description
81.1Sfvdl#	/sys/arch/amd64/conf/``machineid''
91.1Sfvdl# after which you should do
101.1Sfvdl#	config machineid
111.1Sfvdl# Machine generic makefile changes should be made in
121.1Sfvdl#	/sys/arch/amd64/conf/Makefile.amd64
131.1Sfvdl# after which config should be rerun for all machines of that type.
141.1Sfvdl#
151.1Sfvdl# To specify debugging, add the config line: makeoptions DEBUG="-g"
161.1Sfvdl# A better way is to specify -g only for a few files.
171.1Sfvdl#
181.1Sfvdl#	makeoptions DEBUGLIST="uvm* trap if_*"
191.1Sfvdl
201.1SfvdlMACHINE_ARCH=x86_64
211.1SfvdlUSETOOLS?=	no
221.1SfvdlNEED_OWN_INSTALL_TARGET?=no
231.71SchristosNOSANITIZER=
241.71Schristos.include <bsd.init.mk>
251.1Sfvdl
261.29StronUSE_SSP?=	yes
271.29Stron
281.1Sfvdl##
291.1Sfvdl## (1) port identification
301.1Sfvdl##
311.1SfvdlAMD64=		$S/arch/amd64
321.6SchristosGENASSYM_CONF=	${AMD64}/amd64/genassym.cf
331.1Sfvdl
341.1Sfvdl##
351.1Sfvdl## (2) compile settings
361.1Sfvdl##
371.45SjakllschDEFCOPTS=	-O2 -fno-omit-frame-pointer
381.1SfvdlCPPFLAGS+=	-Damd64 -Dx86_64
391.66SmaxvCFLAGS+=	-mcmodel=kernel
401.44Sdsl# -mno-sse implies -mno-sse2 (etc), explicitly disable avx to be extra sure
411.43SdslCFLAGS+=	-mno-red-zone -mno-mmx -mno-sse -mno-avx
421.43Sdsl# make absolutely sure we don't get x87 registers used as well
431.44SdslCFLAGS+=	-msoft-float
441.44Sdsl# For gcc we might need this, but other compilers barf
451.44Sdsl# CFLAGS+=	-mno-fp-ret-in-387
461.1Sfvdl
471.85Sjoerg.if ${SPECTRE_V2_GCC_MITIGATION:U0} > 0
481.85SjoergCFLAGS+=	${${ACTIVE_CC} == "gcc" :? -mindirect-branch=thunk :}
491.85SjoergCFLAGS+=	${${ACTIVE_CC} == "gcc" :? -mindirect-branch-register :}
501.67Smrg.endif
511.67Smrg
521.83Smaxv.if ${KASAN:U0} > 0
531.83Smaxv.if ${HAVE_GCC:U0} > 0
541.73SmaxvKASANFLAGS=	-fsanitize=kernel-address \
551.73Smaxv		--param asan-globals=1 --param asan-stack=1 \
561.81Smaxv		--param asan-instrument-allocas=1 \
571.76Smaxv		-fsanitize-address-use-after-scope \
581.73Smaxv		-fasan-shadow-offset=0xDFFF900000000000
591.83Smaxv.elif ${HAVE_LLVM:Uno} == "yes"
601.83SmaxvKASANFLAGS=	-fsanitize=kernel-address \
611.83Smaxv		-mllvm -asan-globals=1 -mllvm -asan-stack=1 \
621.83Smaxv		-mllvm -asan-instrument-dynamic-allocas=1 \
631.83Smaxv		-mllvm -asan-use-after-scope=1 \
641.83Smaxv		-mllvm -asan-instrumentation-with-call-threshold=0 \
651.83Smaxv		-mllvm -asan-mapping-offset=0xDFFF900000000000
661.83Smaxv.endif
671.82Smaxv.for f in subr_asan.c subr_kcov.c
681.73SmaxvKASANFLAGS.${f}=	# empty
691.73Smaxv.endfor
701.73SmaxvCFLAGS+=	${KASANFLAGS.${.IMPSRC:T}:U${KASANFLAGS}}
711.72Smaxv.endif
721.72Smaxv
731.79Smaxv.if ${KCSAN:U0} > 0 && ${HAVE_GCC:U0} > 0
741.79SmaxvKCSANFLAGS=	-fsanitize=thread
751.82Smaxv.for f in subr_csan.c subr_kcov.c clock.c lapic.c
761.79SmaxvKCSANFLAGS.${f}=	# empty
771.79Smaxv.endfor
781.79SmaxvCFLAGS+=	${KCSANFLAGS.${.IMPSRC:T}:U${KCSANFLAGS}}
791.79Smaxv.endif
801.79Smaxv
811.80Smaxv.if ${KMSAN:U0} > 0 && ${HAVE_LLVM:Uno} == "yes"
821.80SmaxvKMSANFLAGS=	-fsanitize=kernel-memory
831.80Smaxv.for f in subr_msan.c
841.80SmaxvKMSANFLAGS.${f}=	# empty
851.80Smaxv.endfor
861.80SmaxvCFLAGS+=	${KMSANFLAGS.${.IMPSRC:T}:U${KMSANFLAGS}}
871.80Smaxv.endif
881.80Smaxv
891.84SbouyerEXTRA_INCLUDES= -I$S/external/mit/xen-include-public/dist/
901.84Sbouyer
911.1Sfvdl##
921.1Sfvdl## (3) libkern and compat
931.1Sfvdl##
941.41SchristosOPT_MODULAR=	%MODULAR%
951.1Sfvdl
961.1Sfvdl##
971.1Sfvdl## (4) local objects, compile rules, and dependencies
981.1Sfvdl##
991.1Sfvdl
1001.1Sfvdl##
1011.1Sfvdl## (5) link settings
1021.1Sfvdl##
1031.56SmaxvTEXTADDR?=	0xffffffff80200000
1041.59Smaxv.if defined(KASLR)
1051.64SmaxvEXTRA_LINKFLAGS=	--split-by-file=0x100000 -r -d
1061.61SmaxvKERNLDSCRIPT?= ${AMD64}/conf/kern.ldscript.kaslr
1071.59Smaxv.else
1081.57SmaxvEXTRA_LINKFLAGS=	-z max-page-size=0x200000
1091.61SmaxvKERNLDSCRIPT?= ${AMD64}/conf/kern.ldscript
1101.59Smaxv.endif
1111.1SfvdlLINKFLAGS_NORMAL=	-X
1121.86SchristosEXTRA_LINKFLAGS+=	-z noseparate-code
1131.1Sfvdl
1141.1Sfvdl##
1151.1Sfvdl## (6) port specific target dependencies
1161.1Sfvdl##
1171.1Sfvdl
1181.1Sfvdl# depend on CPU configuration
1191.1Sfvdllocore.o machdep.o: Makefile
1201.1Sfvdl
1211.78Smaxvacpi_wakeup_low.o busfunc.o cpufunc.o cpu_in_cksum.o: assym.h
1221.60Smaxvlinux_sigcode.o linux32_sigcode.o lock_stubs.o mptramp.o: assym.h
1231.25Sjoergnetbsd32_sigcode.o: assym.h
1241.1Sfvdl
1251.1Sfvdl##
1261.1Sfvdl## (7) misc settings
1271.1Sfvdl##
1281.1Sfvdl
1291.1Sfvdl##
1301.1Sfvdl## (8) config(8) generated machinery
1311.1Sfvdl##
1321.1Sfvdl%INCLUDES
1331.1Sfvdl
1341.1Sfvdl%OBJS
1351.1Sfvdl
1361.1Sfvdl%CFILES
1371.1Sfvdl
1381.1Sfvdl%SFILES
1391.1Sfvdl
1401.1Sfvdl%LOAD
1411.1Sfvdl
1421.1Sfvdl%RULES
1431.26Salc
1441.1Sfvdl##
1451.1Sfvdl## (9) port independent kernel machinery
1461.1Sfvdl##
1471.1Sfvdl.include "$S/conf/Makefile.kern.inc"
1481.5Sthorpej
1491.39Schristos## Include rules for ACPI wakecode
1501.39Schristos.include "$S/arch/x86/acpi/Makefile.wakecode.inc"
1511.39Schristos
1521.5Sthorpej##
1531.5Sthorpej## (10) Appending make options.
1541.5Sthorpej##
1551.5Sthorpej%MAKEOPTIONSAPPEND
156