Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/usermode machdep.c: Cleanup the machine dependent c...



details:   https://anonhg.NetBSD.org/src/rev/0350aa8cb74e
branches:  trunk
changeset: 769421:0350aa8cb74e
user:      reinoud <reinoud%NetBSD.org@localhost>
date:      Fri Sep 09 12:44:27 2011 +0000

description:
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.

diffstat:

 sys/arch/usermode/include/machdep.h  |   5 +-
 sys/arch/usermode/usermode/machdep.c |  84 ++++++++++++++++-------------------
 sys/arch/usermode/usermode/syscall.c |  42 ++++++++++++-----
 3 files changed, 72 insertions(+), 59 deletions(-)

diffs (259 lines):

diff -r 637db7ab6890 -r 0350aa8cb74e sys/arch/usermode/include/machdep.h
--- a/sys/arch/usermode/include/machdep.h       Fri Sep 09 12:43:14 2011 +0000
+++ b/sys/arch/usermode/include/machdep.h       Fri Sep 09 12:44:27 2011 +0000
@@ -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 <reinoud%netbsd.org@localhost>
@@ -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);
diff -r 637db7ab6890 -r 0350aa8cb74e sys/arch/usermode/usermode/machdep.c
--- a/sys/arch/usermode/usermode/machdep.c      Fri Sep 09 12:43:14 2011 +0000
+++ b/sys/arch/usermode/usermode/machdep.c      Fri Sep 09 12:44:27 2011 +0000
@@ -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 <reinoud%netbsd.org@localhost>
@@ -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;
+       register_t *reg = (register_t *) &ucp->uc_mcontext;
+
+       reg[16] &= ~PSL_C;              /* EFL */
+       if (error) {
+               rval[0] = error;
+               reg[16] |= PSL_C;       /* EFL */
+       }
 
        /* set return parameters */
-       reg[11] = rval[0];      /* EAX */
-       reg[ 9] = rval[1];      /* EDX */
+       reg[11] = rval[0];              /* EAX */
+       if (!error)
+               reg[ 9] = rval[1];      /* EDX */
 
-#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"};
-
-       for (i =0; i < 19; i++)
-               printf("reg[%02d] (%6s) = %"PRIx32"\n", i, name[i], reg[i]);
-#endif
-
+       //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
 
diff -r 637db7ab6890 -r 0350aa8cb74e sys/arch/usermode/usermode/syscall.c
--- a/sys/arch/usermode/usermode/syscall.c      Fri Sep 09 12:43:14 2011 +0000
+++ b/sys/arch/usermode/usermode/syscall.c      Fri Sep 09 12:44:27 2011 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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;
 
+       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);
 
-       args  = copyargs;
-       rval[0] = rval[1] = 0;
-       error = md_syscall_getargs(l, ucp, nargs, argsize, args);
+       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);



Home | Main Index | Thread Index | Old Index