stivale: Add requested stack sanity checks. Closes #95
diff --git a/stage23/protos/stivale.c b/stage23/protos/stivale.c
index aa2b0284..0f6224d0 100644
--- a/stage23/protos/stivale.c
+++ b/stage23/protos/stivale.c
@@ -174,6 +174,16 @@ void stivale_load(char *config, char *cmdline) {
print("stivale: Requested stack at: %X\n", stivale_hdr.stack);
}
+ // The spec says the stack has to be 16-byte aligned
+ if ((stivale_hdr.stack & (16 - 1)) != 0) {
+ panic("stivale: Requested stack is not 16-byte aligned\n");
+ }
+
+ // It also says the stack cannot be NULL for 32-bit kernels
+ if (bits == 32 && stivale_hdr.stack == 0) {
+ panic("stivale: The stack cannot be 0 for 32-bit kernels");
+ }
+
stivale_struct.module_count = 0;
uint64_t *prev_mod_ptr = &stivale_struct.modules;
for (int i = 0; ; i++) {
diff --git a/stage23/protos/stivale2.c b/stage23/protos/stivale2.c
index 9483403c..b20f61c7 100644
--- a/stage23/protos/stivale2.c
+++ b/stage23/protos/stivale2.c
@@ -193,6 +193,16 @@ failed_to_load_header_section:
print("stivale2: Requested stack at: %X\n", stivale2_hdr.stack);
}
+ // The spec says the stack has to be 16-byte aligned
+ if ((stivale2_hdr.stack & (16 - 1)) != 0) {
+ panic("stivale2: Requested stack is not 16-byte aligned");
+ }
+
+ // It also says the stack cannot be NULL for 32-bit kernels
+ if (bits == 32 && stivale2_hdr.stack == 0) {
+ panic("stivale2: The stack cannot be 0 for 32-bit kernels");
+ }
+
strcpy(stivale2_struct.bootloader_brand, "Limine");
strcpy(stivale2_struct.bootloader_version, LIMINE_VERSION);
