Compare commits
2 Commits
process
...
458ba375f3
| Author | SHA1 | Date | |
|---|---|---|---|
|
458ba375f3
|
|||
| b920c87bab |
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -32,4 +34,4 @@
|
|||||||
/* term */
|
/* term */
|
||||||
#define TERM_HISTORY_MAX_LINES 256
|
#define TERM_HISTORY_MAX_LINES 256
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -217,4 +213,4 @@ struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
17
src/kmain.c
17
src/kmain.c
@@ -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();
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -104,4 +107,4 @@ void pmm_init(struct limine_memmap_response* memmap, struct limine_hhdm_response
|
|||||||
// Now we have biggest USABLE region,
|
// Now we have biggest USABLE region,
|
||||||
// so to populate the free list we just iterate through it
|
// so to populate the free list we just iterate through it
|
||||||
pmm_init_freelist();
|
pmm_init_freelist();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
7
src/sched/task.S
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
; Task (process) switching
|
||||||
|
|
||||||
|
bits 64
|
||||||
|
|
||||||
|
global switch_to_task
|
||||||
|
switch_to_task:
|
||||||
|
|
||||||
Reference in New Issue
Block a user