52 asm volatile (
"lgdt %0" : :
"m" (gdtr_operand));
53 asm volatile (
"ltr %w0" : :
"q" (
SEL_TSS));
93 ASSERT (type >= 0 && type <= 15);
94 ASSERT (dpl >= 0 && dpl <= 3);
97 e0 = ((limit & 0xffff)
100 e1 = (((base >> 16) & 0xff)
107 | (granularity << 23)
108 | (base & 0xff000000));
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
static uint64_t make_gdtr_operand(uint16_t limit, void *base)
Returns a descriptor that yields the given LIMIT and BASE when used as an operand for the LGDT instru...
static uint64_t make_data_desc(int dpl)
Returns a descriptor for a writable data segment with base at 0, a limit of 4 GB, and the given DPL.
seg_granularity
Limit has byte or 4 kB page granularity?
@ GRAN_PAGE
Limit has 4 kB granularity.
@ GRAN_BYTE
Limit has 1-byte granularity.
static uint64_t make_seg_desc(uint32_t base, uint32_t limit, enum seg_class class, int type, int dpl, enum seg_granularity granularity)
Returns a segment descriptor with the given 32-bit BASE and 20-bit LIMIT (whose interpretation depend...
static uint64_t gdt[SEL_CNT]
The Global Descriptor Table (GDT).
seg_class
System segment or code/data segment?
@ CLS_CODE_DATA
Code or data segment.
@ CLS_SYSTEM
System segment.
void gdt_init(void)
Sets up a proper GDT.
static uint64_t make_code_desc(int dpl)
GDT helpers.
static uint64_t make_tss_desc(void *laddr)
Returns a descriptor for an "available" 32-bit Task-State Segment with its base at the given linear a...
#define SEL_UCSEG
Segment selectors.
#define SEL_CNT
Number of segments.
#define SEL_UDSEG
User data selector.
#define SEL_TSS
Task-state segment.
#define SEL_NULL
GDT selectors defined by loader.
#define SEL_KDSEG
Kernel data selector.
#define SEL_KCSEG
Kernel code selector.
unsigned long long int uint64_t
unsigned short int uint16_t
struct tss * tss_get(void)
Returns the kernel TSS.