diff --git a/kernel/cpu/idt.c b/kernel/cpu/idt.c index 1e5fb448..71480d2a 100644 --- a/kernel/cpu/idt.c +++ b/kernel/cpu/idt.c @@ -2,6 +2,7 @@ * This file is part of ToaruOS and is released under the terms * of the NCSA / University of Illinois License - see LICENSE.md * Copyright (C) 2011-2013 Kevin Lange + * Copyright (C) 2015 Dale Weiler * * Interrupt Descriptor Tables * @@ -9,55 +10,44 @@ #include #include -/* - * IDT Entry - */ -struct idt_entry { - unsigned short base_low; - unsigned short sel; - unsigned char zero; - unsigned char flags; - unsigned short base_high; -} __attribute__((packed)); +typedef struct { + uint16_t base_low; + uint16_t sel; + uint8_t zero; + uint8_t flags; + uint16_t base_high; +} __attribute__((packed)) idt_entry_t; -/* - * IDT pointer - */ -struct idt_ptr { - unsigned short limit; +typedef struct { + uint16_t limit; uintptr_t base; -} __attribute__((packed)); +} __attribute__((packed)) idt_pointer_t; -struct idt_entry idt[256]; -struct idt_ptr idtp; +/* In the future we may need to put a lock on the access of this */ +static struct { + idt_entry_t entries[256]; + idt_pointer_t pointer; +} idt __attribute__((used)); + +#define ENTRY(X) (idt.entries[(X)]) + +typedef void (*idt_gate_t)(void); extern void idt_load(uintptr_t); -/* - * idt_set_gate - * Set an IDT gate - */ -void idt_set_gate( - unsigned char num, - void (*base)(void), - unsigned short sel, - unsigned char flags - ) { - idt[num].base_low = ((uintptr_t)base & 0xFFFF); - idt[num].base_high = ((uintptr_t)base >> 16) & 0xFFFF; - idt[num].sel = sel; - idt[num].zero = 0; - idt[num].flags = flags | 0x60; +void idt_set_gate(uint8_t num, idt_gate_t base, uint16_t sel, uint8_t flags) { + ENTRY(num).base_low = ((uintptr_t)base & 0xFFFF); + ENTRY(num).base_high = ((uintptr_t)base >> 16) & 0xFFFF; + ENTRY(num).sel = sel; + ENTRY(num).zero = 0; + ENTRY(num).flags = flags | 0x60; } -/* - * idt_install - * Install the IDTs - */ void idt_install(void) { - idtp.limit = (sizeof(struct idt_entry) * 256) - 1; - idtp.base = (uintptr_t)&idt; - memset(&idt, 0, sizeof(struct idt_entry) * 256); + idt_pointer_t *idtp = &idt.pointer; + idtp->limit = sizeof idt.entries - 1; + idtp->base = (uintptr_t)&ENTRY(0); + memset(&ENTRY(0), 0, sizeof idt.entries); - idt_load((uintptr_t)&idtp); + idt_load((uintptr_t)idtp); }