Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/usermode/usermode Create syscall() prototype and le...



details:   https://anonhg.NetBSD.org/src/rev/217f0c8c74eb
branches:  trunk
changeset: 769399:217f0c8c74eb
user:      reinoud <reinoud%NetBSD.org@localhost>
date:      Thu Sep 08 14:49:42 2011 +0000

description:
Create syscall() prototype and let illegal instruction handler switch to that
switchframe

diffstat:

 sys/arch/usermode/usermode/syscall.c |  68 +++++++++++++++++++++++++++++------
 sys/arch/usermode/usermode/trap.c    |  32 ++++++----------
 2 files changed, 68 insertions(+), 32 deletions(-)

diffs (174 lines):

diff -r 1ce2d3075d7b -r 217f0c8c74eb sys/arch/usermode/usermode/syscall.c
--- a/sys/arch/usermode/usermode/syscall.c      Thu Sep 08 14:47:17 2011 +0000
+++ b/sys/arch/usermode/usermode/syscall.c      Thu Sep 08 14:49:42 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: syscall.c,v 1.6 2011/09/08 12:01:22 reinoud Exp $ */
+/* $NetBSD: syscall.c,v 1.7 2011/09/08 14:49:42 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.6 2011/09/08 12:01:22 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.7 2011/09/08 14:49:42 reinoud Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -35,33 +35,77 @@
 #include <sys/proc.h>
 #include <sys/lwp.h>
 #include <sys/sched.h>
-#include <sys/userret.h>
 #include <sys/ktrace.h>
 #include <sys/syscall.h>
+#include <sys/syscallvar.h>
+#include <sys/syscallargs.h>
+
+#include <sys/userret.h>
 #include <machine/pcb.h>
 #include <machine/thunk.h>
 
-extern int syscall(lwp_t *l);
+extern void syscall(void);
+
+void userret(struct lwp *l);
+
+void
+userret(struct lwp *l)
+{
+       /* invoke MI userret code */
+       mi_userret(l);
+}
 
 void
 child_return(void *arg)
 {
        lwp_t *l = arg;
 //     struct pcb *pcb = lwp_getpcb(l);
-//     struct trapframe *frame = pcb->pcb_tf;
 
        /* XXX? */
 //     frame->registers[0] = 0;
 
-printf("child returned! arg %p\n", arg);
-       mi_userret(l);
+       printf("child return! lwp %p\n", l);
+       userret(l);
        ktrsysret(SYS_fork, 0, 0);
 }
 
+void
+syscall(void)
+{      
+       lwp_t *l = curlwp;
+       struct pcb *pcb = lwp_getpcb(l);
+       ucontext_t *ucp = &pcb->pcb_userland_ucp;
+       uint *reg, i;
 
-int
-syscall(lwp_t *l)
-{
-printf("syscall called for lwp %p!\n", l);
-       return ENOENT;
+       l = curlwp;
+
+       printf("syscall called for lwp %p!\n", l);
+       reg = (int *) &ucp->uc_mcontext;
+#if 1
+       /* 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
+
+       /* system call accounting */
+       curcpu()->ci_data.cpu_nsyscall++;
+
+       /* XXX do we want do do emulation? */
+       LWP_CACHE_CREDS(l, l->l_proc);
+       /* TODO issue!! */
+
+       printf("syscall no. %d\n", reg[11]);
+/* skip instruction */
+reg[14] += 2;
+
+/* retval */
+reg[11] = 0;
+       printf("end of syscall : return to userland\n");
+       userret(l);
+printf("jump back to %p\n", (void *) reg[14]);
 }
+
diff -r 1ce2d3075d7b -r 217f0c8c74eb sys/arch/usermode/usermode/trap.c
--- a/sys/arch/usermode/usermode/trap.c Thu Sep 08 14:47:17 2011 +0000
+++ b/sys/arch/usermode/usermode/trap.c Thu Sep 08 14:49:42 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.34 2011/09/08 11:56:48 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.35 2011/09/08 14:49:42 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <reinoud%netbsd.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.34 2011/09/08 11:56:48 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.35 2011/09/08 14:49:42 reinoud Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -43,8 +43,6 @@
 #include <machine/pmap.h>
 #include <machine/thunk.h>
 
-#include <sys/syscallvar.h>
-#include <sys/syscallargs.h>
 
 //#include <machine/ctlreg.h>
 //#include <machine/trap.h>
@@ -234,6 +232,7 @@
 static void
 illegal_instruction_handler(int sig, siginfo_t *info, void *ctx)
 {
+       ucontext_t *uct = ctx;
        struct proc *p;
        struct lwp *l;
        struct pcb *pcb;
@@ -282,23 +281,16 @@
                printf("\n");
 #endif
 
-#if 0
-               /* MD syscall pre-fixup: extract `trapframe' from the MD ctx */
-               syscall_pre_fixup(info->si_addr, ctx, &pcb->pcb_tf);
-
-printf("retrieved opcode %"PRIiPTR"\n", opcode);
-
-               /* system call issueing  */
-               curcpu()->ci_data.cpu_nsyscall++;
+               /* copy this state to return to */
+               memcpy(&pcb->pcb_userland_ucp, uct, sizeof(ucontext_t));
 
-               /* XXX do we want do do emulation? */
-               LWP_CACHE_CREDS(l, l->l_proc);
-               syscall(l, &pcb->pcb_tf);
+               /* if its a syscall, switch to the syscall entry */
+//             if (syscall_check_opcode(info->si_addr)) {
+                       thunk_setcontext(&pcb->pcb_syscall_ucp);
+                       /* NOT REACHED */
+//             }
 
-               /* MD syscall post-fixup : convert `trapframe' back to MD ctx */
-               syscall_post_fixup(info->si_addr, ctx, &pcb->pcb_tf);
-#endif
-
-               panic("illegal instruction encountered\n");
+               panic("should deliver a trap to the process : illegal instruction "
+                       "encountered\n");
        }
 }



Home | Main Index | Thread Index | Old Index