From 38710653be247fcca65761eebab9dcd28d65c3bd Mon Sep 17 00:00:00 2001 From: xamidev Date: Fri, 6 Feb 2026 13:59:46 +0100 Subject: [PATCH] Config header file + comment header --- README.md | 2 +- src/config.h | 30 ++++++++++++++++++++++++++++++ src/idt/idt.S | 6 +++++- src/idt/idt.c | 6 ++++++ src/idt/idt.h | 6 ++++++ src/io/kbd/ps2.c | 6 +++++- src/io/kbd/ps2.h | 6 ++++++ src/io/serial/serial.c | 6 ++++++ src/io/serial/serial.h | 6 ++++++ src/io/term/term.c | 9 ++++++++- src/io/term/term.h | 6 ++++++ src/kernel.h | 10 ++++++---- src/kmain.c | 7 +++++++ src/mem/gdt/gdt.c | 6 ++++++ src/mem/gdt/gdt.h | 6 ++++++ src/mem/heap/kheap.c | 7 +++++++ src/mem/heap/kheap.h | 9 ++++++--- src/mem/misc/utils.c | 6 ++++++ src/mem/misc/utils.h | 7 +++++++ src/mem/paging/paging.c | 7 +++++++ src/mem/paging/paging.h | 13 ++++++------- src/mem/paging/pmm.c | 6 +++++- src/mem/paging/pmm.h | 6 ++++++ src/mem/paging/vmm.c | 6 ++++++ src/mem/paging/vmm.h | 6 ++++++ src/sched/process.c | 7 +++++++ src/sched/process.h | 10 +++++++--- src/sched/scheduler.c | 8 +++++++- src/sched/scheduler.h | 6 ++++++ src/string/string.c | 6 ++++++ src/string/string.h | 6 ++++++ src/time/timer.c | 6 ++++++ src/time/timer.h | 6 ++++++ 33 files changed, 223 insertions(+), 23 deletions(-) create mode 100644 src/config.h diff --git a/README.md b/README.md index e6cc45a..d2faa93 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The basics that I'm targeting are: ### Basic utility of what we call a "kernel" - Fix terminal driver (backspace issues, scrolling) OR add Flanterm or equivalent -- Implement tasks, and task switching +- Implement tasks, and task switching + context switching and spinlock acquire/release - Load an executable - Filesystem (TAR for read-only initfs, then maybe read-write using FAT12/16/32 or easier fs) w/ VFS layer - Getting to userspace (syscalls) diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..4ddea04 --- /dev/null +++ b/src/config.h @@ -0,0 +1,30 @@ +/* + * @author xamidev + * @brief PepperOS configuration file + * @license GPL-3.0-only + */ + +#ifndef CONFIG_H +#define CONFIG_H + +/* version */ +#define PEPPEROS_VERSION_MAJOR "0" +#define PEPPEROS_VERSION_MINOR "0" +#define PEPPEROS_VERSION_PATCH "1" + +/* process */ +#define PROCESS_NAME_MAX 64 +#define PROCESS_STACK_SIZE 0x10000 // 64kb + +/* kernel */ +#define KERNEL_BASE 0xFFFFFFFF80000000ULL +// 2 MB should be enough (as of now, the whole kernel ELF is around 75kb) +#define KERNEL_SIZE 0x200000 + +/* heap */ +#define KHEAP_SIZE (16*1024*1024) + +/* term */ +#define TERM_HISTORY_MAX_LINES 256 + +#endif \ No newline at end of file diff --git a/src/idt/idt.S b/src/idt/idt.S index fe5cf58..de819e6 100644 --- a/src/idt/idt.S +++ b/src/idt/idt.S @@ -1,4 +1,8 @@ -; Assembly stub for the IDT +; +; @author xamidev +; @brief Stub for Interrupt Descriptor Table handlers +; @license GPL-3.0-only +; bits 64 diff --git a/src/idt/idt.c b/src/idt/idt.c index 8ac633f..44584e3 100644 --- a/src/idt/idt.c +++ b/src/idt/idt.c @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Interrupt Descriptor Table setup and dispatching + * @license GPL-3.0-only + */ + #include "idt.h" #include #include diff --git a/src/idt/idt.h b/src/idt/idt.h index 3b61abb..898e49c 100644 --- a/src/idt/idt.h +++ b/src/idt/idt.h @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Interrupt Descriptor Table setup and dispatching + * @license GPL-3.0-only + */ + #ifndef IDT_H #define IDT_H diff --git a/src/io/kbd/ps2.c b/src/io/kbd/ps2.c index df82811..79d777e 100644 --- a/src/io/kbd/ps2.c +++ b/src/io/kbd/ps2.c @@ -1,4 +1,8 @@ -// PS/2 Keyboard support +/* + * @author xamidev + * @brief PS/2 Keyboard driver + * @license GPL-3.0-only + */ #include "io/serial/serial.h" #include "ps2.h" diff --git a/src/io/kbd/ps2.h b/src/io/kbd/ps2.h index 5b1c207..031fd91 100644 --- a/src/io/kbd/ps2.h +++ b/src/io/kbd/ps2.h @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief PS/2 Keyboard driver + * @license GPL-3.0-only + */ + #ifndef PS2_H #define PS2_H diff --git a/src/io/serial/serial.c b/src/io/serial/serial.c index c70af76..9073839 100644 --- a/src/io/serial/serial.c +++ b/src/io/serial/serial.c @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Debug serial driver + * @license GPL-3.0-only + */ + #include #include "serial.h" diff --git a/src/io/serial/serial.h b/src/io/serial/serial.h index 6144ce8..dc29d14 100644 --- a/src/io/serial/serial.h +++ b/src/io/serial/serial.h @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Debug serial driver + * @license GPL-3.0-only + */ + #ifndef SERIAL_H #define SERIAL_H diff --git a/src/io/term/term.c b/src/io/term/term.c index ae91835..98893ed 100644 --- a/src/io/term/term.c +++ b/src/io/term/term.c @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Framebuffer-based terminal driver + * @license GPL-3.0-only + */ + // Terminal output /* There are a couple of bugs here and there but for now I don't care too much @@ -10,6 +16,7 @@ because this shitty implementation will be replaced one day by Flanterm #include #include "term.h" #include "mem/misc/utils.h" +#include "config.h" extern struct boot_context boot_ctx; @@ -37,7 +44,7 @@ static Cursor cursor = {0, 0}; static uint8_t* fb; static struct limine_framebuffer* framebuffer; -uint8_t lines_length[MAX_LINES]; +uint8_t lines_length[TERM_HISTORY_MAX_LINES]; static inline size_t term_max_cols(void) { diff --git a/src/io/term/term.h b/src/io/term/term.h index e53981d..1ed14f1 100644 --- a/src/io/term/term.h +++ b/src/io/term/term.h @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Framebuffer-based terminal driver + * @license GPL-3.0-only + */ + #ifndef TERM_H #define TERM_H diff --git a/src/kernel.h b/src/kernel.h index 1ce75d6..2ac193c 100644 --- a/src/kernel.h +++ b/src/kernel.h @@ -1,10 +1,12 @@ +/* + * @author xamidev + * @brief Kernel global macros + * @license GPL-3.0-only + */ + #ifndef KERNEL_H #define KERNEL_H -#define PEPPEROS_VERSION_MAJOR "0" -#define PEPPEROS_VERSION_MINOR "0" -#define PEPPEROS_VERSION_PATCH "1" - enum ErrorCodes { ENOMEM, diff --git a/src/kmain.c b/src/kmain.c index 68cd159..d324331 100644 --- a/src/kmain.c +++ b/src/kmain.c @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief PepperOS kernel entry point + * @license GPL-3.0-only + */ + #include #include #include @@ -16,6 +22,7 @@ #include "mem/heap/kheap.h" #include "sched/process.h" #include "sched/scheduler.h" +#include "config.h" // Limine version used __attribute__((used, section(".limine_requests"))) diff --git a/src/mem/gdt/gdt.c b/src/mem/gdt/gdt.c index 68961b5..fd5a318 100644 --- a/src/mem/gdt/gdt.c +++ b/src/mem/gdt/gdt.c @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Global Descriptor Table (for legacy reasons) + * @license GPL-3.0-only + */ + #include "gdt.h" #include #include "io/serial/serial.h" diff --git a/src/mem/gdt/gdt.h b/src/mem/gdt/gdt.h index 3c15b3a..a122387 100644 --- a/src/mem/gdt/gdt.h +++ b/src/mem/gdt/gdt.h @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Global Descriptor Table (for legacy reasons) + * @license GPL-3.0-only + */ + #ifndef GDT_H #define GDT_H diff --git a/src/mem/heap/kheap.c b/src/mem/heap/kheap.c index ee1ee34..220471a 100644 --- a/src/mem/heap/kheap.c +++ b/src/mem/heap/kheap.c @@ -1,9 +1,16 @@ +/* + * @author xamidev + * @brief Kernel heap + * @license GPL-3.0-only + */ + #include "kheap.h" #include "mem/paging/paging.h" #include "mem/paging/pmm.h" #include #include #include "sched/process.h" +#include "config.h" extern uint64_t kernel_phys_base; extern uint64_t kernel_virt_base; diff --git a/src/mem/heap/kheap.h b/src/mem/heap/kheap.h index 61b097e..111cf7b 100644 --- a/src/mem/heap/kheap.h +++ b/src/mem/heap/kheap.h @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Kernel heap + * @license GPL-3.0-only + */ + #ifndef KHEAP_H #define KHEAP_H @@ -6,9 +12,6 @@ // When the kernel heap is ready, we can alloc our VM object linked list // and then continue working on the VMM. -// 16MB should be enough for some linked lists -#define KHEAP_SIZE (16*1024*1024) - #include #include diff --git a/src/mem/misc/utils.c b/src/mem/misc/utils.c index bb5ca8a..8f7a43f 100644 --- a/src/mem/misc/utils.c +++ b/src/mem/misc/utils.c @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Common memory utilities + * @license GPL-3.0-only + */ + #include #include #include diff --git a/src/mem/misc/utils.h b/src/mem/misc/utils.h index 169d88d..197bf12 100644 --- a/src/mem/misc/utils.h +++ b/src/mem/misc/utils.h @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Common memory utilities + * @license GPL-3.0-only + */ + #ifndef MEM_UTILS_H #define MEM_UTILS_H @@ -8,6 +14,7 @@ void* memset(void* s, int c, size_t n); void* memmove(void *dest, const void* src, size_t n); int memcmp(const void* s1, const void* s2, size_t n); +// DEBUG void memmap_display(struct limine_memmap_response* response); void hhdm_display(struct limine_hhdm_response* hhdm); diff --git a/src/mem/paging/paging.c b/src/mem/paging/paging.c index c2a1a28..0597943 100644 --- a/src/mem/paging/paging.c +++ b/src/mem/paging/paging.c @@ -1,8 +1,15 @@ +/* + * @author xamidev + * @brief x64 4-level paging implementation + * @license GPL-3.0-only + */ + #include "paging.h" #include "pmm.h" #include #include #include +#include "config.h" /* Paging on x86 uses four different page table levels: diff --git a/src/mem/paging/paging.h b/src/mem/paging/paging.h index b93be70..34afeaa 100644 --- a/src/mem/paging/paging.h +++ b/src/mem/paging/paging.h @@ -1,8 +1,13 @@ +/* + * @author xamidev + * @brief x64 4-level paging implementation + * @license GPL-3.0-only + */ + #ifndef PAGING_H #define PAGING_H #define PAGE_SIZE 4096 -#define BITS_PER_ROW 64 #include #include @@ -40,10 +45,4 @@ extern uint64_t hhdm_off; #define PTE_HUGE (1ULL << 7) #define PTE_NOEXEC (1ULL << 63) -// Specified in linker.ld -#define KERNEL_BASE 0xFFFFFFFF80000000ULL - -// 2 MB should be enough (as of now, the whole kernel ELF is around 75kb) -#define KERNEL_SIZE 0x200000 - #endif \ No newline at end of file diff --git a/src/mem/paging/pmm.c b/src/mem/paging/pmm.c index 2128f88..6b0d616 100644 --- a/src/mem/paging/pmm.c +++ b/src/mem/paging/pmm.c @@ -1,4 +1,8 @@ -// OMG here we are. I'm cooked. +/* + * @author xamidev + * @brief Physical memory manager from freelist + * @license GPL-3.0-only + */ /* pmm - Physical Memory Manager diff --git a/src/mem/paging/pmm.h b/src/mem/paging/pmm.h index 084c334..a166727 100644 --- a/src/mem/paging/pmm.h +++ b/src/mem/paging/pmm.h @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Physical memory manager from freelist + * @license GPL-3.0-only + */ + #ifndef PAGING_PMM_H #define PAGING_PMM_H diff --git a/src/mem/paging/vmm.c b/src/mem/paging/vmm.c index 1d5a4ad..f7f3256 100644 --- a/src/mem/paging/vmm.c +++ b/src/mem/paging/vmm.c @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Virtual memory manager + * @license GPL-3.0-only + */ + /* The VMM (virtual memory manager) will have two roles: - mapping pages diff --git a/src/mem/paging/vmm.h b/src/mem/paging/vmm.h index 3f862be..b70e1a8 100644 --- a/src/mem/paging/vmm.h +++ b/src/mem/paging/vmm.h @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Virtual memory manager + * @license GPL-3.0-only + */ + #ifndef VMM_H #define VMM_H diff --git a/src/sched/process.c b/src/sched/process.c index e8e8201..9161a37 100644 --- a/src/sched/process.c +++ b/src/sched/process.c @@ -1,9 +1,16 @@ +/* + * @author xamidev + * @brief Process linked list implementation + * @license GPL-3.0-only + */ + #include #include "process.h" #include "mem/heap/kheap.h" #include "kernel.h" #include "string/string.h" #include "mem/gdt/gdt.h" +#include "config.h" struct process_t* processes_list; struct process_t* current_process; diff --git a/src/sched/process.h b/src/sched/process.h index 9ec19bd..b5b0124 100644 --- a/src/sched/process.h +++ b/src/sched/process.h @@ -1,7 +1,14 @@ +/* + * @author xamidev + * @brief Process definition + * @license GPL-3.0-only + */ + #ifndef PROCESS_H #define PROCESS_H #include +#include "config.h" typedef enum { @@ -10,9 +17,6 @@ typedef enum DEAD } status_t; -#define PROCESS_NAME_MAX 64 -#define PROCESS_STACK_SIZE 0x10000 // 64kb - struct process_t { size_t pid; diff --git a/src/sched/scheduler.c b/src/sched/scheduler.c index 6a94bf0..0299ce8 100644 --- a/src/sched/scheduler.c +++ b/src/sched/scheduler.c @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Round-robin scheduler + * @license GPL-3.0-only + */ + #include "kernel.h" #include "process.h" @@ -35,6 +41,6 @@ struct cpu_status_t* scheduler_schedule(struct cpu_status_t* context) } } - DEBUG("SCHEDULER CALLED: current_process=%p", current_process); + DEBUG("current_process={pid=%u name='%s'}", current_process->pid, current_process->name); return current_process->context; } \ No newline at end of file diff --git a/src/sched/scheduler.h b/src/sched/scheduler.h index 6da8442..b4d7516 100644 --- a/src/sched/scheduler.h +++ b/src/sched/scheduler.h @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Round-robin scheduler + * @license GPL-3.0-only + */ + #ifndef SCHEDULER_H #define SCHEDULER_H diff --git a/src/string/string.c b/src/string/string.c index 0d52028..f95f000 100644 --- a/src/string/string.c +++ b/src/string/string.c @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief String manipulation utilities + * @license GPL-3.0-only + */ + #include char* strcpy(char *dest, const char *src) diff --git a/src/string/string.h b/src/string/string.h index 7e9d8a5..7a59a3a 100644 --- a/src/string/string.h +++ b/src/string/string.h @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief String manipulation functions + * @license GPL-3.0-only + */ + #ifndef STRING_H #define STRING_H diff --git a/src/time/timer.c b/src/time/timer.c index a632a57..781c677 100644 --- a/src/time/timer.c +++ b/src/time/timer.c @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief Programmable Interval Timer init and enabling + * @license GPL-3.0-only + */ + #include #include "io/serial/serial.h" #include diff --git a/src/time/timer.h b/src/time/timer.h index bb0c8d4..8b398fd 100644 --- a/src/time/timer.h +++ b/src/time/timer.h @@ -1,3 +1,9 @@ +/* + * @author xamidev + * @brief PIT functions + * @license GPL-3.0-only + */ + #ifndef TIMER_H #define TIMER_H