| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: machdep.c,v 1.37 2011/12/14 19:40:02 reinoud Exp $ */ | | 1 | /* $NetBSD: machdep.c,v 1.38 2011/12/20 15:43:51 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.37 2011/12/14 19:40:02 reinoud Exp $"); | | 35 | __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.38 2011/12/20 15:43:51 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> |
| @@ -269,82 +269,88 @@ md_syscall_set_returnargs(lwp_t *l, ucon | | | @@ -269,82 +269,88 @@ md_syscall_set_returnargs(lwp_t *l, ucon |
269 | | | 269 | |
270 | /* set return parameters */ | | 270 | /* set return parameters */ |
271 | reg[11] = rval[0]; /* EAX */ | | 271 | reg[11] = rval[0]; /* EAX */ |
272 | if (error == 0) | | 272 | if (error == 0) |
273 | reg[ 9] = rval[1]; /* EDX */ | | 273 | reg[ 9] = rval[1]; /* EDX */ |
274 | | | 274 | |
275 | //dump_regs(reg); | | 275 | //dump_regs(reg); |
276 | } | | 276 | } |
277 | | | 277 | |
278 | int | | 278 | int |
279 | md_syscall_check_opcode(ucontext_t *ucp) | | 279 | md_syscall_check_opcode(ucontext_t *ucp) |
280 | { | | 280 | { |
281 | uint32_t opcode; | | 281 | uint32_t opcode; |
282 | #if 0 | | | |
283 | register_t *reg; | | | |
284 | | | | |
285 | reg = (register_t *) &ucp->uc_mcontext; | | | |
286 | dump_regs(reg); | | | |
287 | #endif | | | |
288 | | | 282 | |
289 | md_syscall_get_opcode(ucp, &opcode); | | 283 | md_syscall_get_opcode(ucp, &opcode); |
290 | | | 284 | |
291 | /* undefined instruction */ | | 285 | switch (opcode) { |
292 | if (opcode == 0xff0f) | | 286 | case 0xff0f: /* UD1 */ |
| | | 287 | case 0xff0b: /* UD2 */ |
| | | 288 | case 0x80cd: /* int $80 */ |
| | | 289 | case 0x340f: /* sysenter */ |
293 | return 1; | | 290 | return 1; |
294 | if (opcode == 0xff0b) | | 291 | default: |
295 | return 1; | | 292 | return 0; |
296 | | | 293 | } |
297 | /* TODO int $80 and sysenter */ | | | |
298 | return 0; | | | |
299 | } | | 294 | } |
300 | | | 295 | |
301 | void | | 296 | void |
302 | md_syscall_get_opcode(ucontext_t *ucp, uint32_t *opcode) | | 297 | md_syscall_get_opcode(ucontext_t *ucp, uint32_t *opcode) |
303 | { | | 298 | { |
304 | register_t *reg = (register_t *) &ucp->uc_mcontext; | | 299 | register_t *reg = (register_t *) &ucp->uc_mcontext; |
305 | // uint8_t *p8 = (uint8_t *) (reg[14]); | | 300 | // uint8_t *p8 = (uint8_t *) (reg[14]); |
306 | uint16_t *p16 = (uint16_t*) (reg[14]); | | 301 | uint16_t *p16 = (uint16_t*) (reg[14]); |
307 | | | 302 | |
308 | *opcode = 0; | | 303 | switch (*p16) { |
309 | | | 304 | case 0xff0f: /* UD1 */ |
310 | if (*p16 == 0xff0f) | | 305 | case 0xff0b: /* UD2 */ |
311 | *opcode = *p16; | | 306 | case 0x80cd: /* int $80 */ |
312 | if (*p16 == 0xff0b) | | 307 | case 0x340f: /* sysenter */ |
313 | *opcode = *p16; | | 308 | *opcode = *p16; |
314 | | | 309 | break; |
315 | /* TODO int $80 and sysenter */ | | 310 | default: |
| | | 311 | *opcode = 0; |
| | | 312 | } |
316 | } | | 313 | } |
317 | | | 314 | |
318 | void | | 315 | void |
319 | md_syscall_inc_pc(ucontext_t *ucp, uint32_t opcode) | | 316 | md_syscall_inc_pc(ucontext_t *ucp, uint32_t opcode) |
320 | { | | 317 | { |
321 | uint *reg = (int *) &ucp->uc_mcontext; | | 318 | uint *reg = (int *) &ucp->uc_mcontext; |
322 | | | 319 | |
323 | /* advance program counter */ | | 320 | /* advance program counter */ |
324 | if (opcode == 0xff0f) | | 321 | switch (opcode) { |
325 | reg[14] += 2; /* EIP */ | | 322 | case 0xff0f: /* UD1 */ |
326 | if (opcode == 0xff0b) | | 323 | case 0xff0b: /* UD2 */ |
| | | 324 | case 0x80cd: /* int $80 */ |
| | | 325 | case 0x340f: /* sysenter */ |
327 | reg[14] += 2; /* EIP */ | | 326 | reg[14] += 2; /* EIP */ |
328 | | | 327 | break; |
329 | /* TODO int $80 and sysenter */ | | 328 | default: |
| | | 329 | panic("%s, unknown illegal instruction: opcode = %x\n", |
| | | 330 | __func__, (uint32_t) opcode); |
| | | 331 | } |
330 | } | | 332 | } |
331 | | | 333 | |
332 | void | | 334 | void |
333 | md_syscall_dec_pc(ucontext_t *ucp, uint32_t opcode) | | 335 | md_syscall_dec_pc(ucontext_t *ucp, uint32_t opcode) |
334 | { | | 336 | { |
335 | uint *reg = (int *) &ucp->uc_mcontext; | | 337 | uint *reg = (int *) &ucp->uc_mcontext; |
336 | | | 338 | |
337 | /* advance program counter */ | | 339 | switch (opcode) { |
338 | if (opcode == 0xff0f) | | 340 | case 0xff0f: /* UD1 */ |
339 | reg[14] -= 2; /* EIP */ | | 341 | case 0xff0b: /* UD2 */ |
340 | if (opcode == 0xff0b) | | 342 | case 0x80cd: /* int $80 */ |
| | | 343 | case 0x340f: /* sysenter */ |
341 | reg[14] -= 2; /* EIP */ | | 344 | reg[14] -= 2; /* EIP */ |
342 | | | 345 | break; |
343 | /* TODO int $80 and sysenter */ | | 346 | default: |
| | | 347 | panic("%s, unknown illegal instruction: opcode = %x\n", |
| | | 348 | __func__, (uint32_t) opcode); |
| | | 349 | } |
344 | } | | 350 | } |
345 | | | 351 | |
346 | | | 352 | |
347 | #else | | 353 | #else |
348 | # error machdep functions not yet ported to this architecture | | 354 | # error machdep functions not yet ported to this architecture |
349 | #endif | | 355 | #endif |
350 | | | 356 | |