git: 9front

Download patch

ref: 7980c670a598eb7da99dbafd3b1e2e95c1c7b437
parent: a1b143a4027c7c77f620c43a4e76f7ad5c4129f3
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Nov 17 18:18:08 EST 2020

pc/l.s: load virtual gdt pointer after mmu switch

before removing the double map at 0, load our
initial gdt pointer with its new KZERO based
virtual address.

this is prerequisite for handling traps early during
bootup before mmuinit() loads the final gdt.

--- a/sys/src/9/pc/l.s
+++ b/sys/src/9/pc/l.s
@@ -71,8 +71,7 @@
 	STD
 	REP; MOVSB
 	MOVL	BX, multibootptr-KZERO(SB)
-	MOVL	$_startPADDR(SB), AX
-	ANDL	$~KZERO, AX
+	MOVL	$_startPADDR-KZERO(SB), AX
 	JMP*	AX
 
 /* multiboot structure pointer (physical address) */
@@ -98,8 +97,7 @@
 	CLI					/* make sure interrupts are off */
 
 	/* set up the gdt so we have sane plan 9 style gdts. */
-	MOVL	$tgdtptr(SB), AX
-	ANDL	$~KZERO, AX
+	MOVL	$tgdtptr-KZERO(SB), AX
 	MOVL	(AX), GDTR
 	MOVW	$1, AX
 	MOVW	AX, MSW
@@ -158,9 +156,11 @@
 	WORD $(256*8-1)
 	LONG $IDTADDR
 
-TEXT mode32bit(SB), $0
-	/* At this point, the GDT setup is done. */
+TEXT vtgdtptr(SB), $0
+	WORD	$(3*8)
+	LONG	$tgdt(SB)
 
+TEXT mode32bit(SB), $0
 	MOVL	$((CPU0END-CPU0PDB)>>2), CX
 	MOVL	$PADDR(CPU0PDB), DI
 	XORL	AX, AX
@@ -231,6 +231,9 @@
  * be initialised here.
  */
 TEXT _startpg(SB), $0
+	MOVL	$vtgdtptr(SB), AX
+	MOVL	(AX), GDTR
+
 	MOVL	$0, (PDO(0))(CX)		/* undo double-map of KZERO at 0 */
 	MOVL	CX, CR3				/* load and flush the mmu */
 
--