diff --git a/debug.gdb b/debug.gdb index 616ded2..2b97864 100644 --- a/debug.gdb +++ b/debug.gdb @@ -1,3 +1,3 @@ target remote localhost:1234 set disassembly-flavor intel -display/8i $rip \ No newline at end of file +display/4i $rip diff --git a/src/config.h b/src/config.h index a77d092..1fb3b16 100644 --- a/src/config.h +++ b/src/config.h @@ -16,6 +16,8 @@ /* process */ #define PROCESS_NAME_MAX 64 #define PROCESS_STACK_SIZE 0x10000 // 64kb +#define PROCESS_BASE 0x400000 +#define PROCESS_STACK_BASE 0x1000000 /* sched */ // 1 tick = 1 ms => quantum = 10ms @@ -32,4 +34,4 @@ /* term */ #define TERM_HISTORY_MAX_LINES 256 -#endif \ No newline at end of file +#endif diff --git a/src/idt/idt.c b/src/idt/idt.c index d70e89a..025dedd 100644 --- a/src/idt/idt.c +++ b/src/idt/idt.c @@ -87,11 +87,7 @@ static void page_fault_handler(struct cpu_status_t* ctx) CHECK_BIT(ctx->error_code, 7) ? " SGX_VIOLATION" : "", cr2); - /* if (CHECK_BIT(ctx->error_code, 0)) - { - panic(ctx); - } */ - panic(ctx); + panic(ctx, "page fault"); } static void gp_fault_handler(struct cpu_status_t* ctx) @@ -117,7 +113,7 @@ static void gp_fault_handler(struct cpu_status_t* ctx) index); } - panic(ctx); + panic(ctx, "gp fault"); } struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context) @@ -217,4 +213,4 @@ struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context) } return context; -} \ No newline at end of file +} diff --git a/src/kernel.h b/src/kernel.h index 11f5777..e8fcae1 100644 --- a/src/kernel.h +++ b/src/kernel.h @@ -22,11 +22,13 @@ enum ErrorCodes #define DEBUG(log, ...) fctprintf((void*)&skputc, 0, "debug: [%s]: " log "\r\n", __FILE__, ##__VA_ARGS__) +#define DIE_DEBUG(str) fctprintf((void*)&skputc, 0, str) + #define CHECK_BIT(var,pos) ((var) & (1<<(pos))) // printf("debug: [%s]: " log "\n", __FILE__, ##__VA_ARGS__); -void panic(struct cpu_status_t* ctx); +void panic(struct cpu_status_t* ctx, const char* str); void hcf(); #define assert(check) do { if(!(check)) hcf(); } while(0) diff --git a/src/kmain.c b/src/kmain.c index 7d74dd2..922e7cb 100644 --- a/src/kmain.c +++ b/src/kmain.c @@ -37,8 +37,17 @@ void hcf() // Doing nothing (can be interrupted) void idle() {for(;;)asm("hlt");} -void panic(struct cpu_status_t* ctx) +void panic(struct cpu_status_t* ctx, const char* str) { + CLEAR_INTERRUPTS; + if (ctx == NULL) + { + DEBUG("\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m Something went horribly wrong! (no cpu ctx)"); + DIE_DEBUG(str); + skputc('\n'); + DEBUG("\x1b[38;5;231m\x1b[48;5;196mend Kernel panic - halting...\x1b[0m"); + hcf(); + } 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...", ctx->iret_rip, ctx->vector_number, ctx->error_code, ctx->rax, ctx->rbx, ctx->rcx, ctx->rdx, ctx->rsi, ctx->rdi, @@ -59,7 +68,7 @@ extern struct process_t* current_process; void pedicel_main(void* arg) { - + panic(NULL, "we did it!"); } void two_main(void* arg) @@ -104,8 +113,8 @@ void kmain() vmm_init(); struct process_t* pedicel = process_create("pedicel", (void*)pedicel_main, 0); - struct process_t* two = process_create("two", (void*)two_main, 0); - struct process_t* three = process_create("three", (void*)three_main, 0); + //struct process_t* two = process_create("two", (void*)two_main, 0); + //struct process_t* three = process_create("three", (void*)three_main, 0); process_display_list(processes_list); scheduler_init(); diff --git a/src/mem/paging/pmm.c b/src/mem/paging/pmm.c index 6b0d616..2b45699 100644 --- a/src/mem/paging/pmm.c +++ b/src/mem/paging/pmm.c @@ -66,7 +66,10 @@ static uintptr_t g_freelist = 0; uintptr_t pmm_alloc() { - if (!g_freelist) return 0; + if (!g_freelist) + { + panic(NULL, "PMM is out of memory!"); + } uintptr_t addr = g_freelist; g_freelist = *(uintptr_t*) PHYS_TO_VIRT(g_freelist); return addr; @@ -104,4 +107,4 @@ void pmm_init(struct limine_memmap_response* memmap, struct limine_hhdm_response // Now we have biggest USABLE region, // so to populate the free list we just iterate through it pmm_init_freelist(); -} \ No newline at end of file +} diff --git a/src/sched/process.h b/src/sched/process.h index e6dedbc..9b8e572 100644 --- a/src/sched/process.h +++ b/src/sched/process.h @@ -24,6 +24,7 @@ struct process_t status_t status; struct cpu_status_t* context; + void* root_page_table; // Process PML4 (should contain kernel PML4 in higher half [256-511] struct process_t* next; }; diff --git a/src/sched/task.S b/src/sched/task.S new file mode 100644 index 0000000..9aa669b --- /dev/null +++ b/src/sched/task.S @@ -0,0 +1,7 @@ +; Task (process) switching + +bits 64 + +global switch_to_task +switch_to_task: +