Page 1 of 1

Exceptions - reboot

Posted: Tue Jun 29, 2004 11:39 am
by Loader
I got a big problem. When an exceptions occurs, the computer reboots.. I do have filled the IDT, I do load the IDTR... any idea whats wrong? Im doing like this

Disable interrupts
Remapping the PIC / disable IRQs
setting up a IDT-table
load the IDTR
enabling interrupts..

and then I try something like
int a = 1/0;
and the computer reboots (instead of printing a message as the first ISR does)

Re:Exceptions - reboot

Posted: Tue Jun 29, 2004 11:54 am
by Neo
cant rerally help you without seeing what youre doing wrong (or right). :)

Re:Exceptions - reboot

Posted: Tue Jun 29, 2004 1:13 pm
by Loader
Well I?ll show some code then =)
Here?s the structs where I store the IDT and IDTR
struct IDTinterrupt
{
   unsigned short low_offset; // low nibble of offset to handler of interrupt
   unsigned short selector; // GDT selector used
   unsigned short settings; // settings for int
   unsigned short high_offset; // high nibble to handler code
};
typedef struct IDTinterrupt IDTinterrupt;

struct IDTR
{
unsigned short limit; // limit or Size of IDT
struct IDTinterrupt *base; // a pointer to the base of the IDT
};
typedef struct IDTR IDTR;

then I got this:

IDTinterrupt theIDT[256];
IDTR idtr;

void loadIDTR()
{
   idtr.limit = 256*sizeof(IDTinterrupt);
   idtr.base = theIDT;

   IDTR *IDTRptr = &idtr;

   /* load IDTR with lidt */
   asm volatile("LIDT (%0) ": :"p" (IDTRptr));
}

void AddInt(int number, void (*handler)(), int a)
{
   unsigned short selector = 0x08;
   unsigned short settings = 0x8E00;
   unsigned int offset = (unsigned int)handler;


   theIDT[number].low_offset = (offset & 0xFFFF);
   theIDT[number].selector = selector;
   theIDT[number].settings = settings;
   theIDT[number].high_offset = (offset >> 16);
}

void LoadExceptions() {
AddInt(0, int00, 0);
AddInt(1, int01, 0);
AddInt(2, int02, 0);
....
}

the int00.. are stored in a file like this

[extern _int_00]
[global _int00]
_int00:
pusha
push ds
push es
push fs
push gs
call _int_00 ; call a C-function
pop gs
pop fs
pop es
pop ds
popa
iret

of course I disabling interrupts and mask the IRQs when I set it up

Re:Exceptions - reboot

Posted: Tue Jun 29, 2004 2:23 pm
by Loader
hmm I used (packed) on the structs, seems to work better now..how come?

Re:Exceptions - reboot

Posted: Tue Jun 29, 2004 2:30 pm
by Loader
Well it catches the exception now.. but.. what do I do to ignore them? if I write something like

int a = 1/0;
then the ISR for divide by zero will run lots and lots of time..is there anyway for me to "ignore" the exception after it has occured and just procede with the program? I tried
   out(0x20, 0x20); //send PIC EOI command
doesnt work..

Re:Exceptions - reboot

Posted: Tue Jun 29, 2004 2:45 pm
by Pype.Clicker
Loader wrote: hmm I used (packed) on the structs, seems to work better now..how come?
just explained it in the "structs in C" thread :)

You cannot "ignore" and exception. You cannot mask it either. If the exception cannot be dispatched to some handler code, it will raise a "double fault" and the CPU will reset if double fault cannot be dispatched either.

So as soon as you start doing more complex things, provide a simple support for exceptions.

Re:Exceptions - reboot

Posted: Tue Jun 29, 2004 3:48 pm
by Loader
Yeah, I dont wanna ignore the problem, but how can I persue the running? if I got something like this:

...
int a = 1/0;
print("hello");

then when the DBZ exception occurs, it should print something nice to the screen (from the ISR)..and then I want to move on and execute the print("hello")-line..

Re:Exceptions - reboot

Posted: Tue Jun 29, 2004 4:44 pm
by Pype.Clicker
1. locate eip return value on the stack,
2. know the size of the DIV instruction
3. increment eip by that amount
4. return

alternatively, just jmp MoreTests