major refactorings
Signed-off-by: kaguya3311 <kaguya3311@national.shitposting.agency>
This commit is contained in:
+227
@@ -0,0 +1,227 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <limine.h>
|
||||
#include "arch/x86_64/boot/gdt.h"
|
||||
#include "arch/x86_64/boot/idt.h"
|
||||
#include "arch/x86_64/boot/isr.h"
|
||||
#include "mm/memory.h"
|
||||
#include "mm/pmm.h"
|
||||
#include "mm/vmm.h"
|
||||
#include "arch/x86_64/bus/ata.h"
|
||||
#include "string.h"
|
||||
#include "arch/x86_64/cpu/io.h"
|
||||
#include "arch/x86_64/sys/pit.h"
|
||||
#include "arch/x86_64/bus/pci.h"
|
||||
#include "arch/x86_64/sys/apic.h"
|
||||
#include "mp/mp.h"
|
||||
#include "drivers/fb/fb.h"
|
||||
#include "libk/debug.h"
|
||||
#include "fs/elf.h"
|
||||
#include "sched/sched_types.h"
|
||||
#include "arch/x86_64/sys/halt.h"
|
||||
#include <cpuid.h>
|
||||
#include "libk/random.h"
|
||||
#include "libk/kargs.h"
|
||||
#include "sched/sched_types.h"
|
||||
#include "sched/sched.h"
|
||||
#include "arch/x86_64/serial/serial.h"
|
||||
#include "arch/x86_64/sys/tsc.h"
|
||||
#include "arch/x86_64/fw/acpi.h"
|
||||
|
||||
extern bool print_now;
|
||||
|
||||
|
||||
static volatile struct limine_framebuffer_request framebuffer_request = {
|
||||
.id = LIMINE_FRAMEBUFFER_REQUEST,
|
||||
.revision = 6
|
||||
};
|
||||
|
||||
|
||||
static volatile struct limine_kernel_file_request limine_kernel_file_request = {
|
||||
.id = LIMINE_KERNEL_FILE_REQUEST, .revision = 0};
|
||||
|
||||
|
||||
static volatile struct limine_memmap_request memmap_request = {
|
||||
.id = LIMINE_MEMMAP_REQUEST,
|
||||
.revision = 6
|
||||
};
|
||||
|
||||
|
||||
static volatile struct limine_rsdp_request rsdp_request = {
|
||||
.id = LIMINE_RSDP_REQUEST,
|
||||
.revision = 6
|
||||
};
|
||||
|
||||
|
||||
volatile struct limine_stack_size_request stack_size_request = {
|
||||
.id = LIMINE_STACK_SIZE_REQUEST,
|
||||
.revision = 0,
|
||||
.stack_size = CPU_STACK_SIZE,
|
||||
};
|
||||
|
||||
|
||||
volatile struct limine_smp_request mp_request = {
|
||||
.id = LIMINE_SMP_REQUEST,
|
||||
.revision = 0
|
||||
};
|
||||
|
||||
|
||||
static volatile struct limine_module_request module_request = {
|
||||
.id = LIMINE_MODULE_REQUEST, .revision = 0};
|
||||
|
||||
extern bool is_halting;
|
||||
extern uint8_t is_pausing;
|
||||
|
||||
void nmi_vector(registers_t *reg) {
|
||||
if (is_halting) {
|
||||
for (;;) {
|
||||
cli();
|
||||
halt();
|
||||
}
|
||||
} else if (is_pausing) {
|
||||
while (is_pausing & PAUSING) {
|
||||
pause();
|
||||
}
|
||||
apic_eoi();
|
||||
} else {
|
||||
panic_((void *)(reg->rip), (void *)(reg->rbp), "Unexpected NMI\n");
|
||||
}
|
||||
}
|
||||
|
||||
void breakpoint_handler(registers_t *reg);
|
||||
|
||||
static uint64_t rdseed(void) {
|
||||
uint64_t r = 0;
|
||||
asm volatile("rdseed %0" : "=r"(r));
|
||||
return r;
|
||||
}
|
||||
|
||||
static uint64_t rdrand(void) {
|
||||
uint64_t r = 0;
|
||||
asm volatile("rdrand %0" : "=r"(r));
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
void random_setup_seed_source(void) {
|
||||
uint32_t a = 0, b = 0, c = 0, d = 0;
|
||||
__get_cpuid(7, &a, &b, &c, &d);
|
||||
if (b & bit_RDSEED) {
|
||||
kprintf("Using RDSEED as seed source\n");
|
||||
random_get_seed = rdseed;
|
||||
}
|
||||
if (c & bit_RDRND) {
|
||||
kprintf("Using RDRAND as seed source\n");
|
||||
random_get_seed = rdrand;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint64_t g_rsdp_phys = 0;
|
||||
|
||||
void _entry(void) {
|
||||
cli();
|
||||
|
||||
struct limine_memmap_entry **memmap = memmap_request.response->entries;
|
||||
size_t memmap_entries = memmap_request.response->entry_count;
|
||||
|
||||
struct limine_rsdp_response *rsdp_response = rsdp_request.response;
|
||||
|
||||
if (rsdp_response) {
|
||||
g_rsdp_phys = (uint64_t)rsdp_response->address - MEM_PHYS_OFFSET;
|
||||
}
|
||||
|
||||
|
||||
|
||||
pmm_init(memmap, memmap_entries);
|
||||
slab_init();
|
||||
vmm_init(memmap, memmap_entries);
|
||||
|
||||
struct limine_framebuffer *framebuffer = framebuffer_request.response->framebuffers[0];
|
||||
struct framebuffer fb = {0};
|
||||
fb.address = (uint32_t *)framebuffer->address;
|
||||
fb.pitch = framebuffer->pitch;
|
||||
fb.bpp = framebuffer->bpp;
|
||||
fb.width = framebuffer->width;
|
||||
fb.height = framebuffer->height;
|
||||
fb.tex_color = 0x00eee8d5;
|
||||
fb.tex_x = 0;
|
||||
fb.tex_y = 0;
|
||||
fb.bg_color = 0x00124560;
|
||||
fb.color_masks[0].offset = framebuffer->red_mask_shift;
|
||||
fb.color_masks[0].length = framebuffer->red_mask_size;
|
||||
fb.color_masks[1].offset = framebuffer->green_mask_shift;
|
||||
fb.color_masks[1].length = framebuffer->green_mask_size;
|
||||
fb.color_masks[2].offset = framebuffer->blue_mask_shift;
|
||||
fb.color_masks[2].length = framebuffer->blue_mask_size;
|
||||
framebuffer_init(&fb);
|
||||
|
||||
print_now = true;
|
||||
serial_init();
|
||||
|
||||
struct limine_file *kernel_file =
|
||||
limine_kernel_file_request.response->kernel_file;
|
||||
|
||||
kargs_init(kernel_file->cmdline);
|
||||
uint16_t kernel_args_num = kernel_arguments.kernel_args;
|
||||
uint32_t cpu_count = kernel_arguments.cpu_count;
|
||||
|
||||
if ((kernel_args_num & KERNEL_ARGS_KPRINTF_LOGS)) {
|
||||
put_to_fb = true;
|
||||
}
|
||||
|
||||
|
||||
kprintf("Hello x86_64!\n");
|
||||
kprintf("Kernel base: %p Mem phys base: %p\n", KERNEL_BASE,
|
||||
MEM_PHYS_OFFSET);
|
||||
|
||||
kprintf("KirkOS Ver. %s\n", KIRKOS_VERSION);
|
||||
|
||||
kprintf("Got kernel cmdline as \"%s\"\n", kernel_file->cmdline);
|
||||
if ((kernel_args_num & KERNEL_ARGS_CPU_COUNT_GIVEN))
|
||||
kprintf("CPU count is %u\n", cpu_count);
|
||||
|
||||
gdt_init();
|
||||
isr_install();
|
||||
|
||||
isr_register_handler(2, nmi_vector);
|
||||
isr_register_handler(3, breakpoint_handler);
|
||||
isr_register_handler(48, resched);
|
||||
|
||||
elf_init_function_table(kernel_file->address);
|
||||
|
||||
acpi_init();
|
||||
|
||||
apic_init();
|
||||
|
||||
mp_init(mp_request.response);
|
||||
|
||||
// The NSA has also forced hardware manufacturers to backdoor their 'Random
|
||||
// Number Generators' to allow them to break RSA encryption
|
||||
|
||||
if (!(kernel_arguments.kernel_args &
|
||||
KERNEL_ARGS_DONT_TRUST_CPU_RANDOM_SEED)) {
|
||||
random_setup_seed_source();
|
||||
}
|
||||
random_set_seed(random_get_seed());
|
||||
|
||||
size_t module_info[2] = {0};
|
||||
if (module_request.response && module_request.response->module_count > 0) {
|
||||
struct limine_file *module = module_request.response->modules[0];
|
||||
module_info[0] = (size_t)module->address;
|
||||
module_info[1] = (size_t)module->size;
|
||||
}
|
||||
|
||||
|
||||
//time_init(); on hold for the time being, heh get it?
|
||||
sched_init((uint64_t)module_info);
|
||||
|
||||
timer_sched_oneshot(48, 20000);
|
||||
sti();
|
||||
|
||||
for (;;) {
|
||||
halt();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user