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
set disassembly-flavor intel
display/8i $rip
display/4i $rip

View File

@@ -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
#endif

View File

@@ -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;
}
}

View File

@@ -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)

View File

@@ -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();

View File

@@ -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();
}
}

View File

@@ -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;
};

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: