Module Name: src Committed By: reinoud Date: Fri Sep 9 12:44:27 UTC 2011
Modified Files: src/sys/arch/usermode/include: machdep.h src/sys/arch/usermode/usermode: machdep.c syscall.c Log Message: machdep.c: Cleanup the machine dependent code and set the carry flag on error out. While here also clean up register printing. syscall.c: Add debug syscall printing code to track basic syscalls being taken. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/arch/usermode/include/machdep.h cvs rdiff -u -r1.27 -r1.28 src/sys/arch/usermode/usermode/machdep.c cvs rdiff -u -r1.8 -r1.9 src/sys/arch/usermode/usermode/syscall.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/usermode/include/machdep.h diff -u src/sys/arch/usermode/include/machdep.h:1.2 src/sys/arch/usermode/include/machdep.h:1.3 --- src/sys/arch/usermode/include/machdep.h:1.2 Thu Sep 8 19:38:59 2011 +++ src/sys/arch/usermode/include/machdep.h Fri Sep 9 12:44:27 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.h,v 1.2 2011/09/08 19:38:59 reinoud Exp $ */ +/* $NetBSD: machdep.h,v 1.3 2011/09/09 12:44:27 reinoud Exp $ */ /*- * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org> @@ -30,7 +30,8 @@ void md_syscall_get_syscallnumber(ucontext_t *ucp, uint32_t *code); int md_syscall_getargs(lwp_t *l, ucontext_t *ucp, int nargs, int argsize, register_t *args); -void md_syscall_set_returnargs(lwp_t *l, ucontext_t *ucp, register_t *rval); +void md_syscall_set_returnargs(lwp_t *l, ucontext_t *ucp, + int error, register_t *rval); void md_syscall_inc_pc(ucontext_t *ucp); void syscall(void); Index: src/sys/arch/usermode/usermode/machdep.c diff -u src/sys/arch/usermode/usermode/machdep.c:1.27 src/sys/arch/usermode/usermode/machdep.c:1.28 --- src/sys/arch/usermode/usermode/machdep.c:1.27 Thu Sep 8 19:39:00 2011 +++ src/sys/arch/usermode/usermode/machdep.c Fri Sep 9 12:44:27 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.27 2011/09/08 19:39:00 reinoud Exp $ */ +/* $NetBSD: machdep.c,v 1.28 2011/09/09 12:44:27 reinoud Exp $ */ /*- * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org> @@ -32,7 +32,7 @@ #include "opt_urkelvisor.h" #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.27 2011/09/08 19:39:00 reinoud Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.28 2011/09/09 12:44:27 reinoud Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -42,6 +42,7 @@ #include <sys/boot_flag.h> #include <sys/ucontext.h> #include <machine/pcb.h> +#include <machine/psl.h> #include <uvm/uvm_extern.h> #include <uvm/uvm_page.h> @@ -156,6 +157,22 @@ #ifdef __i386__ +#if 0 +static void dump_regs(ucontext_t *ctx); + +static void +dump_regs(register_t *reg) +{ + /* register dump before call */ + const char *name[] = {"GS", "FS", "ES", "DS", "EDI", "ESI", "EBP", "ESP", + "EBX", "EDX", "ECX", "EAX", "TRAPNO", "ERR", "EIP", "CS", "EFL", + "UESP", "SS"}; + + for (i =0; i < 19; i++) + printf("reg[%02d] (%6s) = %"PRIx32"\n", i, name[i], reg[i]); +} +#endif + void setregs(struct lwp *l, struct exec_package *pack, vaddr_t stack) { @@ -189,15 +206,7 @@ reg[ 8] = l->l_proc->p_psstrp; /* _REG_EBX */ reg[17] = (stack); /* _REG_UESP */ -#if 0 - /* register dump before call */ - const char *name[] = {"GS", "FS", "ES", "DS", "EDI", "ESI", "EBP", "ESP", - "EBX", "EDX", "ECX", "EAX", "TRAPNO", "ERR", "EIP", "CS", "EFL", - "UESP", "SS"}; - - for (i =0; i < 19; i++) - printf("reg[%02d] (%6s) = %"PRIx32"\n", i, name[i], reg[i]); -#endif + //dump_regs(reg); #ifdef DEBUG_EXEC printf("updated pcb %p\n", pcb); @@ -229,28 +238,15 @@ uint *reg = (int *) &ucp->uc_mcontext; register_t *sp = (register_t *) reg[17];/* ESP */ int ret; - uint i; - - i = 0; -#if 0 - reg = (int *) &ucp->uc_mcontext; - /* register dump before call */ - const char *name[] = {"GS", "FS", "ES", "DS", "EDI", "ESI", "EBP", "ESP", - "EBX", "EDX", "ECX", "EAX", "TRAPNO", "ERR", "EIP", "CS", "EFL", - "UESP", "SS"}; - - for (i =0; i < 19; i++) - printf("reg[%02d] (%6s) = %"PRIx32"\n", i, name[i], reg[i]); - printf("\n"); -#endif + //dump_regs(reg); ret = copyin(sp + 1, args, argsize); #if 0 + int i; for (i = 0; i < nargs+4; i++) printf("stack[%02d] = %"PRIx32"\n", i, (uint) sp[i]); -#endif -#if 0 + for (i = 0; i < nargs; i++) printf("arg[%02d] = %"PRIx32"\n", i, (uint) args[i]); printf("\n"); @@ -260,26 +256,23 @@ } void -md_syscall_set_returnargs(lwp_t *l, ucontext_t *ucp, register_t *rval) +md_syscall_set_returnargs(lwp_t *l, ucontext_t *ucp, + int error, register_t *rval) { - uint *reg = (int *) &ucp->uc_mcontext; - - /* set return parameters */ - reg[11] = rval[0]; /* EAX */ - reg[ 9] = rval[1]; /* EDX */ + register_t *reg = (register_t *) &ucp->uc_mcontext; -#if 0 - uint i; - reg = (int *) &ucp->uc_mcontext; - /* register dump before call */ - const char *name[] = {"GS", "FS", "ES", "DS", "EDI", "ESI", "EBP", "ESP", - "EBX", "EDX", "ECX", "EAX", "TRAPNO", "ERR", "EIP", "CS", "EFL", - "UESP", "SS"}; + reg[16] &= ~PSL_C; /* EFL */ + if (error) { + rval[0] = error; + reg[16] |= PSL_C; /* EFL */ + } - for (i =0; i < 19; i++) - printf("reg[%02d] (%6s) = %"PRIx32"\n", i, name[i], reg[i]); -#endif + /* set return parameters */ + reg[11] = rval[0]; /* EAX */ + if (!error) + reg[ 9] = rval[1]; /* EDX */ + //dump_regs(reg); } int @@ -295,6 +288,7 @@ return 1; /* TODO int $80 and sysenter */ + return 0; } @@ -313,11 +307,11 @@ /* TODO int $80 and sysenter */ - printf("jump back to %p\n", (void *) reg[14]); + // printf("jump back to %p\n", (void *) reg[14]); } #else -# error setregs() not yet ported to this architecture +# error machdep functions not yet ported to this architecture #endif Index: src/sys/arch/usermode/usermode/syscall.c diff -u src/sys/arch/usermode/usermode/syscall.c:1.8 src/sys/arch/usermode/usermode/syscall.c:1.9 --- src/sys/arch/usermode/usermode/syscall.c:1.8 Thu Sep 8 19:39:00 2011 +++ src/sys/arch/usermode/usermode/syscall.c Fri Sep 9 12:44:27 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: syscall.c,v 1.8 2011/09/08 19:39:00 reinoud Exp $ */ +/* $NetBSD: syscall.c,v 1.9 2011/09/09 12:44:27 reinoud Exp $ */ /*- * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.8 2011/09/08 19:39:00 reinoud Exp $"); +__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.9 2011/09/09 12:44:27 reinoud Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -84,8 +84,6 @@ uint nargs, argsize; int error; -// printf("syscall called for lwp %p!\n", l); - /* system call accounting */ curcpu()->ci_data.cpu_nsyscall++; LWP_CACHE_CREDS(l, l->l_proc); @@ -98,24 +96,44 @@ nargs = callp->sy_narg; argsize = callp->sy_argsize; - printf("syscall no. %d, ", code); - printf("nargs %d, argsize %d => ", nargs, argsize); - args = copyargs; rval[0] = rval[1] = 0; error = md_syscall_getargs(l, ucp, nargs, argsize, args); + +#if 0 + printf("syscall no. %d, ", code); + printf("nargs %d, argsize %d => ", nargs, argsize); + + if (code == 3) + printf("read(%d, %p, %d) => ", (int) args[0], + (void *) args[1], (int) args[2]); + if (code == 4) + printf("write(%d, %p ('%s'), %d) => ", + (int) args[0], (void *) args[1], + (char *) args[1], (int) args[2]); + if (code == 5) + printf("open('%s', %d,...) => ", (char *) (args[0]), + (int) (args[1])); + if (code == 440) + printf("stat(%d, %p) => ", (uint32_t) args[0], + (void *) args[1]); +#endif + if (!error) error = (*callp->sy_call)(l, args, rval); - printf("error = %d, rval[0] = %"PRIx32", retval[1] = %"PRIx32"\n", - error, (uint) rval[0], (uint) rval[1]); +#if 0 + if (code ==3) + printf("{'%s'} => ", (char *) args[1]); + printf("error = %d, rval[0] = 0x%"PRIx32", retval[1] = 0x%"PRIx32"\n", + error, (uint) (rval[0]), (uint) (rval[1])); +#endif + switch (error) { default: - rval[0] = error; -// rval[1] = 0; /* fall trough */ case 0: - md_syscall_set_returnargs(l, ucp, rval); + md_syscall_set_returnargs(l, ucp, error, rval); /* fall trough */ case EJUSTRETURN: md_syscall_inc_pc(ucp);