Rev 116 | Rev 125 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 116 | Rev 120 | ||
---|---|---|---|
Line 84... | Line 84... | ||
84 | write_cr3(KA2PA(dba)); |
84 | write_cr3(KA2PA(dba)); |
85 | } |
85 | } |
86 | 86 | ||
87 | paging_on(); |
87 | paging_on(); |
88 | } |
88 | } |
89 | - | ||
90 | /* |
- | |
91 | * Besides mapping pages to frames, this function also sets the present bit of |
- | |
92 | * the page's specifier in both page directory and respective page table. If |
- | |
93 | * the page table for this page has not been allocated so far, it will take |
- | |
94 | * care of it and allocate the necessary frame. |
- | |
95 | * |
- | |
96 | * PAGE_CACHEABLE flag: when set, it turns caches for that page on |
- | |
97 | * PAGE_NOT_PRESENT flag: when set, it marks the page not present |
- | |
98 | * PAGE_USER flag: when set, the page is accessible from userspace |
- | |
99 | * |
- | |
100 | * When the root parameter is non-zero, it is used as the page directory address. |
- | |
101 | * Otherwise, the page directory address is read from CPU. |
- | |
102 | */ |
- | |
103 | void map_page_to_frame(__address page, __address frame, int flags, __address root) |
- | |
104 | { |
- | |
105 | struct page_specifier *pd, *pt; |
- | |
106 | __address dba, newpt; |
- | |
107 | int pde, pte; |
- | |
108 | - | ||
109 | if (root) dba = root; |
- | |
110 | else dba = read_cr3(); |
- | |
111 | - | ||
112 | pde = page >> 22; /* page directory entry */ |
- | |
113 | pte = (page >> 12) & 0x3ff; /* page table entry */ |
- | |
114 | - | ||
115 | pd = (struct page_specifier *) PA2KA(dba); |
- | |
116 | - | ||
117 | if (!pd[pde].present) { |
- | |
118 | /* |
- | |
119 | * There is currently no page table for this address. Allocate |
- | |
120 | * frame for the page table and clean it. |
- | |
121 | */ |
- | |
122 | newpt = frame_alloc(FRAME_KA); |
- | |
123 | pd[pde].frame_address = KA2PA(newpt) >> 12; |
- | |
124 | memsetb(newpt, PAGE_SIZE, 0); |
- | |
125 | pd[pde].present = 1; |
- | |
126 | pd[pde].uaccessible = 1; |
- | |
127 | } |
- | |
128 | - | ||
129 | pt = (struct page_specifier *) PA2KA((pd[pde].frame_address << 12)); |
- | |
130 | - | ||
131 | pt[pte].frame_address = frame >> 12; |
- | |
132 | pt[pte].present = !(flags & PAGE_NOT_PRESENT); |
- | |
133 | pt[pte].page_cache_disable = !(flags & PAGE_CACHEABLE); |
- | |
134 | pt[pte].uaccessible = (flags & PAGE_USER) != 0; |
- | |
135 | pt[pte].writeable = (flags & PAGE_WRITE) != 0; |
- | |
136 | } |
- |