boot_alloc:
simple memory allocator
只有在boot的時候使用, allocate physical memory, 之後就使用page_alloc
i386_vm_init
( called by i386_init(void) )
1. 分配一塊空間給page directory, cr3指向此地址
2. 分配一塊空間給struct Page, 用來儲存physical page entry
3. page_init
4. map pages toUPAGES
5. map physical bootstack 到 virtual address上
6. 把從KERNBASE到4G map到physical address 0x00000000的地方
7. 因為一開始segmentation會把va = va - KERNBASE, 所以在開paging之前要設定pgdir[0]
access to address higher than KERNBASE will subtract KERNBASE by segmentation and map to pgdir[0];
- pgdir[0] = pgdir[PDX(KERNBASE)]
然後turn on paging, 把新的segment mapping(不做轉換)寫入, 然後才清空pgdir[0].
page_init
用一個linked list把所有的free physical page都link起來, 0-640K是可以用, 大於640K到1M, 1M到kernel end是不可以用.
page_alloc:
allocate a physical page, remove it from the page_free_list
page_free:
return the page to the free list
page_insert:
insert a mapping (virtual to physical) at page table. Need to call pgdir_walk.
page_lookup:
給一個virtual address, 回傳mapped到的physical page和pte
pgdir_walk:
給一個virtual address, 到page directory裡面去找出paget table entry.
如果已經存在pdt, 回傳現有的
如果沒有pdt, allocate一個新的page table, 最後回傳page table entry.
boot_map_segment:
把virtual address map到physical address
沒有留言:
張貼留言