Skip to contentSkip to conversation

x86: Enhanced dump of segment registers

PATCH RESEND In review Jan Kiszka 5 participants 11 messages Mar 11, 2009 – Mar 12, 2009

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH RESEND 1/1 x86: Enhanced dump of segment registers

Parse the descriptor flags that segment registers refer to and show the result in a more human-friendly format. The output of info registers eg. then looks like this:

[...]
ES =007b 00000000 ffffffff 00cff300 DPL=3 DS [-WA]
CS =0060 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0068 00000000 ffffffff 00c09300 DPL=0 DS [-WA]
DS =007b 00000000 ffffffff 00cff300 DPL=3 DS [-WA]
FS =0000 00000000 00000000 00000000
GS =0033 b7dd66c0 ffffffff b7dff3dd DPL=3 DS [-WA]
LDT=0000 00000000 00000000 00008200 DPL=0 LDT TR =0080 c06da700 0000206b 00008900 DPL=0 TSS32-avl [...]

---

 target-i386/cpu.h    |    3 ++
 target-i386/helper.c |   62 +++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 58 insertions(+), 7 deletions(-)
target-i386/cpu.h +2 -1
index 90bceab..f38f194 100644
@@ -82,9 +82,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 */
target-i386/helper.c +56 -6

108 lines not on this page · raw message

#1 lore raw
Quoted 3 lines · Jan Kiszka

FS =0000 00000000 00000000 00000000

LDT=0000 00000000 00000000 00008200 DPL=0 LDT

Both are =0000, but different descriptors - is that right?

Also I'm thinking the null descriptor doesn't need to show offset and size:

FS =0000

is enough?

-- Jamie

author
#2 lore raw
Quoted 6 lines · Jamie Lokier
Quoted 3 lines · Jan Kiszka

FS =0000 00000000 00000000 00000000

LDT=0000 00000000 00000000 00008200 DPL=0 LDT

Both are =0000, but different descriptors - is that right?

Good question. My patch only parses to descriptor cache content without evaluating the selector. I guess that 0x00008200 is a leftover from a previous, valid LDT descriptor.

Quoted 7 lines

Also I'm thinking the null descriptor doesn't need to show offset and size:

FS =0000

is enough?

Yes, makes sense. IOW: stop parsing if selector == 0. Will post an update.

Thanks,
Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#3 lore raw
Quoted 13 lines · Jan Kiszka
Quoted 6 lines · Jamie Lokier
Quoted 3 lines · Jan Kiszka

FS =0000 00000000 00000000 00000000

LDT=0000 00000000 00000000 00008200 DPL=0 LDT

Both are =0000, but different descriptors - is that right?

Good question. My patch only parses to descriptor cache content without evaluating the selector. I guess that 0x00008200 is a leftover from a previous, valid LDT descriptor.

Quoted 1 line
Quoted 8 lines
Quoted 6 lines

Also I'm thinking the null descriptor doesn't need to show offset and size:

FS =0000

is enough?

Yes, makes sense. IOW: stop parsing if selector == 0. Will post an update.

Hmm.

Does a real x86 look at the selector value ever (except when loading it), or does it base all decisions on the descriptor cache?

It's an accuracy of emulation thing, as you can legitimately put the CPU into states where the descriptor cache and selector values are inconsistent, and it does have a well-defined behaviour.

If a real x86 always uses the descriptor cache, presumably there shouldn't be a leftover value in it when LDT is loaded with 0, and perhaps choosing to show a null descriptor should depend on the descriptor cache entry rather than the selector value.

In real mode (and its siblings, unreal mode, big real mode etc.) segment register == 0 usually still has a non-null descriptor.

-- Jamie

#4 lore raw
Quoted 19 lines · Jamie Lokier
Quoted 18 lines · Jan Kiszka
Quoted 6 lines · Jamie Lokier
Quoted 3 lines · Jan Kiszka

FS =0000 00000000 00000000 00000000

LDT=0000 00000000 00000000 00008200 DPL=0 LDT

Both are =0000, but different descriptors - is that right?

Good question. My patch only parses to descriptor cache content without evaluating the selector. I guess that 0x00008200 is a leftover from a previous, valid LDT descriptor.

Quoted 6 lines

Also I'm thinking the null descriptor doesn't need to show offset and size:

FS =0000

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

is enough?

Yes, makes sense. IOW: stop parsing if selector == 0. Will post an update.

Hmm.

Does a real x86 look at the selector value ever (except when loading it), or does it base all decisions on the descriptor cache?

The latter.

Quoted 16 lines

It's an accuracy of emulation thing, as you can legitimately put the CPU into states where the descriptor cache and selector values are inconsistent, and it does have a well-defined behaviour.

If a real x86 always uses the descriptor cache, presumably there shouldn't be a leftover value in it when LDT is loaded with 0, and perhaps choosing to show a null descriptor should depend on the descriptor cache entry rather than the selector value.

In real mode (and its siblings, unreal mode, big real mode etc.) segment register == 0 usually still has a non-null descriptor.

-- Jamie

Signature · 1 line
mailto:[email protected]
#5 lore raw
In reply to Jamie Lokier
Quoted 18 lines · Jamie Lokier
Quoted 9 lines · Jan Kiszka
Quoted 4 lines · Jamie Lokier
Quoted 2 lines · Jan Kiszka

FS =0000 00000000 00000000 00000000
LDT=0000 00000000 00000000 00008200 DPL=0 LDT

Both are =0000, but different descriptors - is that right?

Good question. My patch only parses to descriptor cache content without evaluating the selector. I guess that 0x00008200 is a leftover from a previous, valid LDT descriptor.

Quoted 7 lines
Quoted 6 lines

Also I'm thinking the null descriptor doesn't need to show offset and size:

FS =0000

is enough?

Yes, makes sense. IOW: stop parsing if selector == 0. Will post an update.

Quoted 8 lines

Hmm.

Does a real x86 look at the selector value ever (except when loading it), or does it base all decisions on the descriptor cache?

It's an accuracy of emulation thing, as you can legitimately put the CPU into states where the descriptor cache and selector values are inconsistent, and it does have a well-defined behaviour.

Yeah, there is some truth in this. While you can't load NULL into the task register e.g., it may still work based on its boot-up cache content.

Quoted 5 lines

If a real x86 always uses the descriptor cache, presumably there shouldn't be a leftover value in it when LDT is loaded with 0, and perhaps choosing to show a null descriptor should depend on the descriptor cache entry rather than the selector value.

Let's don't try to be too clever here (even 0 in all cache fields can have a meaning in 64-bit mode) and simply keep the output as is.

However, your suggestion led to a nice code cleanup as I folded all descriptor dumping into a single helper. :)

Jan

#10 lore raw

PATCH v2 1/1 x86: Enhanced dump of segment registers

In reply to Jan Kiszka

Parse the descriptor flags that segment registers refer to and show the result in a more human-friendly format. The output of info registers eg. then looks like this:

[...]
ES =007b 00000000 ffffffff 00cff300 DPL=3 DS [-WA]
CS =0060 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0068 00000000 ffffffff 00c09300 DPL=0 DS [-WA]
DS =007b 00000000 ffffffff 00cff300 DPL=3 DS [-WA]
FS =0000 00000000 00000000 00000000
GS =0033 b7dd66c0 ffffffff b7dff3dd DPL=3 DS [-WA]
LDT=0000 00000000 00000000 00008200 DPL=0 LDT TR =0080 c06da700 0000206b 00008900 DPL=0 TSS32-avl [...]

Changes in this version:
- refactoring so that only a single helper is used for dumping the segment descriptor cache
- tiny typo fixed that broke 64-bit segment type names

---

 target-i386/cpu.h    |    3 +-
 target-i386/helper.c |  100 +++++++++++++++++++++++++++++++-------------------
 2 files changed, 64 insertions(+), 39 deletions(-)
target-i386/cpu.h +2 -1
index 90bceab..f38f194 100644
@@ -82,9 +82,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 */
target-i386/helper.c +62 -38

120 lines not on this page · raw message

#6 lore raw
In reply to Jan Kiszka
Quoted 10 lines · Jan Kiszka
Quoted 7 lines

Also I'm thinking the null descriptor doesn't need to show offset and size:

FS =0000

is enough?

Yes, makes sense. IOW: stop parsing if selector == 0. Will post an update.

For gs and gs, base is meaningful even with null selectors (through MSR_[FG]S_BASE or MSR_KERNEL_GS_BASE+swapgs).

Signature · 1 line
error compiling committee.c: too many arguments to function
author
#7 lore raw
Quoted 9 lines · Avi Kivity
Quoted 8 lines · Jan Kiszka
Quoted 7 lines

Also I'm thinking the null descriptor doesn't need to show offset and size:

FS =0000

is enough?

Quoted 7 lines
Quoted 3 lines

Yes, makes sense. IOW: stop parsing if selector == 0. Will post an update.

For gs and gs, base is meaningful even with null selectors (through MSR_[FG]S_BASE or MSR_KERNEL_GS_BASE+swapgs).

I dropped any ideas to filter the output, -v2 is just a bug fix and code refactoring.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#8 lore raw
Quoted 2 lines · Jan Kiszka

I dropped any ideas to filter the output, -v2 is just a bug fix and code refactoring.

The other thing I noticed, from your example, was LDT set to a null selector but what might have been odd values in the descriptor cache for LDT. I wonder if that's correct emulation behaviour?

-- Jamie

author
#9 lore raw
Quoted 7 lines · Jamie Lokier
Quoted 2 lines · Jan Kiszka

I dropped any ideas to filter the output, -v2 is just a bug fix and code refactoring.

The other thing I noticed, from your example, was LDT set to a null selector but what might have been odd values in the descriptor cache for LDT. I wonder if that's correct emulation behaviour?

The flags doesn't matter (they are set during CPU reset, but I'm even unsure if there is any code evaluation them except cpu_dump_state). As the limit is 0, any attempt to load a descriptor from that LDT will raise an exception - on real hw as in the emulation.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux