Module Name:    src
Committed By:   reinoud
Date:           Thu Sep  8 14:49:42 UTC 2011

Modified Files:
        src/sys/arch/usermode/usermode: syscall.c trap.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/usermode/usermode/syscall.c
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/usermode/usermode/trap.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/usermode/syscall.c
diff -u src/sys/arch/usermode/usermode/syscall.c:1.6 src/sys/arch/usermode/usermode/syscall.c:1.7
--- src/sys/arch/usermode/usermode/syscall.c:1.6	Thu Sep  8 12:01:22 2011
+++ src/sys/arch/usermode/usermode/syscall.c	Thu Sep  8 14:49:42 2011
@@ -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 <[email protected]>
@@ -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);
 }
 
-
-int
-syscall(lwp_t *l)
-{
-printf("syscall called for lwp %p!\n", l);
-	return ENOENT;
+void
+syscall(void)
+{	
+	lwp_t *l = curlwp;
+	struct pcb *pcb = lwp_getpcb(l);
+	ucontext_t *ucp = &pcb->pcb_userland_ucp;
+	uint *reg, i;
+
+	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]);
 }
+

Index: src/sys/arch/usermode/usermode/trap.c
diff -u src/sys/arch/usermode/usermode/trap.c:1.34 src/sys/arch/usermode/usermode/trap.c:1.35
--- src/sys/arch/usermode/usermode/trap.c:1.34	Thu Sep  8 11:56:48 2011
+++ src/sys/arch/usermode/usermode/trap.c	Thu Sep  8 14:49:42 2011
@@ -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 <[email protected]>
@@ -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);
-
-		/* MD syscall post-fixup : convert `trapframe' back to MD ctx */
-		syscall_post_fixup(info->si_addr, ctx, &pcb->pcb_tf);
-#endif
+		/* if its a syscall, switch to the syscall entry */
+//		if (syscall_check_opcode(info->si_addr)) {
+			thunk_setcontext(&pcb->pcb_syscall_ucp);
+			/* NOT REACHED */
+//		}
 
-		panic("illegal instruction encountered\n");
+		panic("should deliver a trap to the process : illegal instruction "
+			"encountered\n");
 	}
 }

Reply via email to