process_mem #10

Merged
xamidev merged 5 commits from process_mem into main 2026-02-21 19:57:31 +01:00
8 changed files with 36 additions and 16 deletions
Showing only changes of commit 458ba375f3 - Show all commits

View File

@@ -1,3 +1,3 @@
target remote localhost:1234 target remote localhost:1234
set disassembly-flavor intel set disassembly-flavor intel
display/8i $rip display/4i $rip

View File

@@ -16,6 +16,8 @@
/* process */ /* process */
#define PROCESS_NAME_MAX 64 #define PROCESS_NAME_MAX 64
#define PROCESS_STACK_SIZE 0x10000 // 64kb #define PROCESS_STACK_SIZE 0x10000 // 64kb
#define PROCESS_BASE 0x400000
#define PROCESS_STACK_BASE 0x1000000
/* sched */ /* sched */
// 1 tick = 1 ms => quantum = 10ms // 1 tick = 1 ms => quantum = 10ms

View File

@@ -87,11 +87,7 @@ static void page_fault_handler(struct cpu_status_t* ctx)
CHECK_BIT(ctx->error_code, 7) ? " SGX_VIOLATION" : "", CHECK_BIT(ctx->error_code, 7) ? " SGX_VIOLATION" : "",
cr2); cr2);
/* if (CHECK_BIT(ctx->error_code, 0)) panic(ctx, "page fault");
{
panic(ctx);
} */
panic(ctx);
} }
static void gp_fault_handler(struct cpu_status_t* ctx) 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); index);
} }
panic(ctx); panic(ctx, "gp fault");
} }
struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context) struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context)

View File

@@ -22,11 +22,13 @@ enum ErrorCodes
#define DEBUG(log, ...) fctprintf((void*)&skputc, 0, "debug: [%s]: " log "\r\n", __FILE__, ##__VA_ARGS__) #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))) #define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
// printf("debug: [%s]: " log "\n", __FILE__, ##__VA_ARGS__); // 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(); void hcf();
#define assert(check) do { if(!(check)) hcf(); } while(0) #define assert(check) do { if(!(check)) hcf(); } while(0)

View File

@@ -37,8 +37,17 @@ void hcf()
// Doing nothing (can be interrupted) // Doing nothing (can be interrupted)
void idle() {for(;;)asm("hlt");} 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...", 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->iret_rip,
ctx->vector_number, ctx->error_code, ctx->rax, ctx->rbx, ctx->rcx, ctx->rdx, ctx->rsi, ctx->rdi, 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) void pedicel_main(void* arg)
{ {
panic(NULL, "we did it!");
} }
void two_main(void* arg) void two_main(void* arg)
@@ -104,8 +113,8 @@ void kmain()
vmm_init(); vmm_init();
struct process_t* pedicel = process_create("pedicel", (void*)pedicel_main, 0); 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* two = process_create("two", (void*)two_main, 0);
struct process_t* three = process_create("three", (void*)three_main, 0); //struct process_t* three = process_create("three", (void*)three_main, 0);
process_display_list(processes_list); process_display_list(processes_list);
scheduler_init(); scheduler_init();

View File

@@ -66,7 +66,10 @@ static uintptr_t g_freelist = 0;
uintptr_t pmm_alloc() uintptr_t pmm_alloc()
{ {
if (!g_freelist) return 0; if (!g_freelist)
{
panic(NULL, "PMM is out of memory!");
}
uintptr_t addr = g_freelist; uintptr_t addr = g_freelist;
g_freelist = *(uintptr_t*) PHYS_TO_VIRT(g_freelist); g_freelist = *(uintptr_t*) PHYS_TO_VIRT(g_freelist);
return addr; return addr;

View File

@@ -24,6 +24,7 @@ struct process_t
status_t status; status_t status;
struct cpu_status_t* context; struct cpu_status_t* context;
void* root_page_table; // Process PML4 (should contain kernel PML4 in higher half [256-511]
struct process_t* next; struct process_t* next;
}; };

7
src/sched/task.S Normal file
View File

@@ -0,0 +1,7 @@
; Task (process) switching
bits 64
global switch_to_task
switch_to_task: