Page 1 of 1

16bit exception handling question

Posted: Tue Mar 25, 2008 3:36 pm
by Ninjarider
what data is passed when an exception is handles.

lets say the exception is a divide error exception.
the system would call the appropriate code throu the ivt - entry 0
what is the data structure that it pushes onto the stack when calling the appropriate handler. (error code, ip, cs, etc)

Posted: Wed Mar 26, 2008 7:42 am
by Zenith
I'd assume it would be the same as in protected mode, but there's no task switching and CPL stuff... So, all you're basically asking is what the INT opcode does in real mode.

See http://pdos.csail.mit.edu/6.828/2005/re ... 86/INT.htm. It pushes the FLAGS, clears IF/TF, pushes CS, IP. There are no error codes, as exceptions like #PF don't exist.

A list of hardware/software interrupts in real/protected mode can be found here: http://www.bioscentral.com/misc/interrupts.htm. I'd say to ignore any of those that have something like (80386) after them and stick with the ones on the original 8086.

Posted: Wed Mar 26, 2008 3:12 pm
by Ninjarider
thanks for the reading material

Posted: Wed Mar 26, 2008 8:13 pm
by Brendan
Hi,

Just a quick note...
karekare0 wrote:There are no error codes, as exceptions like #PF don't exist.
A general protection fault is entirely possible in real mode (the CPU won't push an error code on the stack for any exception in real mode, probably because of backward compatability).


Cheers,

Brendan

Posted: Thu Mar 27, 2008 9:51 pm
by Ninjarider
ok 1 other question.
int 8 from my understanding are used for 2 things. the system clock irq and double fault exception.

in both 32 and 16, how do you distinguish between the 2?

Posted: Fri Mar 28, 2008 1:34 am
by xyzzy
You can remap the PICs so that they do not conflict. The code below will map IRQs 0 to 15 to IDT entries 32 to 47:

Code: Select all

out8(0x20, 0x11);
out8(0xA0, 0x11);
out8(0x21, 0x20);
out8(0xA1, 0x28);
out8(0x21, 0x04);
out8(0xA1, 0x02);
out8(0x21, 0x01);
out8(0xA1, 0x01);
out8(0x21, 0x0);
out8(0xA1, 0x0);
out8 is the same as outb/outportb.

Posted: Sat Mar 29, 2008 3:09 am
by Ninjarider
ok i get the port numbers but what does all the other stuff do?

Posted: Mon Mar 31, 2008 7:22 am
by Zenith
STFW :wink: http://www.osdev.org/wiki/PIC

Anyway the commands basically program both PICs to trigger IRQs using different interrupts (32-47) instead of the ones in use at 0-15.