try to fix page fault
This commit is contained in:
parent
105a10aba3
commit
4309b666a4
8 changed files with 40 additions and 10 deletions
|
@ -65,7 +65,7 @@ program_t *elf_load(char *data) {
|
|||
if (!(phdr[i].p_flags & PF_X))
|
||||
flags |= VMM_NX;
|
||||
|
||||
flags |= VMM_USER; // User mode access
|
||||
flags |= VMM_USER;
|
||||
|
||||
log("elf - loading ELF program header %u: vaddr 0x%llx - 0x%llx, offset 0x%llx, filesz 0x%llx, size 0x%llx, flags 0x%llx\n",
|
||||
i, vaddr_start, vaddr_end, offset, phdr[i].p_filesz, phdr[i].p_memsz, flags);
|
||||
|
@ -81,7 +81,9 @@ program_t *elf_load(char *data) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
log("elf - vmm_map(%p, %p, %p, %d)\n", pm, vaddr, phys, flags);
|
||||
vmm_map(pm, vaddr, phys, flags);
|
||||
log("elf - memset(%p, 0, 0x1000)\n", HIGHER_HALF(phys));
|
||||
memset((void *)HIGHER_HALF(phys), 0, PMM_PAGE_SIZE);
|
||||
|
||||
uint64_t file_page_offset = offset + (vaddr - vaddr_start);
|
||||
|
@ -109,6 +111,7 @@ program_t *elf_load(char *data) {
|
|||
{
|
||||
void *dest = (void *)(HIGHER_HALF(phys) + page_data_offset);
|
||||
void *src = (uint8_t *)data + copy_offset;
|
||||
log("elf - memcpy(%p, %p, %d)\n", dest, src, copy_size);
|
||||
memcpy(dest, src, copy_size);
|
||||
|
||||
//log("elf - copied 0x%llx bytes from ELF file offset 0x%llx to vaddr 0x%llx (phys 0x%llx)\n",
|
||||
|
|
|
@ -171,18 +171,19 @@ uint64_t vmm_get_flags(pagemap_t* pm, uint64_t vaddr) {
|
|||
|
||||
return pml1[pml1_entry] & 0x7000000000000FFF;
|
||||
}
|
||||
|
||||
|
||||
uint64_t virt_to_phys(pagemap_t *pagemap, uint64_t virt)
|
||||
{
|
||||
uint64_t pml1_idx = (virt & (uint64_t)0x1ff << 12) >> 12;
|
||||
uint64_t pml2_idx = (virt & (uint64_t)0x1ff << 21) >> 21;
|
||||
uint64_t pml3_idx = (virt & (uint64_t)0x1ff << 30) >> 30;
|
||||
uint64_t pml4_idx = (virt & (uint64_t)0x1ff << 39) >> 39;
|
||||
uint64_t pml4_idx = (virt >> 39) & 0x1FF;
|
||||
uint64_t pml3_idx = (virt >> 30) & 0x1FF;
|
||||
uint64_t pml2_idx = (virt >> 21) & 0x1FF;
|
||||
uint64_t pml1_idx = (virt >> 12) & 0x1FF;
|
||||
|
||||
uint64_t *pml3 = __vmm_get_next_lvl(pagemap->toplevel, pml4_idx, 0);
|
||||
uint64_t *pml2 = __vmm_get_next_lvl(pml3, pml3_idx, 0);
|
||||
uint64_t *pml1 = __vmm_get_next_lvl(pml2, pml2_idx, 0);
|
||||
uint64_t phys_addr = pml1[pml1_idx] & 0x000FFFFFFFFFF000;
|
||||
|
||||
uint64_t phys_addr = pml1[pml1_idx] & 0x000FFFFFFFFFF000; // Masque pour obtenir l'adresse physique (en retirant les bits de flags)
|
||||
|
||||
return phys_addr;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
//#include "mm/pmm.h"
|
||||
//#include "mm/vmm.h"
|
||||
#include "mm/pmm.h"
|
||||
#include "mm/vmm.h"
|
||||
#include "sched/sched.h"
|
||||
#include "sys/arch/x86_64/pic.h"
|
||||
|
@ -44,8 +45,9 @@ void exception_handler(registers_t *regs) {
|
|||
if(regs->int_no == 0xe) {
|
||||
uint64_t cr2;
|
||||
asm ("mov %%cr2, %0" : "=r"(cr2));
|
||||
log("ints - PF: Faulting location: %p\n", cr2);
|
||||
log("ints - PF: Faulting location: %p (%p)\n", cr2, virt_to_phys(vmm_current_pm, cr2));
|
||||
log("ints - PF: Faulting page flags: %p\n", vmm_get_flags(vmm_current_pm, cr2));
|
||||
log("ints - PF: Faulting page map: %p\n", PHYSICAL(vmm_current_pm));
|
||||
}
|
||||
|
||||
// dump_backtrace(regs);
|
||||
|
|
3
testing/build.sh
Executable file
3
testing/build.sh
Executable file
|
@ -0,0 +1,3 @@
|
|||
nasm -f elf64 test.asm -o test.o
|
||||
ld -T link.ld -nostdlib --no-dynamic-linker --strip-all test.o -o sk-hello.elf
|
||||
echo "Test executable has been built successfully."
|
Binary file not shown.
|
@ -4,5 +4,7 @@ section .text
|
|||
|
||||
_start:
|
||||
int 0x80
|
||||
lol:
|
||||
jmp lol
|
||||
; tell the kernel to exit the process.
|
||||
mov rax, 10
|
||||
int 0x80
|
||||
ret
|
BIN
testing/test.o
BIN
testing/test.o
Binary file not shown.
19
util/get_vaddr_info.py
Executable file
19
util/get_vaddr_info.py
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print(f"Usage: {sys.argv[0]} <virtual_address (hex)>")
|
||||
sys.exit(1)
|
||||
|
||||
va = int(sys.argv[1], 16)
|
||||
|
||||
def extract_index(name, shift):
|
||||
return (va >> shift) & 0x1FF
|
||||
|
||||
print(f"Virtual address : 0x{va:016x}")
|
||||
print(f"PML4 index : {extract_index('PML4', 39)}")
|
||||
print(f"PDPT index : {extract_index('PDPT', 30)}")
|
||||
print(f" PD index : {extract_index('PD', 21)}")
|
||||
print(f" PT index : {extract_index('PT', 12)}")
|
||||
print(f" Offset : {va & 0xFFF}")
|
Loading…
Add table
Add a link
Reference in a new issue