Paging: Difference between revisions
Jump to navigation
Jump to search
[unchecked revision] | [unchecked revision] |
Content added Content deleted
m (Add 5-level paging and improve code indent) |
m (Fix lang source option) |
||
Line 51: | Line 51: | ||
Say the kernel is loaded to 0x100000. However, it needed to be remapped to 0xc0000000. After loading the kernel, it'll initiate paging, and set up the appropriate tables. (See [[Higher Half Kernel]]) After [[Identity Paging]] the first megabyte,it'll need to create a second table (ie. at entry #768 in the paging directory.) to map 0x100000 to 0xC0000000. The code may be like: |
Say the kernel is loaded to 0x100000. However, it needed to be remapped to 0xc0000000. After loading the kernel, it'll initiate paging, and set up the appropriate tables. (See [[Higher Half Kernel]]) After [[Identity Paging]] the first megabyte,it'll need to create a second table (ie. at entry #768 in the paging directory.) to map 0x100000 to 0xC0000000. The code may be like: |
||
<source lang=" |
<source lang="ASM"> |
||
mov eax, 0x0 |
mov eax, 0x0 |
||
mov ebx, 0x100000 |
mov ebx, 0x100000 |
||
Line 69: | Line 69: | ||
Enabling paging is actually very simple. All that is needed is to load CR3 with the address of the page directory and to set the paging (PG) and protection (PE) bits of CR0. Note: setting the paging flag when the protection flag is clear causes a general-protection exception. |
Enabling paging is actually very simple. All that is needed is to load CR3 with the address of the page directory and to set the paging (PG) and protection (PE) bits of CR0. Note: setting the paging flag when the protection flag is clear causes a general-protection exception. |
||
<source lang=" |
<source lang="ASM"> |
||
mov eax, page_directory |
mov eax, page_directory |
||
mov cr3, eax |
mov cr3, eax |
||
Line 82: | Line 82: | ||
To enable PSE (4 MiB pages) the following code is required. |
To enable PSE (4 MiB pages) the following code is required. |
||
<source lang=" |
<source lang="ASM"> |
||
mov eax, cr4 |
mov eax, cr4 |
||
or eax, 0x00000010 |
or eax, 0x00000010 |
||
Line 178: | Line 178: | ||
NASM example: |
NASM example: |
||
<source lang=" |
<source lang="ASM"> |
||
invlpg [0] |
|||
</source> |
</source> |
||