need some help with my screen of death

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.
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

need some help with my screen of death

Post by Pyrofan1 »

my screen of death is invoked by exceptions
my regs struct

Code: Select all

struct regs
{
    unsigned int gs, fs, es, ds;      /* pushed the segs last */
    unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax;  /* pushed by 'pusha' */
    unsigned int int_no, err;    /* our 'push byte #' and ecodes do this */
    unsigned int eip, cs, eflags, useresp, ss;   /* pushed by the processor automatically */ 
};
my isr_common

Code: Select all

.type isr_common,@function
isr_common:
pusha
push %ds
push %es
push %fs
push %gs
call RSOD
sti
iret
RSOD

Code: Select all

void RSOD(struct regs r)
{
	text_color(WHITE,RED);
	clrscr();

	Puts("ChaoS has encounted a problem\n");
	if(r.int_no<19)
	{
		Printf("%s, interrupt %d, error %d\n",messages[r.int_no],r.int_no,r.err);
	}
	Puts("Registers:\n");
	Printf("eax: %d ebx: %d ecx: %d\n",r.eax,r.ebx,r.ecx);
	Printf("edx: %d esi: %d edi: %d\n",r.edx,r.esi,r.edi);
	Printf("ebp: %d esp: %d gs: %d\n",r.ebp,r.esp,r.gs);
	Printf("fs: %d es: %d ds: %d\n\n",r.fs,r.es,r.ds);
	Printf("EFLAGS: %d\neip: %d\ncs: %d\n",r.eflags,r.eip,r.cs);
	Printf("ss: %d\n",r.ss);
	asm("hlt");
}
this prints the contents of the rodata section of my executable.
User avatar
Bughunter
Member
Member
Posts: 94
Joined: Mon Dec 18, 2006 5:49 am
Location: Netherlands
Contact:

Post by Bughunter »

Why do a 'sti' and 'iret' after 'call RSOD', it won't ever return.

As for the rest of your post, what exactly is your question? Where do you want help?
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

Why do a 'sti' and 'iret' after 'call RSOD', it won't ever return.
that was just left over code
Where do you want help?
well i'd like it to do what it's suppose to do instead of doing this
this prints the contents of the rodata section of my executable.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

well in your assembly you don't push the the struct r parameter of the c function. so that would be pointing anywhere producing the garbage you discribe.

insert a push %esp before the call. if this doesn't work then your c function should be void RSOD(struct regs * r)
Author of COBOS
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

I would also suggest that for debugging it would be a lot more useful to have hex numbers rather than decimal - it will tend to flag up bits that should be set but aren't in e.g. the EFLAGS register.

Cheers,
Adam
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

insert a push %esp before the call. if this doesn't work then your c function should be void RSOD(struct regs * r)
nope, didn't work
useful to have hex numbers
i know that
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Post by t0xic »

@Pyrofan1

Try and use:

Code: Select all

struct regs *r
I found the same problem you did when regs wasn't a pointer

--t0xic
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

nope :(
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

It should work if you are correctly passing the pointer. Could we see your source files, please? Also, is the value of ESP in Bochs what you would expect?

Just one thought - if an exception has occurred, you should think about loading your segment registers with known "good values" in case they are scrapped.

Cheers,
Adam
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Post by t0xic »

Here's my common stub... my gsod works perfectly so try this:
Try using an indirect push of esp, and load the segments like AJ said
Notice the following:

Code: Select all

mov eax, esp
push eax

Code: Select all

_isrcommonstub:
    pusha
    push ds
    push es
    push fs
    push gs
    mov ax, 0x10
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    mov eax, esp
    push eax
    mov eax, _fault_handler
    call eax
    pop eax
    pop gs
    pop fs
    pop es
    pop ds
    popa
    add esp, 8
    iret
--t0xic
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

Also, is the value of ESP in Bochs what you would expect?
I don't use bochs or qemu. also i'm not triggering any exceptions (purposfully)
RSOD

Code: Select all

void RSOD(struct regs *r)
{
	text_color(WHITE,RED);
	clrscr();

	Puts("ChaoS has encounted a problem\n");
	if(r->int_no<19)
	{
		Printf("%s, interrupt %d, error %d\n",messages[r->int_no],r->int_no,r->err);
	}
	else
	{
		Printf("Reserved, interrupt %d, error %d\n",r->int_no,r->err);
	} 

	Puts("Registers:\n");
	Printf("eax: %x ebx: %x ecx: %x\n",r->eax,r->ebx,r->ecx);
	Printf("edx: %x esi: %x edi: %x\n",r->edx,r->esi,r->edi);
	Printf("ebp: %x esp: %x gs: %x\n",r->ebp,r->esp,r->gs);
	Printf("fs: %x es: %x ds: %x\n",r->fs,r->es,r->ds);
	Printf("EFLAGS: %x\neip: %x\ncs: %x\n",r->eflags,r->eip,r->cs);
	Printf("ss: %x\n",r->ss);
	asm("hlt");
}
Attachments

[The extension s has been deactivated and can no longer be displayed.]

User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Pyrofan1 wrote: I don't use bochs or qemu.
Please do. It will make debugging this much easier.

I can't see any glaringly obvious mistakes in your code, although the syntax is not one I'm familiar with - I assume it's AT&T.

You might still try to put known good segments in to the segment registers. Out of interest, if you aren't causing any exceptions, how do you know that your exception handlers aren't working :?:

Cheers,
Adam
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

Please do. It will make debugging this much easier.
I tried to, but qemu wouldn't run it
You might still try to put known good segments in to the segment registers.
i tried that, didn't work
Out of interest, if you aren't causing any exceptions, how do you know that your exception handlers aren't working
because when i boot, i get a red screen
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

so it could be your Puts that fails in case of an exeption handler. or do you see white text also.

edit: hmm you told this already. can we see the linker script?
Author of COBOS
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

I do see white text.
Post Reply