JOS实验——lab2 exercise 5

  1. 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:
    Entry Base Virtual Address Points to (logically):
    1023 ? Page table for top 4MB of phys memory
    1022 ? ?
    . ? ?
    . ? ?
    . ? ?
    2 0x00800000 ?
    1 0x00400000 ?
    0 0x00000000 [see next question]
  2. (From Lecture 3) 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 protec tthe kernel memory?
  3. What is the maximum amount of physical memory that this operating system can support? Why?
  4. 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?
  5. Revisit the page table setup in kern/entry.S and kern/entrypgdir.c. Immediately after we turn on paging, EIP is still a low number (a little over 1MB). At what point do we transition to running at an EIP above KERNBASE? What makes it possible for us to continue executing at a low EIP between when we enable paging and when we begin running at an EIP above KERNBASE? Why is this transition necessary?

问题3:因为我们在初始化页目录项的时候,在目录项的低12位给内核设定了权限,但是并没有给用户相应的权限,见如下代码:

	boot_map_region(kern_pgdir, KERNBASE, 0xffffffff - KERNBASE, 0 , PTE_W | PTE_P);
采用了内存管理中的页保护机制。

问题4: 这个操作系统最大可以支持4G的内存,它在32位的i386上运行,并且实现了虚存管理,因此可以支持4G的内存,而且最多4G,因为超过4G时32的地址是无法寻址的。

问题5:在当前的情况下,为了支持虚存管理我们占用的页面情况是:分配一个页面作为全局页目录表,而且这一个页面已经足够管理4G的空间了,也就是说以后不用再申请页目录了;申请了npages * 8 / PGSIZE个页面来存储struct Page结构,将所有的物理内存对应到某个struct Page上;对于每个已经P标志位为1的页目录项,还分配了一个页面作为页表,总共是67个页面;将PTE_PS置位,使得页面大小由4K变为4M即可减少。

问题6:

	mov	$relocated, %eax
	jmp	*%eax
在jmp之后,eip的值是在KERNBASE以上的,因为relocated = 0xf010002f;在这之前eip=0x10002d,在这之后eip=0xf010002f;

pde_t entry_pgdir[NPDENTRIES] = {					//在页目录中只初始化了两项,第一项和第960项。
	// Map VA's [0, 4MB) to PA's [0, 4MB)
	[0]
		= ((uintptr_t)entry_pgtable - KERNBASE) + PTE_P,		
	// Map VA's [KERNBASE, KERNBASE+4MB) to PA's [0, 4MB)
	[KERNBASE>>PDXSHIFT]
		= ((uintptr_t)entry_pgtable - KERNBASE) + PTE_P + PTE_W
};
由上面的代码可以知道,在初始化页目录中第0项页目录项和和KERNBASE>>PDXSHIFT项页目录项指向相同的页表,因此在eip变为32位后,其指向的实际的物理地址是不变的。

你可能感兴趣的:(JOS实验——lab2 exercise 5)