From f5264c73adc15dff0c8510b5a4609af793400f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Wed, 28 May 2014 02:04:43 +0200 Subject: [PATCH] About infos about how to enable pagination --- Chapter-8/README.md | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Chapter-8/README.md b/Chapter-8/README.md index 124ace0..b37a656 100644 --- a/Chapter-8/README.md +++ b/Chapter-8/README.md @@ -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) @@ -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. + +