From e04a9b82cfb5b50b28b7793996e35832f1d1334f Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Fri, 19 Dec 2025 12:30:57 -0500 Subject: [PATCH] check if we have initfs instead of assuming first module exists and is initfs --- disk/limine/limine.conf | 7 ++++--- kernel/include/utility.h | 21 +++++++++++++++++++++ kernel/src/entry.c | 14 +++++++++++++- kernel/src/utility.c | 29 +++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 kernel/include/utility.h create mode 100644 kernel/src/utility.c diff --git a/disk/limine/limine.conf b/disk/limine/limine.conf index 2f7adf6..b82e1bb 100644 --- a/disk/limine/limine.conf +++ b/disk/limine/limine.conf @@ -2,6 +2,7 @@ timeout: 0 quiet: yes /Calcite -protocol: limine -path: boot():/calcite/kernel.elf -module_path: boot():/calcite/initfs.tar +protocol: limine +path: boot():/calcite/kernel.elf +module_path: boot():/calcite/initfs.tar +module_cmdline: initfs diff --git a/kernel/include/utility.h b/kernel/include/utility.h new file mode 100644 index 0000000..19d3995 --- /dev/null +++ b/kernel/include/utility.h @@ -0,0 +1,21 @@ +/* Calcite, kernel/include/utility.h + * Copyright 2025 Benji Dial + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#pragma once + +//returns 1 if equal, 0 if not. +int strequ(const char *str1, const char *str2); diff --git a/kernel/src/entry.c b/kernel/src/entry.c index 1e9a46c..6a8771b 100644 --- a/kernel/src/entry.c +++ b/kernel/src/entry.c @@ -15,6 +15,7 @@ * this program. If not, see . */ +#include #include #include #include @@ -100,7 +101,18 @@ static uint64_t initfs_length; fb->blue_mask_shift != 0 || fb->blue_mask_size != 8) die(); - struct limine_file *initfs = module_request.response->modules[0]; + //find the initfs, and die if we don't have one. + + struct limine_file *initfs = 0; + struct limine_module_response *response = module_request.response; + for (uint64_t i = 0; i < response->module_count; ++i) + if (strequ(response->modules[i]->cmdline, "initfs")) { + initfs = response->modules[i]; + break; + } + + if (!initfs) + die(); //set up page tables. we will mark the regions with bootloader structures as //usable, so we need to be careful not to allocate any physical pages until diff --git a/kernel/src/utility.c b/kernel/src/utility.c new file mode 100644 index 0000000..a46a357 --- /dev/null +++ b/kernel/src/utility.c @@ -0,0 +1,29 @@ +/* Calcite, kernel/src/utility.c + * Copyright 2025 Benji Dial + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include + +int strequ(const char *str1, const char *str2) { + while (1) { + if (!*str1 && !*str2) + return 1; + if (*str1 != *str2) + return 0; + ++str1; + ++str2; + } +}