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