mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-30 22:18:21 +00:00
user thread/process and elf loader stub
This commit is contained in:
@@ -22,5 +22,7 @@ void* arch_mmu_getphysicaladdr(arch_mmu_tableptr, void*);
|
||||
void arch_mmu_unmap(arch_mmu_tableptr, void*);
|
||||
void arch_mmu_init();
|
||||
void arch_mmu_apinit();
|
||||
arch_mmu_tableptr arch_mmu_newcontext();
|
||||
void arch_mmu_switchcontext(arch_mmu_tableptr);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,5 +9,6 @@ typedef struct{
|
||||
} arch_regs;
|
||||
|
||||
void arch_regs_setupkernel(arch_regs* regs, void* ip, void* stack, bool interrupts);
|
||||
void arch_regs_setupuser(arch_regs* regs, void* ip, void* stack, bool interrupts);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,8 +27,20 @@ struct limine_terminal_response* liminetty;
|
||||
|
||||
int ttylock = 0;
|
||||
|
||||
static vmm_context* liminettyctx;
|
||||
|
||||
void liminewrite(char* str, size_t c){
|
||||
|
||||
vmm_context* old = arch_getcls()->context;
|
||||
|
||||
if(liminettyctx)
|
||||
vmm_switchcontext(liminettyctx);
|
||||
|
||||
liminetty->write(liminetty->terminals[0], str, c);
|
||||
|
||||
if(liminettyctx)
|
||||
vmm_switchcontext(old);
|
||||
|
||||
}
|
||||
|
||||
void kmain(){
|
||||
@@ -52,6 +64,8 @@ void kmain(){
|
||||
arch_mmu_init();
|
||||
|
||||
vmm_init();
|
||||
|
||||
liminettyctx = arch_getcls()->context;
|
||||
|
||||
alloc_init();
|
||||
|
||||
@@ -82,6 +96,8 @@ void kmain(){
|
||||
|
||||
smp_init();
|
||||
|
||||
sched_runinit();
|
||||
|
||||
_panic("End of kmain()", 0);
|
||||
|
||||
}
|
||||
|
||||
+19
-5
@@ -26,8 +26,8 @@ static void changeentry(uint64_t* entry, void* paddr, uint64_t flags){
|
||||
|
||||
#define PTR_FLAGS ARCH_MMU_MAP_READ | ARCH_MMU_MAP_WRITE | ARCH_MMU_MAP_USER | ARCH_MMU_MAP_NOEXEC
|
||||
|
||||
static void switchcontext(arch_mmu_tableptr context){
|
||||
asm("mov %%rax, %%cr3" : : "a"(context));
|
||||
void arch_mmu_switchcontext(arch_mmu_tableptr context){
|
||||
asm("mov %%rax, %%cr3" : : "a"(context) : "memory");
|
||||
}
|
||||
|
||||
void* inv = NULL;
|
||||
@@ -162,7 +162,21 @@ void arch_mmu_unmap(arch_mmu_tableptr context, void* vaddr){
|
||||
|
||||
}
|
||||
|
||||
static arch_mmu_tableptr context; //boostrap context
|
||||
static arch_mmu_tableptr context; //boostrap context; also holds the kernel page tables
|
||||
|
||||
arch_mmu_tableptr arch_mmu_newcontext(){
|
||||
|
||||
arch_mmu_tableptr newcontext = pmm_alloc(1);
|
||||
if(!newcontext)
|
||||
return NULL;
|
||||
|
||||
memcpy((void*)newcontext + (size_t)limine_hhdm_offset, context, PAGE_SIZE);
|
||||
|
||||
memset((void*)newcontext + (size_t)limine_hhdm_offset, 0, PAGE_SIZE / 2);
|
||||
|
||||
return newcontext;
|
||||
|
||||
}
|
||||
|
||||
void arch_mmu_init(){
|
||||
|
||||
@@ -252,7 +266,7 @@ void arch_mmu_init(){
|
||||
}
|
||||
|
||||
|
||||
switchcontext(context);
|
||||
arch_mmu_switchcontext(context);
|
||||
arch_getcls()->context->context = context;
|
||||
|
||||
printf("In bootstrap context\n");
|
||||
@@ -261,7 +275,7 @@ void arch_mmu_init(){
|
||||
|
||||
void arch_mmu_apinit(){
|
||||
|
||||
switchcontext(context);
|
||||
arch_mmu_switchcontext(context);
|
||||
|
||||
arch_getcls()->context = pmm_hhdmalloc(1);
|
||||
|
||||
|
||||
@@ -11,3 +11,16 @@ void arch_regs_setupkernel(arch_regs* regs, void* ip, void* stack, bool interrup
|
||||
regs->ss = 0x30;
|
||||
regs->rflags = interrupts ? 0x200 : 0;
|
||||
}
|
||||
|
||||
void arch_regs_setupuser(arch_regs* regs, void* ip, void* stack, bool interrupts){
|
||||
regs->rip = ip;
|
||||
regs->rsp = stack;
|
||||
regs->cs = 0x38 | 3;
|
||||
regs->ds = 0x40 | 3;
|
||||
regs->es = 0x40 | 3;
|
||||
regs->fs = 0x40 | 3;
|
||||
regs->gs = 0x40 | 3;
|
||||
regs->ss = 0x40 | 3;
|
||||
regs->rflags = interrupts ? 0x200 : 0;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user