In xv6-x86 every cpu struct has a 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;
};
but it is removed in 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()?
};
so the gdt is not necessary in OS? quite confused and appreciate for any reply.
The Global Descriptor Table (GDT) is a hardware data structure specific to x86 Instruction Set Architecture, and relates to the segmented memory models of that ISA. It is required for x86 protected mode even in flat memory models, and even needs to be set up in x86-64 long mode (which doesn't apply segmentation at all).
Other ISAs such as RISC-V don't use segmentation, and thus have no equivalent to the GDT.