diff --git a/notes/chapter3-page-tables b/notes/chapter3-page-tables index 9b7f4e4..5fecdb3 100644 --- a/notes/chapter3-page-tables +++ b/notes/chapter3-page-tables @@ -33,6 +33,8 @@ vocabulary, acronyms, et caetera: - Virtual memory = ideas and techniques associated with managing page tables used to achieve isolation & such - direct mapping = virt@ == phy@ +- KVM/UVM = Kernel/User virtual memory +- a page table = 512 PTEs = can be contained into 1 memory page virt@ = [ 25-bit EXT ; 27-bit index ; 12-bit offset ] ↑64 ↑39 ↑12 ↑0 @@ -83,3 +85,32 @@ XV6 kernel page table: => these pages are related to the processes (`kstack` in the `proc` structure) => the kstack is followed by an invalid guard page (PTE_V not set) to prevent memory corruption from stack overflows + +Virtual memory functions: + - walk: find PTE for a virt@ + - mappages: install PTEs for new mappings + - kvm_* = kernel virtual memory functions (kernel page table) + - uvm_* = same but for a user process + - copyin = copy data from user space to kernel space + - copyout = copy data from kernel space to user space + - copyinstr = copy a null-terminated string from user to kernel + = used for paths given in syscalls for example + - kvminit sets the root kernel page table created by kvmmake + - kvmmake creates a direct-map page table for the kernel + 1. create the root kernel page table with a call to `kalloc` + (kalloc provides a pointer to a page, which is the type `pagetable_t`) + 2. call kvmmap multiple times to set a few direct-map pages + kvmmap adds mapping to the kernel page table (when booting only), doesn't flush TLB or enable paging + mapped stuff: + uart registers, virtio mmio disk interface, PLIC, kernel text and data + and trampoline (for trap entry/exit) is mapped to the highest virtual address in the kernel + 3. proc_mapstacks + +Function signatures (for reference): + void kvminit(void); // set the kernel root page table + pagetable_t kvmmake(void); // create the kernel page table + void kvmmap(pagetable_t, uint64 virt@, uint64 phy@, uint64 sz, int perm); // add PTEs to the kernel page table + (this is only a call to mappages + a call to "panic" in case of an error) + int mappages(pagetable_t, uint64 virt@, uint64 size, uint64 phy@, int perm); // create PTEs + pte_t * walk(pagetable_t pagetable, uint64 va, int alloc); // virt@ -> PTE + uint64 walkaddr(pagetable_t pagetable, uint64 va); // virt@ -> phy@