linux segment part2
时间:2005-11-02 来源:redog
Segmentation in linux
Linux prefers paging to segmentation form the following reasons:
1.Memory management is simpler when all processes use the same segment register values,that is when they share the same set of linear address.
2.One of the disign objective of linux is portabling to most popular architectures;however several PISC processers support segmentation in a very limited way.
Here are the segments used by Linux:
1.A kernel code segment The fields of the corresponding Segment Descriptor in the GDT have the following values:
base=0x00000000
limit=0xfffff
G=1,for segment size expressed in pages
S=1,for normal code or date segment
Type=0xa,for code segment that can be read and executed
DPL=0,for Kernel Mode
B/D=1,for 32-bit offset address
2.A kernel date segment The fields of the corresponding Segment Descriptor in the GDT have the following values:
base=0x00000000
limit=0xfffff
G=1,for segment size expressed in pages
S=1,for normal code or date segment
Type=2,for code segment that can be read and executed
DPL=0,for Kernel Mode
B/D=1,for 32-bit offset address
3.A user code segment The fields of the corresponding Segment Descriptor in the GDT have the following values:
base=0x00000000
limit=0xfffff
G=1,for segment size expressed in pages
S=1,for normal code or date segment
Type=0xa,for code segment that can be read and executed
DPL=3,for Kernel Mode
B/D=1,for 32-bit offset address
4.A user data segment The fields of the corresponding Segment Descriptor in the GDT have the following values:
base=0x00000000
limit=0xfffff
G=1,for segment size expressed in pages
S=1,for normal code or date segment
Type=2,for code segment that can be read and executed
DPL=3,for Kernel Mode
B/D=1,for 32-bit offset address
5 A Task State Segment(TSS)segment for each process.The description of whese segment area stored in the GDT.the
base field of the TSS description associated with each process contains the address of the tss field of the corresponding process descriptor
The G flag is claeard while the limit filed is set to 0xeb,since the TSS segment is 236 byte long ,the type field is set to 9 ro 11,and the Dpl
is set to 0,since processes in user mode are not allowed to access Tss Segment.
6 A dafault LDT segment that is usually shared by all processes,This segment is stored in the default_ldt variable. .The default LDT includes a single entry consisting
of a null segment descriptor.Each process has its own LDT segment descriptor ,which usually points to the common default LDT segment the base field is set to the
address of default_idt and the limit field is set to 7.if a process requires a real LDT a new 4096-byte segment is created ,and the default LDT segment Descriptor associated
with that process is replaced in the GDT with a new descriptor with specific values for the base and limit fields.
For each process ,therefore,the GDT contains two different segment Descriptors:one for the TSS segment and one for the LDT segment