Module Name:    src
Committed By:   maxv
Date:           Sat Sep 30 11:43:57 UTC 2017

Modified Files:
        src/sys/arch/amd64/amd64: locore.S machdep.c
        src/sys/arch/i386/i386: locore.S machdep.c
        src/sys/arch/x86/include: pmap.h
        src/sys/arch/x86/x86: pmap.c

Log Message:
Add a bootspace structure. It describes the physical and virtual space
layout created by the early kernel bootstrap code. Start using it, and
eliminate several references to KERNBASE and other global symbols. While
here clean up xen-i386, it's really tiring.


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.261 -r1.262 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.152 -r1.153 src/sys/arch/i386/i386/locore.S
cvs rdiff -u -r1.794 -r1.795 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/x86/include/pmap.h
cvs rdiff -u -r1.257 -r1.258 src/sys/arch/x86/x86/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.130 src/sys/arch/amd64/amd64/locore.S:1.131
--- src/sys/arch/amd64/amd64/locore.S:1.130	Thu Sep 28 17:35:08 2017
+++ src/sys/arch/amd64/amd64/locore.S	Sat Sep 30 11:43:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.130 2017/09/28 17:35:08 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.131 2017/09/30 11:43:57 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -972,6 +972,9 @@ longmode_hi:
 	subq	$KERNBASE,%rdi	/* init_x86_64 wants a physical address */
 #endif	/* XEN */
 
+	pushq	%rdi
+	call	_C_LABEL(init_bootspace)
+	popq	%rdi
 	call	_C_LABEL(init_x86_64)
 	call 	_C_LABEL(main)
 END(start)
@@ -1477,4 +1480,3 @@ ENTRY(intrfastexit)
 do_iret:
 	iretq
 END(intrfastexit)
-

Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.261 src/sys/arch/amd64/amd64/machdep.c:1.262
--- src/sys/arch/amd64/amd64/machdep.c:1.261	Thu Sep 28 17:35:08 2017
+++ src/sys/arch/amd64/amd64/machdep.c	Sat Sep 30 11:43:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.261 2017/09/28 17:35:08 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.262 2017/09/30 11:43:57 maxv Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.261 2017/09/28 17:35:08 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.262 2017/09/30 11:43:57 maxv Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -264,6 +264,7 @@ paddr_t ldt_paddr;
 vaddr_t module_start, module_end;
 static struct vm_map module_map_store;
 extern struct vm_map *module_map;
+extern struct bootspace bootspace;
 vaddr_t kern_end;
 
 struct vm_map *phys_map = NULL;
@@ -321,6 +322,7 @@ int dump_header_finish(void);
 int dump_seg_count_range(paddr_t, paddr_t);
 int dumpsys_seg(paddr_t, paddr_t);
 
+void init_bootspace(void);
 void init_x86_64(paddr_t);
 
 /*
@@ -1487,6 +1489,41 @@ init_x86_64_ksyms(void)
 }
 
 void
+init_bootspace(void)
+{
+	extern char __rodata_start;
+	extern char __data_start;
+	extern char __kernel_end;
+
+	memset(&bootspace, 0, sizeof(bootspace));
+
+	bootspace.text.va = KERNTEXTOFF;
+	bootspace.text.pa = KERNTEXTOFF - KERNBASE;
+	bootspace.text.sz = (size_t)&__rodata_start - KERNTEXTOFF;
+
+	bootspace.rodata.va = (vaddr_t)&__rodata_start;
+	bootspace.rodata.pa = (paddr_t)&__rodata_start - KERNBASE;
+	bootspace.rodata.sz = (size_t)&__data_start - (size_t)&__rodata_start;
+
+	bootspace.data.va = (vaddr_t)&__data_start;
+	bootspace.data.pa = (paddr_t)&__data_start - KERNBASE;
+	bootspace.data.sz = (size_t)&__kernel_end - (size_t)&__data_start;
+
+	bootspace.boot.va = (vaddr_t)&__kernel_end;
+	bootspace.boot.pa = (paddr_t)&__kernel_end - KERNBASE;
+	bootspace.boot.sz = (size_t)(atdevbase + IOM_SIZE) -
+	    (size_t)&__kernel_end;
+
+	/* In locore.S, we allocated a tmp va. We will use it now. */
+	bootspace.spareva = KERNBASE + NKL2_KIMG_ENTRIES * NBPD_L2;
+
+	/* Virtual address of the L4 page */
+	bootspace.pdir = (vaddr_t)(PDPpaddr + KERNBASE);
+
+	bootspace.emodule = KERNBASE + NKL2_KIMG_ENTRIES * NBPD_L2;
+}
+
+void
 init_x86_64(paddr_t first_avail)
 {
 	extern void consinit(void);
@@ -1567,7 +1604,7 @@ init_x86_64(paddr_t first_avail)
 
 	/* The area for the module map. */
 	module_start = kern_end;
-	module_end = KERNBASE + NKL2_KIMG_ENTRIES * NBPD_L2;
+	module_end = bootspace.emodule;
 
 	/*
 	 * Call pmap initialization to make new kernel address space.
@@ -1951,7 +1988,7 @@ cpu_initclocks(void)
 int
 mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled)
 {
-	extern int start, __data_start;
+	extern char start, __data_start;
 	const vaddr_t v = (vaddr_t)ptr;
 
 	if (v >= (vaddr_t)&start && v < (vaddr_t)kern_end) {

Index: src/sys/arch/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.152 src/sys/arch/i386/i386/locore.S:1.153
--- src/sys/arch/i386/i386/locore.S:1.152	Sun Sep 17 09:59:23 2017
+++ src/sys/arch/i386/i386/locore.S	Sat Sep 30 11:43:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.152 2017/09/17 09:59:23 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.153 2017/09/30 11:43:57 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.152 2017/09/17 09:59:23 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.153 2017/09/30 11:43:57 maxv Exp $");
 
 #include "opt_copy_symtab.h"
 #include "opt_ddb.h"
@@ -838,6 +838,7 @@ begin:
 	pushl	$0	/* init386() expects a 64 bits paddr_t with PAE */
 #endif
 	pushl	%eax
+	call	_C_LABEL(init_bootspace)
 	call	_C_LABEL(init386)
 	addl	$PDE_SIZE,%esp		/* pop paddr_t */
 	addl	$NGDT*8,%esp		/* pop temporary gdt */

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.794 src/sys/arch/i386/i386/machdep.c:1.795
--- src/sys/arch/i386/i386/machdep.c:1.794	Sun Sep 17 09:41:35 2017
+++ src/sys/arch/i386/i386/machdep.c	Sat Sep 30 11:43:57 2017
@@ -1,14 +1,14 @@
-/*	$NetBSD: machdep.c,v 1.794 2017/09/17 09:41:35 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.795 2017/09/30 11:43:57 maxv Exp $	*/
 
-/*-
- * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
+/*
+ * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009, 2017
  *     The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
  * by Charles M. Hannum, by Jason R. Thorpe of the Numerical Aerospace
  * Simulation Facility NASA Ames Research Center, by Julio M. Merino Vidal,
- * and by Andrew Doran.
+ * by Andrew Doran, and by Maxime Villard.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -32,7 +32,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*-
+/*
  * Copyright (c) 1982, 1987, 1990 The Regents of the University of California.
  * All rights reserved.
  *
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.794 2017/09/17 09:41:35 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.795 2017/09/30 11:43:57 maxv Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_freebsd.h"
@@ -144,23 +144,12 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 
 #include <x86/machdep.h>
 
 #include <machine/multiboot.h>
+
 #ifdef XEN
 #include <xen/evtchn.h>
 #include <xen/xen.h>
 #include <xen/hypervisor.h>
-
-/* #define	XENDEBUG */
-/* #define	XENDEBUG_LOW */
-
-#ifdef XENDEBUG
-#define	XENPRINTF(x) printf x
-#define	XENPRINTK(x) printk x
-#else
-#define	XENPRINTF(x)
-#define	XENPRINTK(x)
 #endif
-#define	PRINTK(x) printf x
-#endif /* XEN */
 
 #include <dev/isa/isareg.h>
 #include <machine/isa_machdep.h>
@@ -243,6 +232,8 @@ vaddr_t pentium_idt_vaddr;
 
 struct vm_map *phys_map = NULL;
 
+extern struct bootspace bootspace;
+
 extern paddr_t lowmem_rsvd;
 extern paddr_t avail_start, avail_end;
 #ifdef XEN
@@ -265,6 +256,7 @@ void (*initclock_func)(void) = i8254_ini
 phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
 int mem_cluster_cnt = 0;
 
+void init_bootspace(void);
 void init386(paddr_t);
 void initgdt(union descriptor *);
 
@@ -491,10 +483,6 @@ i386_proc0_pcb_ldt_init(void)
 	lldt(GSEL(GLDT_SEL, SEL_KPL));
 #else
 	HYPERVISOR_fpu_taskswitch(1);
-	XENPRINTF(("lwp tss sp %p ss %04x/%04x\n",
-	    (void *)pcb->pcb_esp0,
-	    GSEL(GDATA_SEL, SEL_KPL),
-	    IDXSEL(GSEL(GDATA_SEL, SEL_KPL))));
 	HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), pcb->pcb_esp0);
 #endif
 }
@@ -547,7 +535,7 @@ i386_tls_switch(lwp_t *l)
 	/* Update TLS segment pointers */
 	update_descriptor(&ci->ci_gdt[GUFS_SEL],
 			  (union descriptor *) &pcb->pcb_fsd);
-	update_descriptor(&ci->ci_gdt[GUGS_SEL], 
+	update_descriptor(&ci->ci_gdt[GUGS_SEL],
 			  (union descriptor *) &pcb->pcb_gsd);
 
 }
@@ -944,7 +932,6 @@ unsetgate(struct gate_descriptor *gd)
 	gd->gd_dpl = 0;
 }
 
-
 void
 setregion(struct region_descriptor *rd, void *base, size_t limit)
 {
@@ -980,25 +967,24 @@ int xen_idt_idx;
 extern union descriptor tmpgdt[];
 #endif
 
-void 
+void
 cpu_init_idt(void)
 {
 #ifndef XEN
 	struct region_descriptor region;
 	setregion(&region, pentium_idt, NIDT * sizeof(idt[0]) - 1);
 	lidt(&region);
-#else /* XEN */
-	XENPRINTF(("HYPERVISOR_set_trap_table %p\n", xen_idt));
+#else
 	if (HYPERVISOR_set_trap_table(xen_idt))
 		panic("HYPERVISOR_set_trap_table %p failed\n", xen_idt);
-#endif /* !XEN */
+#endif
 }
 
 void
 initgdt(union descriptor *tgdt)
 {
 	KASSERT(tgdt != NULL);
-	
+
 	gdtstore = tgdt;
 #ifdef XEN
 	u_long	frames[16];
@@ -1059,11 +1045,8 @@ initgdt(union descriptor *tgdt)
 		    UVMF_INVLPG) < 0) {
 			panic("gdt page RO update failed.\n");
 		}
-
 	}
 
-	XENPRINTK(("loading gdt %lx, %d entries\n", frames[0] << PAGE_SHIFT,
-	    NGDT));
 	if (HYPERVISOR_set_gdt(frames, NGDT /* XXX is it right ? */))
 		panic("HYPERVISOR_set_gdt failed!\n");
 
@@ -1115,6 +1098,36 @@ init386_ksyms(void)
 }
 
 void
+init_bootspace(void)
+{
+	extern char __rodata_start;
+	extern char __data_start;
+	extern char __kernel_end;
+
+	memset(&bootspace, 0, sizeof(bootspace));
+
+	bootspace.text.va = KERNTEXTOFF;
+	bootspace.text.pa = KERNTEXTOFF - KERNBASE;
+	bootspace.text.sz = (size_t)&__rodata_start - KERNTEXTOFF;
+
+	bootspace.rodata.va = (vaddr_t)&__rodata_start;
+	bootspace.rodata.pa = (paddr_t)(vaddr_t)&__rodata_start - KERNBASE;
+	bootspace.rodata.sz = (size_t)&__data_start - (size_t)&__rodata_start;
+
+	bootspace.data.va = (vaddr_t)&__data_start;
+	bootspace.data.pa = (paddr_t)(vaddr_t)&__data_start - KERNBASE;
+	bootspace.data.sz = (size_t)&__kernel_end - (size_t)&__data_start;
+
+	bootspace.boot.va = (vaddr_t)&__kernel_end;
+	bootspace.boot.pa = (paddr_t)(vaddr_t)&__kernel_end - KERNBASE;
+	bootspace.boot.sz = (size_t)(atdevbase + IOM_SIZE) -
+	    (size_t)&__kernel_end;
+
+	/* Virtual address of the top level page */
+	bootspace.pdir = (vaddr_t)(PDPpaddr + KERNBASE);
+}
+
+void
 init386(paddr_t first_avail)
 {
 	extern void consinit(void);
@@ -1133,8 +1146,6 @@ init386(paddr_t first_avail)
 	KASSERT(first_avail % PAGE_SIZE == 0);
 
 #ifdef XEN
-	XENPRINTK(("HYPERVISOR_shared_info %p (%x)\n", HYPERVISOR_shared_info,
-	    xen_start_info.shared_info));
 	KASSERT(HYPERVISOR_shared_info != NULL);
 	cpu_info_primary.ci_vcpu = &HYPERVISOR_shared_info->vcpu_info[0];
 #endif
@@ -1153,12 +1164,6 @@ init386(paddr_t first_avail)
 	pcb = lwp_getpcb(&lwp0);
 #ifdef XEN
 	pcb->pcb_cr3 = PDPpaddr;
-	__PRINTK(("pcb_cr3 0x%lx cr3 0x%lx\n",
-	    PDPpaddr, xpmap_ptom(PDPpaddr)));
-	XENPRINTK(("lwp0uarea %p first_avail %p\n",
-	    lwp0uarea, (void *)(long)first_avail));
-	XENPRINTK(("ptdpaddr %p atdevbase %p\n", (void *)PDPpaddr,
-	    (void *)atdevbase));
 #endif
 
 #if defined(PAE) && !defined(XEN)
@@ -1168,7 +1173,7 @@ init386(paddr_t first_avail)
 	 */
 	cpu_info_primary.ci_pae_l3_pdirpa = rcr3();
 	cpu_info_primary.ci_pae_l3_pdir = (pd_entry_t *)(rcr3() + KERNBASE);
-#endif /* PAE && !XEN */
+#endif
 
 	uvm_md_init();
 
@@ -1222,8 +1227,8 @@ init386(paddr_t first_avail)
 
 #if NISA > 0 || NPCI > 0
 	x86_bus_space_init();
-#endif /* NISA > 0 || NPCI > 0 */
-	
+#endif
+
 	consinit();	/* XXX SHOULD NOT BE DONE HERE */
 
 #ifdef DEBUG_MEMLOAD
@@ -1243,10 +1248,6 @@ init386(paddr_t first_avail)
 	/* Internalize the physical pages into the VM system. */
 	init_x86_vm(avail_start);
 #else /* !XEN */
-	XENPRINTK(("load the memory cluster 0x%" PRIx64 " (%" PRId64 ") - "
-	    "0x%" PRIx64 " (%" PRId64 ")\n",
-	    (uint64_t)avail_start, (uint64_t)atop(avail_start),
-	    (uint64_t)avail_end, (uint64_t)atop(avail_end)));
 	uvm_page_physload(atop(avail_start), atop(avail_end),
 	    atop(avail_start), atop(avail_end),
 	    VM_FREELIST_DEFAULT);
@@ -1263,7 +1264,6 @@ init386(paddr_t first_avail)
 			panic("tmpgdt page relaim RW update failed.\n");
 		}
 	}
-
 #endif /* !XEN */
 
 	init_x86_msgbuf();
@@ -1394,7 +1394,6 @@ init386(paddr_t first_avail)
 #endif
 
 #ifdef XEN
-	XENPRINTF(("events_default_setup\n"));
 	events_default_setup();
 #else
 	intr_default_setup();
@@ -1433,7 +1432,7 @@ init386(paddr_t first_avail)
 
 	x86_dbregs_setup_initdbstate();
 
-	pool_init(&x86_dbregspl, sizeof(struct dbreg), 16, 0, 0, "dbregs",                                                                                   
+	pool_init(&x86_dbregspl, sizeof(struct dbreg), 16, 0, 0, "dbregs",
 	    NULL, IPL_NONE);
 }
 
@@ -1469,7 +1468,7 @@ cpu_reset(void)
 	 * 2) Write 0xf to PCI Configuration Data Register (0xcfc)
 	 *    to reset IDE controller, IDE bus, and PCI bus, and
 	 *    to trigger a system-wide reset.
-	 * 
+	 *
 	 * See AMD Geode SC1100 Processor Data Book, Revision 2.0,
 	 * sections 6.3.1, 6.3.2, and 6.4.1.
 	 */

Index: src/sys/arch/x86/include/pmap.h
diff -u src/sys/arch/x86/include/pmap.h:1.68 src/sys/arch/x86/include/pmap.h:1.69
--- src/sys/arch/x86/include/pmap.h:1.68	Fri Sep 29 03:17:18 2017
+++ src/sys/arch/x86/include/pmap.h	Sat Sep 30 11:43:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.68 2017/09/29 03:17:18 ozaki-r Exp $	*/
+/*	$NetBSD: pmap.h,v 1.69 2017/09/30 11:43:57 maxv Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -111,6 +111,45 @@
 #include <sys/kcpuset.h>
 #include <uvm/pmap/pmap_pvt.h>
 
+struct bootspace {
+	/* Kernel segments. */
+	struct {
+		vaddr_t va;
+		paddr_t pa;
+		size_t sz;
+	} text;
+	struct {
+		vaddr_t va;
+		paddr_t pa;
+		size_t sz;
+	} rodata;
+	struct {
+		vaddr_t va;
+		paddr_t pa;
+		size_t sz;
+	} data;
+
+	/*
+	 * The area used by the early kernel bootstrap. It contains the kernel
+	 * symbols, the preloaded modules, the bootstrap tables, and the ISA I/O
+	 * mem.
+	 */
+	struct {
+		vaddr_t va;
+		paddr_t pa;
+		size_t sz;
+	} boot;
+
+	/* A magic VA usable by the bootstrap code. */
+	vaddr_t spareva;
+
+	/* Virtual address of the page directory. */
+	vaddr_t pdir;
+
+	/* End of the area dedicated to kernel modules (amd64 only). */
+	vaddr_t emodule;
+};
+
 /*
  * pmap data structures: see pmap.c for details of locking.
  */

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.257 src/sys/arch/x86/x86/pmap.c:1.258
--- src/sys/arch/x86/x86/pmap.c:1.257	Tue Sep 12 01:01:25 2017
+++ src/sys/arch/x86/x86/pmap.c	Sat Sep 30 11:43:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.257 2017/09/12 01:01:25 mrg Exp $	*/
+/*	$NetBSD: pmap.c,v 1.258 2017/09/30 11:43:57 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc.
@@ -171,7 +171,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.257 2017/09/12 01:01:25 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.258 2017/09/30 11:43:57 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -369,6 +369,8 @@ static bool cpu_pat_enabled __read_mostl
 static struct pmap kernel_pmap_store;	/* the kernel's pmap (proc0) */
 struct pmap *const kernel_pmap_ptr = &kernel_pmap_store;
 
+struct bootspace bootspace __read_mostly;
+
 /*
  * pmap_pg_nx: if our processor supports PG_NX in the PTE then we
  * set pmap_pg_nx to PG_NX (otherwise it is zero).
@@ -1255,7 +1257,7 @@ pmap_bootstrap(vaddr_t kva_start)
 	}
 	memset(&kpm->pm_list, 0, sizeof(kpm->pm_list));  /* pm_list not used */
 
-	kpm->pm_pdir = (pd_entry_t *)(PDPpaddr + KERNBASE);
+	kpm->pm_pdir = (pd_entry_t *)bootspace.pdir;
 	for (i = 0; i < PDP_SIZE; i++)
 		kpm->pm_pdirpa[i] = PDPpaddr + PAGE_SIZE * i;
 
@@ -1295,7 +1297,7 @@ pmap_bootstrap(vaddr_t kva_start)
 			kva_end = kern_end;
 		}
 
-		for (kva = KERNBASE; kva < kva_end; kva += PAGE_SIZE) {
+		for (kva = bootspace.text.va; kva < kva_end; kva += PAGE_SIZE) {
 			p1i = pl1_i(kva);
 			if (pmap_valid_entry(PTE_BASE[p1i]))
 				PTE_BASE[p1i] |= PG_G;
@@ -1470,8 +1472,8 @@ pmap_init_directmap(struct pmap *kpm)
 		panic("pmap_init_directmap: lastpa incorrect");
 	}
 
-	/* In locore.S, we allocated a tmp va. We will use it now. */
-	tmpva = (KERNBASE + NKL2_KIMG_ENTRIES * NBPD_L2);
+	/* We will use this temporary va. */
+	tmpva = bootspace.spareva;
 	pte = PTE_BASE + pl1_i(tmpva);
 
 	/* Number of L4 entries. */
@@ -1570,33 +1572,26 @@ pmap_init_directmap(struct pmap *kpm)
 static void
 pmap_remap_largepages(void)
 {
-	extern char __rodata_start;
-	extern char __data_start;
-	extern char __kernel_end;
 	pd_entry_t *pde;
 	vaddr_t kva, kva_end;
 	paddr_t pa;
 
 	/* Remap the kernel text using large pages. */
-	kva = rounddown((vaddr_t)KERNTEXTOFF, NBPD_L2);
-	kva_end = rounddown((vaddr_t)&__rodata_start, NBPD_L1);
-	pa = kva - KERNBASE;
+	kva = rounddown(bootspace.text.va, NBPD_L2);
+	kva_end = rounddown(bootspace.text.va +
+	    bootspace.text.sz, NBPD_L1);
+	pa = rounddown(bootspace.text.pa, NBPD_L2);
 	for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2, pa += NBPD_L2) {
 		pde = &L2_BASE[pl2_i(kva)];
 		*pde = pa | pmap_pg_g | PG_PS | PG_KR | PG_V;
 		tlbflushg();
 	}
-#if defined(DEBUG)
-	aprint_normal("kernel text is mapped with %" PRIuPSIZE " large "
-	    "pages and %" PRIuPSIZE " normal pages\n",
-	    howmany(kva - KERNBASE, NBPD_L2),
-	    howmany((vaddr_t)&__rodata_start - kva, NBPD_L1));
-#endif /* defined(DEBUG) */
 
 	/* Remap the kernel rodata using large pages. */
-	kva = roundup((vaddr_t)&__rodata_start, NBPD_L2);
-	kva_end = rounddown((vaddr_t)&__data_start, NBPD_L1);
-	pa = kva - KERNBASE;
+	kva = roundup(bootspace.rodata.va, NBPD_L2);
+	kva_end = rounddown(bootspace.rodata.va +
+	    bootspace.rodata.sz, NBPD_L1);
+	pa = roundup(bootspace.rodata.pa, NBPD_L2);
 	for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2, pa += NBPD_L2) {
 		pde = &L2_BASE[pl2_i(kva)];
 		*pde = pa | pmap_pg_g | PG_PS | pmap_pg_nx | PG_KR | PG_V;
@@ -1604,9 +1599,10 @@ pmap_remap_largepages(void)
 	}
 
 	/* Remap the kernel data+bss using large pages. */
-	kva = roundup((vaddr_t)&__data_start, NBPD_L2);
-	kva_end = rounddown((vaddr_t)&__kernel_end, NBPD_L1);
-	pa = kva - KERNBASE;
+	kva = roundup(bootspace.data.va, NBPD_L2);
+	kva_end = rounddown(bootspace.data.va +
+	    bootspace.data.sz, NBPD_L1);
+	pa = roundup(bootspace.data.pa, NBPD_L2);
 	for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2, pa += NBPD_L2) {
 		pde = &L2_BASE[pl2_i(kva)];
 		*pde = pa | pmap_pg_g | PG_PS | pmap_pg_nx | PG_KW | PG_V;

Reply via email to