2 * Copyright (c) 2004 Marcel Moolenaar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
33 #include <sys/sysproto.h>
34 #include <sys/kernel.h>
36 #include <sys/mutex.h>
37 #include <sys/pioctl.h>
39 #include <sys/ptrace.h>
40 #include <sys/signalvar.h>
41 #include <sys/syscall.h>
42 #include <sys/sysent.h>
43 #include <machine/cpu.h>
44 #include <machine/fpu.h>
45 #include <machine/frame.h>
46 #include <machine/md_var.h>
47 #include <x86/include/psl.h>
49 #include <security/audit/audit.h>
51 #include <compat/ia32/ia32_util.h>
54 ia32_set_syscall_retval(struct thread *td, int error)
63 tf->tf_scratch.gr8 = td->td_retval[0]; /* eax */
64 tf->tf_scratch.gr10 = td->td_retval[1]; /* edx */
65 ia64_set_eflag(ia64_get_eflag() & ~PSL_C);
70 * Reconstruct pc, assuming lcall $X,y is 7 bytes,
71 * int 0x80 is 2 bytes. XXX Assume int 0x80.
73 tf->tf_special.iip -= 2;
81 if (p->p_sysent->sv_errsize) {
82 if (error >= p->p_sysent->sv_errsize)
85 error = p->p_sysent->sv_errtbl[error];
87 tf->tf_scratch.gr8 = error;
88 ia64_set_eflag(ia64_get_eflag() | PSL_C);
94 ia32_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
105 params = (caddr_t)(tf->tf_special.sp & ((1L<<32)-1)) +
107 sa->code = tf->tf_scratch.gr8; /* eax */
109 if (sa->code == SYS_syscall) {
110 /* Code is first argument, followed by actual args. */
111 sa->code = fuword32(params);
112 params += sizeof(int);
113 } else if (sa->code == SYS___syscall) {
115 * Like syscall, but code is a quad, so as to maintain
116 * quad alignment for the rest of the arguments. We
117 * use a 32-bit fetch in case params is not aligned.
119 sa->code = fuword32(params);
120 params += sizeof(quad_t);
123 if (p->p_sysent->sv_mask)
124 sa->code &= p->p_sysent->sv_mask;
125 if (sa->code >= p->p_sysent->sv_size)
126 sa->callp = &p->p_sysent->sv_table[0];
128 sa->callp = &p->p_sysent->sv_table[sa->code];
129 sa->narg = sa->callp->sy_narg;
131 if (params != NULL && sa->narg != 0)
132 error = copyin(params, (caddr_t)args, sa->narg * sizeof(int));
135 sa->args = &sa->args32[0];
138 for (i = 0; i < sa->narg; i++)
139 sa->args32[i] = args[i];
140 td->td_retval[0] = 0;
141 td->td_retval[1] = tf->tf_scratch.gr10; /* edx */
147 #include "../../kern/subr_syscall.c"
150 ia32_syscall(struct trapframe *tf)
153 struct syscall_args sa;
159 eflags = ia64_get_eflag();
161 error = syscallenter(td, &sa);
166 if ((eflags & PSL_T) && !(eflags & PSL_VM)) {
167 ia64_set_eflag(ia64_get_eflag() & ~PSL_T);
168 ksiginfo_init_trap(&ksi);
169 ksi.ksi_signo = SIGTRAP;
170 ksi.ksi_code = TRAP_TRACE;
171 ksi.ksi_addr = (void *)tf->tf_special.iip;
172 trapsignal(td, &ksi);
175 syscallret(td, error, &sa);
179 * ia32_trap() is called from exception.S to handle the IA-32 specific
180 * interruption vectors.
183 ia32_trap(int vector, struct trapframe *tf)
191 KASSERT(TRAPF_USERMODE(tf), ("%s: In kernel mode???", __func__));
193 ia64_set_fpsr(IA64_FPSR_DEFAULT);
194 PCPU_INC(cnt.v_trap);
200 if (td->td_ucred != p->p_ucred)
201 cred_update_thread(td);
205 case IA64_VEC_IA32_EXCEPTION:
206 switch ((tf->tf_special.isr >> 16) & 0xffff) {
207 case IA32_EXCEPTION_DIVIDE:
211 case IA32_EXCEPTION_DEBUG:
212 case IA32_EXCEPTION_BREAK:
215 case IA32_EXCEPTION_OVERFLOW:
219 case IA32_EXCEPTION_BOUND:
223 case IA32_EXCEPTION_DNA:
227 case IA32_EXCEPTION_NOT_PRESENT:
228 case IA32_EXCEPTION_STACK_FAULT:
229 case IA32_EXCEPTION_GPFAULT:
230 ucode = (tf->tf_special.isr & 0xffff) + BUS_SEGM_FAULT;
233 case IA32_EXCEPTION_FPERROR:
237 case IA32_EXCEPTION_ALIGNMENT_CHECK:
238 ucode = tf->tf_special.ifa; /* VA */
241 case IA32_EXCEPTION_STREAMING_SIMD:
246 trap_panic(vector, tf);
251 case IA64_VEC_IA32_INTERCEPT:
252 /* XXX Maybe need to emulate ia32 instruction. */
253 trap_panic(vector, tf);
255 case IA64_VEC_IA32_INTERRUPT:
256 /* INT n instruction - probably a syscall. */
257 if (((tf->tf_special.isr >> 16) & 0xffff) == 0x80) {
261 ucode = (tf->tf_special.isr >> 16) & 0xffff;
266 /* Should never happen of course. */
267 trap_panic(vector, tf);
271 KASSERT(sig != 0, ("%s: signal not set", __func__));
273 ksiginfo_init_trap(&ksi);
275 ksi.ksi_code = (int)ucode; /* XXX */
277 trapsignal(td, &ksi);