The holy bible of SWEB - Institute of Applied Information Processing ...
The holy bible of SWEB - Institute of Applied Information Processing ...
The holy bible of SWEB - Institute of Applied Information Processing ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
3.3. BASIC CONCEPTS CHAPTER 3. VM, PROTECTION AND PAGING<br />
but contains only Descriptors specific to one program. Usually there is one LDT for<br />
each separate program. <strong>The</strong> running program can then choose between segments<br />
by writing the corresponding index into one <strong>of</strong> the segment registers (CS for Code<br />
Segment Register ,DS for Data Segment Register ,SS for Stack Segment Register)<br />
Privilege Level<br />
Four degrees between 0 and 3 <strong>of</strong> privileges exist on the IA32 Platform. <strong>The</strong> privilege<br />
level determines how large a part <strong>of</strong> the instruction set a piece <strong>of</strong> code can use without<br />
triggering a Protection Fault. <strong>The</strong> highest privilege is 0 and usually held only by the<br />
operating system since everything is allowed here. In Sweb, the Kernel has Level<br />
0 while user programs have Level 3. <strong>The</strong> Privilege Level is defined by setting the<br />
DPL field <strong>of</strong> the Segment Descriptor in which a programs code runs. When changing<br />
Segments (by loading a different Descriptor Index into a Segment Register) a program<br />
may only decrease or hold its present privilege level. A program can however, access<br />
privileged code through a Call Gate or asking the Operation System to increase its<br />
Privilege Level.<br />
3.3.3 Paging<br />
Paging is the other protection mechanism and instead <strong>of</strong> Segmentation, was newly<br />
introduced with Protected Mode. (Of course, the principle did exist long before the<br />
IA32 platform adopted the concept).<br />
Paging works by separating the physical memory into Pages <strong>of</strong> variable size and<br />
mapping Pages in linear memory to Pages in physical memory. A Page can be 4 KiB,<br />
2 MiB or 4MiB in size. It is also possible to mix 4KiB and 4MiB Pages. In Sweb we<br />
mainly concern ourselves with 4KiB Pages. Physical Memory is the range <strong>of</strong> addresses<br />
which translate directly into a memory register on the hardware. A linear memory<br />
address however, does not necessarily correspond to an address in physical hardware<br />
(see Figure 3.2). Rather the CPU translates a linear address into a physical address<br />
according to the mapping that was set up by the operating system. Separation works<br />
by assigning each program its own linear address space starting from 0 to 4 GiB.<br />
In Sweb however, a user thread is not allowed to access an address beyond 2GiB.<br />
Translation happens transparently and usually only the operating system knows what<br />
the mapping looks like. Should an unmapped linear address be referenced, the CPU<br />
causes a Page-Fault (Fault is a type <strong>of</strong> Exception) and calls Sweb’s Page-Fault-Handler<br />
(as defined in the IDT) to deal with the problem.<br />
Page-Directory and Page-Tables<br />
<strong>The</strong> Mapping <strong>of</strong> Linear Memory to Physical Memory is defined in a Page-Directory<br />
and its Page-Tables. A Page-Directory has 1024 entries. Each Entry has 32 bits.<br />
A Page-Directory-Entry can either map a 4MiB Page or hold the physical address<br />
<strong>of</strong> a Page-Table. (Actually it holds only the most significant 20 bits <strong>of</strong> the physical<br />
address, which equal the physical 4KiB page number). A Page-Table again has 1024<br />
Entries, each 32 bit in size. A Page-Table-Entry maps to a 4KiB Page in physical<br />
memory. <strong>The</strong> structure <strong>of</strong> the Page-Directory-Entries and Page-Table-Entries is shown<br />
in the following listing <strong>of</strong> paging-definitions.h. Note that the least significant 20 bits<br />
in a Page-Directory-Entry can have different interpretations depending on the state<br />
28 <strong>of</strong> 151