*****************
Protected Mode
*****************
Segment Selector: 16 bits field.
15-3: index of entries in gdt or in ldt
2: table indicator (0 descriptor stores in gdt; 1 descriptor stores in ldt )
1-0: requester privilege level(in CS register, it is current privilege level called CPL, 0 denotes kernel mode, 3 denotes user mode.)
Segmentation Registers: is to hold segment selectors, these registers are called cs, ss, ds, es, fs and gs.
cs: The code segment registers, which points to a segment containing program insturction
ss: The stack segment registers, which points to a segment containing the current program stack
ds: The data segment registers, which points to a segment containing global and static data
Segment Descriptor: 8 bytes, it describes the segment characteristics.
segment descirptor are stored either in the global descriptors table (GDT) or in local descriptors table (LDT).
Remember Descriptor privilege level (DPL) is in segment descriptor. we need to check CPL < DPL, then we could access that memory.
Translating a logical address to linear address by using SEGMENTATION UNIT
index * 8 + (base address of gdt or ldt) + (32 bits offset) = linear address
please see understanding Linux kernel chapter 2. page 41 for more information.
*****************
Real Mode
*****************
In real mode, the CS is different from CS in protected mode, It stores physical address
like instruction ljmp 0xa000, 0x0000
it will set the cs = 0xa000, and eip =0x0000
translating to physical address is:
so the instruction will be executing is: cs * 16 + eip = 0xa0000
remember, there is no global descriptor table in real mode.
No comments:
Post a Comment