mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 06:58:22 +00:00
elf loading and userland
This commit is contained in:
@@ -35,6 +35,7 @@ static void reloadgdtr(){
|
||||
gdtr.offset = &arch_getcls()->gdt;
|
||||
gdtr.size = sizeof(gdt_t) - 1;
|
||||
asm("lgdt (%%rax)" : : "a"(&gdtr) : "memory");
|
||||
asm("ltr %%ax" : : "a"(0x48));
|
||||
}
|
||||
|
||||
void gdt_init(){
|
||||
|
||||
@@ -4,20 +4,22 @@
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct{
|
||||
uint32_t IOPB;
|
||||
uint64_t reserved3;
|
||||
uint64_t ist7;
|
||||
uint64_t ist6;
|
||||
uint64_t ist5;
|
||||
uint64_t ist4;
|
||||
uint64_t ist3;
|
||||
uint64_t ist2;
|
||||
uint64_t ist1;
|
||||
uint64_t reserved2;
|
||||
uint64_t rsp2;
|
||||
uint64_t rsp1;
|
||||
uint32_t reserved;
|
||||
uint64_t rsp0;
|
||||
uint64_t reserved;
|
||||
uint64_t rsp1;
|
||||
uint64_t rsp2;
|
||||
uint32_t reserved2;
|
||||
uint64_t ist1;
|
||||
uint64_t ist2;
|
||||
uint64_t ist3;
|
||||
uint64_t ist4;
|
||||
uint64_t ist5;
|
||||
uint64_t ist6;
|
||||
uint64_t ist7;
|
||||
uint32_t reserved3;
|
||||
uint32_t reserved4;
|
||||
uint32_t reserved5;
|
||||
uint32_t IOPB;
|
||||
} __attribute((packed)) ist_t;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,5 +24,6 @@ void arch_mmu_init();
|
||||
void arch_mmu_apinit();
|
||||
arch_mmu_tableptr arch_mmu_newcontext();
|
||||
void arch_mmu_switchcontext(arch_mmu_tableptr);
|
||||
void arch_mmu_changeflags(arch_mmu_tableptr context, void* addr, size_t flags, size_t count);
|
||||
|
||||
#endif
|
||||
|
||||
+20
-4
@@ -114,11 +114,13 @@ static uint64_t getmapping(arch_mmu_tableptr context, void* vaddr){
|
||||
size_t pd = (addr >> 30) & 0b111111111;
|
||||
size_t pt = (addr >> 21) & 0b111111111;
|
||||
size_t page = (addr >> 12) & 0b111111111;
|
||||
|
||||
uint64_t* table = next(context, pdpt);
|
||||
|
||||
if(!table) return 0;
|
||||
|
||||
table = next(table, pd);
|
||||
|
||||
if(!context[pdpt]) return 0;
|
||||
|
||||
uint64_t* table = next(context, pd);
|
||||
|
||||
if(!table) return 0;
|
||||
|
||||
table = next(table, pt);
|
||||
@@ -142,6 +144,20 @@ bool arch_mmu_isaccessed(arch_mmu_tableptr context, void* addr){
|
||||
return (getmapping(context, addr) & ARCH_MMU_MAP_ACCESSED) != 0;
|
||||
}
|
||||
|
||||
void arch_mmu_changeflags(arch_mmu_tableptr context, void* addr, size_t flags, size_t count){
|
||||
for(size_t i = 0; i < count; ++i){
|
||||
uint64_t mapping = getmapping(context, addr);
|
||||
if(!mapping)
|
||||
continue;
|
||||
mapping &= ~(0xFFF); // get addr
|
||||
mapping &= ~ARCH_MMU_MAP_NOEXEC;
|
||||
mapping |= flags;
|
||||
setpage(context, addr, mapping);
|
||||
addr += PAGE_SIZE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int arch_mmu_map(arch_mmu_tableptr context, void* paddr, void* vaddr, size_t flags){
|
||||
uint64_t entry;
|
||||
changeentry(&entry, paddr, flags);
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#define TRACE_MAXDEPTH 10
|
||||
|
||||
static void tracestack(uint64_t** addr){
|
||||
|
||||
for(size_t depth = 0; depth < TRACE_MAXDEPTH; ++depth){
|
||||
|
||||
uint64_t *calleeaddr = *(addr + 1);
|
||||
@@ -34,8 +33,11 @@ __attribute((noreturn)) void _panic(char* reason, arch_regs *reg){
|
||||
);
|
||||
|
||||
printf("Panic location: %p\n", reg->rip);
|
||||
printf("Stack trace:\n");
|
||||
tracestack((uint64_t**)reg->rbp);
|
||||
|
||||
if(reg->rbp != 0){
|
||||
printf("Stack trace:\n");
|
||||
tracestack((uint64_t**)reg->rbp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user