99 lines
2.8 KiB
C
99 lines
2.8 KiB
C
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <limine.h>
|
|
#include "bootinfo.h"
|
|
#include "hal/hal.h"
|
|
|
|
BootInfo BOOT_INFO;
|
|
|
|
static volatile struct limine_paging_mode_request PAGING_REQ = {
|
|
.id = LIMINE_PAGING_MODE_REQUEST,
|
|
.revision = 0,
|
|
#if defined(__x86_64__)
|
|
.mode = LIMINE_PAGING_MODE_X86_64_4LVL,
|
|
#else
|
|
# error "Paging mode is unknown for this architecture"
|
|
#endif
|
|
};
|
|
|
|
static volatile struct limine_kernel_address_request KERN_ADDR_REQ = {
|
|
.id = LIMINE_KERNEL_ADDRESS_REQUEST, .revision = 0,
|
|
};
|
|
|
|
static volatile struct limine_hhdm_request HHDM_REQ = {
|
|
.id = LIMINE_HHDM_REQUEST, .revision = 0,
|
|
};
|
|
|
|
static volatile struct limine_memmap_request MEMMAP_REQ = {
|
|
.id = LIMINE_MEMMAP_REQUEST, .revision = 0,
|
|
};
|
|
|
|
static volatile struct limine_smp_request SMP_REQ = {
|
|
.id = LIMINE_SMP_REQUEST, .revision = 0,
|
|
};
|
|
|
|
static volatile struct limine_rsdp_request RSDP_REQ = {
|
|
.id = LIMINE_RSDP_REQUEST, .revision = 0,
|
|
};
|
|
|
|
static volatile struct limine_framebuffer_request FB_REQ = {
|
|
.id = LIMINE_FRAMEBUFFER_REQUEST, .revision = 0,
|
|
};
|
|
|
|
static volatile struct limine_module_request MODULE_REQ = {
|
|
.id = LIMINE_MODULE_REQUEST, .revision = 0,
|
|
};
|
|
|
|
void bootinfo_init(void) {
|
|
if (FB_REQ.response == NULL || FB_REQ.response->framebuffer_count < 1) {
|
|
hal_hang();
|
|
}
|
|
BOOT_INFO.fb = FB_REQ.response->framebuffers[0];
|
|
|
|
struct limine_module_response *modulesres= MODULE_REQ.response;
|
|
BOOT_INFO.modules = modulesres;
|
|
|
|
struct limine_paging_mode_response *pagingres = PAGING_REQ.response;
|
|
#if defined(__x86_64__)
|
|
if (pagingres->mode != LIMINE_PAGING_MODE_X86_64_4LVL) {
|
|
#endif
|
|
hal_hang();
|
|
}
|
|
|
|
struct limine_hhdm_response *hhdmres = HHDM_REQ.response;
|
|
BOOT_INFO.hhdm_off = hhdmres->offset;
|
|
|
|
struct limine_kernel_address_response *kernaddrres = KERN_ADDR_REQ.response;
|
|
BOOT_INFO.kern_virtbase = kernaddrres->virtual_base;
|
|
BOOT_INFO.kern_physbase = kernaddrres->physical_base;
|
|
|
|
struct limine_memmap_response *memmapres = MEMMAP_REQ.response;
|
|
BOOT_INFO.memmap_entries = memmapres->entries;
|
|
BOOT_INFO.memmap_entrycount = memmapres->entry_count;
|
|
|
|
BOOT_INFO.memmap_total = 0;
|
|
for (size_t i = 0; i < memmapres->entry_count; i++) {
|
|
struct limine_memmap_entry *entry = memmapres->entries[i];
|
|
if (entry->type != LIMINE_MEMMAP_RESERVED) {
|
|
BOOT_INFO.memmap_total += entry->length;
|
|
}
|
|
}
|
|
|
|
struct limine_smp_response *smpres = SMP_REQ.response;
|
|
BOOT_INFO.smp = smpres;
|
|
|
|
BOOT_INFO.smp_bspindex = (uint64_t)(-1);
|
|
for (size_t i = 0; i < smpres->cpu_count; i++) {
|
|
struct limine_smp_info *entry = smpres->cpus[i];
|
|
if (entry->lapic_id == smpres->bsp_lapic_id) {
|
|
BOOT_INFO.smp_bspindex = i;
|
|
}
|
|
}
|
|
if (BOOT_INFO.smp_bspindex == (uint64_t)-1) {
|
|
hal_hang();
|
|
}
|
|
|
|
struct limine_rsdp_response *rsdpres = RSDP_REQ.response;
|
|
BOOT_INFO.rsdp = (size_t)rsdpres->address - BOOT_INFO.hhdm_off;
|
|
}
|