86,51 → 86,3 |
|
paging_on(); |
} |
|
/* |
* Besides mapping pages to frames, this function also sets the present bit of |
* the page's specifier in both page directory and respective page table. If |
* the page table for this page has not been allocated so far, it will take |
* care of it and allocate the necessary frame. |
* |
* PAGE_CACHEABLE flag: when set, it turns caches for that page on |
* PAGE_NOT_PRESENT flag: when set, it marks the page not present |
* PAGE_USER flag: when set, the page is accessible from userspace |
* |
* When the root parameter is non-zero, it is used as the page directory address. |
* Otherwise, the page directory address is read from CPU. |
*/ |
void map_page_to_frame(__address page, __address frame, int flags, __address root) |
{ |
struct page_specifier *pd, *pt; |
__address dba, newpt; |
int pde, pte; |
|
if (root) dba = root; |
else dba = read_cr3(); |
|
pde = page >> 22; /* page directory entry */ |
pte = (page >> 12) & 0x3ff; /* page table entry */ |
|
pd = (struct page_specifier *) PA2KA(dba); |
|
if (!pd[pde].present) { |
/* |
* There is currently no page table for this address. Allocate |
* frame for the page table and clean it. |
*/ |
newpt = frame_alloc(FRAME_KA); |
pd[pde].frame_address = KA2PA(newpt) >> 12; |
memsetb(newpt, PAGE_SIZE, 0); |
pd[pde].present = 1; |
pd[pde].uaccessible = 1; |
} |
|
pt = (struct page_specifier *) PA2KA((pd[pde].frame_address << 12)); |
|
pt[pte].frame_address = frame >> 12; |
pt[pte].present = !(flags & PAGE_NOT_PRESENT); |
pt[pte].page_cache_disable = !(flags & PAGE_CACHEABLE); |
pt[pte].uaccessible = (flags & PAGE_USER) != 0; |
pt[pte].writeable = (flags & PAGE_WRITE) != 0; |
} |