Wed Dec 14 18:51:39 2011 UTC ()
Remove the need for a siginfo structure in illegal instruction handling.


(reinoud)
diff -r1.5 -r1.6 src/sys/arch/usermode/include/machdep.h
diff -r1.35 -r1.36 src/sys/arch/usermode/usermode/machdep.c
diff -r1.44 -r1.45 src/sys/arch/usermode/usermode/trap.c

cvs diff -r1.5 -r1.6 src/sys/arch/usermode/include/machdep.h (expand / switch to unified diff)

--- src/sys/arch/usermode/include/machdep.h 2011/12/14 04:12:22 1.5
+++ src/sys/arch/usermode/include/machdep.h 2011/12/14 18:51:39 1.6
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: machdep.h,v 1.5 2011/12/14 04:12:22 jmcneill Exp $ */ 1/* $NetBSD: machdep.h,v 1.6 2011/12/14 18:51:39 reinoud Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2011 Reinoud Zandijk <reinoud@netbsd.org> 4 * Copyright (c) 2011 Reinoud Zandijk <reinoud@netbsd.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -16,27 +16,27 @@ @@ -16,27 +16,27 @@
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29int md_syscall_check_opcode(void *ptr); 29int md_syscall_check_opcode(ucontext_t *ucp);
30void md_syscall_get_opcode(ucontext_t *ucp, uint32_t *opcode); 30void md_syscall_get_opcode(ucontext_t *ucp, uint32_t *opcode);
31void md_syscall_get_syscallnumber(ucontext_t *ucp, uint32_t *code); 31void md_syscall_get_syscallnumber(ucontext_t *ucp, uint32_t *code);
32int md_syscall_getargs(lwp_t *l, ucontext_t *ucp, int nargs, int argsize, 32int md_syscall_getargs(lwp_t *l, ucontext_t *ucp, int nargs, int argsize,
33 register_t *args); 33 register_t *args);
34void md_syscall_set_returnargs(lwp_t *l, ucontext_t *ucp, 34void md_syscall_set_returnargs(lwp_t *l, ucontext_t *ucp,
35 int error, register_t *rval); 35 int error, register_t *rval);
36void md_syscall_inc_pc(ucontext_t *ucp, uint32_t opcode); 36void md_syscall_inc_pc(ucontext_t *ucp, uint32_t opcode);
37void md_syscall_dec_pc(ucontext_t *ucp, uint32_t opcode); 37void md_syscall_dec_pc(ucontext_t *ucp, uint32_t opcode);
38 38
39/* handlers */ 39/* handlers */
40void syscall(void); 40void syscall(void);
41void pagefault(void); 41void pagefault(void);
42 42

cvs diff -r1.35 -r1.36 src/sys/arch/usermode/usermode/machdep.c (expand / switch to unified diff)

--- src/sys/arch/usermode/usermode/machdep.c 2011/12/13 20:59:20 1.35
+++ src/sys/arch/usermode/usermode/machdep.c 2011/12/14 18:51:39 1.36
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: machdep.c,v 1.35 2011/12/13 20:59:20 reinoud Exp $ */ 1/* $NetBSD: machdep.c,v 1.36 2011/12/14 18:51:39 reinoud Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2011 Reinoud Zandijk <reinoud@netbsd.org> 4 * Copyright (c) 2011 Reinoud Zandijk <reinoud@netbsd.org>
5 * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> 5 * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -22,27 +22,27 @@ @@ -22,27 +22,27 @@
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE. 27 * POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30#include "opt_memsize.h" 30#include "opt_memsize.h"
31#include "opt_sdl.h" 31#include "opt_sdl.h"
32#include "opt_urkelvisor.h" 32#include "opt_urkelvisor.h"
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.35 2011/12/13 20:59:20 reinoud Exp $"); 35__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.36 2011/12/14 18:51:39 reinoud Exp $");
36 36
37#include <sys/types.h> 37#include <sys/types.h>
38#include <sys/param.h> 38#include <sys/param.h>
39#include <sys/time.h> 39#include <sys/time.h>
40#include <sys/exec.h> 40#include <sys/exec.h>
41#include <sys/buf.h> 41#include <sys/buf.h>
42#include <sys/boot_flag.h> 42#include <sys/boot_flag.h>
43#include <sys/ucontext.h> 43#include <sys/ucontext.h>
44#include <machine/pcb.h> 44#include <machine/pcb.h>
45#include <machine/psl.h> 45#include <machine/psl.h>
46 46
47#include <uvm/uvm_extern.h> 47#include <uvm/uvm_extern.h>
48#include <uvm/uvm_page.h> 48#include <uvm/uvm_page.h>
@@ -264,35 +264,36 @@ md_syscall_set_returnargs(lwp_t *l, ucon @@ -264,35 +264,36 @@ md_syscall_set_returnargs(lwp_t *l, ucon
264 rval[0] = error; 264 rval[0] = error;
265 reg[16] |= PSL_C; /* EFL */ 265 reg[16] |= PSL_C; /* EFL */
266 } 266 }
267 267
268 /* set return parameters */ 268 /* set return parameters */
269 reg[11] = rval[0]; /* EAX */ 269 reg[11] = rval[0]; /* EAX */
270 if (error == 0) 270 if (error == 0)
271 reg[ 9] = rval[1]; /* EDX */ 271 reg[ 9] = rval[1]; /* EDX */
272 272
273 //dump_regs(reg); 273 //dump_regs(reg);
274} 274}
275 275
276int 276int
277md_syscall_check_opcode(void *ptr) 277md_syscall_check_opcode(ucontext_t *ucp)
278{ 278{
279 uint16_t *p16; 279 uint32_t opcode;
 280
 281 md_syscall_get_opcode(ucp, &opcode);
280 282
281 /* undefined instruction */ 283 /* undefined instruction */
282 p16 = (uint16_t *) ptr; 284 if (opcode == 0xff0f)
283 if (*p16 == 0xff0f) 
284 return 1; 285 return 1;
285 if (*p16 == 0xff0b) 286 if (opcode == 0xff0b)
286 return 1; 287 return 1;
287 288
288 /* TODO int $80 and sysenter */ 289 /* TODO int $80 and sysenter */
289 return 0; 290 return 0;
290} 291}
291 292
292void 293void
293md_syscall_get_opcode(ucontext_t *ucp, uint32_t *opcode) 294md_syscall_get_opcode(ucontext_t *ucp, uint32_t *opcode)
294{ 295{
295 uint *reg = (int *) &ucp->uc_mcontext; 296 uint *reg = (int *) &ucp->uc_mcontext;
296// uint8_t *p8 = (uint8_t *) (reg[14]); 297// uint8_t *p8 = (uint8_t *) (reg[14]);
297 uint16_t *p16 = (uint16_t*) (reg[14]); 298 uint16_t *p16 = (uint16_t*) (reg[14]);
298 299

cvs diff -r1.44 -r1.45 src/sys/arch/usermode/usermode/trap.c (expand / switch to unified diff)

--- src/sys/arch/usermode/usermode/trap.c 2011/12/14 04:12:22 1.44
+++ src/sys/arch/usermode/usermode/trap.c 2011/12/14 18:51:39 1.45
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: trap.c,v 1.44 2011/12/14 04:12:22 jmcneill Exp $ */ 1/* $NetBSD: trap.c,v 1.45 2011/12/14 18:51:39 reinoud Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2011 Reinoud Zandijk <reinoud@netbsd.org> 4 * Copyright (c) 2011 Reinoud Zandijk <reinoud@netbsd.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.44 2011/12/14 04:12:22 jmcneill Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.45 2011/12/14 18:51:39 reinoud Exp $");
31 31
32#include <sys/types.h> 32#include <sys/types.h>
33#include <sys/param.h> 33#include <sys/param.h>
34#include <sys/systm.h> 34#include <sys/systm.h>
35#include <sys/proc.h> 35#include <sys/proc.h>
36#include <sys/systm.h> 36#include <sys/systm.h>
37#include <sys/userret.h> 37#include <sys/userret.h>
38#include <sys/errno.h> 38#include <sys/errno.h>
39 39
40#include <uvm/uvm_extern.h> 40#include <uvm/uvm_extern.h>
41#include <machine/cpu.h> 41#include <machine/cpu.h>
42#include <machine/pcb.h> 42#include <machine/pcb.h>
43#include <machine/pmap.h> 43#include <machine/pmap.h>
@@ -218,27 +218,27 @@ illegal_instruction_handler(int sig, sig @@ -218,27 +218,27 @@ illegal_instruction_handler(int sig, sig
218 printf("%p : ", info->si_addr); 218 printf("%p : ", info->si_addr);
219 for (int i = 0; i < 10; i++) 219 for (int i = 0; i < 10; i++)
220 printf("%02x ", *((uint8_t *) info->si_addr + i)); 220 printf("%02x ", *((uint8_t *) info->si_addr + i));
221 printf("\n"); 221 printf("\n");
222#endif 222#endif
223 223
224 l = curlwp; 224 l = curlwp;
225 pcb = lwp_getpcb(l); 225 pcb = lwp_getpcb(l);
226 226
227 /* copy this state to return to */ 227 /* copy this state to return to */
228 memcpy(&pcb->pcb_userret_ucp, uct, sizeof(ucontext_t)); 228 memcpy(&pcb->pcb_userret_ucp, uct, sizeof(ucontext_t));
229 229
230 /* if its a syscall ... */ 230 /* if its a syscall ... */
231 if (md_syscall_check_opcode(info->si_addr)) { 231 if (md_syscall_check_opcode(uct)) {
232 /* switch to the syscall entry on return from signal */ 232 /* switch to the syscall entry on return from signal */
233 memcpy(uct, &pcb->pcb_syscall_ucp, sizeof(ucontext_t)); 233 memcpy(uct, &pcb->pcb_syscall_ucp, sizeof(ucontext_t));
234 return; 234 return;
235 } 235 }
236 236
237 panic("should deliver a trap to the process : illegal instruction " 237 panic("should deliver a trap to the process : illegal instruction "
238 "encountered\n"); 238 "encountered\n");
239} 239}
240 240
241 241
242/* 242/*
243 * Entry point from the segv handler; check if its a pmap reference fault or 243 * Entry point from the segv handler; check if its a pmap reference fault or
244 * let uvm handle it. 244 * let uvm handle it.