1#	$NetBSD: genassym.cf,v 1.97 2023/10/04 20:28:05 ad Exp $
2
3#
4# Copyright (c) 1998, 2006, 2007, 2008, 2023 The NetBSD Foundation, Inc.
5# All rights reserved.
6#
7# This code is derived from software contributed to The NetBSD Foundation
8# by Charles M. Hannum, and by Andrew Doran.
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
32#
33# Copyright (c) 1982, 1990 The Regents of the University of California.
34# All rights reserved.
35#
36# This code is derived from software contributed to Berkeley by
37# William Jolitz.
38#
39# Redistribution and use in source and binary forms, with or without
40# modification, are permitted provided that the following conditions
41# are met:
42# 1. Redistributions of source code must retain the above copyright
43#    notice, this list of conditions and the following disclaimer.
44# 2. Redistributions in binary form must reproduce the above copyright
45#    notice, this list of conditions and the following disclaimer in the
46#    documentation and/or other materials provided with the distribution.
47# 3. Neither the name of the University nor the names of its contributors
48#    may be used to endorse or promote products derived from this software
49#    without specific prior written permission.
50#
51# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61# SUCH DAMAGE.
62#
63#	@(#)genassym.c	5.11 (Berkeley) 5/10/91
64#
65
66if defined(_KERNEL_OPT)
67include "opt_compat_netbsd32.h"
68include "opt_compat_linux32.h"
69include "opt_xen.h"
70endif
71
72if defined(_KERNEL) && defined(_KERNEL_OPT)
73include "isa.h"
74include "ioapic.h"
75endif
76
77quote #define __MUTEX_PRIVATE
78quote #define __RWLOCK_PRIVATE
79
80include <sys/param.h>
81include <sys/proc.h>
82include <sys/resourcevar.h>
83include <sys/device.h>
84include <sys/mbuf.h>
85include <sys/mutex.h>
86include <sys/rwlock.h>
87include <sys/cpu_data.h>
88include <sys/evcnt.h>
89include <sys/cpu.h>
90include <sys/acl.h>
91
92include <netinet/in.h>
93include <netinet/in_systm.h>
94include <netinet/ip.h>
95include <netinet/ip_var.h>
96
97include <uvm/uvm.h>
98
99include <machine/trap.h>
100include <machine/pmap.h>
101include <machine/pmap_private.h>
102include <machine/vmparam.h>
103include <machine/intr.h>
104include <machine/types.h>
105include <machine/cpufunc.h>
106
107if defined(COMPAT_NETBSD32)
108include <machine/netbsd32_machdep.h>
109endif
110
111if defined(COMPAT_LINUX32)
112include <machine/linux32_machdep.h>
113endif
114
115if NISA > 0
116include <machine/isa_machdep.h>
117endif
118
119if NIOAPIC > 0
120include <machine/i82093reg.h>
121include <machine/i82093var.h>
122endif
123
124ifdef XEN
125include <xen/include/public/xen.h>
126include <xen/include/public/arch-x86/hvm/start_info.h>
127endif
128
129include <sys/bus.h>
130
131# general constants
132define	PAGE_SIZE		PAGE_SIZE
133define	UPAGES			UPAGES
134define	USPACE			USPACE
135define	PGOFSET			PGOFSET
136define	PGSHIFT			PGSHIFT
137
138define	KERNBASE_LO		KERNBASE_LO
139define	KERNBASE_HI		KERNBASE_HI
140define	KERNBASE		KERNBASE
141define	KERNTEXTOFF_LO		KERNTEXTOFF_LO
142define	KERNTEXTOFF		KERNTEXTOFF
143
144define	NBPG			NBPG
145
146define	L4_SLOT_KERNBASE	L4_SLOT_KERNBASE
147define	L3_SLOT_KERNBASE	pl3_pi(KERNBASE)
148define	L2_SLOT_KERNBASE	pl2_pi(KERNBASE)
149define	L1_SLOT_KERNBASE	pl1_pi(KERNBASE)
150
151define	PDE_SIZE		sizeof(pd_entry_t)
152
153define	VM_MAXUSER_ADDRESS	(unsigned long long)VM_MAXUSER_ADDRESS
154
155# lwp & proc fields and values
156define	L_PCB			offsetof(struct lwp, l_addr)
157define	L_CPU			offsetof(struct lwp, l_cpu)
158define	L_FLAG			offsetof(struct lwp, l_flag)
159define	L_PROC			offsetof(struct lwp, l_proc)
160define	L_RU			offsetof(struct lwp, l_ru)
161define	L_NOPREEMPT		offsetof(struct lwp, l_nopreempt)
162define	L_DOPREEMPT		offsetof(struct lwp, l_dopreempt)
163define	L_MD_REGS		offsetof(struct lwp, l_md.md_regs)
164define	L_MD_FLAGS		offsetof(struct lwp, l_md.md_flags)
165define	L_MD_ASTPENDING		offsetof(struct lwp, l_md.md_astpending)
166
167define	RU_NIVCSW		offsetof(struct rusage, ru_nivcsw)
168
169define	LW_SYSTEM		LW_SYSTEM
170define	MDL_IRET		MDL_IRET
171define	MDL_COMPAT32		MDL_COMPAT32
172define	MDL_FPU_IN_CPU		MDL_FPU_IN_CPU
173
174define	P_FLAG			offsetof(struct proc, p_flag)
175define	P_RASLIST		offsetof(struct proc, p_raslist)
176define	P_MD_SYSCALL		offsetof(struct proc, p_md.md_syscall)
177
178# pcb fields
179define	PCB_CR3			offsetof(struct pcb, pcb_cr3)
180define	PCB_CR0			offsetof(struct pcb, pcb_cr0)
181define	PCB_ONFAULT		offsetof(struct pcb, pcb_onfault)
182define	PCB_RBP			offsetof(struct pcb, pcb_rbp)
183define	PCB_RSP			offsetof(struct pcb, pcb_rsp)
184define	PCB_RSP0		offsetof(struct pcb, pcb_rsp0)
185define	PCB_FLAGS		offsetof(struct pcb, pcb_flags)
186define	PCB_COMPAT32		PCB_COMPAT32
187define	PCB_FS			offsetof(struct pcb, pcb_fs)
188define	PCB_GS			offsetof(struct pcb, pcb_gs)
189define	PCB_SAVEFPU		offsetof(struct pcb, pcb_savefpu)
190
191define	TF_RDI			offsetof(struct trapframe, tf_rdi)
192define	TF_RSI			offsetof(struct trapframe, tf_rsi)
193define	TF_RDX			offsetof(struct trapframe, tf_rdx)
194define	TF_RCX			offsetof(struct trapframe, tf_rcx)
195define	TF_R8			offsetof(struct trapframe, tf_r8)
196define	TF_R9			offsetof(struct trapframe, tf_r9)
197define	TF_R10			offsetof(struct trapframe, tf_r10)
198define	TF_R11			offsetof(struct trapframe, tf_r11)
199define	TF_R12			offsetof(struct trapframe, tf_r12)
200define	TF_R13			offsetof(struct trapframe, tf_r13)
201define	TF_R14			offsetof(struct trapframe, tf_r14)
202define	TF_R15			offsetof(struct trapframe, tf_r15)
203define	TF_RBP			offsetof(struct trapframe, tf_rbp)
204define	TF_RBX			offsetof(struct trapframe, tf_rbx)
205define	TF_RAX			offsetof(struct trapframe, tf_rax)
206define	TF_GS			offsetof(struct trapframe, tf_gs)
207define	TF_FS			offsetof(struct trapframe, tf_fs)
208define	TF_ES			offsetof(struct trapframe, tf_es)
209define	TF_DS			offsetof(struct trapframe, tf_ds)
210define	TF_TRAPNO		offsetof(struct trapframe, tf_trapno)
211define	TF_ERR			offsetof(struct trapframe, tf_err)
212define	TF_RIP			offsetof(struct trapframe, tf_rip)
213define	TF_CS			offsetof(struct trapframe, tf_cs)
214define	TF_RFLAGS		offsetof(struct trapframe, tf_rflags)
215define	TF_RSP			offsetof(struct trapframe, tf_rsp)
216define	TF_SS			offsetof(struct trapframe, tf_ss)
217
218# Size of stack area needed for saving registers
219define	TF_REGSIZE		offsetof(struct trapframe, tf_trapno)
220# Total size includes registers pushed by hardware
221define	FRAMESIZE		sizeof(struct trapframe)
222
223ifdef COMPAT_LINUX32
224define  LINUX32_SF_HANDLER	offsetof(struct linux32_sigframe, sf_handler)
225define  LINUX32_SF_SC		offsetof(struct linux32_sigframe, sf_sc)
226define  LINUX32_RT_SF_HANDLER	offsetof(struct linux32_rt_sigframe, sf_handler)
227define  LINUX32_RT_SF_UC	offsetof(struct linux32_rt_sigframe, sf_uc)
228define  LINUX32_SYS_rt_sigreturn	LINUX32_SYS_rt_sigreturn
229define  LINUX32_SYS_sigreturn		LINUX32_SYS_sigreturn
230define  LINUX32_SYS_exit		LINUX32_SYS_exit
231endif
232
233define	TSS_RSP0		offsetof(struct cpu_tss, tss.tss_rsp0)
234
235# CPU info structure
236define	CPU_INFO_SCRATCH	offsetof(struct cpu_info, ci_scratch)
237define	CPU_INFO_SELF		offsetof(struct cpu_info, ci_self)
238define	CPU_INFO_RESCHED	offsetof(struct cpu_info, ci_want_resched)
239define	CPU_INFO_WANT_PMAPLOAD	offsetof(struct cpu_info, ci_want_pmapload)
240define	CPU_INFO_TLBSTATE	offsetof(struct cpu_info, ci_tlbstate)
241define	TLBSTATE_VALID		TLBSTATE_VALID
242define	CPU_INFO_CURLWP		offsetof(struct cpu_info, ci_curlwp)
243define	CPU_INFO_CURLDT		offsetof(struct cpu_info, ci_curldt)
244define	CPU_INFO_IDLELWP	offsetof(struct cpu_info, ci_data.cpu_idlelwp)
245define	CPU_INFO_PMAP		offsetof(struct cpu_info, ci_pmap)
246define	CPU_INFO_TSS		offsetof(struct cpu_info, ci_tss)
247ifdef SVS
248define	CPU_INFO_UPDIRPA	offsetof(struct cpu_info, ci_svs_updirpa)
249define	CPU_INFO_RSP0		offsetof(struct cpu_info, ci_svs_rsp0)
250define	CPU_INFO_URSP0		offsetof(struct cpu_info, ci_svs_ursp0)
251define	CPU_INFO_KRSP0		offsetof(struct cpu_info, ci_svs_krsp0)
252endif
253define	CPU_INFO_NSYSCALL	offsetof(struct cpu_info, ci_data.cpu_nsyscall)
254define	CPU_INFO_NTRAP		offsetof(struct cpu_info, ci_data.cpu_ntrap)
255define	CPU_INFO_NINTR		offsetof(struct cpu_info, ci_data.cpu_nintr)
256define	CPU_INFO_CC_SKEW	offsetof(struct cpu_info, ci_data.cpu_cc_skew)
257define	CPU_INFO_CURPRIORITY	offsetof(struct cpu_info, ci_schedstate.spc_curpriority)
258
259define	CPU_INFO_GDT		offsetof(struct cpu_info, ci_gdt)
260define	CPU_INFO_ILEVEL		(offsetof(struct cpu_info, ci_istate) + 7)
261define	CPU_INFO_IDEPTH		offsetof(struct cpu_info, ci_idepth)
262define	CPU_INFO_IPENDING	offsetof(struct cpu_info, ci_istate)
263define	CPU_INFO_IMASKED	offsetof(struct cpu_info, ci_imasked)
264define	CPU_INFO_IMASK		offsetof(struct cpu_info, ci_imask)
265define	CPU_INFO_IUNMASK	offsetof(struct cpu_info, ci_iunmask)
266define	CPU_INFO_ISOURCES	offsetof(struct cpu_info, ci_isources)
267define	CPU_INFO_MTX_COUNT	offsetof(struct cpu_info, ci_mtx_count)
268define	CPU_INFO_MTX_OLDSPL	offsetof(struct cpu_info, ci_mtx_oldspl)
269define  CPU_INFO_CPUID		offsetof(struct cpu_info, ci_cpuid)
270define	CPU_INFO_ISTATE		offsetof(struct cpu_info, ci_istate)
271
272define	ACPI_SUSPEND_GDT	offsetof(struct cpu_info, ci_suspend_gdt)
273define	ACPI_SUSPEND_IDT	offsetof(struct cpu_info, ci_suspend_idt)
274define	ACPI_SUSPEND_TR		offsetof(struct cpu_info, ci_suspend_tr)
275define	ACPI_SUSPEND_LDT	offsetof(struct cpu_info, ci_suspend_ldt)
276define	ACPI_SUSPEND_FS		offsetof(struct cpu_info, ci_suspend_fs)
277define	ACPI_SUSPEND_GS		offsetof(struct cpu_info, ci_suspend_gs)
278define	ACPI_SUSPEND_KGS	offsetof(struct cpu_info, ci_suspend_kgs)
279define	ACPI_SUSPEND_EFER	offsetof(struct cpu_info, ci_suspend_efer)
280define	ACPI_SUSPEND_REG	offsetof(struct cpu_info, ci_suspend_reg)
281define	ACPI_SUSPEND_CR0	offsetof(struct cpu_info, ci_suspend_cr0)
282define	ACPI_SUSPEND_CR2	offsetof(struct cpu_info, ci_suspend_cr2)
283define	ACPI_SUSPEND_CR3	offsetof(struct cpu_info, ci_suspend_cr3)
284define	ACPI_SUSPEND_CR4	offsetof(struct cpu_info, ci_suspend_cr4)
285define	ACPI_SUSPEND_CR8	offsetof(struct cpu_info, ci_suspend_cr8)
286
287define	INVPCID_ADDRESS		INVPCID_ADDRESS
288define	INVPCID_CONTEXT		INVPCID_CONTEXT
289define	INVPCID_ALL		INVPCID_ALL
290define	INVPCID_ALL_NONGLOBAL	INVPCID_ALL_NONGLOBAL
291
292define	PMAP_PCID_USER		PMAP_PCID_USER
293define	PMAP_PCID_KERN		PMAP_PCID_KERN
294
295if NIOAPIC > 0
296define		PIC_IOAPIC		offsetof(struct pic, pic_ioapic)
297define		IOAPIC_SC_REG		offsetof(struct ioapic_softc, sc_reg)
298define		IOAPIC_SC_DATA		offsetof(struct ioapic_softc, sc_data)
299define		PIC_LOCK		offsetof(struct pic, pic_lock)
300endif
301
302# interrupt handler fields
303define	IH_FUN			offsetof(struct intrhand, ih_fun)
304define	IH_ARG			offsetof(struct intrhand, ih_arg)
305define	IH_LEVEL		offsetof(struct intrhand, ih_level)
306define	IH_NEXT			offsetof(struct intrhand, ih_next)
307
308ifdef COMPAT_NETBSD32
309define	SC_FS32			offsetof(struct netbsd32_sigcontext, sc_fs)
310define	SC_GS32			offsetof(struct netbsd32_sigcontext, sc_gs)
311endif
312
313define	IS_RECURSE	offsetof(struct intrsource, is_recurse)
314define	IS_RESUME	offsetof(struct intrsource, is_resume)
315define	IS_EVCNT	offsetof(struct intrsource, is_evcnt.ev_count)
316define	IS_HANDLERS	offsetof(struct intrsource, is_handlers)
317define	IS_PIC		offsetof(struct intrsource, is_pic)
318define	IS_FLAGS	offsetof(struct intrsource, is_flags)
319define	IS_PIN		offsetof(struct intrsource, is_pin)
320define	IS_TYPE		offsetof(struct intrsource, is_type)
321define	IS_MAXLEVEL	offsetof(struct intrsource, is_maxlevel)
322define	IS_LWP		offsetof(struct intrsource, is_lwp)
323define	IS_MASK_COUNT	offsetof(struct intrsource, is_mask_count)
324
325define	IPL_NONE		IPL_NONE
326define	IPL_PREEMPT		IPL_PREEMPT
327define	IPL_NET			IPL_NET
328define	IPL_CLOCK		IPL_CLOCK
329define	IPL_VM			IPL_VM
330define	IPL_SCHED		IPL_SCHED
331define	IPL_HIGH		IPL_HIGH
332
333define	LIR_IPI			LIR_IPI
334define	LIR_TIMER		LIR_TIMER
335define	LIR_HV			LIR_HV
336
337define	SIR_NET			SIR_NET
338define	SIR_CLOCK		SIR_CLOCK
339define	SIR_SERIAL		SIR_SERIAL
340
341define	IREENT_MAGIC		IREENT_MAGIC
342
343define	PSL_MBO			PSL_MBO
344
345# Constants required for in_cksum() and friends.
346define	M_DATA			offsetof(struct mbuf, m_data)
347define	M_LEN			offsetof(struct mbuf, m_len)
348define	M_NEXT			offsetof(struct mbuf, m_next)
349define	IP_SRC			offsetof(struct ip, ip_src)
350define	IP_DST			offsetof(struct ip, ip_dst)
351
352# Locking
353define	MTX_IPL			offsetof(struct kmutex, u.s.mtxs_ipl)
354define	MTX_LOCK		offsetof(struct kmutex, u.s.mtxs_lock)
355define	MTX_OWNER		offsetof(struct kmutex, u.mtxa_owner)
356
357define	RW_OWNER		offsetof(struct krwlock, rw_owner)
358define	RW_WRITE_LOCKED		RW_WRITE_LOCKED
359define	RW_WRITE_WANTED		RW_WRITE_WANTED
360define	RW_READ_INCR		RW_READ_INCR
361define	RW_HAS_WAITERS		RW_HAS_WAITERS
362define	RW_THREAD		RW_THREAD
363define	RW_READER		RW_READER
364define	RW_WRITER		RW_WRITER
365
366define	EV_COUNT		offsetof(struct evcnt, ev_count)
367
368define	OPTERON_MSR_PASSCODE	OPTERON_MSR_PASSCODE
369
370define	X86_BUS_SPACE_IO	X86_BUS_SPACE_IO
371
372define	BST_TYPE		offsetof(struct bus_space_tag, bst_type)
373
374define	VM_GUEST_XENPV		VM_GUEST_XENPV
375define	VM_GUEST_XENPVH		VM_GUEST_XENPVH
376
377ifdef XEN
378define CPU_INFO_VCPU		offsetof(struct cpu_info, ci_vcpu)
379define IH_PENDING		offsetof(struct intrhand, ih_pending)
380define SIR_XENIPL_VM		SIR_XENIPL_VM
381define SIR_XENIPL_SCHED		SIR_XENIPL_SCHED
382define SIR_XENIPL_HIGH		SIR_XENIPL_HIGH
383define EVTCHN_UPCALL_MASK	offsetof(struct vcpu_info, evtchn_upcall_mask)
384ifdef XENPV
385define XEN_PT_BASE		offsetof(struct start_info, pt_base)    
386define XEN_NR_PT_FRAMES		offsetof(struct start_info, nr_pt_frames)
387define __HYPERVISOR_iret	__HYPERVISOR_iret
388define CPU_INFO_XEN_CLOCKF_USERMODE offsetof(struct cpu_info, ci_xen_clockf_usermode)
389define CPU_INFO_XEN_CLOCKF_PC	offsetof(struct cpu_info, ci_xen_clockf_pc)
390endif /* XENPV */
391endif /* XEN */
392
393define	NKL4_KIMG_ENTRIES	NKL4_KIMG_ENTRIES
394define	NKL3_KIMG_ENTRIES	NKL3_KIMG_ENTRIES
395define	NKL2_KIMG_ENTRIES	NKL2_KIMG_ENTRIES
396
397define	VM_SPACE_SEP_HIGH32	(0xFFFF800000000000 >> 32)
398
399define	SEL_RPL_MASK		SEL_RPL
400