Module Name: src Committed By: reinoud Date: Thu Sep 8 12:01:22 UTC 2011
Modified Files: src/sys/arch/usermode/dev: cpu.c src/sys/arch/usermode/include: pcb.h src/sys/arch/usermode/usermode: syscall.c Log Message: Create a ucontext for the system call to work in; its cloned from the new pcb's call `userland' ucontext. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/sys/arch/usermode/dev/cpu.c cvs rdiff -u -r1.10 -r1.11 src/sys/arch/usermode/include/pcb.h cvs rdiff -u -r1.5 -r1.6 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/dev/cpu.c diff -u src/sys/arch/usermode/dev/cpu.c:1.34 src/sys/arch/usermode/dev/cpu.c:1.35 --- src/sys/arch/usermode/dev/cpu.c:1.34 Tue Sep 6 09:55:04 2011 +++ src/sys/arch/usermode/dev/cpu.c Thu Sep 8 12:01:22 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.c,v 1.34 2011/09/06 09:55:04 jmcneill Exp $ */ +/* $NetBSD: cpu.c,v 1.35 2011/09/08 12:01:22 reinoud Exp $ */ /*- * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca> @@ -29,7 +29,7 @@ #include "opt_cpu.h" #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.34 2011/09/06 09:55:04 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.35 2011/09/08 12:01:22 reinoud Exp $"); #include <sys/param.h> #include <sys/conf.h> @@ -296,6 +296,7 @@ panic("%s: shouldn't return", __func__); } +extern int syscall(lwp_t *l); void cpu_lwp_fork(struct lwp *l1, struct lwp *l2, void *stack, size_t stacksize, void (*func)(void *), void *arg) @@ -324,12 +325,23 @@ if (thunk_getcontext(&pcb2->pcb_ucp)) panic("getcontext failed"); + /* set up the ucontext for the userland */ pcb2->pcb_ucp.uc_stack.ss_sp = stack; pcb2->pcb_ucp.uc_stack.ss_size = stacksize; pcb2->pcb_ucp.uc_link = NULL; pcb2->pcb_ucp.uc_flags = _UC_STACK | _UC_CPU; thunk_makecontext(&pcb2->pcb_ucp, (void (*)(void))cpu_lwp_trampoline, 2, func, arg); + + /* set up the ucontext for the syscall */ + pcb2->pcb_ucp.uc_flags = _UC_CPU; + /* hack for it sets the stack anyway!! */ + pcb2->pcb_syscall_ucp.uc_stack.ss_sp = + ((uint8_t *) pcb2->pcb_syscall_ucp.uc_stack.ss_sp) - 4; + pcb2->pcb_syscall_ucp.uc_stack.ss_size = 0; + + thunk_makecontext_1(&pcb2->pcb_syscall_ucp, (void (*)(void)) syscall, + l2); } void @@ -337,7 +349,6 @@ { } -int syscall(lwp_t *l, struct trapframe *tr); void cpu_startup(void) { @@ -355,8 +366,8 @@ uvm_lwp_setuarea(&lwp0, (vaddr_t)&lwp0pcb); /* init trapframe (going nowhere!), maybe a panic func? */ - lwp0pcb.pcb_tf.tf_syscall = syscall; memcpy(&lwp0pcb.pcb_userland_ucp, &lwp0pcb.pcb_ucp, sizeof(ucontext_t)); + memcpy(&lwp0pcb.pcb_syscall_ucp, &lwp0pcb.pcb_ucp, sizeof(ucontext_t)); // thunk_makecontext_trapframe2go(&lwp0pcb.pcb_userland_ucp, NULL, NULL); } Index: src/sys/arch/usermode/include/pcb.h diff -u src/sys/arch/usermode/include/pcb.h:1.10 src/sys/arch/usermode/include/pcb.h:1.11 --- src/sys/arch/usermode/include/pcb.h:1.10 Sun Sep 4 21:01:39 2011 +++ src/sys/arch/usermode/include/pcb.h Thu Sep 8 12:01:22 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: pcb.h,v 1.10 2011/09/04 21:01:39 reinoud Exp $ */ +/* $NetBSD: pcb.h,v 1.11 2011/09/08 12:01:22 reinoud Exp $ */ /*- * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca> @@ -37,22 +37,18 @@ * XXX move to frame.h? */ -/* XXX unused XXX */ -typedef struct trapframe { - int (*tf_syscall)(lwp_t *, struct trapframe *); - int tf_reason; /* XXX unused */ - uintptr_t tf_io[8]; /* to transport info */ -} trapframe_t; - +//typedef ucontext_t trapframe; struct pcb { ucontext_t pcb_ucp; /* lwp switchframe */ ucontext_t pcb_userland_ucp; /* userland switchframe */ + ucontext_t pcb_syscall_ucp; /* to switch to for syscall */ + bool pcb_needfree; - struct trapframe pcb_tf; void * pcb_onfault; /* on fault handler */ int pcb_errno; /* save/restore place */ + int pcb_oldspl; }; #endif /* !_ARCH_USERMODE_INCLUDE_PCB_H */ Index: src/sys/arch/usermode/usermode/syscall.c diff -u src/sys/arch/usermode/usermode/syscall.c:1.5 src/sys/arch/usermode/usermode/syscall.c:1.6 --- src/sys/arch/usermode/usermode/syscall.c:1.5 Mon Aug 29 12:37:20 2011 +++ src/sys/arch/usermode/usermode/syscall.c Thu Sep 8 12:01:22 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: syscall.c,v 1.5 2011/08/29 12:37:20 reinoud Exp $ */ +/* $NetBSD: syscall.c,v 1.6 2011/09/08 12:01:22 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.5 2011/08/29 12:37:20 reinoud Exp $"); +__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.6 2011/09/08 12:01:22 reinoud Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -41,7 +41,7 @@ #include <machine/pcb.h> #include <machine/thunk.h> -int syscall(lwp_t *l, struct trapframe *tr); +extern int syscall(lwp_t *l); void child_return(void *arg) @@ -60,8 +60,8 @@ int -syscall(lwp_t *l, struct trapframe *tr) +syscall(lwp_t *l) { -printf("syscall called for lwp %p, trapframe %p!\n", l, tr); +printf("syscall called for lwp %p!\n", l); return ENOENT; }