qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@web.de>
To: qemu-devel <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH] x86: Enhanced dump of segment registers
Date: Fri, 30 Jan 2009 00:51:52 +0100	[thread overview]
Message-ID: <49824118.1070300@web.de> (raw)

Parse the descriptor flags segment registers refer to and show the
result in a more human-friendly format.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

 target-i386/cpu.h    |    3 ++
 target-i386/helper.c |   62 +++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 58 insertions(+), 7 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 0a4f1d7..9e5ca27 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -80,9 +80,10 @@
 #define DESC_AVL_MASK   (1 << 20)
 #define DESC_P_MASK     (1 << 15)
 #define DESC_DPL_SHIFT  13
-#define DESC_DPL_MASK   (1 << DESC_DPL_SHIFT)
+#define DESC_DPL_MASK   (3 << DESC_DPL_SHIFT)
 #define DESC_S_MASK     (1 << 12)
 #define DESC_TYPE_SHIFT 8
+#define DESC_TYPE_MASK  (15 << DESC_TYPE_SHIFT)
 #define DESC_A_MASK     (1 << 8)
 
 #define DESC_CS_MASK    (1 << 11) /* 1=code segment 0=data segment */
diff --git a/target-i386/helper.c b/target-i386/helper.c
index db9f397..239b29b 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -542,6 +542,50 @@ static const char *cc_op_str[] = {
     "SARQ",
 };
 
+static void
+cpu_x86_dump_desc_flags(CPUState *env, FILE *f,
+                        int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
+                        uint32_t dflags)
+{
+    if (!(env->hflags & HF_PE_MASK) || !(dflags & DESC_P_MASK))
+        goto done;
+
+    cpu_fprintf(f, " P DPL=%d ", (dflags & DESC_DPL_MASK) >> DESC_DPL_SHIFT);
+    if (dflags & DESC_S_MASK) {
+        if (dflags & DESC_CS_MASK) {
+            cpu_fprintf(f, (dflags & DESC_L_MASK) ? "CS64" :
+                           ((dflags & DESC_B_MASK) ? "CS32" : "CS16"));
+            cpu_fprintf(f, " [%c%c", (dflags & DESC_C_MASK) ? 'C' : '-',
+                        (dflags & DESC_R_MASK) ? 'R' : '-');
+        } else {
+            cpu_fprintf(f, (dflags & DESC_B_MASK) ? "DS  " : "DS16");
+            cpu_fprintf(f, " [%c%c", (dflags & DESC_E_MASK) ? 'E' : '-',
+                        (dflags & DESC_W_MASK) ? 'W' : '-');
+        }
+        cpu_fprintf(f, "%c]", (dflags & DESC_A_MASK) ? 'A' : '-');
+    } else {
+        static const char *sys_type_name[2][16] = {
+            { /* 32 bit mode */
+                "Reserved", "TSS16-avl", "LDT", "TSS16-busy",
+                "CallGate16", "TaskGate", "IntGate16", "TrapGate16",
+                "Reserved", "TSS32-avl", "Reserved", "TSS32-busy",
+                "CallGate32", "Reserved", "IntGate32", "TrapGate32"
+            },
+            { /* 64 bit mode */
+                "<hiword>", "Reserved", "LDT", "Reserved", "Reserved"
+                "Reserved", "Reserved", "Reserved", "Reserved",
+                "TSS64-avl", "Reserved", "TSS64-busy", "CallGate64",
+                "Reserved", "IntGate64", "TrapGate64"
+            }
+        };
+        cpu_fprintf(f, sys_type_name[(env->hflags & HF_LMA_MASK) ? 1 : 0]
+                                    [(dflags & DESC_TYPE_MASK)
+                                     >> DESC_TYPE_SHIFT]);
+    }
+done:
+    cpu_fprintf(f, "\n");
+}
+
 void cpu_dump_state(CPUState *env, FILE *f,
                     int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
                     int flags)
@@ -621,23 +665,26 @@ void cpu_dump_state(CPUState *env, FILE *f,
     if (env->hflags & HF_LMA_MASK) {
         for(i = 0; i < 6; i++) {
             SegmentCache *sc = &env->segs[i];
-            cpu_fprintf(f, "%s =%04x %016" PRIx64 " %08x %08x\n",
+            cpu_fprintf(f, "%s =%04x %016" PRIx64 " %08x %08x",
                         seg_name[i],
                         sc->selector,
                         sc->base,
                         sc->limit,
                         sc->flags);
+            cpu_x86_dump_desc_flags(env, f, cpu_fprintf, sc->flags);
         }
-        cpu_fprintf(f, "LDT=%04x %016" PRIx64 " %08x %08x\n",
+        cpu_fprintf(f, "LDT=%04x %016" PRIx64 " %08x %08x",
                     env->ldt.selector,
                     env->ldt.base,
                     env->ldt.limit,
                     env->ldt.flags);
-        cpu_fprintf(f, "TR =%04x %016" PRIx64 " %08x %08x\n",
+        cpu_x86_dump_desc_flags(env, f, cpu_fprintf, env->ldt.flags);
+        cpu_fprintf(f, "TR =%04x %016" PRIx64 " %08x %08x",
                     env->tr.selector,
                     env->tr.base,
                     env->tr.limit,
                     env->tr.flags);
+        cpu_x86_dump_desc_flags(env, f, cpu_fprintf, env->tr.flags);
         cpu_fprintf(f, "GDT=     %016" PRIx64 " %08x\n",
                     env->gdt.base, env->gdt.limit);
         cpu_fprintf(f, "IDT=     %016" PRIx64 " %08x\n",
@@ -656,23 +703,26 @@ void cpu_dump_state(CPUState *env, FILE *f,
     {
         for(i = 0; i < 6; i++) {
             SegmentCache *sc = &env->segs[i];
-            cpu_fprintf(f, "%s =%04x %08x %08x %08x\n",
+            cpu_fprintf(f, "%s =%04x %08x %08x %08x",
                         seg_name[i],
                         sc->selector,
                         (uint32_t)sc->base,
                         sc->limit,
                         sc->flags);
+            cpu_x86_dump_desc_flags(env, f, cpu_fprintf, sc->flags);
         }
-        cpu_fprintf(f, "LDT=%04x %08x %08x %08x\n",
+        cpu_fprintf(f, "LDT=%04x %08x %08x %08x",
                     env->ldt.selector,
                     (uint32_t)env->ldt.base,
                     env->ldt.limit,
                     env->ldt.flags);
-        cpu_fprintf(f, "TR =%04x %08x %08x %08x\n",
+        cpu_x86_dump_desc_flags(env, f, cpu_fprintf, env->ldt.flags);
+        cpu_fprintf(f, "TR =%04x %08x %08x %08x",
                     env->tr.selector,
                     (uint32_t)env->tr.base,
                     env->tr.limit,
                     env->tr.flags);
+        cpu_x86_dump_desc_flags(env, f, cpu_fprintf, env->tr.flags);
         cpu_fprintf(f, "GDT=     %08x %08x\n",
                     (uint32_t)env->gdt.base, env->gdt.limit);
         cpu_fprintf(f, "IDT=     %08x %08x\n",

                 reply	other threads:[~2009-01-29 23:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=49824118.1070300@web.de \
    --to=jan.kiszka@web.de \
    --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).