I am having trouble getting my IDT to work using C Code. I have a fully working one that is done in ASM, however I want to initialize and manage it in C. Below is the details of my problem :-
I have these constants defined
#define MEMORY_KERNEL_DATA 0x400000
#define KERNEL_IDT_LOCATION 0x800
Before I jump to my kernel I load the IDTR with the appropriate stuff (ie: size and base address) and then the first thing my kernel does is setup the IDT. Below is what the kernel does :
This function installs interrupt gate handlers
Code: Select all
DWORD INSTALL_INTERRUPT_GATE( BYTE bIdx, WORD wDesc, DWORD dwAddr, WORD wAttrs )
{
// Local data
DWORD dwPrevAddr;
// Get a ptr to the entry
WORD* wIdt = (WORD*)(MEMORY_KERNEL_DATA + KERNEL_IDT_LOCATION + (bIdx * 8));
// Save the return address
dwPrevAddr = ((wIdt[3] << 16) | wIdt[0]);
// Write the entry
*wIdt = (WORD)(dwAddr);
wIdt += 2; // I have tried wIdt++ and it doesn't work either
*wIdt = wDesc;
wIdt += 2;
*wIdt = wAttrs;
wIdt += 2;
*wIdt = (WORD)(dwAddr >> 16);
// Return the previous handler address
return dwPrevAddr;
}
Code: Select all
VOID PIC_REMAP()
{
// ICW1
OUTPORTB( 0X20, 0X11 );
OUTPORTB( 0XA0, 0X11 );
// ICW2
OUTPORTB( 0X21, 0X20 );
OUTPORTB( 0XA1, 0X28 );
// ICW3
OUTPORTB( 0X21, 0X04 );
OUTPORTB( 0XA1, 0X02 );
// ICW4
OUTPORTB( 0X21, 0X01 );
OUTPORTB( 0XA1, 0X01 );
// OPEN IRQ'S
OUTPORTB( 0X21, 0X00 );
OUTPORTB( 0XA1, 0X00 );
}
Once this is all done I STI() and I get the 3rd exception error, can anyone see the problem in this code, I think that it is my INSTALL_INTERRUPT_GATE() function.
thanks.