SoD code problems...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

SoD code problems...

Post by inflater »

Hello,
I'm having a little problem in my BSOD code:
I can't get properly CS:EIP and EFLAGS values from stack :( It always will display something that's terribly wrong (I compared the values between crashed QEMU register dump and "panic'ed Bochs" emulator screen (not the debugger, because it would throw other EIP, logically), I invoked the error on purpose)

Here's my commented code:

Code: Select all

div_error:
	mov   [TempEAX],eax      ;save EAX and all 32bit regs
        mov   [TempEBX],ebx
	mov   [TempECX],ecx
	mov   [TempEDX],edx
	mov   [TempESI],esi
	mov   [TempEDI],edi
        pop   eax                        ;get EIP
        pop   ebx                        ;get CS
	pop   ecx                        ;get EFLAGS
	mov   [EIPValue],eax      ;store EIP
	mov   [CSValue],ebx       ;store CS
	mov   [EFlagsValue],ecx  ;store Eflags
	push  ecx                       ;and return them on the stack:
	push  bx                        ;sometime there will be a option
	push  eax                      ;about continuing in OS execution
	mov   eax,TempEAX       ;and ignoring the BSOD
	mov   ebx,TempEBX       ;return the registers
	mov   ecx,TempECX
	mov   edi,Div_Flt            ;just a simple exception handling
	push  edx                      ;save EDX
	mov   edx,00h               ;exception handling
	mov   [CanContinue_BSOD],1 ;....
	call  DoException            ;draw the RSOD etc.
	iret                                ;this will never trigger
Thanks for your advice...
inflater
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

A stab at the dark: I don't know of QEMU providing register dumps, maybe you are looking at cs:eip/eflags of the emulator?

The best reference would be the state of bochs at the faulting instruction. You should use the debugger feature for that.

Also, could you give you the reported CS:EIP, SS:ESP and EFLAGS and the actual values at the exception for reference?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post by inflater »

Combuster wrote:A stab at the dark: I don't know of QEMU providing register dumps, maybe you are looking at cs:eip/eflags of the emulator?

The best reference would be the state of bochs at the faulting instruction. You should use the debugger feature for that.

Also, could you give you the reported CS:EIP, SS:ESP and EFLAGS and the actual values at the exception for reference?
Well, QEMU provides register dumps when a serious error has occured. So QEMU crashed and supplied the register dump before exiting. Bochs has freezed with my RSOD and with that data. Looking at the Bochs debugger wouldn't help much as EAX, EBX, ECX and EDX are changed in my BSOD code. Of course I should add the restoring function (mov eax,[TempEAX]) to the very end of my code if I want to compare my results from my RSOD with Bochs.

Everything except EBX, CS:EIP, EFLAGS is correct (EAX, ECX, CR0, etc.), with that QEMU register dump-out, even SS:ESP is correct.

Okay Combuster, i will try to add the "restoring" function to the end of the code and I will post my results :)

inflater
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post by inflater »

Okay, the exception is INT 0x06 - Invalid instruction. I added the "register restoring" function as the EAX, EBX, ECX, EDX... registers (except cs:eip, eflags and ss:esp) will be loaded from their backups (like mentioned, mov eax,[TempEAX], etc).

SoD reported codes:
EAX=0
EBX=0xC7B8 [it's fixed now]
ECX=0
EDX=0
ESI=0xA84A
EDI=0x18
ES,FS,GS,SS,DS=0x18
ESP=0xFA8
CS=0x10
EIP=0xED5
CR0=0x00000011
EFLAGS=0x00010282
EBP=0x00400002

Bochs reported codes:
EAX=0
EBX=0xc7b8
ECX=0
EDX=0
ESI=0xA84A
EDI=0x18
ES,FS,GS,SS,DS=0x18
CS=0x10
EIP=0x691D (it shows EIP of instruction JMP $)
EFLAGS=0x202
EBP=0x00400002
ESP=0xfa8

I'll try what is triggering INT 0x06 (I lied, I didn't trigger that interrupt by myself...) and it's correct EIP in Bochs debugger by using these infinite loop things.

inflater
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
Post Reply