From chapter 2. page 38
1. Logical address translation
- Logical address 經由segmentation轉成linear address
- Linear address 經由 paging 轉成physical address
2. Segment selector and GDT
(用來做logical to linear 轉換)
一個logical address包含segment identifier (16bits) and offset (32bits)
segment identifier就是segment selector
Linux提供了segment registers:
CS: code segment, 指向program instruction
SS: stack segment
DS: data segment
...
Segment selector裡面有個13bit index, 指向Global Description Table (GDT)
每個segment description entry有8byte, 裡面有Base and Limit, 用來做address translation
3. Segment selector
分成兩部份visible and invisible. Visible: 16 bit, 前13bit為index指到GDT entry. 從GDT entry 拿到segment descriptor後會把descriptor存到invisible part給processor當cache.
"The processor automatically fetches the base address, limit, type, and other information from a descriptor table and loads them into the invisible part of the segment register." from 5.1.4 ref2
4. 80386系統其實有兩種memory organization
reference: http://www.cs.sunysb.edu/~porter/courses/cse506/f11/ref/i386/s02_01.htm
- flat model: 一個process只有4G記憶體空間
- segmentation model: 每個process有64 Terabyte, 因為每個segment有14 bits (2^14)
再加上32 bits的offset, 總共有46 bits, 64 Terabyte.
Extract from the ref:
- A segment selector, which is a 16-bit field that identifies a segment- An offset, which is a 32-bit ordinal that addresses to the byte level within a segment.
5. Page Translation (Paging)
- Linear address包含三部份: DIR to index the page directory, Page to index the page table, OFFSET則指到最後4G address space的地方
- CR3存的是目前task的page table physical address
- CR0有個PG bit, set時paging才會enable
from ref2:
6. Page table entry
因為page table指到的是4K page boundary, 所以address的前12 bit都是零, Page table entry利用這12 bit來放一些page table的property.
Page table entry跟page directory entry的格式差不多相同.
Reference:1. Understanding the Linux Kernel
2. 80386 Programmer's Reference Manual, Chapter 5
沒有留言:
張貼留言