cfenollosa_os-tutorial/18-interrupts/cpu/idt.c
ppw a61be311da
fix the multiple definition of idt & idt_reg
remove the definition of idt & idt_reg in 'idt.h', which is included by 2 files and causes multiple definition.
Definite the variable idt & idt_reg here to solve the problem.
2020-09-21 10:20:48 +08:00

22 lines
569 B
C

#include "idt.h"
#include "../kernel/util.h"
#define IDT_ENTRIES 256
idt_gate_t idt[IDT_ENTRIES];
idt_register_t idt_reg;
void set_idt_gate(int n, u32 handler) {
idt[n].low_offset = low_16(handler);
idt[n].sel = KERNEL_CS;
idt[n].always0 = 0;
idt[n].flags = 0x8E;
idt[n].high_offset = high_16(handler);
}
void set_idt() {
idt_reg.base = (u32) &idt;
idt_reg.limit = IDT_ENTRIES * sizeof(idt_gate_t) - 1;
/* Don't make the mistake of loading &idt -- always load &idt_reg */
__asm__ __volatile__("lidtl (%0)" : : "r" (&idt_reg));
}