* [PATCH] target/sparc: Fix gdbstub incorrectly handling registers f32-f62
@ 2025-02-03 14:50 Mikael Szreder
2025-02-13 15:12 ` Mikael Szreder
2025-02-13 16:57 ` Richard Henderson
0 siblings, 2 replies; 5+ messages in thread
From: Mikael Szreder @ 2025-02-03 14:50 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, Mark Cave-Ayland, Artyom Tarasenko,
Mikael Szreder
The gdbstub implementation for the Sparc architecture would incorectly
calculate the the floating point register offset.
This would cause register pairs(eg f32,f33) to point to the same value.
Fixes: 30038fd81808 ("target-sparc: Change fpr representation to doubles.")
Signed-off-by: Mikael Szreder <git@miszr.win>
---
target/sparc/gdbstub.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/target/sparc/gdbstub.c b/target/sparc/gdbstub.c
index ec0036e9ef..5578fa9813 100644
--- a/target/sparc/gdbstub.c
+++ b/target/sparc/gdbstub.c
@@ -80,7 +80,7 @@ int sparc_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
}
if (n < 80) {
/* f32-f62 (double width, even numbers only) */
- return gdb_get_reg64(mem_buf, env->fpr[(n - 32) / 2].ll);
+ return gdb_get_reg64(mem_buf, env->fpr[(n - 64) + 16].ll);
}
switch (n) {
case 80:
@@ -174,7 +174,7 @@ int sparc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
return 4;
} else if (n < 80) {
/* f32-f62 (double width, even numbers only) */
- env->fpr[(n - 32) / 2].ll = tmp;
+ env->fpr[(n - 64) + 16].ll = tmp;
} else {
switch (n) {
case 80:
--
2.48.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] target/sparc: Fix gdbstub incorrectly handling registers f32-f62
2025-02-03 14:50 [PATCH] target/sparc: Fix gdbstub incorrectly handling registers f32-f62 Mikael Szreder
@ 2025-02-13 15:12 ` Mikael Szreder
2025-02-13 16:57 ` Richard Henderson
1 sibling, 0 replies; 5+ messages in thread
From: Mikael Szreder @ 2025-02-13 15:12 UTC (permalink / raw)
To: qemu-devel; +Cc: Richard Henderson, Mark Cave-Ayland, Artyom Tarasenko
Ping
On February 3, 2025 3:50:56 PM GMT+01:00, Mikael Szreder <git@miszr.win> wrote:
>The gdbstub implementation for the Sparc architecture would incorectly
> calculate the the floating point register offset.
>This would cause register pairs(eg f32,f33) to point to the same value.
>
>Fixes: 30038fd81808 ("target-sparc: Change fpr representation to doubles.")
>Signed-off-by: Mikael Szreder <git@miszr.win>
>---
> target/sparc/gdbstub.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/target/sparc/gdbstub.c b/target/sparc/gdbstub.c
>index ec0036e9ef..5578fa9813 100644
>--- a/target/sparc/gdbstub.c
>+++ b/target/sparc/gdbstub.c
>@@ -80,7 +80,7 @@ int sparc_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
> }
> if (n < 80) {
> /* f32-f62 (double width, even numbers only) */
>- return gdb_get_reg64(mem_buf, env->fpr[(n - 32) / 2].ll);
>+ return gdb_get_reg64(mem_buf, env->fpr[(n - 64) + 16].ll);
> }
> switch (n) {
> case 80:
>@@ -174,7 +174,7 @@ int sparc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
> return 4;
> } else if (n < 80) {
> /* f32-f62 (double width, even numbers only) */
>- env->fpr[(n - 32) / 2].ll = tmp;
>+ env->fpr[(n - 64) + 16].ll = tmp;
> } else {
> switch (n) {
> case 80:
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] target/sparc: Fix gdbstub incorrectly handling registers f32-f62
2025-02-03 14:50 [PATCH] target/sparc: Fix gdbstub incorrectly handling registers f32-f62 Mikael Szreder
2025-02-13 15:12 ` Mikael Szreder
@ 2025-02-13 16:57 ` Richard Henderson
2025-02-13 19:03 ` Mikael Szreder
1 sibling, 1 reply; 5+ messages in thread
From: Richard Henderson @ 2025-02-13 16:57 UTC (permalink / raw)
To: Mikael Szreder, qemu-devel; +Cc: Mark Cave-Ayland, Artyom Tarasenko
On 2/3/25 06:50, Mikael Szreder wrote:
> The gdbstub implementation for the Sparc architecture would incorectly
> calculate the the floating point register offset.
> This would cause register pairs(eg f32,f33) to point to the same value.
>
> Fixes: 30038fd81808 ("target-sparc: Change fpr representation to doubles.")
> Signed-off-by: Mikael Szreder <git@miszr.win>
> ---
> target/sparc/gdbstub.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/target/sparc/gdbstub.c b/target/sparc/gdbstub.c
> index ec0036e9ef..5578fa9813 100644
> --- a/target/sparc/gdbstub.c
> +++ b/target/sparc/gdbstub.c
> @@ -80,7 +80,7 @@ int sparc_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
> }
> if (n < 80) {
> /* f32-f62 (double width, even numbers only) */
> - return gdb_get_reg64(mem_buf, env->fpr[(n - 32) / 2].ll);
> + return gdb_get_reg64(mem_buf, env->fpr[(n - 64) + 16].ll);
I don't understand your issue with f33, since there is no such thing. Sparc v9 has f0,
f1, ... f31, then f32, f34, ... f62. The odd numbers above 32 do not exist.
Certainly the indexing is incorrect afterward.
Originally,
f32 = 64 -> (64 - 32) / 2 = 16
f34 = 66 -> (66 - 32) / 2 = 17
whereas your replacement gives
f34 = 66 -> (66 - 64) + 16 = 18.
One could rewrite this as
(n - 64) / 2 + 16
but that's algebraically identical to what we have now, so I don't see the point.
One plausible adjustment in this area would be to reject odd numbers from this block and
let them fall through to 'return 0' at the end.
r~
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] target/sparc: Fix gdbstub incorrectly handling registers f32-f62
2025-02-13 16:57 ` Richard Henderson
@ 2025-02-13 19:03 ` Mikael Szreder
2025-02-13 19:11 ` Richard Henderson
0 siblings, 1 reply; 5+ messages in thread
From: Mikael Szreder @ 2025-02-13 19:03 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: Mark Cave-Ayland, Artyom Tarasenko
Sorry. As you correctly pointed out there is no f33 register. I wrote f33, when I really meant f34.
I believe the index of f32 is 64 and f34 is 65. This is confirmed when looking at the XML description of the registers in GDB: <https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/features/sparc/sparc64-fpu.xml;h=8710585774d821c660af5e76f92707637633daf7;hb=HEAD>
Thanks in advance
Mikael Szreder
On February 13, 2025 5:57:59 PM GMT+01:00, Richard Henderson <richard.henderson@linaro.org> wrote:
>On 2/3/25 06:50, Mikael Szreder wrote:
>> The gdbstub implementation for the Sparc architecture would incorectly
>> calculate the the floating point register offset.
>> This would cause register pairs(eg f32,f33) to point to the same value.
>>
>> Fixes: 30038fd81808 ("target-sparc: Change fpr representation to doubles.")
>> Signed-off-by: Mikael Szreder <git@miszr.win>
>> ---
>> target/sparc/gdbstub.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/target/sparc/gdbstub.c b/target/sparc/gdbstub.c
>> index ec0036e9ef..5578fa9813 100644
>> --- a/target/sparc/gdbstub.c
>> +++ b/target/sparc/gdbstub.c
>> @@ -80,7 +80,7 @@ int sparc_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
>> }
>> if (n < 80) {
>> /* f32-f62 (double width, even numbers only) */
>> - return gdb_get_reg64(mem_buf, env->fpr[(n - 32) / 2].ll);
>> + return gdb_get_reg64(mem_buf, env->fpr[(n - 64) + 16].ll);
>
>I don't understand your issue with f33, since there is no such thing. Sparc v9 has f0, f1, ... f31, then f32, f34, ... f62. The odd numbers above 32 do not exist.
>
>Certainly the indexing is incorrect afterward.
>
>Originally,
>
> f32 = 64 -> (64 - 32) / 2 = 16
> f34 = 66 -> (66 - 32) / 2 = 17
>
>whereas your replacement gives
>
> f34 = 66 -> (66 - 64) + 16 = 18.
>
>One could rewrite this as
>
> (n - 64) / 2 + 16
>
>but that's algebraically identical to what we have now, so I don't see the point.
>
>One plausible adjustment in this area would be to reject odd numbers from this block and let them fall through to 'return 0' at the end.
>
>
>r~
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-02-13 19:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-03 14:50 [PATCH] target/sparc: Fix gdbstub incorrectly handling registers f32-f62 Mikael Szreder
2025-02-13 15:12 ` Mikael Szreder
2025-02-13 16:57 ` Richard Henderson
2025-02-13 19:03 ` Mikael Szreder
2025-02-13 19:11 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).