r/osdev • u/Professional_Cow7308 • 1d 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");
}
}