Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Add a bootspace structure. It describes the physica...



details:   https://anonhg.NetBSD.org/src/rev/8321c7542ff5
branches:  trunk
changeset: 356504:8321c7542ff5
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Sep 30 11:43:57 2017 +0000

description:
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.

diffstat:

 sys/arch/amd64/amd64/locore.S  |    6 +-
 sys/arch/amd64/amd64/machdep.c |   45 ++++++++++++++++-
 sys/arch/i386/i386/locore.S    |    5 +-
 sys/arch/i386/i386/machdep.c   |  101 ++++++++++++++++++++--------------------
 sys/arch/x86/include/pmap.h    |   41 ++++++++++++++++-
 sys/arch/x86/x86/pmap.c        |   44 ++++++++---------
 6 files changed, 158 insertions(+), 84 deletions(-)

diffs (truncated from 587 to 300 lines):

diff -r 7d9d0a23a964 -r 8321c7542ff5 sys/arch/amd64/amd64/locore.S
--- a/sys/arch/amd64/amd64/locore.S     Sat Sep 30 10:29:10 2017 +0000
+++ b/sys/arch/amd64/amd64/locore.S     Sat Sep 30 11:43:57 2017 +0000
@@ -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 @@
        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 @@
 do_iret:
        iretq
 END(intrfastexit)
-
diff -r 7d9d0a23a964 -r 8321c7542ff5 sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Sat Sep 30 10:29:10 2017 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Sat Sep 30 11:43:57 2017 +0000
@@ -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 @@
 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_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 @@
 }
 
 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 @@
 
        /* 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 @@
 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) {
diff -r 7d9d0a23a964 -r 8321c7542ff5 sys/arch/i386/i386/locore.S
--- a/sys/arch/i386/i386/locore.S       Sat Sep 30 10:29:10 2017 +0000
+++ b/sys/arch/i386/i386/locore.S       Sat Sep 30 11:43:57 2017 +0000
@@ -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 @@
        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 */
diff -r 7d9d0a23a964 -r 8321c7542ff5 sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c      Sat Sep 30 10:29:10 2017 +0000
+++ b/sys/arch/i386/i386/machdep.c      Sat Sep 30 11:43:57 2017 +0000
@@ -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 @@
 #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 @@
 
 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 @@
 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 @@
        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 @@
        /* 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 @@
        gd->gd_dpl = 0;
 }
 
-
 void
 setregion(struct region_descriptor *rd, void *base, size_t limit)
 {
@@ -980,25 +967,24 @@
 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 @@
                    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 @@
 }
 
 void



Home | Main Index | Thread Index | Old Index