Module Name:    src
Committed By:   jmcneill
Date:           Fri Aug 12 11:37:05 UTC 2011

Modified Files:
        src/sys/arch/usermode/dev: cpu.c
        src/sys/arch/usermode/include: thunk.h
        src/sys/arch/usermode/usermode: machdep.c thunk.c

Log Message:
implement reboot using execv


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/usermode/dev/cpu.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/usermode/include/thunk.h
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/usermode/usermode/machdep.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/usermode/usermode/thunk.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.10 src/sys/arch/usermode/dev/cpu.c:1.11
--- src/sys/arch/usermode/dev/cpu.c:1.10	Fri Aug 12 00:57:24 2011
+++ src/sys/arch/usermode/dev/cpu.c	Fri Aug 12 11:37:04 2011
@@ -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 <jmcne...@invisible.ca>
@@ -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 */
 }

Index: src/sys/arch/usermode/include/thunk.h
diff -u src/sys/arch/usermode/include/thunk.h:1.1 src/sys/arch/usermode/include/thunk.h:1.2
--- src/sys/arch/usermode/include/thunk.h:1.1	Fri Aug 12 00:57:24 2011
+++ src/sys/arch/usermode/include/thunk.h	Fri Aug 12 11:37:04 2011
@@ -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 <jmcne...@invisible.ca>
@@ -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 */

Index: src/sys/arch/usermode/usermode/machdep.c
diff -u src/sys/arch/usermode/usermode/machdep.c:1.10 src/sys/arch/usermode/usermode/machdep.c:1.11
--- src/sys/arch/usermode/usermode/machdep.c:1.10	Wed Aug 10 01:32:44 2011
+++ src/sys/arch/usermode/usermode/machdep.c	Fri Aug 12 11:37:04 2011
@@ -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 <jmcne...@invisible.ca>
@@ -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)
 {
 }

Index: src/sys/arch/usermode/usermode/thunk.c
diff -u src/sys/arch/usermode/usermode/thunk.c:1.1 src/sys/arch/usermode/usermode/thunk.c:1.2
--- src/sys/arch/usermode/usermode/thunk.c:1.1	Fri Aug 12 00:57:24 2011
+++ src/sys/arch/usermode/usermode/thunk.c	Fri Aug 12 11:37:05 2011
@@ -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 <jmcne...@invisible.ca>
@@ -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);
+}
+

Reply via email to