toaruos/kernel/cpu/idt.c

61 lines
1.0 KiB
C
Raw Normal View History

/* vim: tabstop=4 shiftwidth=4 noexpandtab
*
* Interrupt Descriptor Tables
*
*/
2011-01-16 06:11:17 +03:00
#include <system.h>
2011-12-27 05:23:58 +04:00
#include <logging.h>
2011-01-16 06:11:17 +03:00
/*
* IDT Entry
*/
struct idt_entry {
unsigned short base_low;
unsigned short sel;
unsigned char zero;
unsigned char flags;
unsigned short base_high;
} __attribute__((packed));
2011-03-05 06:05:03 +03:00
/*
* IDT pointer
*/
2011-01-16 06:11:17 +03:00
struct idt_ptr {
unsigned short limit;
2011-01-18 03:34:50 +03:00
uintptr_t base;
2011-01-16 06:11:17 +03:00
} __attribute__((packed));
struct idt_entry idt[256];
struct idt_ptr idtp;
2013-06-06 10:10:36 +04:00
extern void idt_load(void);
2011-01-16 06:11:17 +03:00
/*
* idt_set_gate
* Set an IDT gate
*/
2013-06-06 10:10:36 +04:00
void idt_set_gate(
2011-01-16 06:11:17 +03:00
unsigned char num,
2013-06-06 10:10:36 +04:00
void (*base)(void),
2011-01-16 06:11:17 +03:00
unsigned short sel,
unsigned char flags
) {
2013-06-06 10:10:36 +04:00
idt[num].base_low = ((uintptr_t)base & 0xFFFF);
idt[num].base_high = ((uintptr_t)base >> 16) & 0xFFFF;
2011-01-16 06:11:17 +03:00
idt[num].sel = sel;
idt[num].zero = 0;
2011-03-30 06:08:56 +04:00
idt[num].flags = flags | 0x60;
2011-01-16 06:11:17 +03:00
}
/*
* idt_install
* Install the IDTs
*/
2013-06-06 10:10:36 +04:00
void idt_install(void) {
2011-01-16 06:11:17 +03:00
idtp.limit = (sizeof(struct idt_entry) * 256) - 1;
2011-01-18 03:22:48 +03:00
idtp.base = (uintptr_t)&idt;
2011-01-16 06:11:17 +03:00
memset(&idt, 0, sizeof(struct idt_entry) * 256);
idt_load();
}