Operating system 为什么像limit和base这样的字段分别存储在操作系统的gdt中?
rt, 例如,在xv6代码mmu.h中, segdesc是这样设计的Operating system 为什么像limit和base这样的字段分别存储在操作系统的gdt中?,operating-system,xv6,Operating System,Xv6,rt, 例如,在xv6代码mmu.h中, segdesc是这样设计的 struct segdesc { uint lim_15_0 : 16; // Low bits of segment limit uint base_15_0 : 16; // Low bits of segment base address uint base_23_16 : 8; // Middle bits of segment base address uint type : 4; //
struct segdesc {
uint lim_15_0 : 16; // Low bits of segment limit
uint base_15_0 : 16; // Low bits of segment base address
uint base_23_16 : 8; // Middle bits of segment base address
uint type : 4; // Segment type (see STS_ constants)
uint s : 1; // 0 = system, 1 = application
uint dpl : 2; // Descriptor Privilege Level
uint p : 1; // Present
uint lim_19_16 : 4; // High bits of segment limit
uint avl : 1; // Unused (available for software use)
uint rsv1 : 1; // Reserved
uint db : 1; // 0 = 16-bit segment, 1 = 32-bit segment
uint g : 1; // Granularity: limit scaled by 4K when set
uint base_31_24 : 8; // High bits of segment base address
};
为什么base被定义为base_15_0、base_23_16、base_31_24,而不是“uint base”
我想这部分是因为每个子字段都有特殊的含义,所以将它们单独存储而不是作为一个整体,这样便于访问。
但我不确定猜测是否完整或正确,因为它不是一个任意的、易于阅读的内部数据结构,而是硬件使用的数据结构的准确描述 资料来源:
另请参见:我猜这反映了某种历史,最初只考虑16位寻址,然后是24位,最后是32位。但这也只是一个猜测。