Skip to content

Commit

Permalink
About infos about how to enable pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyPesse committed May 28, 2014
1 parent 30941bc commit f5264c7
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions Chapter-8/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ In a paged system, each process may execute in its own 4gb area of memory, witho
The translation of a linear address to a physical address is done in multiple steps:

1. The processor use the registry `CR3` to know the physical address of the pages directory.
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.
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.
4. The last 12 bytes of the linear address represent an offset (between 0 and 4095), which indicates the position in the 4ko page.
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.
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.
4. The last 12 bits of the linear address represent an offset (between 0 and 4095), which indicates the position in the 4ko page.

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

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

**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.

* A pages directory or pages table used 1024*4 = 4096 bytes = 4k
* A pages table can address 1024 * 4k = 4 Mo
* A pages directory can address 1024 * (1024 * 4k) = 4 Go

#### How to enable pagination?

To enable pagination, we just need to set bit 31 of the `CR0`registry to 1:

```asm
asm(" mov %%cr0, %%eax; \
or %1, %%eax; \
mov %%eax, %%cr0" \
:: "i"(0x80000000));
```

But before, we need to initialize our pages directory with at least one pages table.



0 comments on commit f5264c7

Please sign in to comment.