i am trying to fill IDT. Firstly I created c function to fill interrupt descriptor (based on brokenthorn.com tutorial)
Code: Select all
int i86_install_ir( uint32_t i, uint16_t flags, uint16_t selector, void (*irq)(void) )
{
uint32_t uiBase = (uint32_t)irq;
_idt[i].baseLo = (uint16_t)uiBase & 0xFFFF;
_idt[i].baseHi = (uint16_t) (uiBase >> 16) & 0xFFFF;
_idt[i].reserved = 0;
_idt[i].flags = (uint8_t)flags;
_idt[i].selector = selector;
return 0;
}
Code: Select all
GLOBAL idete
idete:
PUSH ebp
MOV ebp,esp ; making stack frame
PUSHA ; push all registers to the stack
MOV ecx,260 ; numer of loops (i did 4 more to be sure ;) )
MOV eax,[ebp+8] ; pointer to the array
petla:
MOV ebx,_idt_halt_handler ; pointer to the interrupt handler
MOV [eax],bx ; offset 0-15 of the base
ADD eax,2
MOV word [eax],0x8 ; segment selector (0x8 for code, ring0, 4gb)
ADD eax,2
MOV byte [eax],0x0 ; reserved, should be 0
ADD eax,1
MOV byte [eax],0x8E ; 10001110 interrupt, 32bit, ring 0, present
ADD eax,1
SHR ebx,16 ; get offset 16-31 of the base...
MOV [eax],bx ; ... and put it
ADD ebx,2
LOOP petla
POPA ; popping all registers
POP ebp ; deleting stack frame
RET
_idt_halt_handler:
HLT
IRET
Code: Select all
int i86_idt_initialize( uint16_t codeSel )
{
int i=0;
_idtr.base = (uint32_t)&_idt;
_idtr.limit = sizeof( struct idt_descriptor) * I86_MAX_INTERRUPTS - 1;
memoryset( (void*)&_idt[0], 0, sizeof( struct idt_descriptor)*I86_MAX_INTERRUPTS );
idete(&_idt[0]);
/*for( i=0; i<I86_MAX_INTERRUPTS;++i )
{
i86_install_ir( i, I86_IDT_DESC_PRESENT | I86_IDT_DESC_BIT32, codeSel, i86_halt_handler );
}*/
__asm__ __volatile__ ( "LIDT _idtr\n\t");
}