Reading the GDT in kernel space?

Reading the GDT in kernel space?

am 23.08.2006 16:09:22 von Rajat Jain

Hi,

I'm trying to read & display the GDT contents in kernel space. Is this
permissible? I used the "sgdt" assembly instruction to load the GDT
register, and found out the address & length of GDT from that (It is
"0000c248") . Is this the physical or the virtual address?

I'm now trying to print out the contents of GDT. I am able to print
this address. BUt the moment I try to deference it, the kernel OOPS. I
understand that this is because the address is not in kernel virtual
address space (3GB). I tried using "ioremap" but it always returns
NULL. Any ideas?

Thanks in Advance,

Rajat
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" 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.linux-learn.org/faqs

Re: Reading the GDT in kernel space?

am 23.08.2006 17:29:59 von Josef Sipek

On Wed, Aug 23, 2006 at 07:39:22PM +0530, Rajat Jain wrote:
> Hi,
>
> I'm trying to read & display the GDT contents in kernel space. Is this
> permissible? I used the "sgdt" assembly instruction to load the GDT
> register, and found out the address & length of GDT from that (It is
> "0000c248") . Is this the physical or the virtual address?

I quickly looked at the Intel Instruction Set Reference for SGDT, and it
says that the stored value is 6 bytes long.

"The 16-bit limit field of the register is stored in the low 2 bytes of the
memory location and the 32-bit base address is stored in the high 4 bytes."

0xc248xxxx looks like a valid address, so my guess is that you are off by 2
bytes :)

Hope this helps,

Josef "Jeff" Sipek.

--
Once you have their hardware. Never give it back.
(The First Rule of Hardware Acquisition)
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" 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.linux-learn.org/faqs

Re: Reading the GDT in kernel space?

am 24.08.2006 10:40:08 von mohanlal jangir

> Hi,
>
> I'm trying to read & display the GDT contents in kernel space. Is this
> permissible? I used the "sgdt" assembly instruction to load the GDT
> register, and found out the address & length of GDT from that (It is
> "0000c248") . Is this the physical or the virtual address?

It's a physical address. Convert in virtual address using __va(x) before
dereferencing.


>
> I'm now trying to print out the contents of GDT. I am able to print
> this address. BUt the moment I try to deference it, the kernel OOPS. I
> understand that this is because the address is not in kernel virtual
> address space (3GB). I tried using "ioremap" but it always returns
> NULL. Any ideas?
>
> Thanks in Advance,
>
> Rajat
>

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" 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.linux-learn.org/faqs

Re: Reading the GDT in kernel space?

am 28.08.2006 02:47:23 von Rene Herman

mohanlal jangir wrote:

>> I'm trying to read & display the GDT contents in kernel space. Is
>> this permissible?

Sure. Also note that sgdt is available from userspace even.

>> I used the "sgdt" assembly instruction to load the GDT register,
>> and found out the address & length of GDT from that (It is
>> "0000c248") . Is this the physical or the virtual address?

SGDT gets you a kernel virtual address. That 0000c248 isn't though and
it's incorrect. The problem you will be experiencing is that you haven't
told GCC to pack the struct in which you put the result. If you declare:

struct gdtr {
u16 limit;
u32 base;
};

then gcc will align the 32-bit base field on a 32-bit boundary, meaning
it will end up looking like:

struct gdtr {
u16 limit;
u16 padding
u32 base;
};

SGDT then stores into the limit and padding and only the low 16-bits of
base (your base is actually 0xc248xxxx). To avoid this, tell GCC to pack
the struct:

struct gdtr {
u16 limit;
u32 base;
} __attribute__((packed));

Rene.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" 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.linux-learn.org/faqs