genassym.cf revision 1.136
1#	$NetBSD: genassym.cf,v 1.136 2025/02/18 10:16:03 imil 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_freebsd.h"
68include "opt_compat_linux.h"
69include "opt_compat_netbsd.h"
70include "opt_xen.h"
71endif
72
73if defined(_KERNEL) && defined(_KERNEL_OPT)
74include "isa.h"
75include "ioapic.h"
76endif
77
78quote #define __MUTEX_PRIVATE
79quote #define __RWLOCK_PRIVATE
80
81include <sys/param.h>
82include <sys/proc.h>
83include <sys/resourcevar.h>
84include <sys/device.h>
85include <sys/mbuf.h>
86include <sys/mutex.h>
87include <sys/rwlock.h>
88include <sys/cpu.h>
89
90include <netinet/in.h>
91include <netinet/in_systm.h>
92include <netinet/ip.h>
93include <netinet/ip6.h>
94include <netinet/ip_var.h>
95
96include <uvm/uvm.h>
97
98include <machine/trap.h>
99include <machine/pmap.h>
100include <machine/pmap_private.h>
101include <machine/vmparam.h>
102include <machine/intr.h>
103include <machine/types.h>
104include <machine/segments.h>
105
106include <compat/sys/signal.h>
107
108ifdef COMPAT_LINUX
109include <compat/linux/common/linux_signal.h>
110include <compat/linux/common/linux_machdep.h>
111endif
112
113ifdef COMPAT_FREEBSD
114include <compat/freebsd/freebsd_machdep.h>
115endif
116
117if NISA > 0
118include <machine/isa_machdep.h>
119endif
120
121if NIOAPIC > 0
122include <machine/i82093reg.h>
123include <machine/i82093var.h>
124endif
125
126ifdef XEN
127include <xen/include/public/sched.h>
128include <xen/include/public/arch-x86/hvm/start_info.h>
129endif
130
131include <sys/bus.h>
132
133# general constants
134define	PAGE_SIZE		PAGE_SIZE
135define	UPAGES			UPAGES
136define	USPACE			USPACE
137define	PGOFSET			PGOFSET
138define	PGSHIFT			PGSHIFT
139
140define	KSTACK_SIZE		KSTACK_SIZE
141define	KERNBASE		KERNBASE
142define	KERNTEXTOFF		KERNTEXTOFF
143
144define	PTE_P			PTE_P
145define	PTE_W			PTE_W
146define	PGEX_U			PGEX_U
147
148define	L2_SLOT_KERNBASE	pl2_pi(KERNBASE)
149define	L1_SLOT_KERNBASE	pl1_pi(KERNBASE)
150
151define	PDIR_SLOT_PTE		PDIR_SLOT_PTE
152define	PTE_BASE		PTE_BASE
153
154define	PDP_SIZE		PDP_SIZE
155define	PDE_SIZE		sizeof(pd_entry_t)
156
157define	GUFS_SEL		GUFS_SEL
158define	GUGS_SEL		GUGS_SEL
159
160define	IOMAPSIZE		IOMAPSIZE
161
162define	VM_MAXUSER_ADDRESS	(int)VM_MAXUSER_ADDRESS
163
164# lwp & proc fields and values
165define	L_PCB			offsetof(struct lwp, l_addr)
166define	L_CPU			offsetof(struct lwp, l_cpu)
167define	L_FLAG			offsetof(struct lwp, l_flag)
168define	L_PROC			offsetof(struct lwp, l_proc)
169define	L_RU			offsetof(struct lwp, l_ru)
170define	L_NOPREEMPT		offsetof(struct lwp, l_nopreempt)
171define	L_DOPREEMPT		offsetof(struct lwp, l_dopreempt)
172define	L_MD_REGS		offsetof(struct lwp, l_md.md_regs)
173define	L_MD_FLAGS		offsetof(struct lwp, l_md.md_flags)
174define	L_MD_ASTPENDING		offsetof(struct lwp, l_md.md_astpending)
175
176define	RU_NIVCSW		offsetof(struct rusage, ru_nivcsw)
177
178define	LW_SYSTEM		LW_SYSTEM
179define	MDL_FPU_IN_CPU		MDL_FPU_IN_CPU
180
181define	P_FLAG			offsetof(struct proc, p_flag)
182define	P_RASLIST		offsetof(struct proc, p_raslist)
183define	P_MD_SYSCALL		offsetof(struct proc, p_md.md_syscall)
184
185# pcb fields
186define	PCB_CR3			offsetof(struct pcb, pcb_cr3)
187define	PCB_CR0			offsetof(struct pcb, pcb_cr0)
188define	PCB_ONFAULT		offsetof(struct pcb, pcb_onfault)
189define	PCB_EBP			offsetof(struct pcb, pcb_ebp)
190define	PCB_ESP			offsetof(struct pcb, pcb_esp)
191define	PCB_ESP0		offsetof(struct pcb, pcb_esp0)
192define	PCB_FSD			offsetof(struct pcb, pcb_fsd)
193define	PCB_GSD			offsetof(struct pcb, pcb_gsd)
194define	PCB_IOMAP		offsetof(struct pcb, pcb_iomap)
195define	PCB_SAVEFPU		offsetof(struct pcb, pcb_savefpu)
196
197define	TF_CS			offsetof(struct trapframe, tf_cs)
198define	TF_EIP			offsetof(struct trapframe, tf_eip)
199define	TF_ERR			offsetof(struct trapframe, tf_err)
200define	TF_TRAPNO		offsetof(struct trapframe, tf_trapno)
201define	TF_EFLAGS		offsetof(struct trapframe, tf_eflags)
202
203define	TF_GS			offsetof(struct trapframe, tf_gs)
204define	TF_FS			offsetof(struct trapframe, tf_fs)
205define	TF_ES			offsetof(struct trapframe, tf_es)
206define	TF_DS			offsetof(struct trapframe, tf_ds)
207define	TF_EDI			offsetof(struct trapframe, tf_edi)
208define	TF_ESI			offsetof(struct trapframe, tf_esi)
209define	TF_EBP			offsetof(struct trapframe, tf_ebp)
210define	TF_EBX			offsetof(struct trapframe, tf_ebx)
211define	TF_EDX			offsetof(struct trapframe, tf_edx)
212define	TF_ECX			offsetof(struct trapframe, tf_ecx)
213define	TF_EAX			offsetof(struct trapframe, tf_eax)
214
215define	TF_PUSHSIZE		offsetof(struct trapframe, tf_trapno)
216
217define	FRAMESIZE		sizeof(struct trapframe)
218
219ifdef COMPAT_LINUX
220define	LINUX_SIGF_HANDLER	offsetof(struct linux_sigframe, sf_handler)
221define	LINUX_SIGF_SC		offsetof(struct linux_sigframe, sf_sc)
222define	LINUX_RT_SIGF_HANDLER	offsetof(struct linux_rt_sigframe, sf_handler)
223define	LINUX_RT_SIGF_UC	offsetof(struct linux_rt_sigframe, sf_uc)
224endif
225
226ifdef COMPAT_FREEBSD
227define	FREEBSD_SIGF_HANDLER	offsetof(struct freebsd_sigframe, sf_handler)
228define	FREEBSD_SIGF_SC		offsetof(struct freebsd_sigframe, sf_sc)
229endif
230
231define	TSS_TSS			offsetof(struct cpu_tss, tss)
232define	TSS_ESP0		offsetof(struct cpu_tss, tss.tss_esp0)
233define	TSS_IOBASE		offsetof(struct cpu_tss, tss.tss_iobase)
234define	TSS_IOMAP		offsetof(struct cpu_tss, iomap)
235
236# CPU info structure
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)
247define	IOMAP_INVALOFF		IOMAP_INVALOFF
248define	IOMAP_VALIDOFF		IOMAP_VALIDOFF
249define	CPU_INFO_NSYSCALL	offsetof(struct cpu_info, ci_data.cpu_nsyscall)
250define	CPU_INFO_NTRAP		offsetof(struct cpu_info, ci_data.cpu_ntrap)
251define	CPU_INFO_NINTR		offsetof(struct cpu_info, ci_data.cpu_nintr)
252define	CPU_INFO_CC_SKEW	offsetof(struct cpu_info, ci_data.cpu_cc_skew)
253define	CPU_INFO_CURPRIORITY	offsetof(struct cpu_info, ci_schedstate.spc_curpriority)
254
255define	CPU_INFO_VENDOR		offsetof(struct cpu_info, ci_vendor[0])
256define	CPU_INFO_SIGNATURE	offsetof(struct cpu_info, ci_signature)
257
258define	CPU_INFO_GDT		offsetof(struct cpu_info, ci_gdt)
259define	CPU_INFO_ILEVEL		(offsetof(struct cpu_info, ci_istate) + 7)
260define	CPU_INFO_IDEPTH		offsetof(struct cpu_info, ci_idepth)
261define	CPU_INFO_IPENDING	offsetof(struct cpu_info, ci_istate)
262define	CPU_INFO_IMASKED	offsetof(struct cpu_info, ci_imasked)
263define	CPU_INFO_IMASK		offsetof(struct cpu_info, ci_imask)
264define	CPU_INFO_IUNMASK	offsetof(struct cpu_info, ci_iunmask)
265define	CPU_INFO_ISOURCES	offsetof(struct cpu_info, ci_isources)
266define	CPU_INFO_MTX_COUNT	offsetof(struct cpu_info, ci_mtx_count)
267define	CPU_INFO_MTX_OLDSPL	offsetof(struct cpu_info, ci_mtx_oldspl)
268define	CPU_INFO_INTRSTACK	offsetof(struct cpu_info, ci_intrstack)
269define	CPU_INFO_ISTATE		offsetof(struct cpu_info, ci_istate)
270
271define	ACPI_SUSPEND_GDT	offsetof(struct cpu_info, ci_suspend_gdt)
272define	ACPI_SUSPEND_IDT	offsetof(struct cpu_info, ci_suspend_idt)
273define	ACPI_SUSPEND_TR		offsetof(struct cpu_info, ci_suspend_tr)
274define	ACPI_SUSPEND_LDT	offsetof(struct cpu_info, ci_suspend_ldt)
275define	ACPI_SUSPEND_FS		offsetof(struct cpu_info, ci_suspend_fs)
276define	ACPI_SUSPEND_GS		offsetof(struct cpu_info, ci_suspend_gs)
277define	ACPI_SUSPEND_KGS	offsetof(struct cpu_info, ci_suspend_kgs)
278define	ACPI_SUSPEND_EFER	offsetof(struct cpu_info, ci_suspend_efer)
279define	ACPI_SUSPEND_REG	offsetof(struct cpu_info, ci_suspend_reg)
280define	ACPI_SUSPEND_CR0	offsetof(struct cpu_info, ci_suspend_cr0)
281define	ACPI_SUSPEND_CR2	offsetof(struct cpu_info, ci_suspend_cr2)
282define	ACPI_SUSPEND_CR3	offsetof(struct cpu_info, ci_suspend_cr3)
283define	ACPI_SUSPEND_CR4	offsetof(struct cpu_info, ci_suspend_cr4)
284define	ACPI_SUSPEND_CR8	offsetof(struct cpu_info, ci_suspend_cr8)
285
286if NIOAPIC > 0
287define		PIC_IOAPIC		offsetof(struct pic, pic_ioapic)
288define		IOAPIC_SC_REG		offsetof(struct ioapic_softc, sc_reg)
289define		IOAPIC_SC_DATA		offsetof(struct ioapic_softc, sc_data)
290define		PIC_LOCK		offsetof(struct pic, pic_lock)
291endif
292
293# interrupt handler fields
294define	IH_FUN			offsetof(struct intrhand, ih_fun)
295define	IH_ARG			offsetof(struct intrhand, ih_arg)
296define	IH_LEVEL		offsetof(struct intrhand, ih_level)
297define	IH_NEXT			offsetof(struct intrhand, ih_next)
298
299define	SIZEOF_CPU_INFO		sizeof(struct cpu_info)
300define	SIZEOF_ISTUB		sizeof(struct intrstub)
301
302define	SIZEOF_ISOURCE	sizeof(struct intrsource)
303define	IS_RECURSE	offsetof(struct intrsource, is_recurse)
304define	IS_RESUME	offsetof(struct intrsource, is_resume)
305define	IS_EVCNTLO	offsetof(struct intrsource, is_evcnt.ev_count)
306define	IS_EVCNTHI	offsetof(struct intrsource, is_evcnt.ev_count)+4
307define	IS_HANDLERS	offsetof(struct intrsource, is_handlers)
308define	IS_PIC		offsetof(struct intrsource, is_pic)
309define	IS_FLAGS	offsetof(struct intrsource, is_flags)
310define	IS_PIN		offsetof(struct intrsource, is_pin)
311define	IS_TYPE		offsetof(struct intrsource, is_type)
312define	IS_MAXLEVEL	offsetof(struct intrsource, is_maxlevel)
313define	IS_LWP		offsetof(struct intrsource, is_lwp)
314define	IS_MASK_COUNT	offsetof(struct intrsource, is_mask_count)
315
316define	IPL_NONE		IPL_NONE
317define	IPL_PREEMPT		IPL_PREEMPT
318define	IPL_NET			IPL_NET
319define	IPL_CLOCK		IPL_CLOCK
320define	IPL_VM			IPL_VM
321define	IPL_SCHED		IPL_SCHED
322define	IPL_HIGH		IPL_HIGH
323
324define	IPL_SOFTNET		IPL_SOFTNET
325define	IPL_SOFTCLOCK		IPL_SOFTCLOCK
326define	IPL_SOFTSERIAL		IPL_SOFTSERIAL
327
328define	LIR_IPI			LIR_IPI
329define	LIR_TIMER		LIR_TIMER
330define	LIR_HV			LIR_HV
331
332define	SIR_NET			SIR_NET
333define	SIR_CLOCK		SIR_CLOCK
334define	SIR_SERIAL		SIR_SERIAL
335
336define	IREENT_MAGIC		IREENT_MAGIC
337
338define	PSL_AC			PSL_AC
339define	PSL_MBO			PSL_MBO
340define	PSL_ID			PSL_ID
341define	PSL_I			PSL_I
342
343# Constants required for in_cksum() and friends.
344define	M_DATA			offsetof(struct mbuf, m_data)
345define	M_LEN			offsetof(struct mbuf, m_len)
346define	M_NEXT			offsetof(struct mbuf, m_next)
347define	IP_SRC			offsetof(struct ip, ip_src)
348define	IP_DST			offsetof(struct ip, ip_dst)
349define	IP6_SRC			offsetof(struct ip6_hdr, ip6_src)
350define	IP6_DST			offsetof(struct ip6_hdr, ip6_dst)
351
352# Locking
353define	MTX_IPL			offsetof(struct kmutex, u.s.mtxs_ipl)
354define	MTX_LOCK		offsetof(struct kmutex, mtx_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	L1_SHIFT		L1_SHIFT
375define	L2_SHIFT		L2_SHIFT
376define	L2_FRAME		L2_FRAME
377
378define	VM_GUEST_XENPV		VM_GUEST_XENPV
379define	VM_GUEST_XENPVH		VM_GUEST_XENPVH
380define	VM_GUEST_GENPVH		VM_GUEST_GENPVH
381
382ifdef XEN
383define CPU_INFO_VCPU		offsetof(struct cpu_info, ci_vcpu)
384define IH_PENDING		offsetof(struct intrhand, ih_pending)
385define SIR_XENIPL_VM		SIR_XENIPL_VM
386define SIR_XENIPL_SCHED		SIR_XENIPL_SCHED
387define SIR_XENIPL_HIGH		SIR_XENIPL_HIGH
388define START_INFO_SHARED_INFO	offsetof(struct start_info, shared_info)
389define START_INFO_FLAGS		offsetof(struct start_info, flags)
390define START_INFO_CONSOLE_MFN	offsetof(struct start_info, console.domU.mfn)
391define START_INFO_STORE_MFN	offsetof(struct start_info, store_mfn)
392define SIF_INITDOMAIN		SIF_INITDOMAIN
393define EVTCHN_UPCALL_PENDING	offsetof(struct vcpu_info, evtchn_upcall_pending)
394define EVTCHN_UPCALL_MASK	offsetof(struct vcpu_info, evtchn_upcall_mask)
395define HVM_START_INFO_SIZE	sizeof(struct hvm_start_info)
396define START_INFO_VERSION	offsetof(struct hvm_start_info, version)
397define MMAP_PADDR		offsetof(struct hvm_start_info, memmap_paddr)
398define MMAP_ENTRIES		offsetof(struct hvm_start_info, memmap_entries)
399define MMAP_ENTRY_SIZE		sizeof(struct hvm_memmap_table_entry)
400define CMDLINE_PADDR		offsetof(struct hvm_start_info, cmdline_paddr)
401define HYPERVISOR_sched_op	__HYPERVISOR_sched_op
402define SCHEDOP_yield		SCHEDOP_yield
403endif /* XEN */
404
405ifdef XENPV
406define CPU_INFO_XEN_CLOCKF_USERMODE offsetof(struct cpu_info, ci_xen_clockf_usermode)
407define CPU_INFO_XEN_CLOCKF_PC	offsetof(struct cpu_info, ci_xen_clockf_pc)
408endif /* XENPV */
409