diff --git a/answers-page-tables.txt b/answers-page-tables.txt deleted file mode 100644 index 300ef8f..0000000 --- a/answers-page-tables.txt +++ /dev/null @@ -1,3 +0,0 @@ -Q: Which other xv6 system call(s) could be made faster using this shared page? Explain how. -A: sys_uptime. Make the global tick in a user access page, and map the address of tick into usyscall. - diff --git a/answers-pgtbl.txt b/answers-pgtbl.txt new file mode 100644 index 0000000..07055ca --- /dev/null +++ b/answers-pgtbl.txt @@ -0,0 +1,8 @@ +Q: Which other xv6 system call(s) could be made faster using this shared page? Explain how. +A: sys_uptime. Make the global tick in a user access page, and map the address of tick into usyscall. + +Q: Explain the output of vmprint in terms of Fig 3-4 from the text. What does page 0 contain? What is in page 2? When running in user mode, could the process read/write the memory mapped by page 1? What does the third to last page contain? +A: Page 0 contains process's text (code). + Page 2 is the guard page. + Page 1 could be read and write in user mode, due to its PTE_U(1 << 4), PTE_R(1 << 2) and PTE_W(1 << 3) flags being set. + The third to last page, aka page 255-511-509, is the usyscall page used in the last task. \ No newline at end of file diff --git a/kernel/defs.h b/kernel/defs.h index a3c962b..bdbd654 100644 --- a/kernel/defs.h +++ b/kernel/defs.h @@ -173,6 +173,7 @@ uint64 walkaddr(pagetable_t, uint64); int copyout(pagetable_t, uint64, char *, uint64); int copyin(pagetable_t, char *, uint64, uint64); int copyinstr(pagetable_t, char *, uint64, uint64); +void vmprint(pagetable_t pagetable); // plic.c void plicinit(void); diff --git a/kernel/exec.c b/kernel/exec.c index e18bbb6..d993143 100644 --- a/kernel/exec.c +++ b/kernel/exec.c @@ -128,6 +128,7 @@ exec(char *path, char **argv) p->trapframe->sp = sp; // initial stack pointer proc_freepagetable(oldpagetable, oldsz); + if (p->pid == 1) vmprint(p->pagetable); return argc; // this ends up in a0, the first argument to main(argc, argv) bad: diff --git a/kernel/vm.c b/kernel/vm.c index 9f69783..996f3ed 100644 --- a/kernel/vm.c +++ b/kernel/vm.c @@ -437,3 +437,28 @@ copyinstr(pagetable_t pagetable, char *dst, uint64 srcva, uint64 max) return -1; } } + +static void _vmprint(pagetable_t pagetable, int depth) +{ + if (depth == 3) + return; + for (int i = 0; i < 512; ++i) + { + pte_t pte = pagetable[i]; + if (pte & PTE_V) + { + for (int _i = 0; _i < depth; ++_i) + { + printf(".. "); + } + printf("..%d: pte %p pa %p\n", i, pte, PTE2PA(pte)); + _vmprint((pagetable_t)PTE2PA(pte), depth + 1); + } + } +} + +void vmprint(pagetable_t pagetable) +{ + printf("page table %p\n", pagetable); + _vmprint(pagetable, 0); +} \ No newline at end of file