1#	$NetBSD: Makefile.amd64,v 1.86 2023/01/06 15:35:06 christos Exp $
2
3# Makefile for NetBSD
4#
5# This makefile is constructed from a machine description:
6#	config machineid
7# Most changes should be made in the machine description
8#	/sys/arch/amd64/conf/``machineid''
9# after which you should do
10#	config machineid
11# Machine generic makefile changes should be made in
12#	/sys/arch/amd64/conf/Makefile.amd64
13# after which config should be rerun for all machines of that type.
14#
15# To specify debugging, add the config line: makeoptions DEBUG="-g"
16# A better way is to specify -g only for a few files.
17#
18#	makeoptions DEBUGLIST="uvm* trap if_*"
19
20MACHINE_ARCH=x86_64
21USETOOLS?=	no
22NEED_OWN_INSTALL_TARGET?=no
23NOSANITIZER=
24.include <bsd.init.mk>
25
26USE_SSP?=	yes
27
28##
29## (1) port identification
30##
31AMD64=		$S/arch/amd64
32GENASSYM_CONF=	${AMD64}/amd64/genassym.cf
33
34##
35## (2) compile settings
36##
37DEFCOPTS=	-O2 -fno-omit-frame-pointer
38CPPFLAGS+=	-Damd64 -Dx86_64
39CFLAGS+=	-mcmodel=kernel
40# -mno-sse implies -mno-sse2 (etc), explicitly disable avx to be extra sure
41CFLAGS+=	-mno-red-zone -mno-mmx -mno-sse -mno-avx
42# make absolutely sure we don't get x87 registers used as well
43CFLAGS+=	-msoft-float
44# For gcc we might need this, but other compilers barf
45# CFLAGS+=	-mno-fp-ret-in-387
46
47.if ${SPECTRE_V2_GCC_MITIGATION:U0} > 0
48CFLAGS+=	${${ACTIVE_CC} == "gcc" :? -mindirect-branch=thunk :}
49CFLAGS+=	${${ACTIVE_CC} == "gcc" :? -mindirect-branch-register :}
50.endif
51
52.if ${KASAN:U0} > 0
53.if ${HAVE_GCC:U0} > 0
54KASANFLAGS=	-fsanitize=kernel-address \
55		--param asan-globals=1 --param asan-stack=1 \
56		--param asan-instrument-allocas=1 \
57		-fsanitize-address-use-after-scope \
58		-fasan-shadow-offset=0xDFFF900000000000
59.elif ${HAVE_LLVM:Uno} == "yes"
60KASANFLAGS=	-fsanitize=kernel-address \
61		-mllvm -asan-globals=1 -mllvm -asan-stack=1 \
62		-mllvm -asan-instrument-dynamic-allocas=1 \
63		-mllvm -asan-use-after-scope=1 \
64		-mllvm -asan-instrumentation-with-call-threshold=0 \
65		-mllvm -asan-mapping-offset=0xDFFF900000000000
66.endif
67.for f in subr_asan.c subr_kcov.c
68KASANFLAGS.${f}=	# empty
69.endfor
70CFLAGS+=	${KASANFLAGS.${.IMPSRC:T}:U${KASANFLAGS}}
71.endif
72
73.if ${KCSAN:U0} > 0 && ${HAVE_GCC:U0} > 0
74KCSANFLAGS=	-fsanitize=thread
75.for f in subr_csan.c subr_kcov.c clock.c lapic.c
76KCSANFLAGS.${f}=	# empty
77.endfor
78CFLAGS+=	${KCSANFLAGS.${.IMPSRC:T}:U${KCSANFLAGS}}
79.endif
80
81.if ${KMSAN:U0} > 0 && ${HAVE_LLVM:Uno} == "yes"
82KMSANFLAGS=	-fsanitize=kernel-memory
83.for f in subr_msan.c
84KMSANFLAGS.${f}=	# empty
85.endfor
86CFLAGS+=	${KMSANFLAGS.${.IMPSRC:T}:U${KMSANFLAGS}}
87.endif
88
89EXTRA_INCLUDES= -I$S/external/mit/xen-include-public/dist/
90
91##
92## (3) libkern and compat
93##
94OPT_MODULAR=	%MODULAR%
95
96##
97## (4) local objects, compile rules, and dependencies
98##
99
100##
101## (5) link settings
102##
103TEXTADDR?=	0xffffffff80200000
104.if defined(KASLR)
105EXTRA_LINKFLAGS=	--split-by-file=0x100000 -r -d
106KERNLDSCRIPT?= ${AMD64}/conf/kern.ldscript.kaslr
107.else
108EXTRA_LINKFLAGS=	-z max-page-size=0x200000
109KERNLDSCRIPT?= ${AMD64}/conf/kern.ldscript
110.endif
111LINKFLAGS_NORMAL=	-X
112EXTRA_LINKFLAGS+=	-z noseparate-code
113
114##
115## (6) port specific target dependencies
116##
117
118# depend on CPU configuration
119locore.o machdep.o: Makefile
120
121acpi_wakeup_low.o busfunc.o cpufunc.o cpu_in_cksum.o: assym.h
122linux_sigcode.o linux32_sigcode.o lock_stubs.o mptramp.o: assym.h
123netbsd32_sigcode.o: assym.h
124
125##
126## (7) misc settings
127##
128
129##
130## (8) config(8) generated machinery
131##
132%INCLUDES
133
134%OBJS
135
136%CFILES
137
138%SFILES
139
140%LOAD
141
142%RULES
143
144##
145## (9) port independent kernel machinery
146##
147.include "$S/conf/Makefile.kern.inc"
148
149## Include rules for ACPI wakecode
150.include "$S/arch/x86/acpi/Makefile.wakecode.inc"
151
152##
153## (10) Appending make options.
154##
155%MAKEOPTIONSAPPEND
156