kernel/x86_64: x86_64 gdt handling code overhaul
Virtually no functional change, just rewriting the code from "C in *.cpp files" to C++. Use of constexpr may be advantageous but that code is not performance critical anyway.
This commit is contained in:
@@ -13,13 +13,6 @@
|
||||
#define USER_DATA_SEGMENT 3
|
||||
#define USER_CODE_SEGMENT 4
|
||||
|
||||
#define TSS_BASE_SEGMENT 5
|
||||
|
||||
#define TSS_SEGMENT(cpu) (TSS_BASE_SEGMENT + cpu * 2)
|
||||
|
||||
#define GDT_SEGMENT_COUNT (TSS_BASE_SEGMENT + SMP_MAX_CPUS * 2)
|
||||
|
||||
|
||||
#define KERNEL_CODE_SELECTOR ((KERNEL_CODE_SEGMENT << 3) | DPL_KERNEL)
|
||||
#define KERNEL_DATA_SELECTOR ((KERNEL_DATA_SEGMENT << 3) | DPL_KERNEL)
|
||||
|
||||
@@ -46,23 +39,6 @@ struct segment_descriptor {
|
||||
uint32 base1 : 8;
|
||||
} _PACKED;
|
||||
|
||||
// Structure of a TSS segment descriptor.
|
||||
struct tss_descriptor {
|
||||
uint32 limit0 : 16;
|
||||
uint32 base0 : 24;
|
||||
uint32 type : 4;
|
||||
uint32 desc_type : 1;
|
||||
uint32 dpl : 2;
|
||||
uint32 present : 1;
|
||||
uint32 limit1 : 4;
|
||||
uint32 available : 1;
|
||||
uint32 unused1 : 2;
|
||||
uint32 granularity : 1;
|
||||
uint32 base1 : 8;
|
||||
uint32 base2 : 32;
|
||||
uint32 unused2 : 32;
|
||||
} _PACKED;
|
||||
|
||||
// Structure of an interrupt descriptor.
|
||||
struct interrupt_descriptor {
|
||||
uint32 base0 : 16;
|
||||
@@ -127,29 +103,6 @@ set_segment_descriptor(segment_descriptor* desc, uint8 type, uint8 dpl)
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
set_tss_descriptor(segment_descriptor* _desc, uint64 base, uint32 limit)
|
||||
{
|
||||
clear_segment_descriptor(_desc);
|
||||
clear_segment_descriptor(&_desc[1]);
|
||||
|
||||
// The TSS descriptor is a special format in 64-bit mode, it is 16 bytes
|
||||
// instead of 8.
|
||||
tss_descriptor* desc = (tss_descriptor*)_desc;
|
||||
|
||||
desc->base0 = base & 0xffffff;
|
||||
desc->base1 = (base >> 24) & 0xff;
|
||||
desc->base2 = (base >> 32);
|
||||
desc->limit0 = limit & 0xffff;
|
||||
desc->limit1 = (limit >> 16) & 0xf;
|
||||
|
||||
desc->present = 1;
|
||||
desc->type = DT_TSS;
|
||||
desc->desc_type = DT_SYSTEM_SEGMENT;
|
||||
desc->dpl = DPL_KERNEL;
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
set_interrupt_descriptor(interrupt_descriptor* desc, uint64 addr, uint32 type,
|
||||
uint16 seg, uint32 dpl, uint32 ist)
|
||||
|
||||
Reference in New Issue
Block a user