so anyway i made a little function called die() which is just some nops and i call it from within the ISR, it calls just fine and return just fine but when i get to the iret, it dies saying something about an LDT (not really logical here...) so i have examened the stack and intel book 3 and have come to the understanding that before an interrupt as part of the interrupts "call" (if you could call it that) that EIP, CS and eflags are pushed onto the stack along with an error code. i see all this (except what i think is eflags looks sortof abnormal) and have the notes to myself here
Code: Select all
right before iret!!!!
esp : 0x00103820
esp + 4: 0x00000001
esp + 8: 0x00000005
esp + 12: 0x001007eb (return address, pushed EIP)
esp + 16: 0x00000008 (CS)
esp + 20: 0x00010006 (eflags *guess but complies with intel manual)
esp + 24: 0x00000042
esp + 28: 0x00000028
esp + 32: 0xc0000000
esp + 36: 0x00000007
esp + 42 00000000000i have found out that if i have 3 pops (just to get rid of the junk on the stack (the junk being 0x001007d6 (what looks to be a valid return address for something, not the ISR or function though), 0x00000001 (no idea what this is but 0x1 is the second arg to die() although i see it push the args for die() up earlier and then clean up after itself), and 0x5 and i have no clue what this would be) then if i have these 3 pops then the address at which the interrupt was called (the address of the divby0) goes into eip and cs is correctly popped from the stack and eflags is popped back (although it is not the same as it was before hmmmmm). the thing about this is that since eip is now the instruction that called the interrupt we go into an endless loop of calling the interrupt.
on to the code...
the ISR that is called and the function that it then calls
Code: Select all
void die(char *message, byte halt) //byte can be a bool, or just a bit
{
//clear_screen();
//k_print(message);
// k_print("cought an exception", 2);
// k_print("cought an exception", 3);
// k_print("cought an exception", 7);
asm("nop");
asm("nop");
asm("nop");
//k_print("a fatal\n", 3);
// ints_off();
// asm("hlt");
// outb(MASTER, EOI); //not sure why we have to do this, find out
asm("nop");
}
inline void int00()
{
// asm("pusha");
// asm("push %ds");
// asm("movw $0x10, %ax"); //0x10 (16)is the data segment we setup in the GDT
// asm("movw %ds, %ax");
asm("nop");
asm("nop");
die("aaaa", true);
asm("nop");
asm("nop");
asm("nop");
// asm("pop %ds");
// asm("popa");
asm("nop");
asm("nop");
// there are 2 random things on the stack i have no idea what they are, a reasonable address, then 0x1, then 0x05
//under that is the usuial eip, cs and eflags
//nasty nasty nasty!
asm("popl %eax");
asm("nop");
asm("nop");
asm("popl %eax");
asm("nop");
asm("nop");
asm("popl %eax");
asm("nop");
asm("nop");
asm("nop");
asm("iret");
}i am compiling with
Code: Select all
gcc -fno-builtins -fomit-frame-pointer -c *.calso in intel book3 it says that an interrupt sets up the stack like
esp: error code (what would this be, just 00 for divby0 exception?)
esp + 4: EIP
esp + 8: CS
esp + 12: EFLAGS
anyhow i have tried everything i can think of and googled my heart out, hopefully someone can help.
Thanks for your Time,
Libber
