Module Name: src Committed By: maxv Date: Wed Jun 20 11:49:38 UTC 2018
Modified Files: src/sys/arch/amd64/amd64: machdep.c src/sys/arch/amd64/stand/prekern: mm.c prekern.h src/sys/arch/x86/include: pmap.h Log Message: Add and use bootspace.smodule. Initialize it in locore/prekern to better hide the specifics from the "upper" layers. This allows for greater flexibility. To generate a diff of this commit: cvs rdiff -u -r1.304 -r1.305 src/sys/arch/amd64/amd64/machdep.c cvs rdiff -u -r1.21 -r1.22 src/sys/arch/amd64/stand/prekern/mm.c cvs rdiff -u -r1.19 -r1.20 src/sys/arch/amd64/stand/prekern/prekern.h cvs rdiff -u -r1.79 -r1.80 src/sys/arch/x86/include/pmap.h 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/machdep.c diff -u src/sys/arch/amd64/amd64/machdep.c:1.304 src/sys/arch/amd64/amd64/machdep.c:1.305 --- src/sys/arch/amd64/amd64/machdep.c:1.304 Tue May 8 17:20:44 2018 +++ src/sys/arch/amd64/amd64/machdep.c Wed Jun 20 11:49:37 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.304 2018/05/08 17:20:44 maxv Exp $ */ +/* $NetBSD: machdep.c,v 1.305 2018/06/20 11:49:37 maxv Exp $ */ /* * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011 @@ -110,9 +110,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.304 2018/05/08 17:20:44 maxv Exp $"); - -/* #define XENDEBUG_LOW */ +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.305 2018/06/20 11:49:37 maxv Exp $"); #include "opt_modular.h" #include "opt_user_ldt.h" @@ -261,11 +259,9 @@ paddr_t gdt_paddr; vaddr_t ldt_vaddr; 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; @@ -374,15 +370,15 @@ cpu_startup(void) * Create the module map. * * The kernel uses RIP-relative addressing with a maximum offset of - * 2GB. The problem is, kernel_map is too far away in memory from - * the kernel .text. So we cannot use it, and have to create a - * special module_map. + * 2GB. Because of that, we can't put the kernel modules in kernel_map + * (like i386 does), since kernel_map is too far away in memory from + * the kernel sections. So we have to create a special module_map. * * The module map is taken as what is left of the bootstrap memory - * created in locore.S. This memory is right above the kernel - * image, so this is the best place to put our modules. + * created in locore/prekern. */ - uvm_map_setup(&module_map_store, module_start, module_end, 0); + uvm_map_setup(&module_map_store, bootspace.smodule, + bootspace.emodule, 0); module_map_store.pmap = pmap_kernel(); module_map = &module_map_store; @@ -1577,9 +1573,11 @@ init_bootspace(void) /* 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 */ + /* Virtual address of the L4 page. */ bootspace.pdir = (vaddr_t)(PDPpaddr + KERNBASE); + /* Kernel module map. */ + bootspace.smodule = (vaddr_t)atdevbase + IOM_SIZE; bootspace.emodule = KERNBASE + NKL2_KIMG_ENTRIES * NBPD_L2; } @@ -1665,13 +1663,6 @@ init_x86_64(paddr_t first_avail) pmap_pa_end = avail_end; #endif - /* End of the virtual space we have created so far. */ - kern_end = (vaddr_t)atdevbase + IOM_SIZE; - - /* The area for the module map. */ - module_start = kern_end; - module_end = bootspace.emodule; - /* * Call pmap initialization to make new kernel address space. * We must do this before loading pages into the VM system. @@ -2123,7 +2114,7 @@ mm_md_kernacc(void *ptr, vm_prot_t prot, return 0; } - if (v >= module_start && v < module_end) { + if (v >= bootspace.smodule && v < bootspace.emodule) { *handled = true; if (!uvm_map_checkprot(module_map, v, v + 1, prot)) return EFAULT; Index: src/sys/arch/amd64/stand/prekern/mm.c diff -u src/sys/arch/amd64/stand/prekern/mm.c:1.21 src/sys/arch/amd64/stand/prekern/mm.c:1.22 --- src/sys/arch/amd64/stand/prekern/mm.c:1.21 Thu Dec 21 14:32:06 2017 +++ src/sys/arch/amd64/stand/prekern/mm.c Wed Jun 20 11:49:37 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: mm.c,v 1.21 2017/12/21 14:32:06 maxv Exp $ */ +/* $NetBSD: mm.c,v 1.22 2018/06/20 11:49:37 maxv Exp $ */ /* * Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved. @@ -420,6 +420,7 @@ mm_map_boot(void) extern uint64_t PDPpaddr; bootspace.spareva = bootspace.boot.va + NKL2_KIMG_ENTRIES * NBPD_L2; bootspace.pdir = bootspace.boot.va + (PDPpaddr - bootspace.boot.pa); + bootspace.smodule = (vaddr_t)iom_base + IOM_SIZE; bootspace.emodule = bootspace.boot.va + NKL2_KIMG_ENTRIES * NBPD_L2; } Index: src/sys/arch/amd64/stand/prekern/prekern.h diff -u src/sys/arch/amd64/stand/prekern/prekern.h:1.19 src/sys/arch/amd64/stand/prekern/prekern.h:1.20 --- src/sys/arch/amd64/stand/prekern/prekern.h:1.19 Mon Jan 15 22:38:01 2018 +++ src/sys/arch/amd64/stand/prekern/prekern.h Wed Jun 20 11:49:37 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: prekern.h,v 1.19 2018/01/15 22:38:01 christos Exp $ */ +/* $NetBSD: prekern.h,v 1.20 2018/06/20 11:49:37 maxv Exp $ */ /* * Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved. @@ -75,6 +75,7 @@ struct bootspace { } boot; vaddr_t spareva; vaddr_t pdir; + vaddr_t smodule; vaddr_t emodule; }; Index: src/sys/arch/x86/include/pmap.h diff -u src/sys/arch/x86/include/pmap.h:1.79 src/sys/arch/x86/include/pmap.h:1.80 --- src/sys/arch/x86/include/pmap.h:1.79 Sat May 19 16:55:59 2018 +++ src/sys/arch/x86/include/pmap.h Wed Jun 20 11:49:38 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.h,v 1.79 2018/05/19 16:55:59 jakllsch Exp $ */ +/* $NetBSD: pmap.h,v 1.80 2018/06/20 11:49:38 maxv Exp $ */ /* * Copyright (c) 1997 Charles D. Cranor and Washington University. @@ -149,7 +149,8 @@ struct bootspace { /* Virtual address of the page directory. */ vaddr_t pdir; - /* End of the area dedicated to kernel modules (amd64 only). */ + /* Area dedicated to kernel modules (amd64 only). */ + vaddr_t smodule; vaddr_t emodule; };