Skip to content

Instantly share code, notes, and snippets.

@jessicah
Last active September 15, 2016 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessicah/cfa8b05617e6c496eef6e213ccb66a63 to your computer and use it in GitHub Desktop.
Save jessicah/cfa8b05617e6c496eef6e213ccb66a63 to your computer and use it in GitHub Desktop.
Generating kernel_arg sizes per version
rm -f $(1)
TEMPFILE=$(mktemp)
OUTFILE=$(mktemp)
GENERATORFILE=$(mktemp)
COUNTER=1
CONTINUE=1
cat <<EOF > $GENERATORFILE
#include <kernel_args.h>
#if CURRENT_KERNEL_ARGS_VERSION > MAX_KERNEL_ARGS_VERSION
#error "Unsupported version"
#endif
#include <stdio.h>
int main()
{
printf("\t%lu,\n", sizeof(kernel_args));
return 0;
}
EOF
echo 'size_t kernel_arg_sizes[] = {' > $OUTFILE
while [ $CONTINUE -eq 1 ]; do
$(CC) -o $TEMPFILE $GENERATORFILE -DCURRENT_KERNEL_ARGS_VERSION=$COUNTER
if [ $? -eq 0 ]; then
$TEMPFILE >> $OUTFILE
COUNTER=$((COUNTER + 1))
else
CONTINUE=0
fi
done
echo '};' >> $OUTFILE
rm -f $TEMPFILE $GENERATORFILE
mv $OUTFILE $(1)
From 0967250bbdfc95b3a17bc8b73d1c01e025d4b8b3 Mon Sep 17 00:00:00 2001
From: Jessica Hamilton <jessica.l.hamilton@gmail.com>
Date: Thu, 15 Sep 2016 19:29:26 +1200
Subject: [PATCH] kernel_args: support multiple versions
---
headers/private/kernel/boot/kernel_args.h | 8 ++++-
.../boot/platform/bios_ia32/platform_kernel_args.h | 3 +-
.../boot/platform/efi/platform_kernel_args.h | 7 +++-
src/system/kernel/arch/x86/arch_platform.cpp | 38 ++++++++++++----------
4 files changed, 35 insertions(+), 21 deletions(-)
diff --git a/headers/private/kernel/boot/kernel_args.h b/headers/private/kernel/boot/kernel_args.h
index 9a6a455..45b07af 100644
--- a/headers/private/kernel/boot/kernel_args.h
+++ b/headers/private/kernel/boot/kernel_args.h
@@ -21,7 +21,10 @@
#include <util/FixedWidthPointer.h>
-#define CURRENT_KERNEL_ARGS_VERSION 1
+#ifndef CURRENT_KERNEL_ARGS_VERSION
+#define CURRENT_KERNEL_ARGS_VERSION 2
+#endif
+#define MAX_KERNEL_ARGS_VERSION 2
#define MAX_KERNEL_ARGS_RANGE 20
// names of common boot_volume fields
@@ -33,6 +36,9 @@
#define BOOT_VOLUME_PARTITION_OFFSET "partition offset"
#define BOOT_VOLUME_DISK_IDENTIFIER "disk identifier"
+// needed for versioning the kernel_args
+extern size_t kernel_arg_sizes[MAX_KERNEL_ARGS_VERSION];
+
// boot methods
enum {
BOOT_METHOD_HARD_DISK = 0,
diff --git a/headers/private/kernel/boot/platform/bios_ia32/platform_kernel_args.h b/headers/private/kernel/boot/platform/bios_ia32/platform_kernel_args.h
index 7464468..df422b0 100644
--- a/headers/private/kernel/boot/platform/bios_ia32/platform_kernel_args.h
+++ b/headers/private/kernel/boot/platform/bios_ia32/platform_kernel_args.h
@@ -30,8 +30,9 @@ typedef struct {
// this does not contain the boot drive
apm_info apm;
-
+#if CURRENT_KERNEL_ARGS_VERSION >= 2
FixedWidthPointer<void> acpi_root;
+#endif
} _PACKED platform_kernel_args;
#endif /* KERNEL_BOOT_PLATFORM_BIOS_IA32_KERNEL_ARGS_H */
diff --git a/headers/private/kernel/boot/platform/efi/platform_kernel_args.h b/headers/private/kernel/boot/platform/efi/platform_kernel_args.h
index 2ded98e..e7ee0cc 100644
--- a/headers/private/kernel/boot/platform/efi/platform_kernel_args.h
+++ b/headers/private/kernel/boot/platform/efi/platform_kernel_args.h
@@ -10,6 +10,10 @@
# error This file is included from <boot/kernel_args.h> only
#endif
+#if CURRENT_KERNEL_ARGS_VERSION < 2
+#error "require kernel args version > 2"
+#endif
+
// currently the EFI loader pretends to be the bios_ia32 platform.
// not quite right, as the kernel needs to be aware of efi runtime services
@@ -41,8 +45,9 @@ typedef struct {
// seems to be ignored entirely?
apm_info apm;
-
+#if CURRENT_KERNEL_ARGS_VERSION >= 2
FixedWidthPointer<void> acpi_root;
+#endif
} _PACKED platform_kernel_args;
diff --git a/src/system/kernel/arch/x86/arch_platform.cpp b/src/system/kernel/arch/x86/arch_platform.cpp
index a1f3226..6c231e4 100644
--- a/src/system/kernel/arch/x86/arch_platform.cpp
+++ b/src/system/kernel/arch/x86/arch_platform.cpp
@@ -7,30 +7,32 @@
* Axel Dörfler, axeld@pinc-software.de
*/
-
-#include <arch/platform.h>
-#include <apm.h>
-#include <boot_item.h>
-#include <boot/stage2.h>
-
-
-status_t
+
+#include <arch/platform.h>
+#include <apm.h>
+#include <boot_item.h>
+#include <boot/stage2.h>
+
+
+status_t
arch_platform_init(struct kernel_args *args)
{
return B_OK;
}
-status_t
-arch_platform_init_post_vm(struct kernel_args *args)
-{
- // Now we can add boot items; pass on the ACPI root pointer
- add_boot_item("ACPI_ROOT_POINTER",
- args->platform_args.acpi_root.Pointer(), sizeof(void*));
-
- return B_OK;
-}
-
+status_t
+arch_platform_init_post_vm(struct kernel_args *args)
+{
+ if (args->version >= 2) {
+ // Now we can add boot items; pass on the ACPI root pointer
+ add_boot_item("ACPI_ROOT_POINTER",
+ args->platform_args.acpi_root.Pointer(), sizeof(void*));
+ }
+
+ return B_OK;
+}
+
status_t
arch_platform_init_post_thread(struct kernel_args *args)
--
2.5.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment