Finalisation functions for both multiboot and multiboot2 can only
occur after memory bootstrap is complete. Any transformation or data
copying of the boot data should be done here.
---
 i386/i386at/model_dep.c | 109 ++++++++++++++++++++++------------------
 1 file changed, 59 insertions(+), 50 deletions(-)

diff --git a/i386/i386at/model_dep.c b/i386/i386at/model_dep.c
index 0654c89e..f4278020 100644
--- a/i386/i386at/model_dep.c
+++ b/i386/i386at/model_dep.c
@@ -377,6 +377,59 @@ register_mb2_boot_data(const struct multiboot2_raw_info 
*mb2_info)
   panic("Multiboot2 not implemented yet");
 }
 
+static void
+finalise_mb1_boot_info(void)
+{
+       vm_offset_t addr;
+
+       /* Copy content pointed by boot_info before losing access to it when it
+        * is too far in physical memory.
+        * Also avoids leaving them in precious areas such as DMA memory.  */
+       if (boot_info.flags & MULTIBOOT_CMDLINE) {
+               int len = strlen ((char*)phystokv(boot_info.cmdline)) + 1;
+               if (! init_alloc_aligned(round_page(len), &addr))
+                 panic("could not allocate memory for multiboot command line");
+               kernel_cmdline = (char*) phystokv(addr);
+               memcpy(kernel_cmdline, (void *)phystokv(boot_info.cmdline), 
len);
+               boot_info.cmdline = addr;
+       }
+
+       if (boot_info.flags & MULTIBOOT_MODS && boot_info.mods_count) {
+               struct multiboot_raw_module *m;
+               int i;
+
+               if (! init_alloc_aligned(
+                       round_page(boot_info.mods_count * sizeof(*m)), &addr))
+                 panic("could not allocate memory for multiboot modules");
+               m = (void*) phystokv(addr);
+               memcpy(m, (void*) phystokv(boot_info.mods_addr), 
boot_info.mods_count * sizeof(*m));
+               boot_info.mods_addr = addr;
+
+               for (i = 0; i < boot_info.mods_count; i++) {
+                       vm_size_t size = m[i].mod_end - m[i].mod_start;
+                       if (! init_alloc_aligned(round_page(size), &addr))
+                         panic("could not allocate memory for multiboot "
+                               "module %d", i);
+                       memcpy((void*) phystokv(addr), (void*) 
phystokv(m[i].mod_start), size);
+                       m[i].mod_start = addr;
+                       m[i].mod_end = addr + size;
+
+                       size = strlen((char*) phystokv(m[i].string)) + 1;
+                       if (! init_alloc_aligned(round_page(size), &addr))
+                         panic("could not allocate memory for multiboot "
+                               "module command line %d", i);
+                       memcpy((void*) phystokv(addr), (void*) 
phystokv(m[i].string), size);
+                       m[i].string = addr;
+               }
+       }
+}
+
+static void
+finalise_mb2_boot_info(const struct multiboot2_raw_info *mb2_info)
+{
+  panic("Multiboot2 not implemented yet");
+}
+
 #endif /* MACH_HYP */
 
 /*
@@ -407,9 +460,10 @@ i386at_init(const struct multiboot2_raw_info *mb2_info)
        /*
         * Read memory map and load it into the physical page allocator.
         */
-#ifdef MACH_HYP
+#ifdef MACH_XEN
        biosmem_xen_bootstrap();
-#else /* MACH_HYP */
+       kernel_cmdline = (char*) boot_info.cmd_line;
+#else /* MACH_XEN */
        extern char _start[], _end[];
 
        biosmem_register_boot_data(_kvtophys(&_start), _kvtophys(&_end), FALSE);
@@ -418,60 +472,15 @@ i386at_init(const struct multiboot2_raw_info *mb2_info)
          {
            register_mb1_boot_data(&boot_info);
            biosmem_mb1_bootstrap(&boot_info);
+           finalise_mb1_boot_info();
          }
        else
          {
            register_mb2_boot_data(mb2_info);
            biosmem_mb2_bootstrap(mb2_info);
+           finalise_mb2_boot_info(mb2_info);
          }
-#endif /* MACH_HYP */
-
-#ifdef MACH_XEN
-       kernel_cmdline = (char*) boot_info.cmd_line;
-#else  /* MACH_XEN */
-       vm_offset_t addr;
-
-       /* Copy content pointed by boot_info before losing access to it when it
-        * is too far in physical memory.
-        * Also avoids leaving them in precious areas such as DMA memory.  */
-       if (boot_info.flags & MULTIBOOT_CMDLINE) {
-               int len = strlen ((char*)phystokv(boot_info.cmdline)) + 1;
-               if (! init_alloc_aligned(round_page(len), &addr))
-                 panic("could not allocate memory for multiboot command line");
-               kernel_cmdline = (char*) phystokv(addr);
-               memcpy(kernel_cmdline, (void *)phystokv(boot_info.cmdline), 
len);
-               boot_info.cmdline = addr;
-       }
-
-       if (boot_info.flags & MULTIBOOT_MODS && boot_info.mods_count) {
-               struct multiboot_raw_module *m;
-               int i;
-
-               if (! init_alloc_aligned(
-                       round_page(boot_info.mods_count * sizeof(*m)), &addr))
-                 panic("could not allocate memory for multiboot modules");
-               m = (void*) phystokv(addr);
-               memcpy(m, (void*) phystokv(boot_info.mods_addr), 
boot_info.mods_count * sizeof(*m));
-               boot_info.mods_addr = addr;
-
-               for (i = 0; i < boot_info.mods_count; i++) {
-                       vm_size_t size = m[i].mod_end - m[i].mod_start;
-                       if (! init_alloc_aligned(round_page(size), &addr))
-                         panic("could not allocate memory for multiboot "
-                               "module %d", i);
-                       memcpy((void*) phystokv(addr), (void*) 
phystokv(m[i].mod_start), size);
-                       m[i].mod_start = addr;
-                       m[i].mod_end = addr + size;
-
-                       size = strlen((char*) phystokv(m[i].string)) + 1;
-                       if (! init_alloc_aligned(round_page(size), &addr))
-                         panic("could not allocate memory for multiboot "
-                               "module command line %d", i);
-                       memcpy((void*) phystokv(addr), (void*) 
phystokv(m[i].string), size);
-                       m[i].string = addr;
-               }
-       }
-#endif /* MACH_XEN */
+#endif /* MACH_XEN */
 
        /*
         *      Initialize kernel physical map, mapping the
-- 
2.47.3


Reply via email to