Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 6 Apr 2003 20:58:41 -0700 (PDT)
From:      Peter Wemm <peter@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 28396 for review
Message-ID:  <200304070358.h373wfpU023840@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=28396

Change 28396 by peter@peter_overcee on 2003/04/06 20:57:50

	this is a bit gross, but is a replacement for create_pagetables
	from locore.s.  I want to do this differently but this is a useful
	checkpoint.

Affected files ...

.. //depot/projects/hammer/sys/x86_64/x86_64/machdep.c#42 edit

Differences ...

==== //depot/projects/hammer/sys/x86_64/x86_64/machdep.c#42 (text+ko) ====

@@ -1042,21 +1042,15 @@
 	return (ret);
 }
 
-void
-hammer_time(void)
+static void
+create_pagetables(void)
 {
-	caddr_t kmdp;
-	int gsel_tss, off, x;
-	struct region_descriptor r_gdt, r_idt;
-	struct pcpu *pc;
 	u_int64_t p0kpa;
 	u_int64_t p0upa;
 	u_int64_t KPTphys;
-	u_int64_t first;
+	int i;
 
-	first = physfree;
-printf("made it to hammer_time! first = 0x%x\n", first);
-
+	/* Allocate pages */
 	KPTphys = allocpages(NKPT);
 	printf("KPTphys = 0x%lx\n", KPTphys);
 	IdlePML4 = allocpages(1);
@@ -1070,6 +1064,63 @@
 	p0kpa = allocpages(KSTACK_PAGES);
 	printf("p0kpa = 0x%lx\n", p0kpa);
 
+	/* Fill in the underlying page table pages */
+	/* Read-only from zero to physfree */
+	/* XXX not actually used, underneath 2M pages */
+	for (i = 0; (i << PAGE_SHIFT) < physfree; i++) {
+		((pt_entry_t *)KPTphys)[i] = i << PAGE_SHIFT;
+		((pt_entry_t *)KPTphys)[i] |= PG_RW;
+	}
+		
+	/* Map from zero to end of allocations under 2M pages */
+	for (i = 0; (i << PDRSHIFT) < physfree; i++) {
+		((pd_entry_t *)IdlePTD)[i] = i << PDRSHIFT;
+		((pd_entry_t *)IdlePTD)[i] |= PG_RW | PG_V | PG_PS;
+	}
+
+	/* Now map the page tables at their location within PTmap */
+	for (i = 0; i < NKPT; i++) {
+		((pd_entry_t *)IdlePTD)[i + KPTDI] = KPTphys + (i << PAGE_SHIFT);
+		((pd_entry_t *)IdlePTD)[i + KPTDI] |= PG_RW | PG_V;
+	}
+
+	/* Now map the PTD at the top of the PTmap (ie: PTD[]) */
+	for (i = 0; i < NPGPTD; i++) {
+		((pd_entry_t *)IdlePTD)[i + PTDPTDI] = IdlePTD + (i << PAGE_SHIFT);
+		((pd_entry_t *)IdlePTD)[i + PTDPTDI] |= PG_RW | PG_V;
+	}
+
+	/* And connect up the PTD to the PDP */
+	/* XXX index 1 == 1GB, where the KERNBASE is for now */
+	((pdp_entry_t *)IdlePDP)[1] = IdlePTD;
+	((pdp_entry_t *)IdlePDP)[1] |= PG_RW | PG_V;
+
+	/* And connect up the PDP to the PML4 */
+	((pdp_entry_t *)IdlePML4)[0] = IdlePDP;
+	((pdp_entry_t *)IdlePML4)[0] |= PG_RW | PG_V | PG_U;
+}
+
+void
+hammer_time(void)
+{
+	caddr_t kmdp;
+	int gsel_tss, off, x;
+	struct region_descriptor r_gdt, r_idt;
+	struct pcpu *pc;
+	u_int64_t first;
+
+	first = physfree;
+printf("It is hammer_time!\n");
+printf("first = 0x%lx\n", first);
+
+	create_pagetables();
+
+printf("got to the end; activating page tables...\n");
+
+	load_cr3(IdlePML4);
+
+printf("it worked!\n");
+printf("yippee!\n");
 for(;;);
 
 	proc0.p_uarea = proc0uarea;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200304070358.h373wfpU023840>