xref: /openbsd-src/sys/arch/arm64/conf/Makefile.arm64 (revision 35e332b4d486548d643c15788f0c52e9da31eb9a)
1#	$OpenBSD: Makefile.arm64,v 1.49 2024/07/11 12:07:40 kettenis Exp $
2
3# For instructions on building kernels consult the config(8) and options(4)
4# manual pages.
5#
6# N.B.: NO DEPENDENCIES ON FOLLOWING FLAGS ARE VISIBLE TO MAKEFILE
7#	IF YOU CHANGE THE DEFINITION OF ANY OF THESE RECOMPILE EVERYTHING
8# DEBUG is set to -g by config if debugging is requested (config -g).
9# PROF is set to -pg by config if profiling is requested (config -p).
10
11.include <bsd.own.mk>
12
13SIZE?=	size
14STRIP?=	ctfstrip
15
16# source tree is located via $S relative to the compilation directory
17.ifndef S
18S!=	cd ../../../..; pwd
19.endif
20
21_machdir?=	$S/arch/${_mach}
22_archdir?=	$S/arch/${_arch}
23
24INCLUDES=	-nostdinc -I$S -I${.OBJDIR} -I$S/arch \
25		-I$S/dev/pci/drm/include \
26		-I$S/dev/pci/drm/include/uapi \
27		-I$S/dev/pci/drm/amd/include/asic_reg \
28		-I$S/dev/pci/drm/amd/include \
29		-I$S/dev/pci/drm/amd/amdgpu \
30		-I$S/dev/pci/drm/amd/display \
31		-I$S/dev/pci/drm/amd/display/include \
32		-I$S/dev/pci/drm/amd/display/dc \
33		-I$S/dev/pci/drm/amd/display/amdgpu_dm \
34		-I$S/dev/pci/drm/amd/pm/inc \
35		-I$S/dev/pci/drm/amd/pm/legacy-dpm \
36		-I$S/dev/pci/drm/amd/pm/swsmu \
37		-I$S/dev/pci/drm/amd/pm/swsmu/inc \
38		-I$S/dev/pci/drm/amd/pm/swsmu/smu11 \
39		-I$S/dev/pci/drm/amd/pm/swsmu/smu12 \
40		-I$S/dev/pci/drm/amd/pm/swsmu/smu13 \
41		-I$S/dev/pci/drm/amd/pm/powerplay/inc \
42		-I$S/dev/pci/drm/amd/pm/powerplay/hwmgr \
43		-I$S/dev/pci/drm/amd/pm/powerplay/smumgr \
44		-I$S/dev/pci/drm/amd/pm/swsmu/inc \
45		-I$S/dev/pci/drm/amd/pm/swsmu/inc/pmfw_if \
46		-I$S/dev/pci/drm/amd/display/dc/inc \
47		-I$S/dev/pci/drm/amd/display/dc/inc/hw \
48		-I$S/dev/pci/drm/amd/display/dc/clk_mgr \
49		-I$S/dev/pci/drm/amd/display/modules/inc \
50		-I$S/dev/pci/drm/amd/display/modules/hdcp \
51		-I$S/dev/pci/drm/amd/display/dmub/inc
52CPPFLAGS=	${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -D__${_mach}__ -MD -MP
53CWARNFLAGS=	-Werror -Wall -Wimplicit-function-declaration \
54		-Wno-pointer-sign \
55		-Wno-constant-conversion -Wno-address-of-packed-member \
56		-Wno-unused-but-set-variable -Wno-gnu-folding-constant \
57		-Wframe-larger-than=2047
58
59CMACHFLAGS=	-march=armv8-a+nofp+nosimd+rng \
60		-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer \
61		-ffixed-x18
62CMACHFLAGS+=	-ffreestanding ${NOPIE_FLAGS}
63CMACHFLAGS+=	-moutline-atomics
64SORTR=		sort -R
65.if ${IDENT:M-DNO_PROPOLICE}
66CMACHFLAGS+=	-fno-stack-protector
67.endif
68.if ${IDENT:M-DSMALL_KERNEL}
69SORTR=		cat
70COPTIMIZE?=	-Oz
71CMACHFLAGS+=	-mbranch-protection=none
72.else
73CMACHFLAGS+=	-mbranch-protection=bti
74.endif
75
76DEBUG?=		-g
77COPTIMIZE?=	-O2
78CFLAGS=		${DEBUG} ${CWARNFLAGS} ${CMACHFLAGS} ${COPTIMIZE} ${COPTS} ${PIPE}
79AFLAGS=		-D_LOCORE -x assembler-with-cpp ${CWARNFLAGS} ${CMACHFLAGS}
80LINKFLAGS=	-T ld.script -X --warn-common -nopie
81
82HOSTCC?=	${CC}
83HOSTED_CPPFLAGS=${CPPFLAGS:S/^-nostdinc$//}
84HOSTED_CFLAGS=	${CFLAGS}
85HOSTED_C=	${HOSTCC} ${HOSTED_CFLAGS} ${HOSTED_CPPFLAGS} -c $<
86
87NORMAL_C_NOP=	${CC} ${CFLAGS} ${CPPFLAGS} -fno-ret-protector -c $<
88NORMAL_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
89NORMAL_S=	${CC} ${AFLAGS} ${CPPFLAGS} ${PROF} -c $<
90
91%OBJS
92
93%CFILES
94
95%SFILES
96
97# load lines for config "xxx" will be emitted as:
98# xxx: ${SYSTEM_DEP} swapxxx.o
99#	${SYSTEM_LD_HEAD}
100#	${SYSTEM_LD} swapxxx.o
101#	${SYSTEM_LD_TAIL}
102SYSTEM_HEAD=	locore0.o gap.o
103SYSTEM_OBJ=	${SYSTEM_HEAD} ${OBJS} param.o ioconf.o
104SYSTEM_DEP=	Makefile ${SYSTEM_OBJ} ld.script
105SYSTEM_LD_HEAD=	@rm -f $@
106SYSTEM_LD=	@echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_HEAD} vers.o $${OBJS}'; \
107		umask 007; \
108		echo ${OBJS} param.o ioconf.o vers.o | tr " " "\n" | ${SORTR} > lorder; \
109		${LD} ${LINKFLAGS} -o $@ ${SYSTEM_HEAD} `cat lorder`
110SYSTEM_LD_TAIL=	@${SIZE} $@
111
112.if ${DEBUG} == "-g"
113STRIPFLAGS=	-S
114SYSTEM_LD_TAIL+=; umask 007; \
115		echo mv $@ $@.gdb; rm -f $@.gdb; mv $@ $@.gdb; \
116		echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
117		${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
118.else
119LINKFLAGS+=	-S
120.endif
121
122%LOAD
123
124# cc's -MD puts the source and output paths in the dependency file;
125# since those are temp files here we need to fix it up.  It also
126# puts the file in /tmp, so we use -MF to put it in the current
127# directory as assym.P and then generate assym.d from it with a
128# good target name
129assym.h: $S/kern/genassym.sh Makefile \
130	 ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf
131	cat ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf | \
132	    sh $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} -no-integrated-as -MF assym.P > assym.h.tmp
133	sed '1s/.*/assym.h: \\/' assym.P > assym.d
134	sort -u assym.h.tmp > assym.h
135
136param.c: $S/conf/param.c
137	rm -f param.c
138	cp $S/conf/param.c .
139
140param.o: param.c Makefile
141	${NORMAL_C}
142
143mcount.o: $S/lib/libkern/mcount.c Makefile
144	${NORMAL_C_NOP}
145
146ioconf.o: ioconf.c
147	${NORMAL_C}
148
149ld.script: ${_archdir}/conf/kern.ldscript
150	cat ${_archdir}/conf/kern.ldscript | \
151	    sed -e 's/@KERNEL_BASE_PHYS@/${KERNEL_BASE_PHYS}/' \
152	    -e 's/@KERNEL_BASE_VIRT@/${KERNEL_BASE_VIRT}/' > ld.script
153gapdummy.o:
154	echo '__asm(".section .rodata,\"a\"");' > gapdummy.c
155	${CC} -c ${CFLAGS} ${CPPFLAGS} gapdummy.c -o $@
156
157makegap.sh:
158	cp $S/conf/makegap.sh $@
159
160MAKE_GAP = LD="${LD}" sh makegap.sh 0xd4d4d4d4 gapdummy.o
161
162gap.o:	Makefile makegap.sh gapdummy.o vers.o
163	${MAKE_GAP}
164
165vers.o: ${SYSTEM_DEP:Ngap.o}
166	sh $S/conf/newvers.sh
167	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
168
169clean:
170	rm -f *bsd *bsd.gdb *.[dio] [a-z]*.s assym.* \
171	    gap.link gapdummy.c ld.script lorder makegap.sh param.c
172
173cleandir: clean
174	rm -f Makefile *.h ioconf.c options machine ${_mach} vers.c
175
176depend obj:
177
178locore0.o: ${_archdir}/${_arch}/locore0.S assym.h
179copy.o copystr.o: assym.h
180cpuswitch.o exception.o support.o: assym.h
181locore.o trampoline.o: assym.h
182
183hardlink-obsd:
184	[[ ! -f /bsd ]] || cmp -s bsd /bsd || ln -f /bsd /obsd
185
186newinstall:
187	install -F -m 700 bsd /bsd && sha256 -h /var/db/kernel.SHA256 /bsd
188
189install: update-link hardlink-obsd newinstall
190
191# pull in the dependency information
192.ifnmake clean
193. for o in ${SYSTEM_OBJ:Ngap.o} assym.h
194.  if exists(${o:R}.d)
195.   include "${o:R}.d"
196.  elif exists($o)
197    .PHONY: $o
198.  endif
199. endfor
200.endif
201
202%RULES
203