Files
pepperOS/src/kmain.c

138 lines
3.3 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/serial/serial.h>
#include <mem/gdt.h>
#include <mem/utils.h>
#include <idt/idt.h>
#include <kernel.h>
#include <time/timer.h>
#include <io/kbd/ps2.h>
#include <mem/pmm.h>
#include <mem/paging.h>
#include <mem/vmm.h>
#include <mem/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);
int panic_count = 0;
/*
* hcf - Halt and catch fire
*
* This function is called only in the case of an unrecoverable
* error. It halts interrupts, and stops execution. The machine
* will stay in an infinite loop state.
*/
void hcf()
{
CLEAR_INTERRUPTS; for (;;)asm("hlt");
}
/*
* idle - Make the machine idle
*
* When there is nothing else to do, this function
* gets called. It can be interrupted, so it allows
* the scheduler, timer, and keyboard to work.
*/
void idle() {SET_INTERRUPTS; for(;;)asm("hlt");}
struct flanterm_context *ft_ctx;
struct boot_context boot_ctx;
struct init_status init = {0};
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;
struct process_t* idle_proc;
// Never gets executed although pedicel is scheduled?
void pedicel_main(void* arg)
{
printf("\n\nWelcome to PepperOS! Pedicel speaking.\r\nNothing left to do, let's go idle!\r\n");
}
void idle_main(void* arg)
{
for (;;) {
asm("hlt");
}
}
void thing_main(void* arg)
{
/* printf("What's your name, pal? ");
char name[10];
keyboard_getline(name, 10);
printf("\r\n{%s} is such a nice name!\r\n", name); */
while (ticks < 500);
}
extern uintptr_t kheap_start;
/*
* kmain - Kernel entry point
*
* This is where execution begins at handoff from Limine.
* The function fetches all needed information from the
* bootloader, initializes all kernel modules and structures,
* and then goes in an idle state.
*/
void kmain()
{
CLEAR_INTERRUPTS;
if (!LIMINE_BASE_REVISION_SUPPORTED) hcf();
// 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;
term_init();
serial_init();
timer_init();
boot_mem_display();
pmm_init(boot_ctx);
// Remap kernel , HHDM and framebuffer
paging_init(boot_ctx);
kheap_init();
keyboard_init(FR);
gdt_init();
idt_init();
process_init();
idle_proc = process_create("idle", (void*)idle_main, 0);
struct process_t* pedicel = process_create("pedicel", (void*)pedicel_main, 0);
process_create("thing", thing_main, NULL);
process_display_list(processes_list);
scheduler_init();
kputs(PEPPEROS_SPLASH);
idle();
}