1#	$NetBSD: genassym.cf,v 1.60 2015/11/20 11:58:00 maxv Exp $
2
3#
4# Copyright (c) 1998, 2006, 2007, 2008 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
72quote #define __MUTEX_PRIVATE
73quote #define __RWLOCK_PRIVATE
74
75include <sys/param.h>
76include <sys/proc.h>
77include <sys/resourcevar.h>
78include <sys/device.h>
79include <sys/mbuf.h>
80include <sys/mutex.h>
81include <sys/rwlock.h>
82include <sys/cpu_data.h>
83include <sys/evcnt.h>
84include <sys/cpu.h>
85
86include <netinet/in.h>
87include <netinet/in_systm.h>
88include <netinet/ip.h>
89include <netinet/ip_var.h>
90
91include <uvm/uvm.h>
92
93include <machine/trap.h>
94include <machine/pmap.h>
95include <machine/vmparam.h>
96include <machine/intr.h>
97include <machine/types.h>
98include <machine/cpufunc.h>
99
100if defined(COMPAT_NETBSD32)
101include <machine/netbsd32_machdep.h>
102endif
103
104if defined(COMPAT_LINUX32)
105include <machine/linux32_machdep.h>
106endif
107
108if defined(_KERNEL) && defined(_KERNEL_OPT)
109include "isa.h"
110include "ioapic.h"
111endif
112if NISA > 0
113include <machine/isa_machdep.h>
114endif
115
116if NIOAPIC > 0
117include <machine/i82093reg.h>
118include <machine/i82093var.h>
119endif
120
121ifdef XEN
122include <xen/xen-public/xen.h>
123endif
124
125include <sys/bus.h>
126
127define	LSRUN			LSRUN
128define	LSONPROC		LSONPROC
129
130define	UPAGES			UPAGES
131define	USPACE			USPACE
132
133define	KERNBASE_LO		KERNBASE_LO
134define	KERNBASE_HI		KERNBASE_HI
135define	KERNBASE		KERNBASE
136define	KERNTEXTOFF_LO		KERNTEXTOFF_LO
137define	KERNTEXTOFF		KERNTEXTOFF
138
139define	NBPG			NBPG
140
141define	L4_SLOT_KERNBASE	L4_SLOT_KERNBASE
142define	L3_SLOT_KERNBASE	pl3_pi(KERNBASE)
143define	L2_SLOT_KERNBASE	pl2_pi(KERNBASE)
144define	L1_SLOT_KERNBASE	pl1_pi(KERNBASE)
145
146define	PDIR_SLOT_PTE		PDIR_SLOT_PTE
147
148define	PDE_SIZE		sizeof(pd_entry_t)
149
150define	VM_MAXUSER_ADDRESS	(unsigned long long)VM_MAXUSER_ADDRESS
151
152define	L_PCB			offsetof(struct lwp, l_addr)
153define	L_FLAG			offsetof(struct lwp, l_flag)
154define	L_PROC			offsetof(struct lwp, l_proc)
155define	L_CTXSWTCH		offsetof(struct lwp, l_ctxswtch)
156define	L_NCSW			offsetof(struct lwp, l_ncsw)
157define	L_NOPREEMPT		offsetof(struct lwp, l_nopreempt)
158define	L_DOPREEMPT		offsetof(struct lwp, l_dopreempt)
159define	L_CPU			offsetof(struct lwp, l_cpu)
160define	L_KPRIORITY		offsetof(struct lwp, l_kpriority)
161define	L_MD_REGS		offsetof(struct lwp, l_md.md_regs)
162define	L_MD_FLAGS		offsetof(struct lwp, l_md.md_flags)
163define	L_MD_ASTPENDING		offsetof(struct lwp, l_md.md_astpending)
164
165define	PAGE_SIZE		PAGE_SIZE
166
167define	MDL_IRET		MDL_IRET
168define	MDL_COMPAT32		MDL_COMPAT32
169
170define	P_FLAG			offsetof(struct proc, p_flag)
171define	P_RASLIST		offsetof(struct proc, p_raslist)
172define	P_MD_SYSCALL		offsetof(struct proc, p_md.md_syscall)
173
174define	LW_SYSTEM		LW_SYSTEM
175
176define	M_DATA			offsetof(struct mbuf, m_data)
177define	M_LEN			offsetof(struct mbuf, m_len)
178define	M_NEXT			offsetof(struct mbuf, m_next)
179
180define	IP_SRC			offsetof(struct ip, ip_src)
181define	IP_DST			offsetof(struct ip, ip_dst)
182
183define	PCB_CR3			offsetof(struct pcb, pcb_cr3)
184define	PCB_RBP			offsetof(struct pcb, pcb_rbp)
185define	PCB_RSP			offsetof(struct pcb, pcb_rsp)
186define	PCB_RSP0		offsetof(struct pcb, pcb_rsp0)
187define	PCB_CR0			offsetof(struct pcb, pcb_cr0)
188define	PCB_ONFAULT		offsetof(struct pcb, pcb_onfault)
189define	PCB_FLAGS		offsetof(struct pcb, pcb_flags)
190define	PCB_COMPAT32		PCB_COMPAT32
191define	PCB_FS			offsetof(struct pcb, pcb_fs)
192define	PCB_GS			offsetof(struct pcb, pcb_gs)
193
194define	TF_RDI			offsetof(struct trapframe, tf_rdi)
195define	TF_RSI			offsetof(struct trapframe, tf_rsi)
196define	TF_RDX			offsetof(struct trapframe, tf_rdx)
197define	TF_RCX			offsetof(struct trapframe, tf_rcx)
198define	TF_R8			offsetof(struct trapframe, tf_r8)
199define	TF_R9			offsetof(struct trapframe, tf_r9)
200define	TF_R10			offsetof(struct trapframe, tf_r10)
201define	TF_R11			offsetof(struct trapframe, tf_r11)
202define	TF_R12			offsetof(struct trapframe, tf_r12)
203define	TF_R13			offsetof(struct trapframe, tf_r13)
204define	TF_R14			offsetof(struct trapframe, tf_r14)
205define	TF_R15			offsetof(struct trapframe, tf_r15)
206define	TF_RBP			offsetof(struct trapframe, tf_rbp)
207define	TF_RBX			offsetof(struct trapframe, tf_rbx)
208define	TF_RAX			offsetof(struct trapframe, tf_rax)
209define	TF_GS			offsetof(struct trapframe, tf_gs)
210define	TF_FS			offsetof(struct trapframe, tf_fs)
211define	TF_ES			offsetof(struct trapframe, tf_es)
212define	TF_DS			offsetof(struct trapframe, tf_ds)
213define	TF_TRAPNO		offsetof(struct trapframe, tf_trapno)
214define	TF_ERR			offsetof(struct trapframe, tf_err)
215define	TF_RIP			offsetof(struct trapframe, tf_rip)
216define	TF_CS			offsetof(struct trapframe, tf_cs)
217define	TF_RFLAGS		offsetof(struct trapframe, tf_rflags)
218define	TF_RSP			offsetof(struct trapframe, tf_rsp)
219define	TF_SS			offsetof(struct trapframe, tf_ss)
220
221# Size of stack area needed for saving registers
222define	TF_REGSIZE		offsetof(struct trapframe, tf_trapno)
223# Total size includes registers pushed by hardware
224define	FRAMESIZE		sizeof(struct trapframe)
225
226define	CPU_INFO_SCRATCH	offsetof(struct cpu_info, ci_scratch)
227define	CPU_INFO_SELF		offsetof(struct cpu_info, ci_self)
228define	CPU_INFO_RESCHED	offsetof(struct cpu_info, ci_want_resched)
229define	CPU_INFO_WANT_PMAPLOAD	offsetof(struct cpu_info, ci_want_pmapload)
230define	CPU_INFO_TLBSTATE	offsetof(struct cpu_info, ci_tlbstate)
231define	TLBSTATE_VALID		TLBSTATE_VALID
232define	CPU_INFO_CURLWP		offsetof(struct cpu_info, ci_curlwp)
233define	CPU_INFO_CURLDT		offsetof(struct cpu_info, ci_curldt)
234define	CPU_INFO_IDLELWP	offsetof(struct cpu_info, ci_data.cpu_idlelwp)
235define	CPU_INFO_PMAP		offsetof(struct cpu_info, ci_pmap)
236define	CPU_INFO_RSP0		offsetof(struct cpu_info, ci_tss.tss_rsp0)
237define	CPU_INFO_NSYSCALL	offsetof(struct cpu_info, ci_data.cpu_nsyscall)
238define	CPU_INFO_NTRAP		offsetof(struct cpu_info, ci_data.cpu_ntrap)
239define	CPU_INFO_NINTR		offsetof(struct cpu_info, ci_data.cpu_nintr)
240define	CPU_INFO_CURPRIORITY	offsetof(struct cpu_info, ci_schedstate.spc_curpriority)
241define	CPU_INFO_FPCURLWP	offsetof(struct cpu_info, ci_fpcurlwp)
242
243define	CPU_INFO_GDT		offsetof(struct cpu_info, ci_gdt)
244define	CPU_INFO_IPENDING	offsetof(struct cpu_info, ci_ipending)
245define	CPU_INFO_IMASK		offsetof(struct cpu_info, ci_imask)
246define	CPU_INFO_IUNMASK	offsetof(struct cpu_info, ci_iunmask)
247define	CPU_INFO_ILEVEL		offsetof(struct cpu_info, ci_ilevel)
248define	CPU_INFO_IDEPTH		offsetof(struct cpu_info, ci_idepth)
249define	CPU_INFO_ISOURCES	offsetof(struct cpu_info, ci_isources)
250define	CPU_INFO_MTX_COUNT	offsetof(struct cpu_info, ci_mtx_count)
251define	CPU_INFO_MTX_OLDSPL	offsetof(struct cpu_info, ci_mtx_oldspl)
252define  CPU_INFO_CPUID		offsetof(struct cpu_info, ci_cpuid)
253define	CPU_INFO_ISTATE		offsetof(struct cpu_info, ci_istate)
254define	CPU_INFO_CC_SKEW	offsetof(struct cpu_info, ci_data.cpu_cc_skew)
255
256define	ACPI_SUSPEND_GDT	offsetof(struct cpu_info, ci_suspend_gdt)
257define	ACPI_SUSPEND_IDT	offsetof(struct cpu_info, ci_suspend_idt)
258define	ACPI_SUSPEND_TR		offsetof(struct cpu_info, ci_suspend_tr)
259define	ACPI_SUSPEND_LDT	offsetof(struct cpu_info, ci_suspend_ldt)
260define	ACPI_SUSPEND_FS		offsetof(struct cpu_info, ci_suspend_fs)
261define	ACPI_SUSPEND_GS		offsetof(struct cpu_info, ci_suspend_gs)
262define	ACPI_SUSPEND_KGS	offsetof(struct cpu_info, ci_suspend_kgs)
263define	ACPI_SUSPEND_EFER	offsetof(struct cpu_info, ci_suspend_efer)
264define	ACPI_SUSPEND_REG	offsetof(struct cpu_info, ci_suspend_reg)
265define	ACPI_SUSPEND_CR0	offsetof(struct cpu_info, ci_suspend_cr0)
266define	ACPI_SUSPEND_CR2	offsetof(struct cpu_info, ci_suspend_cr2)
267define	ACPI_SUSPEND_CR3	offsetof(struct cpu_info, ci_suspend_cr3)
268define	ACPI_SUSPEND_CR4	offsetof(struct cpu_info, ci_suspend_cr4)
269define	ACPI_SUSPEND_CR8	offsetof(struct cpu_info, ci_suspend_cr8)
270
271if NIOAPIC > 0
272define		PIC_IOAPIC		offsetof(struct pic, pic_ioapic)
273define		IOAPIC_SC_REG		offsetof(struct ioapic_softc, sc_reg)
274define		IOAPIC_SC_DATA		offsetof(struct ioapic_softc, sc_data)
275define		PIC_LOCK		offsetof(struct pic, pic_lock)
276endif
277
278define	IH_FUN			offsetof(struct intrhand, ih_fun)
279define	IH_ARG			offsetof(struct intrhand, ih_arg)
280define  IH_LEVEL		offsetof(struct intrhand, ih_level)
281ifdef XEN
282define IH_IPL_NEXT		offsetof(struct intrhand, ih_ipl_next)
283else
284define	IH_NEXT			offsetof(struct intrhand, ih_next)
285endif
286
287ifdef COMPAT_NETBSD32
288define	SC_FS32			offsetof(struct netbsd32_sigcontext, sc_fs)
289define	SC_GS32			offsetof(struct netbsd32_sigcontext, sc_gs)
290endif
291
292ifdef COMPAT_LINUX32
293define  LINUX32_SF_HANDLER	offsetof(struct linux32_sigframe, sf_handler)
294define  LINUX32_SF_SC		offsetof(struct linux32_sigframe, sf_sc)
295define  LINUX32_RT_SF_HANDLER	offsetof(struct linux32_rt_sigframe, sf_handler)
296define  LINUX32_RT_SF_UC	offsetof(struct linux32_rt_sigframe, sf_uc)
297define  LINUX32_SYS_rt_sigreturn	LINUX32_SYS_rt_sigreturn
298define  LINUX32_SYS_sigreturn		LINUX32_SYS_sigreturn
299define  LINUX32_SYS_exit		LINUX32_SYS_exit
300endif
301
302ifdef XEN
303define	SIZEOF_IPLSOURCE	sizeof(struct iplsource)
304define	IS_RECURSE      offsetof(struct iplsource, ipl_recurse)
305define	IS_RESUME       offsetof(struct iplsource, ipl_resume)
306define	IS_HANDLERS     offsetof(struct iplsource, ipl_handlers)
307define	EV_EVCNTL	offsetof(struct evcnt, ev_count)
308else
309define	IS_RECURSE	offsetof(struct intrsource, is_recurse)
310define	IS_RESUME	offsetof(struct intrsource, is_resume)
311define	IS_EVCNT	offsetof(struct intrsource, is_evcnt.ev_count)
312define	IS_HANDLERS	offsetof(struct intrsource, is_handlers)
313define	IS_PIC		offsetof(struct intrsource, is_pic)
314define	IS_FLAGS	offsetof(struct intrsource, is_flags)
315define	IS_PIN		offsetof(struct intrsource, is_pin)
316define	IS_TYPE		offsetof(struct intrsource, is_type)
317define	IS_MAXLEVEL	offsetof(struct intrsource, is_maxlevel)
318define	IS_LWP			offsetof(struct intrsource, is_lwp)
319endif
320
321define	IPL_NONE		IPL_NONE
322define	IPL_PREEMPT		IPL_PREEMPT
323define	IPL_CLOCK		IPL_CLOCK
324define	IPL_HIGH		IPL_HIGH
325
326define	LIR_IPI			LIR_IPI
327define	LIR_TIMER		LIR_TIMER
328
329define	SIR_NET			SIR_NET
330define	SIR_CLOCK		SIR_CLOCK
331define	SIR_SERIAL		SIR_SERIAL
332
333define	IREENT_MAGIC		IREENT_MAGIC
334
335define	PSL_MBO			PSL_MBO
336
337define	MTX_IPL			offsetof(struct kmutex, u.s.mtxs_ipl)
338define	MTX_LOCK		offsetof(struct kmutex, u.s.mtxs_lock)
339define	MTX_OWNER		offsetof(struct kmutex, u.mtxa_owner)
340
341define	RW_OWNER		offsetof(struct krwlock, rw_owner)
342define	RW_WRITE_LOCKED		RW_WRITE_LOCKED
343define	RW_WRITE_WANTED		RW_WRITE_WANTED
344define	RW_READ_INCR		RW_READ_INCR
345define	RW_HAS_WAITERS		RW_HAS_WAITERS
346define	RW_THREAD		RW_THREAD
347define	RW_READER		RW_READER
348define	RW_WRITER		RW_WRITER
349
350define	EV_COUNT		offsetof(struct evcnt, ev_count)
351
352define	OPTERON_MSR_PASSCODE	OPTERON_MSR_PASSCODE
353
354define	X86_BUS_SPACE_IO	X86_BUS_SPACE_IO
355
356define	BST_TYPE		offsetof(struct bus_space_tag, bst_type)
357
358ifdef XEN
359define CPU_INFO_VCPU		offsetof(struct cpu_info, ci_vcpu)
360define EVTCHN_UPCALL_MASK	offsetof(struct vcpu_info, evtchn_upcall_mask)
361define XEN_PT_BASE		offsetof(struct start_info, pt_base)
362define XEN_NR_PT_FRAMES		offsetof(struct start_info, nr_pt_frames)
363define __HYPERVISOR_iret	__HYPERVISOR_iret
364endif
365
366define	NKL4_KIMG_ENTRIES	NKL4_KIMG_ENTRIES
367define	NKL3_KIMG_ENTRIES	NKL3_KIMG_ENTRIES
368define	NKL2_KIMG_ENTRIES	NKL2_KIMG_ENTRIES
369
370define	PGOFSET			PGOFSET
371define	PGSHIFT			PGSHIFT
372
373define	VM_MIN_KERNEL_ADDRESS_HIGH32	(VM_MIN_KERNEL_ADDRESS >> 32)
374
375define	RESCHED_KPREEMPT	RESCHED_KPREEMPT
376
377define	SEL_RPL_MASK		SEL_RPL
378