Debug function
Debug function
Im having problems with my debug function that prints the values of the registers when a exception is thrown. I am able to print out all the messages, but the debug info doesnt get displayed.
What kind of designs are you using for this. Maybe someone could post their own design and code to see why my codes not working.
This is what I have so far and its not working.
[attachment deleted by admin]
What kind of designs are you using for this. Maybe someone could post their own design and code to see why my codes not working.
This is what I have so far and its not working.
[attachment deleted by admin]
Re:Debug function
I use a similar mechanism, but I pass a structure called context_t to the function - which is located at the head of the task control block for the faulting process/thread.
What do you pass to the function at the time of call? the context of the *current* process or something like that?
What do you pass to the function at the time of call? the context of the *current* process or something like that?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Debug function
what if you use printk instead of debug to show the registers ?
Re:Debug function
Im not actually sure what you mean.I use a similar mechanism, but I pass a structure called context_t to the function - which is located at the head of the task control block for the faulting process/thread.
What do you pass to the function at the time of call? the context of the *current* process or something like that?
[pype]When I use printk, I get the same output as I stated previously above.
Re:Debug function
In short: Where do you save the registers upon exception?
Do you pass the proper adress of this region to the exception handler? You just pass the bottom of it to the handler, CAST the adress to some pointer of type fault_t * (in your case) and after that read out the values!
Do you push the needed adress to the stack prior to the call to fault handler?
well, further, in my opinion it should be
then you can access the elements of this structure with the arrow-operator ->.
Do you pass the proper adress of this region to the exception handler? You just pass the bottom of it to the handler, CAST the adress to some pointer of type fault_t * (in your case) and after that read out the values!
Do you push the needed adress to the stack prior to the call to fault handler?
well, further, in my opinion it should be
Code: Select all
void fault_handler(fault_t *regs)
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Debug function
one thing i'm unsure of is:
a) does it display "eax=..." but with nonsense info
b) does it display "eax=" and then stop displaying (it could be failing to display hex numbers or something alike)
c) does it displays no "eax=" stuff at all.
Probably seeing your printk / debug would help diagnosis. In case (c),i suspect something like damaged console information or display buffer ... i would suggest then to dump registers as low level as you can (i.e. hardcoding or something alike
In case (a), i would suspect a misuse of fault_t. As BI suggested, i think using fault_t* as the argument makes more sense though it actually depend on how you prepare the arguments on the stack... Showing us this preparation could help aswell...
a) does it display "eax=..." but with nonsense info
b) does it display "eax=" and then stop displaying (it could be failing to display hex numbers or something alike)
c) does it displays no "eax=" stuff at all.
Probably seeing your printk / debug would help diagnosis. In case (c),i suspect something like damaged console information or display buffer ... i would suggest then to dump registers as low level as you can (i.e. hardcoding
Code: Select all
while (register_val) VRAM[offset++]=hexdigit[register_val&0x0F]; register_val>>4;
In case (a), i would suspect a misuse of fault_t. As BI suggested, i think using fault_t* as the argument makes more sense though it actually depend on how you prepare the arguments on the stack... Showing us this preparation could help aswell...
Re:Debug function
BeyondInfinity:
Pype:
Will this piece of code work without any modifications on my part?
I push all the registers including segment registers to the stack, call the handlers, pop the registers off the stack, and iret.Where do you save the registers upon exception?
What exactly do you mean by this?Do you pass the proper adress of this region to the exception handler?
No, should I?Do you push the needed adress to the stack prior to the call to fault handler?
Pype:
Neither of the above. It displays exactly what I type, but its not supposed to. Its supposed to print out the register info.a) does it display "eax=..." but with nonsense info
b) does it display "eax=" and then stop displaying (it could be failing to display hex numbers or something alike)
c) does it displays no "eax=" stuff at all.
Code: Select all
while (register_val) VRAM[offset++]=hexdigit[register_val&0x0F]; register_val>>4;
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:Debug function
Hmmm ... still, we don't know where you take the values for the registers from, do we?
you need an area where to push the registers to --- the stack. You further need to save the position of this stack after all the pushing has been done and *before* you are calling the handler routine. Mark, we are still in the isr-prologue.
Say, your stack is located at an adress saved in p->stack. This variable is accessible in the module of your c exception handler too. The adress is (for inconvenience *gg*) stored as an integer.
Say further, we have all the pushing done already. we save current esp in p->stack.
In your exception handler, you have this function dump_regs(fault_t *regs);
You have to call it with the following:
dump_regs((fault_t *)p->stack);
What I wanna know is: how are you doing it in order to achieve a successful register dump?
you need an area where to push the registers to --- the stack. You further need to save the position of this stack after all the pushing has been done and *before* you are calling the handler routine. Mark, we are still in the isr-prologue.
Say, your stack is located at an adress saved in p->stack. This variable is accessible in the module of your c exception handler too. The adress is (for inconvenience *gg*) stored as an integer.
Say further, we have all the pushing done already. we save current esp in p->stack.
In your exception handler, you have this function dump_regs(fault_t *regs);
You have to call it with the following:
dump_regs((fault_t *)p->stack);
What I wanna know is: how are you doing it in order to achieve a successful register dump?
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Debug function
i guess what BI suggests you is something like what i sketched on the attached figure ...beyondsociety wrote: BeyondInfinity:I push all the registers including segment registers to the stack, call the handlers, pop the registers off the stack, and iret.Where do you save the registers upon exception?What exactly do you mean by this?Do you pass the proper adress of this region to the exception handler?No, should I?Do you push the needed adress to the stack prior to the call to fault handler?
Well, actually, not really...Will this piece of code work without any modifications on my part?
Code: Select all
char hexdigits[]="0123456789abcdef";
int nb=<the amount of dwords you wish to print>;
dword *values=<the address of your dump>;
char *VRAM=<the address of your screen>;
memset(VRAM,0x07,80*25*2);
while (nb) {
int offset;
dword reg;
reg=*values;
for (offset=0;offset<16;offset+=2) {
VRAM[offset]=hexdigits[reg&0x0f];
reg=reg>>4;
}
VRAM+=160;
values++;
nb--;
}

[attachment deleted by admin]
Re:Debug function
This is what I call to save the registers before I call the exception handleryou need an area where to push the registers to --- the stack. You further need to save the position of this stack after all the pushing has been done and *before* you are calling the handler routine. Mark, we are still in the isr-prologue.
Code: Select all
; Save registers
pushad ; Push segment registers
push ds
push es
push fs
push gs
; Put known values in segment registers
mov ax, 0x10
mov ds, eax
mov es, eax
mov fs, eax
mov gs, eax
mov eax, 1
push eax
call _fault_handler
; Restore registers
pop gs
pop fs
pop es
pop ds
popad ; Pop segment registers
iret
Re:Debug function
Hm, I don't know what you think where to get the values of the registers at the time of fault from, but you need to tell your function: Hey, *here* they are stored, be it an adress on the stack (esp holds an adress!), be it a global variable.Code: Select all
correction for your fault handler: declare it as: void fault_handler(int errno,fault_t *regs); ; Save registers pushad ; Push segment registers push ds???????????? push es??? push fs push gs ??? ; Put known values in segment registers mov ax, 0x10 mov ds, eax mov es, eax mov fs, eax mov gs, eax mov eax,esp ;we save the contents of esp for the call; push eax ;we move them onto the stack mov eax, 1 ; I reckon this is the errno? push eax call _fault_handler ;(like '_fault_handler(1,(fault_t *)esp)'!!) ;remove the args from the stack. might also be done with ;add esp,8: twice the size of int for we have pushed two args pop ebx pop ebx ; Restore registers pop gs???????????? pop fs pop es pop ds popad ; Pop segment registers iret
Don't forget: registers (like eax or esp) are located on/in the cpu. with these beasts the cpu does most of the grunt work. You need to save them - f. ex. on the stack, if you wanna analyze them, before they are changed due to the *next* function call, operation or what so ever.
look closely at pypes sketch. It hit's the nail on the head.
stay safe
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Debug function
note: if you declare
and then use
it can also work, as the C code will believe what you pushed on the stack was a copy of a structure for it to work on. Pick the one you prefer 
Code: Select all
struct fault_cpu_status {
int errno;
dword gs;
dword fs;
...
dword esp; // -- the order of pushad' registers should be
dword ebp; // checked in the Holy Intel Manual for i
...
dword ecx; // cannot remember it for sure
dword eax; // --
dword errcode;
dword eip;
dword cs;
}
Code: Select all
void fault_handler(struct cpu status) {
...
}

Re:Debug function
... hehe, just got this idea ...
one push to save them
one push to fetch them
and in the structure bind them.
muuuuaaahahahaha!
Oh, and if you 'vn't yet noticed it, I'm in a behemoth mood. *rofl*
one push to save them
one push to fetch them
and in the structure bind them.
muuuuaaahahahaha!
Oh, and if you 'vn't yet noticed it, I'm in a behemoth mood. *rofl*
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Debug function
Oh Mighty Gods! BIlazy -- aka the Lord of the DPL0 Ring strikes again ... Fortunately enough the Fellowship of the Code will ruin his 3v1l pl4ns :-pBI lazy wrote: muuuuaaahahahaha!
-- enough stupid things -- let's get back to work ;D
Re:Debug function
But will Dust Puppy be able to throw the One Ping into Mt. Redmond?Pype.Clicker wrote:Oh Mighty Gods! BIlazy -- aka the Lord of the DPL0 Ring strikes again ... Fortunately enough the Fellowship of the Code will ruin his 3v1l pl4ns :-pBI lazy wrote: muuuuaaahahahaha!
Oops, too late.-- enough stupid things -- let's get back to work ;D