Module Name:    src
Committed By:   maxv
Date:           Thu May  7 17:10:02 UTC 2020

Modified Files:
        src/sys/arch/amd64/stand/prekern: mm.c

Log Message:
Explain more.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/amd64/stand/prekern/mm.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/stand/prekern/mm.c
diff -u src/sys/arch/amd64/stand/prekern/mm.c:1.25 src/sys/arch/amd64/stand/prekern/mm.c:1.26
--- src/sys/arch/amd64/stand/prekern/mm.c:1.25	Sat Feb 15 10:41:25 2020
+++ src/sys/arch/amd64/stand/prekern/mm.c	Thu May  7 17:10:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: mm.c,v 1.25 2020/02/15 10:41:25 maxv Exp $	*/
+/*	$NetBSD: mm.c,v 1.26 2020/05/07 17:10:02 maxv Exp $	*/
 
 /*
  * Copyright (c) 2017-2020 The NetBSD Foundation, Inc. All rights reserved.
@@ -248,7 +248,7 @@ mm_randva_kregion(size_t size, size_t pa
 }
 
 static paddr_t
-bootspace_getend(void)
+bootspace_get_kern_segs_end_pa(void)
 {
 	paddr_t pa, max = 0;
 	size_t i;
@@ -410,21 +410,29 @@ mm_map_boot(void)
 	 * the number of pages entered is lower.
 	 */
 
-	/* Create the page tree */
+	/* Create the page tree, starting at a random VA */
 	size = (NKL2_KIMG_ENTRIES + 1) * NBPD_L2;
 	randva = mm_randva_kregion(size, PAGE_SIZE);
 
-	/* Enter the area and build the ELF info */
-	bootpa = bootspace_getend();
+	/* The "boot" region begins right after the kernel segments */
+	bootpa = bootspace_get_kern_segs_end_pa();
+
+	/* The prekern consumed some memory up until pa_avail, this covers
+	 * SYM+REL and EXTRA */
 	size = (pa_avail - bootpa);
 	npages = size / PAGE_SIZE;
+
+	/* Enter the whole area linearly */
 	for (i = 0; i < npages; i++) {
 		mm_enter_pa(bootpa + i * PAGE_SIZE,
 		    randva + i * PAGE_SIZE, MM_PROT_READ|MM_PROT_WRITE);
 	}
+
+	/* At this point both "head" and "boot" are mapped, so we can build
+	 * the ELF info */
 	elf_build_boot(randva, bootpa);
 
-	/* Enter the ISA I/O MEM */
+	/* Map the ISA I/O MEM right after EXTRA */
 	iom_base = randva + npages * PAGE_SIZE;
 	npages = IOM_SIZE / PAGE_SIZE;
 	for (i = 0; i < npages; i++) {
@@ -451,23 +459,25 @@ mm_map_boot(void)
  * +------------+-----------------+---------------+------------------+-------+
  * | ELF HEADER | SECTION HEADERS | KERN SECTIONS | SYM+REL SECTIONS | EXTRA |
  * +------------+-----------------+---------------+------------------+-------+
- * Which we abstract into several "regions":
+ * This was done in the loadfile_elf32.c:loadfile_dynamic() function.
+ *
+ * We abstract this layout into several "regions":
  * +------------------------------+---------------+--------------------------+
- * |         Head region          | Several segs  |       Boot region        |
+ * |         Head region          |  Kernel segs  |       Boot region        |
  * +------------------------------+---------------+--------------------------+
- * See loadfile_elf32.c:loadfile_dynamic() for the details.
  *
  * There is a variable number of independent regions we create: one head,
  * several kernel segments, one boot. They are all mapped at random VAs.
  *
- * Head contains the ELF Header and ELF Section Headers, and we use them to
- * map the rest of the regions. Head must be placed in both virtual memory
- * and physical memory *before* the rest.
+ * "Head" contains the ELF Header and ELF Section Headers, and we use them to
+ * map the rest of the regions. Head must be placed *before* the other
+ * regions, in both virtual memory and physical memory.
  *
- * The Kernel Sections are mapped at random VAs using individual segments
- * in bootspace.
+ * The "Kernel Segments" contain the kernel SHT_NOBITS and SHT_PROGBITS
+ * sections, in a 1:1 manner (one segment is associated with one section).
+ * The segments are mapped at random VAs and referenced in bootspace.segs[].
  *
- * Boot contains various information, including the ELF Sym+Rel sections,
+ * "Boot" contains various information, including the ELF Sym+Rel sections,
  * plus extra memory the prekern has used so far; it is a region that the
  * kernel will eventually use for module_map. Boot is placed *after* the
  * other regions in physical memory. In virtual memory however there is no

Reply via email to