Skip to content

Commit f5264c7

Browse files
committed
About infos about how to enable pagination
1 parent 30941bc commit f5264c7

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

Chapter-8/README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ In a paged system, each process may execute in its own 4gb area of memory, witho
2121
The translation of a linear address to a physical address is done in multiple steps:
2222

2323
1. The processor use the registry `CR3` to know the physical address of the pages directory.
24-
2. The first 10 bytes of the linear address represent an offset (between 0 and 1023), pointing to an entry in the pages directory. This entry contains the physical address of a pages table.
25-
3. the next 10 bytes of the linear address represent an offset, pointing to an entry in the pages table. This entry is pointing to a 4ko page.
26-
4. The last 12 bytes of the linear address represent an offset (between 0 and 4095), which indicates the position in the 4ko page.
24+
2. The first 10 bits of the linear address represent an offset (between 0 and 1023), pointing to an entry in the pages directory. This entry contains the physical address of a pages table.
25+
3. the next 10 bits of the linear address represent an offset, pointing to an entry in the pages table. This entry is pointing to a 4ko page.
26+
4. The last 12 bits of the linear address represent an offset (between 0 and 4095), which indicates the position in the 4ko page.
2727

2828
![Address translation](./paging_memory.png)
2929

@@ -44,4 +44,24 @@ The two types of entries (table and directory) look like the same. Only the fiel
4444
* 0 = 4ko
4545
* 1 = 4mo
4646

47+
**Note:** Physical addresses in the pages diretcory or pages table are written using 20 bits because these addresses are aligned on 4ko, so the last 12bits should be equal to 0.
48+
49+
* A pages directory or pages table used 1024*4 = 4096 bytes = 4k
50+
* A pages table can address 1024 * 4k = 4 Mo
51+
* A pages directory can address 1024 * (1024 * 4k) = 4 Go
52+
53+
#### How to enable pagination?
54+
55+
To enable pagination, we just need to set bit 31 of the `CR0`registry to 1:
56+
57+
```asm
58+
asm(" mov %%cr0, %%eax; \
59+
or %1, %%eax; \
60+
mov %%eax, %%cr0" \
61+
:: "i"(0x80000000));
62+
```
63+
64+
But before, we need to initialize our pages directory with at least one pages table.
65+
66+
4767

0 commit comments

Comments
 (0)