Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/usermode implement reboot using execv



details:   https://anonhg.NetBSD.org/src/rev/30874f905909
branches:  trunk
changeset: 768237:30874f905909
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Fri Aug 12 11:37:04 2011 +0000

description:
implement reboot using execv

diffstat:

 sys/arch/usermode/dev/cpu.c          |  11 +++++------
 sys/arch/usermode/include/thunk.h    |   4 +++-
 sys/arch/usermode/usermode/machdep.c |  25 +++++++++++++++++++++++--
 sys/arch/usermode/usermode/thunk.c   |  12 ++++++++++--
 4 files changed, 41 insertions(+), 11 deletions(-)

diffs (160 lines):

diff -r e989bb7d8115 -r 30874f905909 sys/arch/usermode/dev/cpu.c
--- a/sys/arch/usermode/dev/cpu.c       Fri Aug 12 11:22:11 2011 +0000
+++ b/sys/arch/usermode/dev/cpu.c       Fri Aug 12 11:37:04 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.10 2011/08/12 00:57:24 jmcneill Exp $ */
+/* $NetBSD: cpu.c,v 1.11 2011/08/12 11:37:04 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.10 2011/08/12 00:57:24 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.11 2011/08/12 11:37:04 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -108,6 +108,8 @@
 void
 cpu_reboot(int howto, char *bootstr)
 {
+       extern void usermode_reboot(void);
+
        splhigh();
 
        if ((howto & RB_POWERDOWN) == RB_POWERDOWN)
@@ -124,10 +126,7 @@
 
        printf("rebooting...\n");
 
-       /*
-        * XXXJDM If we've panic'd, make sure we dump a core
-        */
-       thunk_abort();
+       usermode_reboot();
 
        /* NOTREACHED */
 }
diff -r e989bb7d8115 -r 30874f905909 sys/arch/usermode/include/thunk.h
--- a/sys/arch/usermode/include/thunk.h Fri Aug 12 11:22:11 2011 +0000
+++ b/sys/arch/usermode/include/thunk.h Fri Aug 12 11:37:04 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.h,v 1.1 2011/08/12 00:57:24 jmcneill Exp $ */
+/* $NetBSD: thunk.h,v 1.2 2011/08/12 11:37:04 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -48,4 +48,6 @@
 int    thunk_getchar(void);
 void   thunk_putchar(int);
 
+int    thunk_execv(const char *, char * const []);
+
 #endif /* !_ARCH_USERMODE_INCLUDE_THUNK_H */
diff -r e989bb7d8115 -r 30874f905909 sys/arch/usermode/usermode/machdep.c
--- a/sys/arch/usermode/usermode/machdep.c      Fri Aug 12 11:22:11 2011 +0000
+++ b/sys/arch/usermode/usermode/machdep.c      Fri Aug 12 11:37:04 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.10 2011/08/10 01:32:44 jmcneill Exp $ */
+/* $NetBSD: machdep.c,v 1.11 2011/08/12 11:37:04 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.10 2011/08/10 01:32:44 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.11 2011/08/12 11:37:04 jmcneill Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -41,6 +41,8 @@
 
 #include <dev/mm.h>
 
+#include <machine/thunk.h>
+
 #include "opt_memsize.h"
 
 char machine[] = "usermode";
@@ -50,7 +52,10 @@
 /* XXX */
 int            physmem = MEMSIZE * 1024 / PAGE_SIZE;
 
+static char **saved_argv;
+
 void   main(int argc, char *argv[]);
+void   usermode_reboot(void);
 
 void
 main(int argc, char *argv[])
@@ -60,6 +65,8 @@
        extern void kernmain(void);
        int i, j, r, tmpopt = 0;
 
+       saved_argv = argv;
+
        ttycons_consinit();
 
        for (i = 1; i < argc; i++) {
@@ -86,6 +93,20 @@
 }
 
 void
+usermode_reboot(void)
+{
+       struct itimerval itimer;
+
+       /* make sure the timer is turned off */
+       memset(&itimer, 0, sizeof(itimer));
+       thunk_setitimer(ITIMER_REAL, &itimer, NULL);
+
+       if (thunk_execv(saved_argv[0], saved_argv) == -1)
+               thunk_abort();
+       /* NOTREACHED */
+}
+
+void
 setstatclockrate(int arg)
 {
 }
diff -r e989bb7d8115 -r 30874f905909 sys/arch/usermode/usermode/thunk.c
--- a/sys/arch/usermode/usermode/thunk.c        Fri Aug 12 11:22:11 2011 +0000
+++ b/sys/arch/usermode/usermode/thunk.c        Fri Aug 12 11:37:04 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.1 2011/08/12 00:57:24 jmcneill Exp $ */
+/* $NetBSD: thunk.c,v 1.2 2011/08/12 11:37:05 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: thunk.c,v 1.1 2011/08/12 00:57:24 jmcneill Exp $");
+__RCSID("$NetBSD: thunk.c,v 1.2 2011/08/12 11:37:05 jmcneill Exp $");
 
 #include <machine/thunk.h>
 
@@ -37,6 +37,7 @@
 #include <stdlib.h>
 #include <time.h>
 #include <ucontext.h>
+#include <unistd.h>
 
 int
 thunk_setitimer(int which, const struct itimerval *value,
@@ -108,3 +109,10 @@
        putchar(c);
        fflush(stdout);
 }
+
+int
+thunk_execv(const char *path, char * const argv[])
+{
+       return execv(path, argv);
+}
+



Home | Main Index | Thread Index | Old Index