1#	$NetBSD: genassym.cf,v 1.16 2024/04/06 10:08:54 skrll Exp $
2
3#-
4# Copyright (c) 2014 The NetBSD Foundation, Inc.
5# All rights reserved.
6#
7# This code is derived from software contributed to The NetBSD Foundation
8# by Matt Thomas of 3am Software Foundry.
9#
10# Redistribution and use in source and binary forms, with or without
11# modification, are permitted provided that the following conditions
12# are met:
13# 1. Redistributions of source code must retain the above copyright
14#    notice, this list of conditions and the following disclaimer.
15# 2. Redistributions in binary form must reproduce the above copyright
16#    notice, this list of conditions and the following disclaimer in the
17#    documentation and/or other materials provided with the distribution.
18#
19# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29# POSSIBILITY OF SUCH DAMAGE.
30#+
31
32quote #define __MUTEX_PRIVATE
33quote #define __RWLOCK_PRIVATE
34quote #define __INTR_PRIVATE
35quote #define __PMAP_PRIVATE
36quote #define __RVSBI_LEGACY
37
38include <sys/param.h>
39
40include <sys/bitops.h>
41include <sys/bus.h>
42include <sys/cpu.h>
43include <sys/intr.h>
44include <sys/lwp.h>
45include <sys/mutex.h>
46include <sys/proc.h>
47include <sys/rwlock.h>
48
49include <uvm/uvm_extern.h>
50
51include <riscv/locore.h>
52include <riscv/frame.h>
53include <riscv/sysreg.h>
54include <riscv/sbi.h>
55
56define	SR_SUM		SR_SUM
57define	SR_SPP		SR_SPP
58define	SR_SIE		SR_SIE
59define	SR_FS		SR_FS
60# define	SR_PS		SR_PS
61# define	SR_S		SR_S
62define	SR_SUM		SR_SUM
63
64define	SIE_SEIE	SIE_SEIE
65define	SIE_STIE	SIE_STIE
66define	SIE_SSIE	SIE_SSIE
67
68define	SIP_SEIP	SIP_SEIP
69define	SIP_STIP	SIP_STIP
70define	SIP_SSIP	SIP_SSIP
71
72define	CAUSE_SYSCALL	CAUSE_SYSCALL
73
74ifdef _LP64
75define	SATP_MODE_MASK	SATP_MODE
76define	SATP_MODE_SV39	__SHIFTIN(SATP_MODE_SV39, SATP_MODE)
77define	SATP_MODE_SV48	__SHIFTIN(SATP_MODE_SV48, SATP_MODE)
78else
79define	SATP_MODE_SV32	__SHIFTIN(SATP_MODE_SV32, SATP_MODE)
80endif
81
82define	IPL_HIGH	IPL_HIGH
83#define	IPL_DDB		IPL_DDB
84define	IPL_SCHED	IPL_SCHED
85define	IPL_VM		IPL_VM
86define	IPL_SOFTSERIAL	IPL_SOFTSERIAL
87define	IPL_SOFTNET	IPL_SOFTNET
88define	IPL_SOFTBIO	IPL_SOFTBIO
89define	IPL_SOFTCLOCK	IPL_SOFTCLOCK
90define	IPL_NONE	IPL_NONE
91
92define	MAXCPUS		MAXCPUS
93
94define	TF_LEN		sizeof(struct trapframe)
95define	TF_RA		offsetof(struct trapframe, tf_reg[_X_RA])
96define	TF_S0		offsetof(struct trapframe, tf_reg[_X_S0])
97define	TF_S1		offsetof(struct trapframe, tf_reg[_X_S1])
98define	TF_S2		offsetof(struct trapframe, tf_reg[_X_S2])
99define	TF_S3		offsetof(struct trapframe, tf_reg[_X_S3])
100define	TF_S4		offsetof(struct trapframe, tf_reg[_X_S4])
101define	TF_S5		offsetof(struct trapframe, tf_reg[_X_S5])
102define	TF_S6		offsetof(struct trapframe, tf_reg[_X_S6])
103define	TF_S7		offsetof(struct trapframe, tf_reg[_X_S7])
104define	TF_S8		offsetof(struct trapframe, tf_reg[_X_S8])
105define	TF_S9		offsetof(struct trapframe, tf_reg[_X_S9])
106define	TF_S10		offsetof(struct trapframe, tf_reg[_X_S10])
107define	TF_S11		offsetof(struct trapframe, tf_reg[_X_S11])
108define	TF_SP		offsetof(struct trapframe, tf_reg[_X_SP])
109define	TF_TP		offsetof(struct trapframe, tf_reg[_X_TP])
110define	TF_A0		offsetof(struct trapframe, tf_reg[_X_A0])
111define	TF_A1		offsetof(struct trapframe, tf_reg[_X_A1])
112define	TF_A2		offsetof(struct trapframe, tf_reg[_X_A2])
113define	TF_A3		offsetof(struct trapframe, tf_reg[_X_A3])
114define	TF_A4		offsetof(struct trapframe, tf_reg[_X_A4])
115define	TF_A5		offsetof(struct trapframe, tf_reg[_X_A5])
116define	TF_A6		offsetof(struct trapframe, tf_reg[_X_A6])
117define	TF_A7		offsetof(struct trapframe, tf_reg[_X_A7])
118define	TF_T0		offsetof(struct trapframe, tf_reg[_X_T0])
119define	TF_T1		offsetof(struct trapframe, tf_reg[_X_T1])
120define	TF_T2		offsetof(struct trapframe, tf_reg[_X_T2])
121define	TF_T3		offsetof(struct trapframe, tf_reg[_X_T3])
122define	TF_T4		offsetof(struct trapframe, tf_reg[_X_T4])
123define	TF_T5		offsetof(struct trapframe, tf_reg[_X_T5])
124define	TF_T6		offsetof(struct trapframe, tf_reg[_X_T6])
125define	TF_GP		offsetof(struct trapframe, tf_reg[_X_GP])
126define	TF_PC		offsetof(struct trapframe, tf_pc)
127define	TF_CAUSE	offsetof(struct trapframe, tf_cause)
128define	TF_TVAL		offsetof(struct trapframe, tf_tval)
129define	TF_SR		offsetof(struct trapframe, tf_sr)
130
131define	L_CPU		offsetof(struct lwp, l_cpu)
132define	L_MD_ASTPENDING	offsetof(struct lwp, l_md.md_astpending)
133define	L_MD_ONFAULT	offsetof(struct lwp, l_md.md_onfault)
134define	L_MD_USP	offsetof(struct lwp, l_md.md_usp)
135define	L_MD_UTF	offsetof(struct lwp, l_md.md_utf)
136define	L_MD_KTF	offsetof(struct lwp, l_md.md_ktf)
137define	L_PCB		offsetof(struct lwp, l_addr)
138define	L_PROC		offsetof(struct lwp, l_proc)
139
140define	P_MD_SYSCALL	offsetof(struct proc, p_md.md_syscall)
141
142define	CI_SIZE		sizeof(struct cpu_info)
143define	CI_CPL		offsetof(struct cpu_info, ci_cpl)
144define	CI_CURLWP	offsetof(struct cpu_info, ci_curlwp)
145define	CI_INTR_DEPTH	offsetof(struct cpu_info, ci_intr_depth)
146define	CI_IDLELWP	offsetof(struct cpu_info, ci_data.cpu_idlelwp)
147define	CI_MTX_COUNT	offsetof(struct cpu_info, ci_mtx_count)
148define	CI_MTX_OLDSPL	offsetof(struct cpu_info, ci_mtx_oldspl)
149define	CI_SOFTINTS	offsetof(struct cpu_info, ci_softints)
150
151define	FB_LEN		sizeof(struct faultbuf)
152define	FB_A0		offsetof(struct faultbuf, fb_reg[FB_A0])
153define	FB_RA		offsetof(struct faultbuf, fb_reg[FB_RA])
154define	FB_S0		offsetof(struct faultbuf, fb_reg[FB_S0])
155define	FB_S1		offsetof(struct faultbuf, fb_reg[FB_S1])
156define	FB_S2		offsetof(struct faultbuf, fb_reg[FB_S2])
157define	FB_S3		offsetof(struct faultbuf, fb_reg[FB_S3])
158define	FB_S4		offsetof(struct faultbuf, fb_reg[FB_S4])
159define	FB_S5		offsetof(struct faultbuf, fb_reg[FB_S5])
160define	FB_S6		offsetof(struct faultbuf, fb_reg[FB_S6])
161define	FB_S7		offsetof(struct faultbuf, fb_reg[FB_S7])
162define	FB_S8		offsetof(struct faultbuf, fb_reg[FB_S8])
163define	FB_S9		offsetof(struct faultbuf, fb_reg[FB_S9])
164define	FB_S10		offsetof(struct faultbuf, fb_reg[FB_S10])
165define	FB_S11		offsetof(struct faultbuf, fb_reg[FB_S11])
166define	FB_SP		offsetof(struct faultbuf, fb_reg[FB_SP])
167define	FB_SR		offsetof(struct faultbuf, fb_sr)
168
169define	EFAULT		EFAULT
170
171define	PAGE_SIZE	PAGE_SIZE
172define	PAGE_MASK	PAGE_MASK
173define	PAGE_SHIFT	PAGE_SHIFT
174define	UPAGES		UPAGES
175define	USRSTACK	USRSTACK
176
177ifdef	__HAVE_FAST_SOFTINTS
178define	__HAVE_FAST_SOFTINTS	1
179endif
180
181ifdef	__HAVE_MUTEX_STUBS
182define	__HAVE_MUTEX_STUBS	1
183endif
184
185ifdef	__HAVE_MUTEX_SPIN_STUBS
186define	__HAVE_MUTEX_SPIN_STUBS	1
187endif
188
189ifdef	__HAVE_RW_STUBS
190define	__HAVE_RW_STUBS		1
191endif
192
193define	RW_OWNER	offsetof(struct krwlock, rw_owner)
194define	RW_WRITE_LOCKED	RW_WRITE_LOCKED
195define	RW_READ_INCR	RW_READ_INCR
196define	RW_READER	RW_READER
197
198define	VM_MAXUSER_ADDRESS	VM_MAXUSER_ADDRESS
199define	VM_MIN_KERNEL_ADDRESS	VM_MIN_KERNEL_ADDRESS
200define	VM_MAX_KERNEL_ADDRESS	VM_MAX_KERNEL_ADDRESS
201define	VM_KERNEL_BASE		VM_KERNEL_BASE
202define	VM_KERNEL_SIZE		VM_KERNEL_SIZE
203define	VM_KERNEL_DTB_BASE	VM_KERNEL_DTB_BASE
204define	VM_KERNEL_DTB_SIZE	VM_KERNEL_DTB_SIZE
205define	VM_KERNEL_IO_BASE	VM_KERNEL_IO_BASE
206define	VM_KERNEL_IO_BASE	VM_KERNEL_IO_BASE
207
208define	USPACE		USPACE
209ifdef XSEGSHIFT
210define	XSEGSHIFT	XSEGSHIFT
211endif
212define	SEGSHIFT	SEGSHIFT
213define	PGSHIFT		PGSHIFT
214define	NPDEPG		NPDEPG
215define	NBSEG		NBSEG
216
217# Constants from pte.h
218define	PTE_D		PTE_D
219define	PTE_A		PTE_A
220define	PTE_G		PTE_G
221define	PTE_U		PTE_U
222define	PTE_X		PTE_X
223define	PTE_W		PTE_W
224define	PTE_R		PTE_R
225define	PTE_V		PTE_V
226
227define	PTE_KERN	PTE_KERN
228define	PTE_HARDWIRED	PTE_HARDWIRED
229
230#define	PTE_PPN0_S	PTE_PPN0_S
231#define	PTE_PPN1_S	PTE_PPN1_S
232#define	PTE_PPN2_S	PTE_PPN2_S
233#define	PTE_PPN3_S	PTE_PPN3_S
234#define	PTE_SIZE	PTE_SIZE
235define	PTE_PPN_SHIFT	PTE_PPN_SHIFT
236
237define	PM_PDETAB	offsetof(struct pmap, pm_pdetab)
238define	PM_MD_PPN	offsetof(struct pmap, pm_md.md_ppn)
239
240define	SBI_LEGACY_CONSOLE_PUTCHAR	SBI_LEGACY_CONSOLE_PUTCHAR
241
242# for bus_space_asm
243define	BS_STRIDE		offsetof(struct bus_space, bs_stride)
244