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 | 105 ++++++++++++++++++++++++----------------
1 file changed, 64 insertions(+), 41 deletions(-)
diff --git a/i386/i386at/model_dep.c b/i386/i386at/model_dep.c
index 27c52385..8b5b8b0d 100644
--- a/i386/i386at/model_dep.c
+++ b/i386/i386at/model_dep.c
@@ -393,6 +393,60 @@ register_boot_data(const struct multiboot2_raw_info
*mb2_info)
register_mb2_boot_data(mb2_info);
}
+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)
+{
+ /* Not implemented yet. */
+ (void)mb2_info;
+}
+
#endif /* MACH_HYP */
/*
@@ -437,48 +491,17 @@ i386at_init(void)
#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;
- }
- }
+ /* Transformation of multiboot data can be completed now that
+ memory has been bootstrapped. */
+ if (mb2_info != NULL)
+ {
+ finalise_mb2_boot_info(mb2_info);
+ }
+ else
+ {
+ finalise_mb1_boot_info();
+ }
#endif /* MACH_XEN */
/*
--
2.47.3