Skip to contentSkip to conversation

Reading the GDT in kernel space?

DISCUSSION Rajat Jain 4 participants 4 messages Aug 23, 2006 – Aug 28, 2006

lore
Share & tools
lore

Rajat Jain

author
#0 lore raw

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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

#1 lore raw
Quoted 6 lines · 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 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.

Signature · 7 lines
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 [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
#2 lore raw
In reply to Rajat Jain
Quoted 6 lines

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.

Quoted 11 lines

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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

#3 lore raw
Quoted 2 lines · mohanlal jangir
Quoted 2 lines

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.

Quoted 2 lines
Quoted 2 lines

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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs