Update on chapter 3 notes.
This commit is contained in:
parent
f8f86c4cb9
commit
c8b60efd77
1 changed files with 31 additions and 0 deletions
|
@ -33,6 +33,8 @@ vocabulary, acronyms, et caetera:
|
||||||
- Virtual memory = ideas and techniques associated with managing page tables
|
- Virtual memory = ideas and techniques associated with managing page tables
|
||||||
used to achieve isolation & such
|
used to achieve isolation & such
|
||||||
- direct mapping = virt@ == phy@
|
- 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 ]
|
virt@ = [ 25-bit EXT ; 27-bit index ; 12-bit offset ]
|
||||||
↑64 ↑39 ↑12 ↑0
|
↑64 ↑39 ↑12 ↑0
|
||||||
|
@ -83,3 +85,32 @@ XV6 kernel page table:
|
||||||
=> these pages are related to the processes (`kstack` in the `proc` structure)
|
=> 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)
|
=> the kstack is followed by an invalid guard page (PTE_V not set)
|
||||||
to prevent memory corruption from stack overflows
|
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@
|
||||||
|
|
Loading…
Add table
Reference in a new issue