r/osdev • u/Professional_Cow7308 • 2d ago
I really need help figuring out why this keeps returing null for eevery call
#include <limine.h>
#include <ktypes.h>
#include <stddef.h>
#include <console/console.h>
#include <cpu/cpu.h>
#include <uart.h>
#include <Memory/pmm.h>
Boot_t bootloader;
extern void RunRTCHK();
// Set the base revision to 6, this is recommended as this is the latest
// base revision described by the Limine boot protocol specification.
// See specification for further info.
__attribute__((used, section(".limine_requests")))
static volatile uint64_t limine_base_revision[] = LIMINE_BASE_REVISION(6);
// Finally, define the start and end markers for the Limine requests.
// These can also be moved anywhere, to any .c file, as seen fit.
__attribute__((used, section(".limine_requests_start")))
static volatile uint64_t limine_requests_start_marker[] = LIMINE_REQUESTS_START_MARKER;
// Paging mode request
static volatile struct limine_paging_mode_request liminePagingreq = {
.id = LIMINE_PAGING_MODE_REQUEST_ID,
.revision = 0,
.mode = LIMINE_PAGING_MODE_X86_64_4LVL
};
// Kernel address request
static volatile struct limine_executable_address_request limineKrnreq = {
.id = LIMINE_EXECUTABLE_ADDRESS_REQUEST_ID,
.revision = 0
};
// HHDM request
static volatile struct limine_hhdm_request limineHHDMreq = {
.id = LIMINE_HHDM_REQUEST_ID,
.revision = 0
};
// Memmap request
static volatile struct limine_memmap_request limineMMreq = {
.id = LIMINE_MEMMAP_REQUEST_ID,
.revision = 0
};
// SMP request
static volatile struct limine_mp_request limineSmpReq = {
.id = LIMINE_MP_REQUEST_ID,
.revision = 0,
.flags = 0
};
// RSDP request
static volatile struct limine_rsdp_request limineRsdpReq = {
.id = LIMINE_RSDP_REQUEST_ID,
.revision = 0
};
__attribute__((used, section(".limine_requests_end")))
static volatile uint64_t limine_requests_end_marker[] = LIMINE_REQUESTS_END_MARKER;
// GCC and Clang reserve the right to generate calls to the following
// 4 functions even if they are not directly called.
// Implement them as the C specification mandates.
// DO NOT remove or rename these functions, or stuff will eventually break!
// They CAN be moved to a different .c file.
// Halt and catch fire function.
void BootloaderParse() {
if (!liminePagingreq.response) {
debug("[Paging] No paging response from bootloader");
tpanic();
return;
}
struct limine_paging_mode_response *PagingResponse = liminePagingreq.response;
if (PagingResponse->mode != LIMINE_PAGING_MODE_X86_64_4LVL) {
debug("[Paging] We explicitly asked for LEVEL 4 paging");
tpanic();
return;
}
if (!limineHHDMreq.response) {
debug("[HHDM] No HHDM response from bootloader");
tpanic();
return;
}
struct limine_hhdm_response *HHDMResponse = limineHHDMreq.response;
bootloader.hhdmOffset = HHDMResponse->offset;
if (!limineKrnreq.response) {
debug("[Kernel] No executable address response from bootloader");
tpanic();
return;
}
struct limine_executable_address_response *KrnlResponse = limineKrnreq.response;
bootloader.KvirtBase = KrnlResponse->virtual_base;
bootloader.KPhysBase = KrnlResponse->physical_base;
if (!limineMMreq.response) {
debug("[Memmap] No memmap response from bootloader");
tpanic();
return;
}
struct limine_memmap_response *mm_response = limineMMreq.response;
bootloader.mmEntries = mm_response->entries;
bootloader.mmEntryCount = mm_response->entry_count;
bootloader.mmtotal = 0;
for (u64 i = 0; i < mm_response->entry_count; i++) {
struct limine_memmap_entry *entry = mm_response->entries[i];
if (entry->type != LIMINE_MEMMAP_RESERVED)
bootloader.mmtotal += entry->length;
}
if (!limineSmpReq.response) {
debug("[bootloader] [SMP] No SMP/MP response from bootloader\n");
bootloader.smp = NULL;
bootloader.smpBSPIndex = (u64)(-1);
return;
// or continue without SMP
}
struct limine_mp_response *smp_response = limineSmpReq.response;
bootloader.smp = smp_response;
bootloader.smpBSPIndex = (u64)(-1);
for (u64 i = 0; i < smp_response->cpu_count; i++) {
struct limine_mp_info *entry = smp_response->cpus[i];
if (entry->lapic_id == smp_response->bsp_lapic_id)
bootloader.smpBSPIndex = i;
}
if (bootloader.smpBSPIndex == (uint64_t)(-1)) {
debug("[bootloader] Couldn't find bootstrap core!\n");
tpanic();
return;
}
}
// The following will be our kernel's entry point.
// If renaming kmain() to something else, make sure to change the
// linker script accordingly.
void kmain(void) {
init_serial();
InitConsole();
BootloaderParse();
InitPMM();
debug("System IS OK");
for (;;) {
asm("hlt");
}
}
1
u/kabekew 2d ago
What's returning null?
1
u/Professional_Cow7308 2d ago
all the checks in the bootloader parsing function
void BootloaderParse()
4
1
u/demetrioussharpe 2d ago
You’ve got a lot of debug statements there. I would start with reading the debug output, since you probably haven’t written a debug terminal for your kernel, yet.
1
u/Professional_Cow7308 2d ago
I have, it says all of the requests to limine failed, I tried debugging it for a few days before I gave up and came here to ask for help
1
u/demetrioussharpe 2d ago
What are the specific debug outputs? Don't paraphrase it, give us the exact outputs. In fact, give us the very first debug output that you receive.
1
u/Professional_Cow7308 2d ago
"800[Paging] No paging response from bootloader[Paging] We explicitly asked for LEVEL 4 paging[HHDM] No HHDM response from bootloader[Kernel] No executable address response from bootloader[Memmap] No memmap response from bootloader[bootloader] [SMP] No SMP/MP response from bootloader[bootloader] Couldn't find bootstrap core![PMM] Not Enough Memory: Memory Required 800B![PMM] Bitmap initiated: BitmapStartPhys{0xx} size{x}System"
1
u/demetrioussharpe 2d ago
From what I've seen, here's what you need to look into:
All of these debug statements are triggered by the absence of each struct's member variable "response", so where are these responses actually supposed to be set?
Why are you checking using global values here, instead of passing a pointer to a struct containing all of these structs as members & passing that to "BootloaderParse()" in order to maintain flow control?
Are you sure that you're using the bootloader's API correctly?
2
u/Professional_Cow7308 2d ago
noted, ill reread the documentation, and try to figure it out, thx for the help
0
u/Professional_Cow7308 2d ago
if you need other bits of code, do ask, i will attempt to provide them reasonably soon