changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: pc, pc64: park application processors in rebootcode with mmu off

changeset 6896: cceb691311bb
parent 6895: 8325e5645c93
child 6897: 53034d183846
author: cinap_lenrek@felloff.net
date: Mon, 19 Nov 2018 18:42:01 +0100
files: sys/src/9/pc/main.c sys/src/9/pc/rebootcode.s sys/src/9/pc64/main.c sys/src/9/pc64/rebootcode.s
description: pc, pc64: park application processors in rebootcode with mmu off

instead of having application processors spin in mpshutdown()
with mmu on, and be subject to reboot() overriding kernel text
and modifying page tables, park the application processors in
rebootcode idle loop with the mmu off.
     1.1--- a/sys/src/9/pc/main.c
     1.2+++ b/sys/src/9/pc/main.c
     1.3@@ -701,34 +701,13 @@ procsave(Proc *p)
     1.4 	mmuflushtlb(PADDR(m->pdb));
     1.5 }
     1.6 
     1.7-void
     1.8-reboot(void *entry, void *code, ulong size)
     1.9+static void
    1.10+rebootjump(uintptr entry, uintptr code, ulong size)
    1.11 {
    1.12-	void (*f)(ulong, ulong, ulong);
    1.13+	void (*f)(uintptr, uintptr, ulong);
    1.14 	ulong *pdb;
    1.15 
    1.16-	writeconf();
    1.17-	vmxshutdown();
    1.18-
    1.19-	/*
    1.20-	 * the boot processor is cpu0.  execute this function on it
    1.21-	 * so that the new kernel has the same cpu0.  this only matters
    1.22-	 * because the hardware has a notion of which processor was the
    1.23-	 * boot processor and we look at it at start up.
    1.24-	 */
    1.25-	if (m->machno != 0) {
    1.26-		procwired(up, 0);
    1.27-		sched();
    1.28-	}
    1.29-	cpushutdown();
    1.30-
    1.31 	splhi();
    1.32-
    1.33-	/* turn off buffered serial console */
    1.34-	serialoq = nil;
    1.35-
    1.36-	/* shutdown devices */
    1.37-	chandevshutdown();
    1.38 	arch->introff();
    1.39 
    1.40 	/*
    1.41@@ -745,7 +724,8 @@ reboot(void *entry, void *code, ulong si
    1.42 
    1.43 	/* off we go - never to return */
    1.44 	coherence();
    1.45-	(*f)((ulong)entry & ~0xF0000000UL, PADDR(code), size);
    1.46+	(*f)(entry, code, size);
    1.47+	for(;;);
    1.48 }
    1.49 
    1.50 
    1.51@@ -753,5 +733,36 @@ void
    1.52 exit(int)
    1.53 {
    1.54 	cpushutdown();
    1.55+	if(m->machno)
    1.56+		rebootjump(0, 0, 0);
    1.57 	arch->reset();
    1.58 }
    1.59+
    1.60+void
    1.61+reboot(void *entry, void *code, ulong size)
    1.62+{
    1.63+	writeconf();
    1.64+	vmxshutdown();
    1.65+
    1.66+	/*
    1.67+	 * the boot processor is cpu0.  execute this function on it
    1.68+	 * so that the new kernel has the same cpu0.  this only matters
    1.69+	 * because the hardware has a notion of which processor was the
    1.70+	 * boot processor and we look at it at start up.
    1.71+	 */
    1.72+	if (m->machno != 0) {
    1.73+		procwired(up, 0);
    1.74+		sched();
    1.75+	}
    1.76+	cpushutdown();
    1.77+	delay(1000);
    1.78+	splhi();
    1.79+
    1.80+	/* turn off buffered serial console */
    1.81+	serialoq = nil;
    1.82+
    1.83+	/* shutdown devices */
    1.84+	chandevshutdown();
    1.85+
    1.86+	rebootjump((ulong)entry & ~0xF0000000UL, PADDR(code), size);
    1.87+}
     2.1--- a/sys/src/9/pc/rebootcode.s
     2.2+++ b/sys/src/9/pc/rebootcode.s
     2.3@@ -20,6 +20,13 @@ TEXT	main(SB),$0
     2.4 	MOVL	$0, DX
     2.5 	MOVL	DX, CR3
     2.6 
     2.7+	/* stack below entry point */
     2.8+	MOVL	AX, SP
     2.9+
    2.10+	/* park cpu for zero entry point */
    2.11+	ORL	AX, AX
    2.12+	JZ	_idle
    2.13+
    2.14 /*
    2.15  * the source and destination may overlap.
    2.16  * determine whether to copy forward or backwards
    2.17@@ -52,3 +59,7 @@ TEXT	main(SB),$0
    2.18 _startkernel:
    2.19 	ORL	AX, AX		/* NOP: avoid link bug */
    2.20 	JMP*	AX
    2.21+
    2.22+_idle:
    2.23+	HLT
    2.24+	JMP	_idle
     3.1--- a/sys/src/9/pc64/main.c
     3.2+++ b/sys/src/9/pc64/main.c
     3.3@@ -336,40 +336,12 @@ main()
     3.4 	schedinit();
     3.5 }
     3.6 
     3.7-void
     3.8-exit(int)
     3.9-{
    3.10-	cpushutdown();
    3.11-	arch->reset();
    3.12-}
    3.13-
    3.14-void
    3.15-reboot(void *entry, void *code, ulong size)
    3.16+static void
    3.17+rebootjump(uintptr entry, uintptr code, ulong size)
    3.18 {
    3.19 	void (*f)(uintptr, uintptr, ulong);
    3.20 
    3.21-	writeconf();
    3.22-	vmxshutdown();
    3.23-
    3.24-	/*
    3.25-	 * the boot processor is cpu0.  execute this function on it
    3.26-	 * so that the new kernel has the same cpu0.  this only matters
    3.27-	 * because the hardware has a notion of which processor was the
    3.28-	 * boot processor and we look at it at start up.
    3.29-	 */
    3.30-	if (m->machno != 0) {
    3.31-		procwired(up, 0);
    3.32-		sched();
    3.33-	}
    3.34-	cpushutdown();
    3.35-
    3.36 	splhi();
    3.37-
    3.38-	/* turn off buffered serial console */
    3.39-	serialoq = nil;
    3.40-
    3.41-	/* shutdown devices */
    3.42-	chandevshutdown();
    3.43 	arch->introff();
    3.44 
    3.45 	/*
    3.46@@ -385,7 +357,48 @@ reboot(void *entry, void *code, ulong si
    3.47 
    3.48 	/* off we go - never to return */
    3.49 	coherence();
    3.50-	(*f)((uintptr)entry & ~0xF0000000UL, (uintptr)PADDR(code), size);
    3.51+	(*f)(entry, code, size);
    3.52+
    3.53+	for(;;);
    3.54+}
    3.55+
    3.56+
    3.57+void
    3.58+exit(int)
    3.59+{
    3.60+	cpushutdown();
    3.61+	if(m->machno)
    3.62+		rebootjump(0, 0, 0);
    3.63+	arch->reset();
    3.64+}
    3.65+
    3.66+void
    3.67+reboot(void *entry, void *code, ulong size)
    3.68+{
    3.69+	writeconf();
    3.70+	vmxshutdown();
    3.71+
    3.72+	/*
    3.73+	 * the boot processor is cpu0.  execute this function on it
    3.74+	 * so that the new kernel has the same cpu0.  this only matters
    3.75+	 * because the hardware has a notion of which processor was the
    3.76+	 * boot processor and we look at it at start up.
    3.77+	 */
    3.78+	if (m->machno != 0) {
    3.79+		procwired(up, 0);
    3.80+		sched();
    3.81+	}
    3.82+	cpushutdown();
    3.83+	delay(1000);
    3.84+	splhi();
    3.85+
    3.86+	/* turn off buffered serial console */
    3.87+	serialoq = nil;
    3.88+
    3.89+	/* shutdown devices */
    3.90+	chandevshutdown();
    3.91+
    3.92+	rebootjump((uintptr)entry & ~0xF0000000UL, PADDR(code), size);
    3.93 }
    3.94 
    3.95 /*
     4.1--- a/sys/src/9/pc64/rebootcode.s
     4.2+++ b/sys/src/9/pc64/rebootcode.s
     4.3@@ -20,9 +20,6 @@ TEXT	main(SB), 1, $-4
     4.4 	MOVL	$_gdtptr64p<>(SB), AX
     4.5 	MOVL	(AX), GDTR
     4.6 
     4.7-	/* move stack below destination */
     4.8-	MOVL	DI, SP
     4.9-
    4.10 	/* load CS with 32bit code segment */
    4.11 	PUSHQ	$SELECTOR(3, SELGDT, 0)
    4.12 	PUSHQ	$_warp32<>(SB)
    4.13@@ -61,6 +58,12 @@ TEXT	_warp32<>(SB), 1, $-4
    4.14 
    4.15 	MOVL	BX, CX			/* byte count */
    4.16 	MOVL	DI, AX			/* save entry point */
    4.17+	MOVL	AX, SP			/* move stack below entry */
    4.18+
    4.19+	/* park cpu for zero entry point */
    4.20+	ORL	AX, AX
    4.21+	JZ	_idle
    4.22+
    4.23 
    4.24 /*
    4.25  * the source and destination may overlap.
    4.26@@ -90,6 +93,10 @@ TEXT	_warp32<>(SB), 1, $-4
    4.27 	REP;	MOVSB
    4.28 	JMP	_startkernel
    4.29 
    4.30+_idle:
    4.31+	HLT
    4.32+	JMP	_idle
    4.33+
    4.34 TEXT _gdt<>(SB), 1, $-4
    4.35 	/* null descriptor */
    4.36 	LONG	$0