在 xv6-x86 中,每个 cpu 结构都有一个 gdt:
struct cpu {
uchar apicid; // LAPIC ID
struct context *scheduler;
struct taskstate ts;
struct segdesc gdt[NSEGS]; // GDT
volatile uint started;
int ncli;
int intena;
struct proc *proc;
};
但它在 xv6-riscv 中被删除:
// Per-CPU state.
struct cpu {
struct proc *proc; // The process running on this cpu, or null.
struct context context; // swtch() here to enter scheduler().
int noff; // Depth of push_off() nesting.
int intena; // Were interrupts enabled before push_off()?
};
所以gdt在操作系统中不是必需的? 很困惑,感谢您的回复。
最佳答案
全局描述符表 (GDT) 是特定于 x86 指令集架构的硬件数据结构,与该 ISA 的分段内存模型相关。即使在平面内存模型中,x86 保护模式也需要它,甚至需要在 x86-64 长模式下设置(根本不应用分段)。
其他 ISA(例如 RISC-V)不使用分段,因此没有与 GDT 等效的功能。
关于operating-system - 为什么xv6-riscv中没有GDT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73397444/