This works fine in bochs, and it's disappointing for my computer (Toshiba Satellite Pro) to instantly reset. After much debugging, CD-Writing and restarting, I worked out that it was when I called a high-numbered interrupt, that it crashed. I can call 32, 33, 34... then I tried the one used in unix systems (0x80) and it works in bochs, but not on my computer.
So I'm completely stuck. Help!
Code: Select all
void CalculateGate(unsigned char* descriptor, void* function)
{
// Get the address.
unsigned int address = (unsigned int)function;
unsigned char* addressSplit = (unsigned char*)&address;
// Set the stuff.
descriptor[0] = addressSplit[0];
descriptor[1] = addressSplit[1];
descriptor[6] = addressSplit[2];
descriptor[7] = addressSplit[3];
// Enable the interrupt.
descriptor[5] |= 0x80;
}
void SetupGates(void* function, unsigned short position, unsigned short count, void* idt)
{
unsigned short t;
idt += position * 8;
for(t = 0; t < count; t++)
{
CalculateGate(idt, function);
idt += 8;
}
}
Code: Select all
; Note that irrelevant code has been cut
push IDTStart
mov eax, 256
push eax
mov eax, 0
push eax
push _itest
call _SetupGates
add esp, 16
lidt[IDTR]
int 32 ; Works.
int 33 ; Works.
int 34 ; Works.
int 0x80 ; Works(bochs). Resets the computer(hardware).
jmp $
_itest:
mov eax, mFoo
push eax
call _Print
add esp, 0x04
iret
mFoo db "Interrupt!", 0x00
IDTR:
dw IDTEnd - IDTStart
dd IDTStart
; This should describe an unprotected flat memory model:
align 8, db 0 ; Optimization!
IDTStart:
times 0x14 dd 0x00000000, 0x00000000 ; Exceptions!
times 0x0C dd 0x00000000, 0x00000000 ; Intel's reserved space.
times 0xD0 dd 0x00080000, 0x00000E00 ; Interrupts for me, interrupts for you.
times 0x10 dd 0x00080000, 0x00000E00 ; Interrupts for the IRQ lines.
IDTEnd: