E1:In the file kern/pmap.c, you must implement code for the following functions.
boot_alloc()
page_init()
page_alloc()
page_free()
最后在i386_vm_init()中把painc()那句删掉,然后指定地方加入
在page_init中,那些被占用页的引用次数是从后面的代码中得到的,但因为这些页不会被释放的,所以写成什么都无所谓,但是写成正确的还是有助于系统完整性。
E2:看intel手册,明白分段保护的机制。
E3:实验看虚拟地址和对应的物理地址是否是相同的数据,略过。
E4:In the file kern/pmap.c, you must implement code for the following functions.
pgdir_walk()
boot_map_segment()
page_lookup()
page_remove()
page_insert()
Exercise 5. Fill in the missing code in i386_vm_init() after the call to page_check().
在指定位置添加如下代码即可完成物理页结构,内核栈,全部256MB内存的映射:
Q1:Assuming that the following JOS kernel code is correct, what type should variable x have, uintptr_t or physaddr_t?
mystery_t x;
char* value = return_a_pointer();
*value = 10;
x = (mystery_t) value;
value是可以直接操作虚拟内存的char * ,x是从value强制转化而来,没有经过虚拟内存转物理内存的步骤,所以mystery_t应该也是虚拟内存的一种,故x是uintptr_t类型。
Q2:What entries (rows) in the page directory have been filled in at this point? What addresses do they map and where do they point? In other words, fill out this table as much as possible:
Q3:After check_boot_pgdir(), i386_vm_init() maps the first four MB of virtual address space to the first four MB of physical memory, then deletes this mapping at the end of the function. Why is this mapping necessary? What would happen if it were omitted? Does this actually limit our kernel to be 4MB? What must be true if our kernel were larger than 4MB?
在开启了分页,但是虚拟内存的段基址仍然是0xf0000000的时候,内核的虚拟地址转化位线性地址后是定位到pgdir[0]页目录项0,所以pgdir[0]必须保存有内核物理页表地址。pgdir[0]=pgdir[PDX(KERNBASE)];这句代码就是做的这件事。直到后面加载完新的GDT时候,内核虚拟地址等同于线性地址,线性地址直接映射到pgdir[PDX(KERNBASE)]上,pgdir[0]就可以清空了。
Q4:(From Lecture 4) We have placed the kernel and user environment in the same address space. Why will user programs not be able to read or write the kernel's memory? What specific mechanisms protect the kernel memory?
因为我们的页表和页目录有PTE_U位,可以来控制用户是否可以访问某页。
Q5:What is the maximum amount of physical memory that this operating system can support? Why?
从目前的代码来看,一共映射了0--256M-1的物理内存地址空间,所以最多是访问256MB的内存。
Q6:How much space overhead is there for managing memory, if we actually had the maximum amount of physical memory? How is this overhead broken down?
目前来看就是这么多,如果要计算物理内存位256MB的极限情况,把256MB带入phymem即可。
总结:大胆猜想,小心求证,高屋建瓴,细致入微。