Re: [ANNOUNCE] desc.c -- dump the i386 descriptor tables

From: Gabriel Paubert (paubert@iram.es)
Date: Thu Apr 24 2003 - 03:53:36 EST


On Wed, Apr 23, 2003 at 11:02:02PM -0400, Chuck Ebbert wrote:
> Sample output:
>
>
> desc.c -- dump linux descriptor tables, version 0.50
>
> GDT at c0306280, 32 entries:
>
> #00: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #01: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #02: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #03: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #04: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #05: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #06: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #07: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #08: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #09: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #10: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #11: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #12: base=00000000 limit=ffff flags=cf9b <G=1 P=1 S=1 DPL=0 Code>
> #13: base=00000000 limit=ffff flags=cf93 <G=1 P=1 S=1 DPL=0 Data>
> #14: base=00000000 limit=ffff flags=cffb <G=1 P=1 S=1 DPL=3 Code>
> #15: base=00000000 limit=ffff flags=cff3 <G=1 P=1 S=1 DPL=3 Data>
> #16: base=c0353800 limit=00eb flags=008b <G=0 P=1 S=0 DPL=0 Busy TSS>
> #17: base=c0307c70 limit=0027 flags=0082 <G=0 P=1 S=0 DPL=0 LDT>
> #18: base=00000000 limit=0000 flags=c09a <G=1 P=1 S=1 DPL=0 Code>
> #19: base=00000000 limit=0000 flags=809a <G=1 P=1 S=1 DPL=0 Code>
> #20: base=00000000 limit=0000 flags=8092 <G=1 P=1 S=1 DPL=0 Data>
> #21: base=00000000 limit=0000 flags=8092 <G=1 P=1 S=1 DPL=0 Data>
> #22: base=00000000 limit=0000 flags=8092 <G=1 P=1 S=1 DPL=0 Data>
> #23: base=00000000 limit=0000 flags=409a <G=0 P=1 S=1 DPL=0 Code>
> #24: base=00000000 limit=0000 flags=009a <G=0 P=1 S=1 DPL=0 Code>
> #25: base=00000000 limit=0000 flags=4092 <G=0 P=1 S=1 DPL=0 Data>
> #26: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #27: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #28: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #29: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #30: base=00000000 limit=0000 flags=0000 <G=0 P=0 S=0 DPL=0 Empty>
> #31: base=c0355600 limit=00eb flags=0089 <G=0 P=1 S=0 DPL=0 Available TSS>

Nice but the limit field is 20 bits (shifted left by 12 bits if G=1).

[snipped]

>
> asm("sgdt %0" : "=m" (gdtr));
> base = gdtr.base, num = (gdtr.limit + 1) >> 3;
> printf(" GDT at %08x, %d entries:\n\n", base, num);
> for (i = 0; i < num; i++) {
> xkm(rkm, kmem, base + 8*i, &gdte, sizeof(gdte), "rkm gdte");
> a = gdte.a, b = gdte.b, t = (b & 0x1f00) >> 8;
> printf("#%02d: base=%08x limit=%04x"
                                                 ^^^
s/%04x/%05x/

> " flags=%04x <G=%d P=%d S=%d DPL=%d %s>\n", i,
> (b & 0xff000000) | ((b & 0xff) << 16) | (a >> 16),
> a & 0xffff, (b & 0x00ffff00) >> 8, TEST_BIT(b,23),
                         ^^^^^^^^^^
s/a & 0xffff/(a & 0xffff) | (b & 0x0f0000)/

And I'd also mask b with 0xf0ff00 to avoid the 4 higher bits of the
limit in the middle of the flags field.

Other suggestions left as an exercise to the reader:

a) distinguish 16 bit code from 32 bit code (GDT entry #19 is 16 bit code),

b) distinguish read/write from read-only and execute/read from
execute-only (are there any read-only or execute-only segments in the GDT?)

c) distinguish 16 and 32 bit expand down data (changes the upper
limit of the valid addresses, but it's never used in the GDT, so like
the conformant code it's not that important)

d) extend this for x86-64 :-)

Nothing to say about the IDT dump, though.

        Gabriel
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Apr 30 2003 - 22:00:12 EST