Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/amd64/stand/prekern Explain more.
details: https://anonhg.NetBSD.org/src/rev/235ce7058ec2
branches: trunk
changeset: 932434:235ce7058ec2
user: maxv <maxv%NetBSD.org@localhost>
date: Thu May 07 17:10:02 2020 +0000
description:
Explain more.
diffstat:
sys/arch/amd64/stand/prekern/mm.c | 40 ++++++++++++++++++++++++--------------
1 files changed, 25 insertions(+), 15 deletions(-)
diffs (87 lines):
diff -r b006865cdfbd -r 235ce7058ec2 sys/arch/amd64/stand/prekern/mm.c
--- a/sys/arch/amd64/stand/prekern/mm.c Thu May 07 16:49:59 2020 +0000
+++ b/sys/arch/amd64/stand/prekern/mm.c Thu May 07 17:10:02 2020 +0000
@@ -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 @@
}
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 @@
* 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 @@
* +------------+-----------------+---------------+------------------+-------+
* | 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
Home |
Main Index |
Thread Index |
Old Index