diff --git a/Makefile b/Makefile index c4394ba..ce177d1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -SOURCES = src/sched/scheduler.c src/sched/process.c src/mem/heap/kheap.c src/mem/paging/vmm.c src/mem/paging/paging.c src/mem/paging/pmm.c src/string/string.c src/io/kbd/ps2.c src/io/serial/serial.c src/io/term/printf.c src/io/term/term.c src/idt/idt.c src/mem/gdt/gdt.c src/mem/misc/utils.c src/time/timer.c src/kmain.c +SOURCES = src/boot/boot.c src/sched/scheduler.c src/sched/process.c src/mem/heap/kheap.c src/mem/paging/vmm.c src/mem/paging/paging.c src/mem/paging/pmm.c src/string/string.c src/io/kbd/ps2.c src/io/serial/serial.c src/io/term/printf.c src/io/term/term.c src/idt/idt.c src/mem/gdt/gdt.c src/mem/misc/utils.c src/time/timer.c src/kmain.c PROBLEMATIC_FLAGS=-Wno-unused-parameter -Wno-unused-variable diff --git a/README.md b/README.md index d2faa93..7b60818 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ The basics that I'm targeting are: ### Scalability/maintenance/expansion features -- Global config header file - Documentation - SOME error handling in functions - Unit tests diff --git a/src/boot/boot.c b/src/boot/boot.c new file mode 100644 index 0000000..f10c4e1 --- /dev/null +++ b/src/boot/boot.c @@ -0,0 +1,41 @@ +/* + * @author xamidev + * @brief Limine requests for boot + * @license GPL-3.0-only + */ + +#include + +// Framebuffer request +__attribute__((used, section(".limine_requests"))) +volatile struct limine_framebuffer_request framebuffer_request = { + .id = LIMINE_FRAMEBUFFER_REQUEST, + .revision = 0 +}; + +// Memory map request +__attribute__((used, section(".limine_requests"))) +volatile struct limine_memmap_request memmap_request = { + .id = LIMINE_MEMMAP_REQUEST, + .revision = 0 +}; + +// Higher Half Direct Map +__attribute__((used, section(".limine_requests"))) +volatile struct limine_hhdm_request hhdm_request = { + .id = LIMINE_HHDM_REQUEST, + .revision = 0 +}; + +// Executable Address/Kernel Address (find base phys/virt address of kernel) +__attribute__((used, section(".limine_requests"))) +volatile struct limine_kernel_address_request kerneladdr_request = { + .id = LIMINE_KERNEL_ADDRESS_REQUEST, + .revision = 0 +}; + +__attribute__((used, section(".limine_requests_start"))) +volatile LIMINE_REQUESTS_START_MARKER; + +__attribute__((used, section(".limine_requests_end"))) +volatile LIMINE_REQUESTS_END_MARKER; \ No newline at end of file diff --git a/src/config.h b/src/config.h index 4ddea04..a77d092 100644 --- a/src/config.h +++ b/src/config.h @@ -11,11 +11,16 @@ #define PEPPEROS_VERSION_MAJOR "0" #define PEPPEROS_VERSION_MINOR "0" #define PEPPEROS_VERSION_PATCH "1" +#define PEPPEROS_SPLASH "pepperOS version "PEPPEROS_VERSION_MAJOR"."PEPPEROS_VERSION_MINOR"."PEPPEROS_VERSION_PATCH"\n" /* process */ #define PROCESS_NAME_MAX 64 #define PROCESS_STACK_SIZE 0x10000 // 64kb +/* sched */ +// 1 tick = 1 ms => quantum = 10ms +#define SCHEDULER_QUANTUM 10 + /* kernel */ #define KERNEL_BASE 0xFFFFFFFF80000000ULL // 2 MB should be enough (as of now, the whole kernel ELF is around 75kb) diff --git a/src/idt/idt.c b/src/idt/idt.c index 44584e3..d70e89a 100644 --- a/src/idt/idt.c +++ b/src/idt/idt.c @@ -12,6 +12,7 @@ #include #include #include "sched/scheduler.h" +#include "config.h" struct interrupt_descriptor idt[256]; struct idtr idt_reg; @@ -191,8 +192,7 @@ struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context) DEBUG("Control Protection Exception!"); break; - case 32: - //DEBUG("Timer Interrupt"); + case 32: // Timer Interrupt ticks++; if (ticks % SCHEDULER_QUANTUM == 0) diff --git a/src/io/term/term.h b/src/io/term/term.h index 1ed14f1..99c0cd9 100644 --- a/src/io/term/term.h +++ b/src/io/term/term.h @@ -17,8 +17,6 @@ enum TermColors WHITE = 0xffffff }; -#define MAX_LINES 256 - #define PSF1_FONT_MAGIC 0x0436 typedef struct diff --git a/src/kernel.h b/src/kernel.h index 2ac193c..11f5777 100644 --- a/src/kernel.h +++ b/src/kernel.h @@ -38,7 +38,4 @@ struct boot_context struct limine_kernel_address_response* kaddr; }; -// 1 tick = 1 ms => quantum = 10ms -#define SCHEDULER_QUANTUM 10 - #endif diff --git a/src/kmain.c b/src/kmain.c index d324331..7d74dd2 100644 --- a/src/kmain.c +++ b/src/kmain.c @@ -26,52 +26,17 @@ // Limine version used __attribute__((used, section(".limine_requests"))) -static volatile LIMINE_BASE_REVISION(3); +volatile LIMINE_BASE_REVISION(3); -// Framebuffer request -__attribute__((used, section(".limine_requests"))) -static volatile struct limine_framebuffer_request framebuffer_request = { - .id = LIMINE_FRAMEBUFFER_REQUEST, - .revision = 0 -}; - -// Memory map request -__attribute__((used, section(".limine_requests"))) -static volatile struct limine_memmap_request memmap_request = { - .id = LIMINE_MEMMAP_REQUEST, - .revision = 0 -}; - -// Higher Half Direct Map -__attribute__((used, section(".limine_requests"))) -static volatile struct limine_hhdm_request hhdm_request = { - .id = LIMINE_HHDM_REQUEST, - .revision = 0 -}; - -// Executable Address/Kernel Address (find base phys/virt address of kernel) -__attribute__((used, section(".limine_requests"))) -static volatile struct limine_kernel_address_request kerneladdr_request = { - .id = LIMINE_KERNEL_ADDRESS_REQUEST, - .revision = 0 -}; - -__attribute__((used, section(".limine_requests_start"))) -static volatile LIMINE_REQUESTS_START_MARKER; - -__attribute__((used, section(".limine_requests_end"))) -static volatile LIMINE_REQUESTS_END_MARKER; - -// Panic (should dump registers etc. in the future) +// Halt and catch fire (makes machine stall) void hcf() { - //CLEAR_INTERRUPTS; - for (;;) - { - asm("hlt"); - } + CLEAR_INTERRUPTS; for (;;)asm("hlt"); } +// Doing nothing (can be interrupted) +void idle() {for(;;)asm("hlt");} + void panic(struct cpu_status_t* ctx) { DEBUG("\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m at rip=%p\nSomething went horribly wrong! vect=0x%.2x errcode=0x%x\n\rrax=%p rbx=%p rcx=%p rdx=%p\n\rrsi=%p rdi=%p r8=%p r9=%p\n\rr10=%p r11=%p r12=%p r13=%p\n\rr14=%p r15=%p\n\n\rflags=%p\n\rstack at rbp=%p\n\rHalting...", @@ -82,10 +47,13 @@ void panic(struct cpu_status_t* ctx) hcf(); } -const char* splash = "pepperOS version "PEPPEROS_VERSION_MAJOR"."PEPPEROS_VERSION_MINOR"."PEPPEROS_VERSION_PATCH"\n"; - 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; @@ -146,7 +114,7 @@ void kmain() keyboard_init(FR); term_init(); - kputs(splash); + kputs(PEPPEROS_SPLASH); - hcf(); + idle(); }