xref: /freebsd/sys/i386/i386/genassym.c (revision 3494f7c0)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1982, 1990 The Regents of the University of California.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * William Jolitz.
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  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 
35 #include <sys/cdefs.h>
36 #include "opt_apic.h"
37 #include "opt_hwpmc_hooks.h"
38 #include "opt_kstack_pages.h"
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/assym.h>
43 #include <sys/bio.h>
44 #include <sys/buf.h>
45 #ifdef	HWPMC_HOOKS
46 #include <sys/pmckern.h>
47 #endif
48 #include <sys/proc.h>
49 #include <sys/errno.h>
50 #include <sys/mount.h>
51 #include <sys/mutex.h>
52 #include <sys/socket.h>
53 #include <sys/resourcevar.h>
54 #include <sys/signalvar.h>
55 #include <sys/ucontext.h>
56 #include <machine/bootinfo.h>
57 #include <machine/tss.h>
58 #include <sys/vmmeter.h>
59 #include <vm/vm.h>
60 #include <vm/vm_param.h>
61 #include <vm/pmap.h>
62 #include <vm/vm_map.h>
63 #include <sys/proc.h>
64 #include <net/if.h>
65 #include <netinet/in.h>
66 #include <nfs/nfsproto.h>
67 #include <nfsclient/nfs.h>
68 #include <nfs/nfsdiskless.h>
69 #ifdef DEV_APIC
70 #include <x86/apicreg.h>
71 #endif
72 #include <machine/cpu.h>
73 #include <machine/pcb_ext.h>
74 #include <machine/pcb.h>
75 #include <machine/sigframe.h>
76 #include <machine/vm86.h>
77 #include <machine/proc.h>
78 
79 ASSYM(P_VMSPACE, offsetof(struct proc, p_vmspace));
80 ASSYM(VM_PMAP, offsetof(struct vmspace, vm_pmap));
81 ASSYM(PM_ACTIVE, offsetof(struct pmap, pm_active));
82 
83 ASSYM(TD_FLAGS, offsetof(struct thread, td_flags));
84 ASSYM(TD_AST, offsetof(struct thread, td_ast));
85 ASSYM(TD_LOCK, offsetof(struct thread, td_lock));
86 ASSYM(TD_PCB, offsetof(struct thread, td_pcb));
87 ASSYM(TD_PFLAGS, offsetof(struct thread, td_pflags));
88 ASSYM(TD_PROC, offsetof(struct thread, td_proc));
89 ASSYM(TD_MD, offsetof(struct thread, td_md));
90 
91 ASSYM(TDP_CALLCHAIN, TDP_CALLCHAIN);
92 
93 ASSYM(P_MD, offsetof(struct proc, p_md));
94 ASSYM(MD_LDT, offsetof(struct mdproc, md_ldt));
95 
96 ASSYM(TD0_KSTACK_PAGES, TD0_KSTACK_PAGES);
97 ASSYM(PAGE_SIZE, PAGE_SIZE);
98 ASSYM(PAGE_SHIFT, PAGE_SHIFT);
99 ASSYM(PAGE_MASK, PAGE_MASK);
100 ASSYM(PCB_CR0, offsetof(struct pcb, pcb_cr0));
101 ASSYM(PCB_CR2, offsetof(struct pcb, pcb_cr2));
102 ASSYM(PCB_CR3, offsetof(struct pcb, pcb_cr3));
103 ASSYM(PCB_CR4, offsetof(struct pcb, pcb_cr4));
104 ASSYM(PCB_EDI, offsetof(struct pcb, pcb_edi));
105 ASSYM(PCB_ESI, offsetof(struct pcb, pcb_esi));
106 ASSYM(PCB_EBP, offsetof(struct pcb, pcb_ebp));
107 ASSYM(PCB_ESP, offsetof(struct pcb, pcb_esp));
108 ASSYM(PCB_EBX, offsetof(struct pcb, pcb_ebx));
109 ASSYM(PCB_EIP, offsetof(struct pcb, pcb_eip));
110 ASSYM(TSS_ESP0, offsetof(struct i386tss, tss_esp0));
111 
112 ASSYM(PCB_DS, offsetof(struct pcb, pcb_ds));
113 ASSYM(PCB_ES, offsetof(struct pcb, pcb_es));
114 ASSYM(PCB_FS, offsetof(struct pcb, pcb_fs));
115 ASSYM(PCB_GS, offsetof(struct pcb, pcb_gs));
116 ASSYM(PCB_SS, offsetof(struct pcb, pcb_ss));
117 ASSYM(PCB_DR0, offsetof(struct pcb, pcb_dr0));
118 ASSYM(PCB_DR1, offsetof(struct pcb, pcb_dr1));
119 ASSYM(PCB_DR2, offsetof(struct pcb, pcb_dr2));
120 ASSYM(PCB_DR3, offsetof(struct pcb, pcb_dr3));
121 ASSYM(PCB_DR6, offsetof(struct pcb, pcb_dr6));
122 ASSYM(PCB_DR7, offsetof(struct pcb, pcb_dr7));
123 ASSYM(PCB_DBREGS, PCB_DBREGS);
124 ASSYM(PCB_EXT, offsetof(struct pcb, pcb_ext));
125 
126 ASSYM(PCB_EXT_TSS, offsetof(struct pcb_ext, ext_tss));
127 
128 ASSYM(PCB_FSD, offsetof(struct pcb, pcb_fsd));
129 ASSYM(PCB_GSD, offsetof(struct pcb, pcb_gsd));
130 ASSYM(PCB_VM86, offsetof(struct pcb, pcb_vm86));
131 ASSYM(PCB_FLAGS, offsetof(struct pcb, pcb_flags));
132 ASSYM(PCB_SAVEFPU, offsetof(struct pcb, pcb_save));
133 ASSYM(PCB_ONFAULT, offsetof(struct pcb, pcb_onfault));
134 
135 ASSYM(PCB_SIZE, sizeof(struct pcb));
136 ASSYM(PCB_VM86CALL, PCB_VM86CALL);
137 
138 ASSYM(PCB_GDT, offsetof(struct pcb, pcb_gdt));
139 ASSYM(PCB_IDT, offsetof(struct pcb, pcb_idt));
140 ASSYM(PCB_LDT, offsetof(struct pcb, pcb_ldt));
141 ASSYM(PCB_TR, offsetof(struct pcb, pcb_tr));
142 
143 ASSYM(TF_FS, offsetof(struct trapframe, tf_fs));
144 ASSYM(TF_ES, offsetof(struct trapframe, tf_es));
145 ASSYM(TF_DS, offsetof(struct trapframe, tf_ds));
146 ASSYM(TF_TRAPNO, offsetof(struct trapframe, tf_trapno));
147 ASSYM(TF_ERR, offsetof(struct trapframe, tf_err));
148 ASSYM(TF_EIP, offsetof(struct trapframe, tf_eip));
149 ASSYM(TF_CS, offsetof(struct trapframe, tf_cs));
150 ASSYM(TF_EFLAGS, offsetof(struct trapframe, tf_eflags));
151 ASSYM(TF_SZ, sizeof(struct trapframe));
152 
153 ASSYM(SIGF_HANDLER, offsetof(struct sigframe, sf_ahu.sf_handler));
154 #ifdef COMPAT_43
155 ASSYM(SIGF_SC, offsetof(struct osigframe, sf_siginfo.si_sc));
156 #endif
157 ASSYM(SIGF_UC, offsetof(struct sigframe, sf_uc));
158 #ifdef COMPAT_FREEBSD4
159 ASSYM(SIGF_UC4, offsetof(struct freebsd4_sigframe, sf_uc));
160 #endif
161 #ifdef COMPAT_43
162 ASSYM(SC_PS, offsetof(struct osigcontext, sc_ps));
163 ASSYM(SC_FS, offsetof(struct osigcontext, sc_fs));
164 ASSYM(SC_GS, offsetof(struct osigcontext, sc_gs));
165 ASSYM(SC_TRAPNO, offsetof(struct osigcontext, sc_trapno));
166 #endif
167 #ifdef COMPAT_FREEBSD4
168 ASSYM(UC4_EFLAGS, offsetof(struct freebsd4_ucontext, uc_mcontext.mc_eflags));
169 ASSYM(UC4_GS, offsetof(struct freebsd4_ucontext, uc_mcontext.mc_gs));
170 #endif
171 ASSYM(UC_EFLAGS, offsetof(ucontext_t, uc_mcontext.mc_eflags));
172 ASSYM(UC_GS, offsetof(ucontext_t, uc_mcontext.mc_gs));
173 ASSYM(ENOENT, ENOENT);
174 ASSYM(EFAULT, EFAULT);
175 ASSYM(ENAMETOOLONG, ENAMETOOLONG);
176 ASSYM(MAXCOMLEN, MAXCOMLEN);
177 ASSYM(MAXPATHLEN, MAXPATHLEN);
178 ASSYM(BOOTINFO_SIZE, sizeof(struct bootinfo));
179 ASSYM(BI_VERSION, offsetof(struct bootinfo, bi_version));
180 ASSYM(BI_KERNELNAME, offsetof(struct bootinfo, bi_kernelname));
181 ASSYM(BI_NFS_DISKLESS, offsetof(struct bootinfo, bi_nfs_diskless));
182 ASSYM(NFSDISKLESS_SIZE, sizeof(struct nfs_diskless));
183 ASSYM(BI_SIZE, offsetof(struct bootinfo, bi_size));
184 ASSYM(BI_SYMTAB, offsetof(struct bootinfo, bi_symtab));
185 ASSYM(BI_ESYMTAB, offsetof(struct bootinfo, bi_esymtab));
186 ASSYM(BI_KERNEND, offsetof(struct bootinfo, bi_kernend));
187 ASSYM(PC_SIZEOF, sizeof(struct pcpu));
188 ASSYM(PC_PRVSPACE, offsetof(struct pcpu, pc_prvspace));
189 ASSYM(PC_CURTHREAD, offsetof(struct pcpu, pc_curthread));
190 ASSYM(PC_FPCURTHREAD, offsetof(struct pcpu, pc_fpcurthread));
191 ASSYM(PC_IDLETHREAD, offsetof(struct pcpu, pc_idlethread));
192 ASSYM(PC_CURPCB, offsetof(struct pcpu, pc_curpcb));
193 ASSYM(PC_COMMON_TSSP, offsetof(struct pcpu, pc_common_tssp));
194 ASSYM(PC_COMMON_TSSD, offsetof(struct pcpu, pc_common_tssd));
195 ASSYM(PC_TSS_GDT, offsetof(struct pcpu, pc_tss_gdt));
196 ASSYM(PC_FSGS_GDT, offsetof(struct pcpu, pc_fsgs_gdt));
197 ASSYM(PC_CURRENTLDT, offsetof(struct pcpu, pc_currentldt));
198 ASSYM(PC_CPUID, offsetof(struct pcpu, pc_cpuid));
199 ASSYM(PC_CURPMAP, offsetof(struct pcpu, pc_curpmap));
200 ASSYM(PC_PRIVATE_TSS, offsetof(struct pcpu, pc_private_tss));
201 ASSYM(PC_KESP0, offsetof(struct pcpu, pc_kesp0));
202 ASSYM(PC_TRAMPSTK, offsetof(struct pcpu, pc_trampstk));
203 ASSYM(PC_COPYOUT_BUF, offsetof(struct pcpu, pc_copyout_buf));
204 ASSYM(PC_IBPB_SET, offsetof(struct pcpu, pc_ibpb_set));
205 ASSYM(PC_MDS_TMP, offsetof(struct pcpu, pc_mds_tmp));
206 ASSYM(PC_MDS_BUF, offsetof(struct pcpu, pc_mds_buf));
207 ASSYM(PC_MDS_BUF64, offsetof(struct pcpu, pc_mds_buf64));
208 ASSYM(PMAP_TRM_MIN_ADDRESS, PMAP_TRM_MIN_ADDRESS);
209 ASSYM(KERNLOAD, KERNLOAD);
210 ASSYM(KERNBASE, KERNBASE);
211 
212 #ifdef DEV_APIC
213 ASSYM(LA_EOI, LAPIC_EOI * LAPIC_MEM_MUL);
214 ASSYM(LA_ISR, LAPIC_ISR0 * LAPIC_MEM_MUL);
215 #endif
216 
217 ASSYM(KCSEL, GSEL(GCODE_SEL, SEL_KPL));
218 ASSYM(KDSEL, GSEL(GDATA_SEL, SEL_KPL));
219 ASSYM(KPSEL, GSEL(GPRIV_SEL, SEL_KPL));
220 
221 ASSYM(BC32SEL, GSEL(GBIOSCODE32_SEL, SEL_KPL));
222 ASSYM(GPROC0_SEL, GPROC0_SEL);
223 ASSYM(VM86_FRAMESIZE, sizeof(struct vm86frame));
224 ASSYM(VM86_STACK_SPACE, VM86_STACK_SPACE);
225 
226 ASSYM(TRAMP_COPYOUT_SZ, TRAMP_COPYOUT_SZ);
227 
228 #ifdef	HWPMC_HOOKS
229 ASSYM(PMC_FN_USER_CALLCHAIN, PMC_FN_USER_CALLCHAIN);
230 #endif
231