IDT problems
Posted: Fri Jul 05, 2013 4:12 am
I got some problems with IDT and ISRs. My ISR routines are not getting called after installing the IDTs. My source code
IDT structure : idt.h
idt.c : setting the data
asm.as
isrs.c :Fault handler and isrs install
Kernel main:
IDT structure : idt.h
Code: Select all
struct idt_entry
{
uint16_t base_lo;
uint16_t sel;
uint8_t always0;
uint8_t flags;
uint16_t base_hi;
} __attribute__((packed));
struct idt_entry
{
uint16_t base_lo;
uint16_t sel;
uint8_t always0;
uint8_t flags;
uint16_t base_hi;
} __attribute__((packed));
Code: Select all
void idt_set_gate(uint8_t num, uint64_t base, uint16_t sel, uint8_t flags)
{
idt[num].base_lo = (base & 0xFFFF);
idt[num].base_hi = (base >> 16) & 0xFFFF ;
idt[num].sel = sel;
idt[num].always0 = 0;
idt[num].flags = flags;
}
void idt_install()
{
idtp.limit = (sizeof(struct idt_entry) * 256) - 1;
idtp.base = &idt;
memset(&idt, 0, sizeof(struct idt_entry) * 256);
idt_load();
}
Code: Select all
.global idt_load
idt_load:
lidt idtp
ret
isr0:
cli
push 0
push 0
jmp isr_common_stub
.....
.extern fault_handler
isr_common_stub :
pusha
push %ds
push %es
push %fs
push %gs
mov %ax, 0x10
mov %ds, %ax
mov %es, %ax
mov %fs, %ax
mov %gs, %ax
mov %eax, %esp
push %eax
mov %eax, fault_handler
call %eax
pop %eax
pop %gs
pop %fs
pop %es
pop %ds
popa
add %esp, 8
iret
Code: Select all
void isrs_install()
{
idt_set_gate(0, (unsigned)isr0, 0x08, 0x8E);
......
}
void fault_handler(struct regs *r)
{
if(r->int_no < 32)
{
terminal_writestring(exception_messages[r->int_no]); // array is defined in isrs.c
terminal_writestring("Exception. System Halted!\n");
for(;;);
}
}
Code: Select all
void kernel_main()
{
gdt_install();
idt_install();
isrs_install();
terminal_initialize();
terminal_writestring("Hello, kernel World!\n");
int a = 5/0; // Not printing the exception error here
terminal_writestring("FFTHourtchSThirdecond line : Hello, kernel World!");
}