diff --git a/arch/x86/include/asm/gdt.h b/arch/x86/include/asm/gdt.h index 75f8ffe8..c86a5d4b 100644 --- a/arch/x86/include/asm/gdt.h +++ b/arch/x86/include/asm/gdt.h @@ -122,6 +122,16 @@ typedef struct { */ void gdt_install(void); +/** @brief Configures and returns a GDT descriptor with chosen attributes + * + * Just feed this function with address, limit and the flags + * you have seen in idt.h + * + * @return a preconfigured gdt descriptor + */ +void configure_gdt_entry(gdt_entry_t *dest_entry, unsigned long base, unsigned long limit, + unsigned char access, unsigned char gran); + #ifdef __cplusplus } #endif diff --git a/arch/x86/kernel/gdt.c b/arch/x86/kernel/gdt.c index c625c8c1..c5a1e673 100644 --- a/arch/x86/kernel/gdt.c +++ b/arch/x86/kernel/gdt.c @@ -188,26 +188,28 @@ int create_default_frame(task_t* task, entry_point_t ep, void* arg) return 0; } -/** @brief Configures GDT descriptor with chosen attributes - * - * Just feed this function with address, limit and the flags - * you have seen in gdt.h - */ +/* Setup a descriptor in the Global Descriptor Table */ static void gdt_set_gate(int num, unsigned long base, unsigned long limit, - unsigned char access, unsigned char gran) + unsigned char access, unsigned char gran) +{ + configure_gdt_entry(&gdt[num], base, limit, access, gran); +} + +void configure_gdt_entry(gdt_entry_t *dest_entry, unsigned long base, unsigned long limit, + unsigned char access, unsigned char gran) { /* Setup the descriptor base address */ - gdt[num].base_low = (base & 0xFFFF); - gdt[num].base_middle = (base >> 16) & 0xFF; - gdt[num].base_high = (base >> 24) & 0xFF; + dest_entry->base_low = (base & 0xFFFF); + dest_entry->base_middle = (base >> 16) & 0xFF; + dest_entry->base_high = (base >> 24) & 0xFF; /* Setup the descriptor limits */ - gdt[num].limit_low = (limit & 0xFFFF); - gdt[num].granularity = ((limit >> 16) & 0x0F); + dest_entry->limit_low = (limit & 0xFFFF); + dest_entry->granularity = ((limit >> 16) & 0x0F); /* Finally, set up the granularity and access flags */ - gdt[num].granularity |= (gran & 0xF0); - gdt[num].access = access; + dest_entry->granularity |= (gran & 0xF0); + dest_entry->access = access; } /*