qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] target/i386/gdbstub: Fix a bug about order of FPU stack in 'g' packets.
@ 2022-12-08 12:30 TaiseiIto
  2022-12-18 19:54 ` Richard Henderson
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: TaiseiIto @ 2022-12-08 12:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: alex.bennee, richard.henderson, TaiseiIto

Before this commit, when GDB attached an OS working on QEMU, order of FPU
stack registers printed by GDB command 'info float' was wrong. There was a
bug causing the problem in 'g' packets sent by QEMU to GDB. The packets have
values of registers of machine emulated by QEMU containing FPU stack
registers. There are 2 ways to specify a x87 FPU stack register. The first
is specifying by absolute indexed register names (R0, ..., R7). The second
is specifying by stack top relative indexed register names (ST0, ..., ST7).
Values of the FPU stack registers should be located in 'g' packet and be
ordered by the relative index. But QEMU had located these registers ordered
by the absolute index. After this commit, when QEMU reads registers to make
a 'g' packet, QEMU specifies FPU stack registers by the relative index.
Then, the registers are ordered correctly in the packet. As a result, GDB,
the packet receiver, can print FPU stack registers in the correct order.

Signed-off-by: TaiseiIto <taisei1212@outlook.jp>
---
 target/i386/gdbstub.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c
index c3a2cf6f28..6109ad166d 100644
--- a/target/i386/gdbstub.c
+++ b/target/i386/gdbstub.c
@@ -121,7 +121,9 @@ int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
             return gdb_get_reg32(mem_buf, env->regs[gpr_map32[n]]);
         }
     } else if (n >= IDX_FP_REGS && n < IDX_FP_REGS + 8) {
-        floatx80 *fp = (floatx80 *) &env->fpregs[n - IDX_FP_REGS];
+        int st_index = n - IDX_FP_REGS;
+        int r_index = (st_index + env->fpstt) % 8;
+        floatx80 *fp = (floatx80 *) &env->fpregs[r_index];
         int len = gdb_get_reg64(mem_buf, cpu_to_le64(fp->low));
         len += gdb_get_reg16(mem_buf, cpu_to_le16(fp->high));
         return len;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-02-15 12:36 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-08 12:30 [PATCH] target/i386/gdbstub: Fix a bug about order of FPU stack in 'g' packets TaiseiIto
2022-12-18 19:54 ` Richard Henderson
2022-12-19  4:01 ` TaiseiIto
2022-12-19  4:04 ` TaiseiIto
2022-12-19 15:40   ` Alex Bennée
2022-12-19 18:11   ` Richard Henderson
2023-01-07  1:28   ` [PATCH v2] [PING] " TaiseiIto
2023-01-07 10:15     ` Alex Bennée
2023-01-08  2:07       ` 伊藤 太清
2023-01-08 16:11         ` [PATCH qemu v3 0/1] Emulating sun keyboard language layout dip switches Henrik Carlqvist
2023-02-04  4:23     ` [PATCH v2] [PING^2] target/i386/gdbstub: Fix a bug about order of FPU stack in 'g' packets TaiseiIto
2023-02-11  4:09   ` [PATCH v2] [PING^3] " TaiseiIto
2023-02-13  9:38     ` Alex Bennée
2023-02-15 12:00   ` [PATCH] [PING] " TaiseiIto
2023-02-15 12:36   ` [PATCH] " Paolo Bonzini

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).