A question on definition: the Intel 64 and IA-32 Architectures Software Developer Manual, Vol 3A, summarises segment descriptor fields in section 5.2. How come the "type" field is defined as bits 8 through 11, and does not include bit 12, which is simply stated to be the "descriptor type flag"? Considering that bits 11 and 12 are used together to determine whether a segment is a code, data, or system segment, isn't it more logical to group them together?
Asked
Active
Viewed 99 times
1 Answers
4
It is because structure of TYPE field (bits 8-11) is very different when S field (bit 12) is 0 or 1.
When this field is 1, we have following table:
11 10 9 8
0 0 0 0 0 Data Read-Only
1 0 0 0 1 Data Read-Only, accessed
2 0 0 1 0 Data Read/Write
3 0 0 1 1 Data Read/Write, accessed
4 0 1 0 0 Data Read-Only, expand-down
5 0 1 0 1 Data Read-Only, expand-down, accessed
6 0 1 1 0 Data Read/Write, expand-down
7 0 1 1 1 Data Read/Write, expand-down, accessed
8 1 0 0 0 Code Execute-Only
9 1 0 0 1 Code Execute-Only, accessed
10 1 0 1 0 Code Execute/Read
11 1 0 1 1 Code Execute/Read, accessed
12 1 1 0 0 Code Execute-Only, conforming
13 1 1 0 1 Code Execute-Only, conforming, accessed
14 1 1 1 0 Code Execute/Read, conforming
15 1 1 1 1 Code Execute/Read, conforming, accessed
But when this field is 0, table is very different:
11 10 9 8 32-Bit Mode IA-32e Mode
0 0 0 0 0 Reserved Upper 8 bytes of an 16-byte descriptor
1 0 0 0 1 16-bit TSS (Available) Reserved
2 0 0 1 0 LDT LDT
3 0 0 1 1 16-bit TSS (Busy) Reserved
4 0 1 0 0 16-bit Call Gate Reserved
5 0 1 0 1 Task Gate Reserved
6 0 1 1 0 16-bit Interrupt Gate Reserved
7 0 1 1 1 16-bit Trap Gate Reserved
8 1 0 0 0 Reserved Reserved
9 1 0 0 1 32-bit TSS (Available) 64-bit TSS (Available)
10 1 0 1 0 Reserved Reserved
11 1 0 1 1 32-bit TSS (Busy) 64-bit TSS (Busy)
12 1 1 0 0 32-bit Call Gate 64-bit Call Gate
13 1 1 0 1 Reserved Reserved
14 1 1 1 0 32-bit Interrupt Gate 64-bit Interrupt Gate
15 1 1 1 1 32-bit Trap Gate 64-bit Trap Gate
So, of course you can consider 12th bit as part of descriptor type, but it is easier to think about them as two separate properties.
So for code/data segments you're using next 4 bits as bit mask (ie each bit determines whether some "feature" is on or off, for example 11th bit 0 means data), but for system segments you're considering it as single value 0-15, where each bit does not have particular meaning

Iłya Bursov
- 23,342
- 4
- 33
- 57