qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Filippov <jcmvbkbc@gmail.com>
To: qemu-devel@nongnu.org
Cc: Max Filippov <jcmvbkbc@gmail.com>
Subject: [Qemu-devel] [PATCH v2 03/11] target/xtensa: use correct number of registers in gdbstub
Date: Wed, 28 Feb 2018 14:16:01 -0800	[thread overview]
Message-ID: <20180228221609.11265-4-jcmvbkbc@gmail.com> (raw)
In-Reply-To: <20180228221609.11265-1-jcmvbkbc@gmail.com>

System emulation should provide access to all registers, userspace
emulation should only provide access to unprivileged registers.
Record register flags from GDB register map definition, calculate both
num_regs and num_core_regs if either is zero. Use num_regs in system
emulation, num_core_regs in userspace emulation gdbstub.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
---
 target/xtensa/cpu.h          |  1 +
 target/xtensa/gdbstub.c      | 14 ++++++++++++--
 target/xtensa/helper.c       | 28 ++++++++++++++++++++--------
 target/xtensa/overlay_tool.h | 11 ++++++++---
 4 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h
index 49c2e3cf9a1b..255cc9e08ed9 100644
--- a/target/xtensa/cpu.h
+++ b/target/xtensa/cpu.h
@@ -310,6 +310,7 @@ typedef struct xtensa_tlb {
 
 typedef struct XtensaGdbReg {
     int targno;
+    unsigned flags;
     int type;
     int group;
     unsigned size;
diff --git a/target/xtensa/gdbstub.c b/target/xtensa/gdbstub.c
index d78a1b437dbf..a8ea98d03fb8 100644
--- a/target/xtensa/gdbstub.c
+++ b/target/xtensa/gdbstub.c
@@ -28,9 +28,14 @@ int xtensa_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
     XtensaCPU *cpu = XTENSA_CPU(cs);
     CPUXtensaState *env = &cpu->env;
     const XtensaGdbReg *reg = env->config->gdb_regmap.reg + n;
+#ifdef CONFIG_USER_ONLY
+    int num_regs = env->config->gdb_regmap.num_core_regs;
+#else
+    int num_regs = env->config->gdb_regmap.num_regs;
+#endif
     unsigned i;
 
-    if (n < 0 || n >= env->config->gdb_regmap.num_regs) {
+    if (n < 0 || n >= num_regs) {
         return 0;
     }
 
@@ -81,8 +86,13 @@ int xtensa_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     CPUXtensaState *env = &cpu->env;
     uint32_t tmp;
     const XtensaGdbReg *reg = env->config->gdb_regmap.reg + n;
+#ifdef CONFIG_USER_ONLY
+    int num_regs = env->config->gdb_regmap.num_core_regs;
+#else
+    int num_regs = env->config->gdb_regmap.num_regs;
+#endif
 
-    if (n < 0 || n >= env->config->gdb_regmap.num_regs) {
+    if (n < 0 || n >= num_regs) {
         return 0;
     }
 
diff --git a/target/xtensa/helper.c b/target/xtensa/helper.c
index 5009fecedcb0..34885038d554 100644
--- a/target/xtensa/helper.c
+++ b/target/xtensa/helper.c
@@ -88,19 +88,31 @@ static void init_libisa(XtensaConfig *config)
 
 void xtensa_finalize_config(XtensaConfig *config)
 {
-    unsigned i, n = 0;
-
     if (config->isa_internal) {
         init_libisa(config);
     }
-    if (config->gdb_regmap.num_regs) {
-        return;
-    }
 
-    for (i = 0; config->gdb_regmap.reg[i].targno >= 0; ++i) {
-        n += (config->gdb_regmap.reg[i].type != 6);
+    if (config->gdb_regmap.num_regs == 0 ||
+        config->gdb_regmap.num_core_regs == 0) {
+        unsigned i;
+        unsigned n_regs = 0;
+        unsigned n_core_regs = 0;
+
+        for (i = 0; config->gdb_regmap.reg[i].targno >= 0; ++i) {
+            if (config->gdb_regmap.reg[i].type != 6) {
+                ++n_regs;
+                if ((config->gdb_regmap.reg[i].flags & 0x1) == 0) {
+                    ++n_core_regs;
+                }
+            }
+        }
+        if (config->gdb_regmap.num_regs == 0) {
+            config->gdb_regmap.num_regs = n_regs;
+        }
+        if (config->gdb_regmap.num_core_regs == 0) {
+            config->gdb_regmap.num_core_regs = n_core_regs;
+        }
     }
-    config->gdb_regmap.num_regs = n;
 }
 
 void xtensa_register_core(XtensaConfigList *node)
diff --git a/target/xtensa/overlay_tool.h b/target/xtensa/overlay_tool.h
index 589dd6285089..b24ad11fec1c 100644
--- a/target/xtensa/overlay_tool.h
+++ b/target/xtensa/overlay_tool.h
@@ -25,9 +25,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#define XTREG(idx, ofs, bi, sz, al, no, flags, cp, typ, grp, name, \
-        a1, a2, a3, a4, a5, a6) \
-    { .targno = (no), .type = (typ), .group = (grp), .size = (sz) },
+#define XTREG(idx, ofs, bi, sz, al, no, fl, cp, typ, grp, name, \
+              a1, a2, a3, a4, a5, a6) { \
+    .targno = (no), \
+    .flags = (fl), \
+    .type = (typ), \
+    .group = (grp), \
+    .size = (sz), \
+},
 #define XTREG_END { .targno = -1 },
 
 #ifndef XCHAL_HAVE_DEPBITS
-- 
2.11.0

  parent reply	other threads:[~2018-02-28 22:16 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-28 22:15 [Qemu-devel] [PATCH v2 00/11] linux-user support for target/xtensa Max Filippov
2018-02-28 22:15 ` [Qemu-devel] [PATCH v2 01/11] target/xtensa: dump correct physical registers Max Filippov
2018-02-28 22:16 ` [Qemu-devel] [PATCH v2 02/11] target/xtensa: mark register windows in the dump Max Filippov
2018-02-28 22:16 ` Max Filippov [this message]
2018-02-28 22:16 ` [Qemu-devel] [PATCH v2 04/11] target/xtensa: support MTTCG Max Filippov
2018-02-28 22:16 ` [Qemu-devel] [PATCH v2 05/11] linux-user: fix mmap/munmap/mprotect/mremap/shmat Max Filippov
2018-02-28 22:16 ` [Qemu-devel] [PATCH v2 06/11] linux-user: fix assertion in shmdt Max Filippov
2018-03-01 10:14   ` Laurent Vivier
2018-03-09 19:57   ` Laurent Vivier
2018-02-28 22:16 ` [Qemu-devel] [PATCH v2 07/11] linux-user: fix target_mprotect/target_munmap error return values Max Filippov
2018-03-01  9:42   ` Laurent Vivier
2018-03-09 19:57   ` Laurent Vivier
2018-02-28 22:16 ` [Qemu-devel] [PATCH v2 08/11] linux-user: drop unused target_msync function Max Filippov
2018-03-01  9:28   ` Laurent Vivier
2018-03-09 19:58   ` Laurent Vivier
2018-02-28 22:16 ` [Qemu-devel] [PATCH v2 09/11] target/xtensa: add linux-user support Max Filippov
2018-02-28 22:16 ` [Qemu-devel] [PATCH v2 10/11] qemu-binfmt-conf.sh: add qemu-xtensa Max Filippov
2018-03-01 14:13   ` Laurent Vivier
2018-03-09 19:58   ` Laurent Vivier
2018-03-09 20:55     ` Max Filippov
2018-02-28 22:16 ` [Qemu-devel] [PATCH v2 11/11] MAINTAINERS: fix W: address for xtensa Max Filippov
2018-02-28 22:29 ` [Qemu-devel] [PATCH v2 00/11] linux-user support for target/xtensa no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180228221609.11265-4-jcmvbkbc@gmail.com \
    --to=jcmvbkbc@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).