OS lab2

Part1
记录那些页被用了,使用链表管理struct Page objects

boot_alloc: 看注释
mem_init: 设置一个二阶表,kern_pgdir是虚拟地址的root
调用boot alloc分配空间

Part2
https://ipads.se.sjtu.edu.cn/courses/os/2015/readings/i386/s05_02.htm
read 5.2 6.4 #TODO
https://pdos.csail.mit.edu/6.828/2007/readings/i386/c05.htm
A linear address refers indirectly to a physical address by specifying a page table, a page within that table, and an offset within that page.
From code executing on the CPU, once we're in protected mode (which we entered first thing in boot/boot.S), there's no way to directly use a linear or physical address. All memory references are interpreted as virtual addresses and translated by the MMU, which means all pointers in C are virtual addresses.
Question
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;
程序里面任何地址都是虚拟地址uintptr_t

JOS需要读取或修改内存,尽管只知道物理地址。给页表添加映射需要分配无力内存去储存一个页目录,然后才能初始化内存。然而内核不能绕过虚拟地址转换,因此不能直接加载和储存物理地址。为了将物理地址转为虚拟地址,内核需要在物理地址加上0xf0000000从而找到相关的虚拟地址,可以使用KADDR(pa)完成这个操作。

同样,如果内核需要通过虚拟地址去找物理地址,就需要减去0xf0000000,可以使用PADDR(va)完成这个操作。

boot_map_region函数:将虚拟地址[va, va+size)映射到物理地址[pa, pa+size),注释中提到可以使用上面写的pgdir_walk,获取页表地址,接着将物理地址的值与上权限位赋给页表地址。

最后一步就是page_insert函数,将页面管理结构 pp 所对应的物理页面分配给线性地址 va。同时,将对应的页表项的 permission 设置成 PTE_P&perm。 注意:一定要考虑到线性地址 va 已经指向了另外一个物理页面或者干脆就是这个函数要指向的物理页面的情况。如果线性地址 va 已经指向了另外一个物理页面,则先要调用 page_remove 将该物理页从线性地址 va 处删除,再将 va 对应的页表项的地址赋值为 pp 对应 的物理页面。如果 va 指向的本来就是参数 pp 所对应的物理页面,则将 va 对应的页表项中 的物理地址赋值重新赋值为 pp 所对应的物理页面的首地址即可。

Part3
The dividing line is defined somewhat arbitrarily by the symbol ULIM in inc/memlayout.h, reserving approximately 256MB of virtual address space for the kernel.

为什么是只要64个 #todo
cr4:https://www.jianshu.com/p/d9fb1aea8cb5
大页:https://www.jianshu.com/p/14f5d648fda9
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]
——https://github.com/Clann24/jos/tree/master/lab2
(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 protect the kernel memory?
——no we have permission pte u
What is the maximum amount of physical memory that this operating system can support? Why?
——2G内存的话,总共页面数就是0.5M个,pages结构体(PageInfo)的大小就是0.5M8Byte=4M,page director是4K, 由于pages的数目为0.5M,所以page table是0.5M4byge=2M,所以总共是6M+4k
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?
——2G, the maximum size of UPAGES is 4MB, sizeof(struct PageInfo))=8Byte, so we can have at most4MB/8B=512K pages, the size of one page is 4KB, so we can have at most 4MB/8B*4KB)=2GB phy memory.
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?
——After jmp *%eax finished. It is possible because entry_pgdir also maps va [0, 4M) to pa [0, 4M), it's necessary because later a kern_pgdir will be loaded and va [0, 4M) will be abandoned.
challenge:

你可能感兴趣的:(OS lab2)