luxos/Kernel/hal/cpu/idt.c

46 lines
1.4 KiB
C
Raw Normal View History

2021-09-14 15:34:14 +00:00
/******************************************************************
* idt.h - INTERRUPT DESCRIPTOR TABLE *
* Contains structures and function declarations for IDT *
******************************************************************/
#include <stdlib.h>
2021-09-14 15:34:14 +00:00
#include "idt.h"
2021-09-14 15:29:04 +00:00
extern void IdtLoad();
2021-09-14 15:46:50 +00:00
/* Declare an IDT of 256 entries. */
struct IdtEntry idt[256];
struct IdtPointer idtp;
2021-09-14 15:29:04 +00:00
/* Use this function to set an entry in the IDT. Alot simpler
* than twiddling with the GDT ;) */
void IdtSetGate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags)
2021-09-14 15:29:04 +00:00
{
/* The interrupt routine's base address */
idt[num].base_lo = (base & 0xFFFF);
idt[num].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;
}
struct IdtEntry* IdtGetGate(unsigned char num)
2021-09-14 15:34:14 +00:00
{
return &idt[num];
}
2021-09-14 15:29:04 +00:00
/* Installs the IDT */
void IdtInstall()
2021-09-14 15:29:04 +00:00
{
/* Sets the special IDT pointer up, just like in 'gdt.c' */
2021-09-14 15:46:50 +00:00
idtp.limit = (sizeof (struct IdtEntry) * 256) - 1;
2021-09-14 15:34:14 +00:00
idtp.base = (unsigned int)&idt;
2021-09-14 15:29:04 +00:00
/* Clear out the entire IDT, initializing it to zeros */
2021-09-14 15:46:50 +00:00
memset (&idt, 0, sizeof(struct IdtEntry) * 256);
2021-09-14 15:29:04 +00:00
/* Points the processor's internal register to the new IDT */
IdtLoad();
2021-09-14 15:29:04 +00:00
}