An exception damages data

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.
User avatar
bellezzasolo
Member
Member
Posts: 110
Joined: Sun Feb 20, 2011 2:01 pm

Re: An exception damages data

Post by bellezzasolo »

mrjbom wrote:
nullplan wrote:
mrjbom wrote:I expect a #DB exception to be thrown when writing a new value, but this does not happen.
Well, maybe because that is a dead store. Or maybe the compiler allocates "a" into some register and will only spill it later. For things like that, I have set and read functions in my io.S that work exactly like the in and out functions, but for memory space instead of I/O space:

Code: Select all

void setl(uint32_t*, uint32_t);

Code: Select all

.global setl
.type setl, @function
setl:
    movl %esi, (%rdi)
    retq
.size setl, .-setl
Then you can force the write to occur with "setl(&a, 123)". And that really should trap with #DB in your case. Of course, this is for 64-bit mode, you would need something like

Code: Select all

.global setl,
.type setl, @function
setl:
  movl 4(%esp), %eax
  movl 8(%esp), %ecx
  movl %ecx, (%eax)
  retl
.size setl,.-setl
I tried using the code you suggested, but the exception still doesn't work.
In addition, I found that DR0 is reset to zero.

Code: Select all

//write addr of 'a' to dr0
__asm__ volatile ("mov %%dr0, %0" :: "r" (&a));
//read dr0
__asm__ volatile ("mov %0, %%dr0" : "=r" (dr0));
serial_printf("dr0 = 0x%x\n", dr0); //0
Why is this happening?
I run qemu without gdb and nothing should overwrite debug registers.
AT&T syntax?

I think you need:

Code: Select all

//write addr of 'a' to dr0
__asm__ volatile ("mov %0, %%dr0" :: "r" (&a));
//read dr0
__asm__ volatile ("mov %%dr0, %0" : "=r" (dr0));
serial_printf("dr0 = 0x%x\n", dr0); //0
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS
User avatar
mrjbom
Member
Member
Posts: 317
Joined: Sun Jul 21, 2019 7:34 am

Re: An exception damages data

Post by mrjbom »

bellezzasolo wrote:
mrjbom wrote:
I tried using the code you suggested, but the exception still doesn't work.
In addition, I found that DR0 is reset to zero.

Code: Select all

//write addr of 'a' to dr0
__asm__ volatile ("mov %%dr0, %0" :: "r" (&a));
//read dr0
__asm__ volatile ("mov %0, %%dr0" : "=r" (dr0));
serial_printf("dr0 = 0x%x\n", dr0); //0
Why is this happening?
I run qemu without gdb and nothing should overwrite debug registers.
AT&T syntax?

I think you need:

Code: Select all

//write addr of 'a' to dr0
__asm__ volatile ("mov %0, %%dr0" :: "r" (&a));
//read dr0
__asm__ volatile ("mov %%dr0, %0" : "=r" (dr0));
serial_printf("dr0 = 0x%x\n", dr0); //0
Oh my God, what a stupid mistake, how could I have made such a mistake, I'm ashamed of such a stupid mistake.
I'm confused about the syntax.
Thank you for noticing.
User avatar
bellezzasolo
Member
Member
Posts: 110
Joined: Sun Feb 20, 2011 2:01 pm

Re: An exception damages data

Post by bellezzasolo »

mrjbom wrote: Oh my God, what a stupid mistake, how could I have made such a mistake, I'm ashamed of such a stupid mistake.
I'm confused about the syntax.
Thank you for noticing.
If you want a stupid mistake, try the hours I spent debugging a keyboard driver...

"=" instead of "==".
:oops:

We've all been there!
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS
User avatar
mrjbom
Member
Member
Posts: 317
Joined: Sun Jul 21, 2019 7:34 am

Re: An exception damages data

Post by mrjbom »

bellezzasolo wrote:
mrjbom wrote: Oh my God, what a stupid mistake, how could I have made such a mistake, I'm ashamed of such a stupid mistake.
I'm confused about the syntax.
Thank you for noticing.
If you want a stupid mistake, try the hours I spent debugging a keyboard driver...

"=" instead of "==".
:oops:

We've all been there!
Heh, you're right.
Perhaps the same stupid error is the cause of this topic's problem... I still can't solve it(
Post Reply