Page 1 of 1

Division By Zero Exception not printed on emulation(both boc

Posted: Thu Apr 20, 2006 11:58 pm
by asmboozer
I continued the tutorial
http://www.osdever.net/bkerndev/index.php?the_id=90
now comes to Sections

Introduction
Getting Started
The basic kernel
Linking sources
Printing onscreen
The GDT
The IDT
Writing ISRs

the main function is
void kmain()
{
/* You would add commands after here */
int i ;
gdt_install();
idt_install();
isrs_install();

init_video();

puts("isrs:Hello World!\n");
i = 10/0;
putch(i);
}

in the kmain, I call i=10/0 to test Division By Zero Exception ,
but both vmware and boch won't print the Division By Zero Exception on screen.

Re:Division By Zero Exception not printed on emulation(both

Posted: Fri Apr 21, 2006 1:04 am
by Pype.Clicker
considering your level, may i suggest once again that you took the time to compile a version of BOCHS that has an internal debugger and take the time to consider the debug commands

Code: Select all

pbreak 0x100000
c
n
n
n ... (until the "div ..." instruction is met) 
?

Oh, just a hint: make sure the compiler let you do the "i=10/0" ... that seems sooo obvious it's something that cannot be done. Pick your .o file and try "objdump -drS <yourKernel.o> | less" then search for the "div ..."

If everything was fine, you will start debugging step by step from your kmain() function (or wrapper), execute to "n"ext instruction until you find the "div xxx", then "s"tep over it, which will trigger the exception and jump to your handler code. You should then have more tools to figure out why nothing gets printed ...

Re:Division By Zero Exception not printed on emulation(both

Posted: Fri Apr 21, 2006 3:15 am
by asmboozer
Pype.Clicker wrote:
Oh, just a hint: make sure the compiler let you do the "i=10/0" ... that seems sooo obvious it's something that cannot be done. Pick your .o file and try "objdump -drS <yourKernel.o> | less" then search for the "div ..."
the boch.out logged

Code: Select all

00072410423e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
00072410423i[CPU0 ] protected mode
00072410423i[CPU0 ] CS.d_b = 32 bit
00072410423i[CPU0 ] SS.d_b = 32 bit
00072410423i[CPU0 ] | EAX=0000000a  EBX=0002bd20  ECX=00000000  EDX=00000000
00072410423i[CPU0 ] | ESP=00103ff0  EBP=00067ec4  ESI=0002be3f  EDI=0002be40
00072410423i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf ZF af PF cf
00072410423i[CPU0 ] | SEG selector     base    limit G D
00072410423i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00072410423i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 000fffff 1 1
00072410423i[CPU0 ] |  DS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00072410423i[CPU0 ] |  SS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00072410423i[CPU0 ] |  ES:0010( 0002| 0|  0) 00000000 000fffff 1 1
00072410423i[CPU0 ] |  FS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00072410423i[CPU0 ] |  GS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00072410423i[CPU0 ] | EIP=00100296 (00100296)
00072410423i[CPU0 ] | CR0=0x00000011 CR1=0 CR2=0x00000000
00072410423i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00072410423i[CPU0 ] >> f7
00072410423i[CPU0 ] >> f9
00072410423i[CPU0 ] >> : idiv eax, ecx
00072410423i[SYS  ] bx_pc_system_c::Reset(SOFTWARE) called
00072410423i[APIC0] local apic in CPU 0 initializing
If everything was fine, you will start debugging step by step from your kmain() function (or wrapper), execute to "n"ext instruction until you find the "div xxx", then "s"tep over it, which will trigger the exception and jump to your handler code. You should then have more tools to figure out why nothing gets printed ...
it sounds very nice to have the ablity to step over it, I would get the source and compile a one with debug supported.
thanks.

Re:Division By Zero Exception not printed on emulation(both

Posted: Fri Apr 21, 2006 5:44 am
by Pype.Clicker
asmboozer wrote: the boch.out logged

Code: Select all

00072410423e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
...
00072410423i[CPU0 ] >> : idiv eax, ecx
00072410423i[SYS  ] bx_pc_system_c::Reset(SOFTWARE) called
00072410423i[APIC0] local apic in CPU 0 initializing
That's clearly a triple fault: while trying to handle the division by zero, there has been another fault (GPF, most likely) and even the "double fault" handler couldn't work properly.

I suggest you have a look at the TroubleShooting pages of the FAQ: you might find more suggestions to see what's going wrong here.