Page 2 of 2
Re: An exception damages data
Posted: Fri Jul 31, 2020 7:02 am
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
.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
Re: An exception damages data
Posted: Fri Jul 31, 2020 8:14 am
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.
Re: An exception damages data
Posted: Fri Jul 31, 2020 12:57 pm
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 "==".
We've all been there!
Re: An exception damages data
Posted: Fri Jul 31, 2020 1:46 pm
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 "==".
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(