Print a page table ok
This commit is contained in:
parent
74c8ae89b6
commit
1107e7bcab
@ -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.
|
|
||||||
|
|
||||||
8
answers-pgtbl.txt
Normal file
8
answers-pgtbl.txt
Normal file
@ -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.
|
||||||
@ -173,6 +173,7 @@ uint64 walkaddr(pagetable_t, uint64);
|
|||||||
int copyout(pagetable_t, uint64, char *, uint64);
|
int copyout(pagetable_t, uint64, char *, uint64);
|
||||||
int copyin(pagetable_t, char *, uint64, uint64);
|
int copyin(pagetable_t, char *, uint64, uint64);
|
||||||
int copyinstr(pagetable_t, char *, uint64, uint64);
|
int copyinstr(pagetable_t, char *, uint64, uint64);
|
||||||
|
void vmprint(pagetable_t pagetable);
|
||||||
|
|
||||||
// plic.c
|
// plic.c
|
||||||
void plicinit(void);
|
void plicinit(void);
|
||||||
|
|||||||
@ -128,6 +128,7 @@ exec(char *path, char **argv)
|
|||||||
p->trapframe->sp = sp; // initial stack pointer
|
p->trapframe->sp = sp; // initial stack pointer
|
||||||
proc_freepagetable(oldpagetable, oldsz);
|
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)
|
return argc; // this ends up in a0, the first argument to main(argc, argv)
|
||||||
|
|
||||||
bad:
|
bad:
|
||||||
|
|||||||
25
kernel/vm.c
25
kernel/vm.c
@ -437,3 +437,28 @@ copyinstr(pagetable_t pagetable, char *dst, uint64 srcva, uint64 max)
|
|||||||
return -1;
|
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);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user