shithub: riscv

Download patch

ref: 4e00cf6b1798fc95b3ccad8cb66a3e80c96b2786
parent: 4cd03abefe80c9d7ce97d7dfb488e7ed5a8163c8
author: cinap_lenrek <[email protected]>
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;