1#	$NetBSD: Makefile.riscv,v 1.11 2024/02/25 14:27:41 skrll 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/<machine>/conf/``machineid''
9# after which you should do
10#	config machineid
11# Machine generic makefile changes should be made in
12#	/sys/arch/riscv/conf/Makefile.riscv
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
20USETOOLS?=	no
21NEED_OWN_INSTALL_TARGET?=no
22.include <bsd.own.mk>
23
24
25.if !defined(LP64) && ${MACHINE_ARCH} == "riscv64"
26. info (Building GENERIC instead of GENERIC64?)
27. error Don't build 32-bit kernel with 64-bit toolchain
28.endif
29
30.if defined(LP64) && ${MACHINE_ARCH} == "riscv32"
31. info (Building GENERIC64 instead of GENERIC?)
32. error Don't build 64-bit kernel with 32-bit toolchain
33.endif
34
35
36##
37## (1) port identification
38##
39.ifndef S
40S=		../../../..
41.endif
42THISRISCV=	$S/arch/${MACHINE}
43RISCV=		$S/arch/riscv
44GENASSYM_CONF=	${RISCV}/riscv/genassym.cf
45.-include "${THISRISCV}/conf/Makefile.${MACHINE}.inc"
46
47##
48## (2) compile settings
49##
50## Note: -ffixed-?? must be kept in sync with cpu.h.
51##
52CPPFLAGS+=	-D${MACHINE}
53CFLAGS+=	-mcmodel=medany
54AFLAGS+=	-x assembler-with-cpp ${AOPTS}
55
56##
57## (3) libkern and compat
58##
59OPT_MODULAR=	%MODULAR%
60
61##
62## (4) local objects, compile rules, and dependencies
63##
64MD_OBJS=	locore.o
65MD_CFILES=
66MD_SFILES=	${RISCV}/riscv/locore.S
67
68locore.o: ${RISCV}/riscv/locore.S assym.h
69	${NORMAL_S}
70
71##
72## (5) link settings
73##
74.if ${MACHINE_ARCH} == "riscv64" && ${LP64:Uyes} == "yes"
75TEXTADDR?=		0xFFFFFFC000000000
76.else
77TEXTADDR?=		0x80200000
78.endif
79KERNLDSCRIPT?=		${RISCV}/conf/kern.ldscript
80EXTRA_LINKFLAGS=	${LDOPTS} --relax
81LINKFLAGS_NORMAL=	-X
82OBJCOPY_STRIPFLAGS=	-g -X
83
84# Set the physical load address (aka LMA) to the address that OpenSBI's
85# fw_jump jumps to.  This allows us to load the kernel with the -kernel flag
86# in QEMU without having to embed it inside BBL or OpenSBI's fw_payload first.
87#
88KERNEL_PHYS?=		0x80200000
89EXTRA_LINKFLAGS+=	--defsym='KERNEL_PHYS=${KERNEL_PHYS}'
90
91##
92## (6) port specific target dependencies
93##
94
95# depend on CPU configuration
96machdep.o mainbus.o trap.o: Makefile
97
98# depend on System V IPC/shmem options
99riscv_machdep.o pmap.o: Makefile
100
101# various assembly files that depend on assym.h
102locore.o: assym.h
103
104##
105## (7) misc settings
106##
107RAMDISKDIR!=    cd ${NETBSDSRCDIR}/distrib/riscv/ramdisk && ${PRINTOBJDIR}
108
109.if defined(NEED_MDSETIMAGE) && ${NEED_MDSETIMAGE} != "no" \
110    && defined(RAMDISKDIR) && exists(${RAMDISKDIR}/ramdisk.fs)
111SYSTEM_DEP+=    ${RAMDISKDIR}/ramdisk.fs
112SYSTEM_LD_TAIL_EXTRA+=; \
113	echo ${TOOL_MDSETIMAGE} -s $@ ${RAMDISKDIR}/ramdisk.fs; \
114	${TOOL_MDSETIMAGE} -s $@ ${RAMDISKDIR}/ramdisk.fs
115.if !empty(DEBUG:M-g*)
116SYSTEM_LD_TAIL_EXTRA+=; \
117	echo ${TOOL_MDSETIMAGE} -s $@.gdb ${RAMDISKDIR}/ramdisk.fs; \
118	${TOOL_MDSETIMAGE} -s $@.gdb ${RAMDISKDIR}/ramdisk.fs
119.endif
120.endif
121
122##
123## (8) config(8) generated machinery
124##
125%INCLUDES
126
127%OBJS
128
129%CFILES
130
131%SFILES
132
133%LOAD
134
135%RULES
136
137##
138## (9) port independent kernel machinery
139##
140.include "$S/conf/Makefile.kern.inc"
141
142##
143## (10) Appending make options.
144##
145%MAKEOPTIONSAPPEND
146