Encapsulated IDT-/GDT-descriptor configuring code into helper functions.

This commit is contained in:
Jacek Galowicz 2011-04-19 18:51:59 +02:00
parent f3972a36c4
commit 6a1fdca0ac
4 changed files with 49 additions and 12 deletions

View file

@ -115,6 +115,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
*/
gdt_entry_t configure_gdt_entry(unsigned long base, unsigned long limit,
unsigned char access, unsigned char gran);
#ifdef __cplusplus
}
#endif

View file

@ -116,6 +116,16 @@ void idt_install(void);
void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel,
unsigned char flags);
/** @brief Configures and returns a IDT entry with chosen attributes
*
* Just feed this function with base, selector and the flags
* you have seen in idt.h
*
* @return a preconfigured idt descriptor
*/
idt_entry_t configure_idt_entry(unsigned long base, unsigned short sel,
unsigned char flags);
#ifdef __cplusplus
}
#endif

View file

@ -157,19 +157,27 @@ int create_default_frame(task_t* task, entry_point_t ep, void* arg)
static void gdt_set_gate(int num, unsigned long base, unsigned long limit,
unsigned char access, unsigned char gran)
{
gdt[num] = configure_gdt_entry(base, limit, access, gran);
}
gdt_entry_t configure_gdt_entry(unsigned long base, unsigned long limit,
unsigned char access, unsigned char gran)
{
gdt_entry_t desc;
/* 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;
desc.base_low = (base & 0xFFFF);
desc.base_middle = (base >> 16) & 0xFF;
desc.base_high = (base >> 24) & 0xFF;
/* Setup the descriptor limits */
gdt[num].limit_low = (limit & 0xFFFF);
gdt[num].granularity = ((limit >> 16) & 0x0F);
desc.limit_low = (limit & 0xFFFF);
desc.granularity = ((limit >> 16) & 0x0F);
/* Finally, set up the granularity and access flags */
gdt[num].granularity |= (gran & 0xF0);
gdt[num].access = access;
desc.granularity |= (gran & 0xF0);
desc.access = access;
return desc;
}
/*

View file

@ -48,16 +48,25 @@ static idt_ptr_t idtp;
void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel,
unsigned char flags)
{
idt[num] = configure_idt_entry(base, sel, flags);
}
idt_entry_t configure_idt_entry(unsigned long base, unsigned short sel,
unsigned char flags)
{
idt_entry_t desc;
/* The interrupt routine's base address */
idt[num].base_lo = (base & 0xFFFF);
idt[num].base_hi = (base >> 16) & 0xFFFF;
desc.base_lo = (base & 0xFFFF);
desc.base_hi = (base >> 16) & 0xFFFF;
/* The segment or 'selector' that this IDT entry will use
* is set here, along with any access flags */
idt[num].sel = sel;
idt[num].always0 = 0;
idt[num].flags = flags;
desc.sel = sel;
desc.always0 = 0;
desc.flags = flags;
return desc;
}
extern void isrsyscall(void);