git: 9front

Download patch

ref: 470caaf32db780184e15e009383e2ce6f036e44b
parent: 0b2093c4da7fa81dba536efd67ff53e6d02cfdb6
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Nov 15 06:43:05 EST 2014

pc64: get rid of fixed 8MB INIMAP and dynamically map KZERO-end in l.s

traditionally, the pc kernel mapped the first 8MB of physical
address space. when the kernel size grows beyond that memory mapping,
it will crash on boot and theres no checking in the build process
making sure it fits.

with the pc64 kernel, it is not hard to always map the whole
kernel memory image from KZERO to end[], so that the kernel will
always fit into the initial mapping.

--- a/sys/src/9/pc64/l.s
+++ b/sys/src/9/pc64/l.s
@@ -144,13 +144,20 @@
 	MOVL	$(PTESIZE|PTEGLOBAL|PTEWRITE|PTEVALID), DX
 	MOVL	DX, PDO(0)(AX)			/* PDE for double-map */
 
+	/*
+	 * map from KZERO to end using 2MB pages
+	 */
 	ADDL	$PDO(KZERO), AX
+	MOVL	$end-KZERO(SB), CX
+	ADDL	$(PGLSZ(1)-1), CX
+	ANDL	$~(PGLSZ(1)-1), CX
+	MOVL	CX, MemMin-KZERO(SB)		/* see memory.c */
+	SHRL	$(1*PTSHIFT+PGSHIFT), CX
 memloop:
-	MOVL	DX, 0(AX)
+	MOVL	DX, (AX)
 	ADDL	$PGLSZ(1), DX
 	ADDL	$8, AX
-	CMPL	DX, $INIMAP
-	JLT	memloop
+	LOOP	memloop
 
 /*
  * Enable and activate Long Mode. From the manual:
--- a/sys/src/9/pc64/mem.h
+++ b/sys/src/9/pc64/mem.h
@@ -79,7 +79,6 @@
 #define CPU0END		(CPU0MACH+MACHSIZE)
 
 #define	MACHSIZE	(2*KSTACK)
-#define	INIMAP		(8*MiB)		/* 4 pages; size of inital map in l.s */
 
 /*
  *  known x86 segments (in GDT) and their selectors
--- a/sys/src/9/pc64/memory.c
+++ b/sys/src/9/pc64/memory.c
@@ -12,6 +12,8 @@
 #include "io.h"
 #include "ureg.h"
 
+u32int	MemMin;		/* set by l.s */
+
 #define MEMDEBUG	0
 
 enum {
@@ -22,8 +24,6 @@
 	NMemType	= 4,
 
 	KB		= 1024,
-
-	MemMin		= INIMAP,
 };
 
 typedef struct Map Map;
--