Module Name:    src
Committed By:   thorpej
Date:           Tue Jan  2 18:10:36 UTC 2024

Modified Files:
        src/sys/arch/virt68k/include: cpu.h
        src/sys/arch/virt68k/virt68k: locore.s machdep.c

Log Message:
Provide a mechanism for a system reset controller to register to be used
to reset/halt the system.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/virt68k/include/cpu.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/virt68k/virt68k/locore.s
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/virt68k/virt68k/machdep.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/virt68k/include/cpu.h
diff -u src/sys/arch/virt68k/include/cpu.h:1.2 src/sys/arch/virt68k/include/cpu.h:1.3
--- src/sys/arch/virt68k/include/cpu.h:1.2	Tue Jan  2 17:16:27 2024
+++ src/sys/arch/virt68k/include/cpu.h	Tue Jan  2 18:10:36 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.2 2024/01/02 17:16:27 thorpej Exp $	*/
+/*	$NetBSD: cpu.h,v 1.3 2024/01/02 18:10:36 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -110,8 +110,7 @@ extern int astpending;		/* need to trap 
 #endif /* _KERNEL */
 
 #ifdef _KERNEL
-void	doboot(int) 
-	__attribute__((__noreturn__));
+void	cpu_set_reset_func(void (*)(void *, int), void *);
 int	nmihand(void *);
 void	loadustp(paddr_t);
 

Index: src/sys/arch/virt68k/virt68k/locore.s
diff -u src/sys/arch/virt68k/virt68k/locore.s:1.1 src/sys/arch/virt68k/virt68k/locore.s:1.2
--- src/sys/arch/virt68k/virt68k/locore.s:1.1	Tue Jan  2 07:41:02 2024
+++ src/sys/arch/virt68k/virt68k/locore.s	Tue Jan  2 18:10:36 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.s,v 1.1 2024/01/02 07:41:02 thorpej Exp $	*/
+/*	$NetBSD: locore.s,v 1.2 2024/01/02 18:10:36 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -694,13 +694,6 @@ ENTRY(getsr)
 	rts
 
 /*
- * Handle the nitty-gritty of rebooting the machine.
- */
-ENTRY_NOPROFILE(doboot)
-	movw	#PSL_HIGHIPL,%sr
-1:	jra	1b			| XXX
-
-/*
  * Misc. global variables.
  */
 	.data

Index: src/sys/arch/virt68k/virt68k/machdep.c
diff -u src/sys/arch/virt68k/virt68k/machdep.c:1.2 src/sys/arch/virt68k/virt68k/machdep.c:1.3
--- src/sys/arch/virt68k/virt68k/machdep.c:1.2	Tue Jan  2 17:13:03 2024
+++ src/sys/arch/virt68k/virt68k/machdep.c	Tue Jan  2 18:10:36 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.2 2024/01/02 17:13:03 thorpej Exp $	*/
+/*	$NetBSD: machdep.c,v 1.3 2024/01/02 18:10:36 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.2 2024/01/02 17:13:03 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.3 2024/01/02 18:10:36 thorpej Exp $");
 
 #include "opt_ddb.h"
 #include "opt_m060sp.h"
@@ -422,6 +422,18 @@ SYSCTL_SETUP(sysctl_machdep_setup, "sysc
 
 int	waittime = -1;
 
+static void (*cpu_reset_func)(void *, int);
+static void *cpu_reset_func_arg;
+
+void
+cpu_set_reset_func(void (*func)(void *, int), void *arg)
+{
+	if (cpu_reset_func == NULL) {
+		cpu_reset_func = cpu_reset_func;
+		cpu_reset_func_arg = arg;
+	}
+}
+
 void
 cpu_reboot(int howto, char *bootstr)
 {
@@ -471,17 +483,29 @@ cpu_reboot(int howto, char *bootstr)
 	}
 #endif
 
+	if (cpu_reset_func == NULL) {
+		printf("WARNING: No reset handler, holding here.\n\n");
+		for (;;) {
+			/* spin forever. */
+		}
+	}
+
 	/* Finally, halt/reboot the system. */
 	if (howto & RB_HALT) {
 		printf("halted\n\n");
-		doboot(RB_HALT);
+		(*cpu_reset_func)(cpu_reset_func_arg, RB_HALT);
+		/* NOTREACHED */
+	} else {
+		printf("rebooting...\n");
+		delay(1000000);
+		(*cpu_reset_func)(cpu_reset_func_arg, RB_AUTOBOOT);
 		/* NOTREACHED */
 	}
-
-	printf("rebooting...\n");
-	delay(1000000);
-	doboot(RB_AUTOBOOT);
-	/*NOTREACHED*/
+	/* ...but just in case it is... */
+	printf("WARNING: System reset handler failed, holding here.\n\n");
+	for (;;) {
+		/* spin forever. */
+	}
 }
 
 /*

Reply via email to