#include <neobbo.h>
#include <assert.h>
#include <limine.h>
#include <error.h>
#include <stdatomic.h>
#include <stddef.h>

static volatile struct limine_hhdm_request hhdm_request = {
    .id = LIMINE_HHDM_REQUEST_ID,
    .revision = 0,
};

volatile struct limine_mp_request smp_request = {
    .id = LIMINE_MP_REQUEST_ID,
    .revision = 0,
};

static volatile struct limine_executable_cmdline_request executable_cmdline_request = {
    .id = LIMINE_EXECUTABLE_CMDLINE_REQUEST_ID,
    .revision = 0,
};

static volatile struct limine_date_at_boot_request date_at_boot_request = {
    .id = LIMINE_DATE_AT_BOOT_REQUEST_ID,
    .revision = 0,
};

extern struct kernel_info kinfo;

void initialize_kinfo(){
    assert(hhdm_request.response != NULL && "HHDM response is NULL");
    assert(smp_request.response != NULL && "SMP response is NULL");
    assert(executable_cmdline_request.response != NULL && "Exec cmdline response is NULL");
    assert(date_at_boot_request.response != NULL && "Date at boot response is NULL");

    kinfo.hhdmoffset = hhdm_request.response->offset;
    kinfo.cmdline = executable_cmdline_request.response->cmdline;
    kinfo.cpu_count = smp_request.response->cpu_count;
    kinfo.boot_timestamp = date_at_boot_request.response->timestamp;

    #ifdef __x86_64__
        kinfo.bsp_id = smp_request.response->bsp_lapic_id;
    #endif
}

struct kernel_info *get_kinfo(){
    return &kinfo;
}