[haiku-commits] Change in haiku[master]: kernel: support kernel args version 1

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 23 Feb 2020 17:56:50 +0000

From Jérôme Duval <jerome.duval@xxxxxxxxx>:

Jérôme Duval has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/2271 ;)


Change subject: kernel: support kernel args version 1
......................................................................

kernel: support kernel args version 1
---
M headers/private/kernel/arch/platform.h
M headers/private/kernel/arch/x86/arch_kernel_args.h
M headers/private/kernel/boot/kernel_args.h
M src/system/kernel/arch/arm/arch_platform.cpp
M src/system/kernel/arch/arm64/arch_platform.cpp
M src/system/kernel/arch/m68k/arch_platform.cpp
M src/system/kernel/arch/ppc/arch_platform.cpp
M src/system/kernel/arch/riscv64/arch_platform.cpp
M src/system/kernel/arch/sparc/arch_platform.cpp
M src/system/kernel/arch/x86/arch_platform.cpp
M src/system/kernel/main.cpp
11 files changed, 212 insertions(+), 4 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/71/2271/1

diff --git a/headers/private/kernel/arch/platform.h 
b/headers/private/kernel/arch/platform.h
index 2766f05..bf18257 100644
--- a/headers/private/kernel/arch/platform.h
+++ b/headers/private/kernel/arch/platform.h
@@ -20,6 +20,8 @@
 status_t arch_platform_init(struct kernel_args *kernelArgs);
 status_t arch_platform_init_post_vm(struct kernel_args *kernelArgs);
 status_t arch_platform_init_post_thread(struct kernel_args *kernelArgs);
+status_t arch_platform_convert_args(struct kernel_args *kernelArgs, bool* 
upgraded);
+

 #ifdef __cplusplus
 }      // extern "C"
diff --git a/headers/private/kernel/arch/x86/arch_kernel_args.h 
b/headers/private/kernel/arch/x86/arch_kernel_args.h
index 7d87016..99315a3 100644
--- a/headers/private/kernel/arch/x86/arch_kernel_args.h
+++ b/headers/private/kernel/arch/x86/arch_kernel_args.h
@@ -45,4 +45,33 @@
        uint32  ucode_data_size;
 } _PACKED arch_kernel_args;

+
+// kernel args
+typedef struct {
+       // architecture specific
+       uint32  system_time_cv_factor;
+       uint64  cpu_clock_speed;
+       uint32  phys_pgdir;
+       uint64  vir_pgdir;
+       uint32  num_pgtables;
+       uint32  pgtables[MAX_BOOT_PTABLES];
+       uint64  virtual_end;
+       uint64  page_hole;
+       // smp stuff
+       uint32  apic_time_cv_factor; // apic ticks per second
+       uint32  apic_phys;
+       FixedWidthPointer<void> apic;
+       uint32  ioapic_phys;
+       uint32  cpu_apic_id[SMP_MAX_CPUS];
+       uint32  cpu_apic_version[SMP_MAX_CPUS];
+       // hpet stuff
+       uint32  hpet_phys;
+       FixedWidthPointer<void> hpet;
+       // needed for UEFI, otherwise kernel acpi support can't find ACPI root
+       FixedWidthPointer<void> acpi_root;
+} _PACKED arch_kernel_args_v1;
+
+#define KERNEL_ARCH_ARGS_V1
+
+
 #endif /* KERNEL_ARCH_x86_KERNEL_ARGS_H */
diff --git a/headers/private/kernel/boot/kernel_args.h 
b/headers/private/kernel/boot/kernel_args.h
index b91f7ff..a9e6d7e 100644
--- a/headers/private/kernel/boot/kernel_args.h
+++ b/headers/private/kernel/boot/kernel_args.h
@@ -109,4 +109,75 @@

 } _PACKED kernel_args;

+
+#ifdef KERNEL_ARCH_ARGS_V1
+// we define kernel_args_v1 only if arch_kernel_args_v1 is also defined
+typedef struct kernel_args_v1 {
+       uint32          kernel_args_size;
+       uint32          version;
+
+       FixedWidthPointer<struct preloaded_image> kernel_image;
+       FixedWidthPointer<struct preloaded_image> preloaded_images;
+
+       uint32          num_physical_memory_ranges;
+       addr_range      physical_memory_range[MAX_PHYSICAL_MEMORY_RANGE];
+       uint32          num_physical_allocated_ranges;
+       addr_range      physical_allocated_range[MAX_PHYSICAL_ALLOCATED_RANGE];
+       uint32          num_virtual_allocated_ranges;
+       addr_range      virtual_allocated_range[MAX_VIRTUAL_ALLOCATED_RANGE];
+       uint32          num_kernel_args_ranges;
+       addr_range      kernel_args_range[MAX_KERNEL_ARGS_RANGE];
+       uint64          ignored_physical_memory;
+
+       uint32          num_cpus;
+       addr_range      cpu_kstack[SMP_MAX_CPUS];
+
+       // boot volume KMessage data
+       FixedWidthPointer<void> boot_volume;
+       int32           boot_volume_size;
+
+       FixedWidthPointer<struct driver_settings_file> driver_settings;
+
+       struct {
+               addr_range      physical_buffer;
+               uint32  bytes_per_row;
+               uint16  width;
+               uint16  height;
+               uint8   depth;
+               bool    enabled;
+       } frame_buffer;
+
+       FixedWidthPointer<void> vesa_modes;
+       uint16          vesa_modes_size;
+       uint8           vesa_capabilities;
+       FixedWidthPointer<void> edid_info;
+
+       FixedWidthPointer<void> debug_output;
+               // If keep_debug_output_buffer, points to a ring_buffer, else 
to a
+               // simple flat buffer. In either case it stores the debug 
output from
+               // the boot loader.
+       FixedWidthPointer<void> previous_debug_output;
+               // A flat pointer to a buffer containing the debug output from 
the
+               // previous session. May be NULL.
+       uint32          debug_size;
+               // If keep_debug_output_buffer, the size of the ring buffer, 
otherwise
+               // the size of the flat buffer debug_output points to.
+       uint32          previous_debug_size;
+               // The size of the buffer previous_debug_output points to. Used 
as a
+               // boolean indicator whether to save the previous session's 
debug output
+               // until initialized for the kernel.
+       bool            keep_debug_output_buffer;
+               // If true, debug_output is a ring buffer, otherwise a flat 
buffer.
+
+       platform_kernel_args platform_args;
+       arch_kernel_args_v1 arch_args;
+
+       // bootsplash data
+       FixedWidthPointer<uint8> boot_splash;
+
+} _PACKED kernel_args_v1;
+
+#endif // KERNEL_ARCH_ARGS_V1
+
+
 #endif /* KERNEL_BOOT_KERNEL_ARGS_H */
diff --git a/src/system/kernel/arch/arm/arch_platform.cpp 
b/src/system/kernel/arch/arm/arch_platform.cpp
index 3083a09..dc7b0cd 100644
--- a/src/system/kernel/arch/arm/arch_platform.cpp
+++ b/src/system/kernel/arch/arm/arch_platform.cpp
@@ -41,3 +41,16 @@
        // now we can create and use semaphores
        return B_OK;
 }
+
+
+status_t
+arch_platform_convert_args(struct kernel_args *args, bool* upgraded)
+{
+       if (args->version == KERNEL_ARGS_VERSION_V1
+                       && args->kernel_args_size == sizeof(kernel_args)) {
+               args->version = KERNEL_ARGS_VERSION_V2;
+               if (upgraded != NULL)
+                       *upgraded = true;
+       }
+       return B_OK;
+}
diff --git a/src/system/kernel/arch/arm64/arch_platform.cpp 
b/src/system/kernel/arch/arm64/arch_platform.cpp
index 95c1285..11cbc0c 100644
--- a/src/system/kernel/arch/arm64/arch_platform.cpp
+++ b/src/system/kernel/arch/arm64/arch_platform.cpp
@@ -26,3 +26,17 @@
 {
        return B_OK;
 }
+
+
+status_t
+arch_platform_convert_args(struct kernel_args *args, bool* upgraded)
+{
+       if (args->version == KERNEL_ARGS_VERSION_V1
+                       && args->kernel_args_size == sizeof(kernel_args)) {
+               args->version = KERNEL_ARGS_VERSION_V2;
+               if (upgraded != NULL)
+                       *upgraded = true;
+       }
+
+       return B_OK;
+}
diff --git a/src/system/kernel/arch/m68k/arch_platform.cpp 
b/src/system/kernel/arch/m68k/arch_platform.cpp
index bf5003b..6fa743c 100644
--- a/src/system/kernel/arch/m68k/arch_platform.cpp
+++ b/src/system/kernel/arch/m68k/arch_platform.cpp
@@ -84,3 +84,16 @@
 {
        return B_OK;
 }
+
+
+status_t
+arch_platform_convert_args(struct kernel_args *args, bool* upgraded)
+{
+       if (args->version == KERNEL_ARGS_VERSION_V1
+                       && args->kernel_args_size == sizeof(kernel_args)) {
+               args->version = KERNEL_ARGS_VERSION_V2;
+               if (upgraded != NULL)
+                       *upgraded = true;
+       }
+       return B_OK;
+}
diff --git a/src/system/kernel/arch/ppc/arch_platform.cpp 
b/src/system/kernel/arch/ppc/arch_platform.cpp
index f7b621a..224561d 100644
--- a/src/system/kernel/arch/ppc/arch_platform.cpp
+++ b/src/system/kernel/arch/ppc/arch_platform.cpp
@@ -388,3 +388,16 @@
 {
        return B_OK;
 }
+
+
+status_t
+arch_platform_convert_args(struct kernel_args *args, bool* upgraded)
+{
+       if (args->version == KERNEL_ARGS_VERSION_V1
+                       && args->kernel_args_size == sizeof(kernel_args)) {
+               args->version = KERNEL_ARGS_VERSION_V2;
+               if (upgraded != NULL)
+                       *upgraded = true;
+       }
+       return B_OK;
+}
diff --git a/src/system/kernel/arch/riscv64/arch_platform.cpp 
b/src/system/kernel/arch/riscv64/arch_platform.cpp
index 30a2394..1031c56 100644
--- a/src/system/kernel/arch/riscv64/arch_platform.cpp
+++ b/src/system/kernel/arch/riscv64/arch_platform.cpp
@@ -25,3 +25,16 @@
 {
        return B_OK;
 }
+
+
+status_t
+arch_platform_convert_args(struct kernel_args *args, bool* upgraded)
+{
+       if (args->version == KERNEL_ARGS_VERSION_V1
+                       && args->kernel_args_size == sizeof(kernel_args)) {
+               args->version = KERNEL_ARGS_VERSION_V2;
+               if (upgraded != NULL)
+                       *upgraded = true;
+       }
+       return B_OK;
+}
diff --git a/src/system/kernel/arch/sparc/arch_platform.cpp 
b/src/system/kernel/arch/sparc/arch_platform.cpp
index 30a2394..1031c56 100644
--- a/src/system/kernel/arch/sparc/arch_platform.cpp
+++ b/src/system/kernel/arch/sparc/arch_platform.cpp
@@ -25,3 +25,16 @@
 {
        return B_OK;
 }
+
+
+status_t
+arch_platform_convert_args(struct kernel_args *args, bool* upgraded)
+{
+       if (args->version == KERNEL_ARGS_VERSION_V1
+                       && args->kernel_args_size == sizeof(kernel_args)) {
+               args->version = KERNEL_ARGS_VERSION_V2;
+               if (upgraded != NULL)
+                       *upgraded = true;
+       }
+       return B_OK;
+}
diff --git a/src/system/kernel/arch/x86/arch_platform.cpp 
b/src/system/kernel/arch/x86/arch_platform.cpp
index ac15e22..66a1892 100644
--- a/src/system/kernel/arch/x86/arch_platform.cpp
+++ b/src/system/kernel/arch/x86/arch_platform.cpp
@@ -42,3 +42,21 @@
        return B_OK;
 }

+
+status_t
+arch_platform_convert_args(struct kernel_args *args, bool* upgraded)
+{
+       if (args->version == KERNEL_ARGS_VERSION_V1
+                       && args->kernel_args_size == sizeof(kernel_args_v1)) {
+               kernel_args_v1* bootKernelArgsV1 = (kernel_args_v1*)args;
+               args->boot_splash = bootKernelArgsV1->boot_splash;
+               args->arch_args.ucode_data = NULL;
+               args->arch_args.ucode_data_size= 0;
+               args->version = KERNEL_ARGS_VERSION_V2;
+               args->kernel_args_size = sizeof(kernel_args);
+               if (upgraded != NULL)
+                       *upgraded = true;
+       }
+       return B_OK;
+}
+
diff --git a/src/system/kernel/main.cpp b/src/system/kernel/main.cpp
index b54a9c2..8b70b80 100644
--- a/src/system/kernel/main.cpp
+++ b/src/system/kernel/main.cpp
@@ -103,17 +103,26 @@
                // released kernels.
                debug_early_boot_message("Version mismatch between boot loader 
and "
                        "kernel!\n");
-               return -1;
        }

        smp_set_num_cpus(bootKernelArgs->num_cpus);

+       bool upgraded = false;
+
        // wait for all the cpus to get here
        smp_cpu_rendezvous(&sCpuRendezvous);

        // the passed in kernel args are in a non-allocated range of memory
-       if (currentCPU == 0)
+       if (currentCPU == 0) {
+               // We try to convert an old kernelArgs format to the current one
+               if (arch_platform_convert_args(bootKernelArgs, &upgraded) != 
B_OK
+                       || bootKernelArgs->kernel_args_size != 
sizeof(kernel_args)
+                       || bootKernelArgs->version != 
CURRENT_KERNEL_ARGS_VERSION) {
+                       debug_early_boot_message("Kernel args upgrade 
failed!\n");
+                       return -1;
+               }
                memcpy(&sKernelArgs, bootKernelArgs, sizeof(kernel_args));
+       }

        smp_cpu_rendezvous(&sCpuRendezvous2);

@@ -130,8 +139,8 @@
                debug_init(&sKernelArgs);
                set_dprintf_enabled(true);
                dprintf("Welcome to kernel debugger output!\n");
-               dprintf("Haiku revision: %s, debug level: %d\n", 
get_haiku_revision(),
-                       KDEBUG_LEVEL);
+               dprintf("Haiku revision: %s, debug level: %d%s\n", 
get_haiku_revision(),
+                       KDEBUG_LEVEL, upgraded ? " kernel args upgraded" : "");

                // init modules
                TRACE("init CPU\n");

-- 
To view, visit https://review.haiku-os.org/c/haiku/+/2271
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: Ibf6bce2d095b459df8a95c77ce4b5e438e5870fe
Gerrit-Change-Number: 2271
Gerrit-PatchSet: 1
Gerrit-Owner: Jérôme Duval <jerome.duval@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: kernel: support kernel args version 1 - Gerrit