关于定义的问题:英特尔64和IA-32体系结构软件开发人员手册,卷3A,总结了第5.2节中的段描述符字段。为什么将“类型”字段定义为位8至11,而不包括位12,该位被简单地称为“描述符类型标志”?考虑到将位11和12一起用于确定段是代码段,数据段还是系统段,将它们组合在一起是否更合乎逻辑?
答案 0 :(得分:4)
这是因为当S字段(位12)为0或1时,TYPE字段(位8-11)的结构非常不同。
此字段为1时,我们有下表:
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
但是,当该字段为0时,表将非常不同:
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
因此,您当然可以将第12位视为描述符类型的一部分,但将它们视为两个单独的属性会更容易。
因此,对于代码/数据段,您使用下4位作为位掩码(即,每个位确定某个“功能”是打开还是关闭,例如第11位0表示数据),但是对于系统段,您使用将其视为0-15的单个值,其中每个位没有特殊含义