Files
pepperOS/src/kmain.c
T

138 lines
3.4 KiB
C

/*
* @author xamidev <xamidev@riseup.net>
* @brief PepperOS kernel entry point
* @license GPL-3.0-only
*/
#include <stdbool.h>
#include <stddef.h>
#include <limine.h>
#include "io/term/term.h"
#include "io/term/printf.h"
#include "io/serial/serial.h"
#include "mem/gdt/gdt.h"
#include "mem/misc/utils.h"
#include "idt/idt.h"
#include "kernel.h"
#include "time/timer.h"
#include "io/kbd/ps2.h"
#include "mem/paging/pmm.h"
#include "mem/paging/paging.h"
#include "mem/paging/vmm.h"
#include "mem/heap/kheap.h"
#include "sched/process.h"
#include "sched/scheduler.h"
#include "config.h"
#include "io/term/flanterm.h"
#include "io/term/flanterm_backends/fb.h"
// Limine version used
__attribute__((used, section(".limine_requests")))
volatile LIMINE_BASE_REVISION(3);
struct flanterm_context *ft_ctx;
// Halt and catch fire (makes machine stall)
void hcf()
{
CLEAR_INTERRUPTS; for (;;)asm("hlt");
}
// Doing nothing (can be interrupted)
void idle() {SET_INTERRUPTS; for(;;)asm("hlt");}
// uint8_t kernel_stack[KERNEL_STACK_SIZE] __attribute__((aligned(16)));
struct boot_context boot_ctx;
extern volatile struct limine_framebuffer_request framebuffer_request;
extern volatile struct limine_memmap_request memmap_request;
extern volatile struct limine_hhdm_request hhdm_request;
extern volatile struct limine_kernel_address_request kerneladdr_request;
extern struct process_t* processes_list;
extern struct process_t* current_process;
void pedicel_main(void* arg)
{
// FROM THE NEXT LINE ONWARDS, CANNOT WRITE TO FRAMEBUFFER WITHOUT PAGE FAULT!
//printf("\n\nWelcome to PepperOS! Pedicel speaking.\nNothing left to do, halting the system!");
}
void idle_main(void* arg)
{
for(;;)asm("hlt");
}
void flanterm_free_wrapper(void* ptr, size_t size)
{
(void)size;
kfree(ptr);
}
extern uintptr_t kheap_start;
// This is our entry point
void kmain()
{
if (!LIMINE_BASE_REVISION_SUPPORTED) hcf();
serial_init();
// Populate boot context
boot_ctx.fb = framebuffer_request.response ? framebuffer_request.response->framebuffers[0] : NULL;
boot_ctx.mmap = memmap_request.response ? memmap_request.response : NULL;
boot_ctx.hhdm = hhdm_request.response ? hhdm_request.response : NULL;
boot_ctx.kaddr = kerneladdr_request.response ? kerneladdr_request.response : NULL;
boot_mem_display();
pmm_init(boot_ctx.mmap, boot_ctx.hhdm);
// Remap kernel , HHDM and framebuffer
paging_init(boot_ctx.kaddr, boot_ctx.fb);
kheap_init();
uint32_t bgColor = 0x252525;
ft_ctx = flanterm_fb_init(
kmalloc,
flanterm_free_wrapper,
boot_ctx.fb->address, boot_ctx.fb->width, boot_ctx.fb->height, boot_ctx.fb->pitch,
boot_ctx.fb->red_mask_size, boot_ctx.fb->red_mask_shift,
boot_ctx.fb->green_mask_size, boot_ctx.fb->green_mask_shift,
boot_ctx.fb->blue_mask_size, boot_ctx.fb->blue_mask_shift,
NULL,
NULL, NULL,
&bgColor, NULL, // &bgColor
NULL, NULL,
NULL, 0, 0, 1,
0, 0,
0,
0
);
CLEAR_INTERRUPTS;
gdt_init();
idt_init();
timer_init();
vmm_init();
process_init();
struct process_t* idle_proc = process_create("idle", (void*)idle_main, 0);
struct process_t* pedicel = process_create("pedicel", (void*)pedicel_main, 0);
process_display_list(processes_list);
scheduler_init();
current_process = idle_proc;
current_process->status = RUNNING;
SET_INTERRUPTS;
keyboard_init(FR);
kputs(PEPPEROS_SPLASH);
idle();
}