01000101 wrote:
? that's what my function did.
it took the memory location of the gdt struct and was then used with the SGDT instruction.
No, your function did a
Code:
asm volatile ("sgdt %0" : "=m" (location) : : "memory");
Your inline assembly statement specifies location as an output operand. The sgdt instruction takes location as an input operand.
EDIT: It seems my code is not correct either.
The following code gives the expected results on linux 2.6.22-14-386.
Code:
#include "stdio.h"
struct gdt_desc
{
unsigned short limit;
unsigned int base;
} __attribute__((packed));
void store_gdt_desc(struct gdt_desc *location) {
asm volatile ("sgdt %0" : : "m"(*location) : "memory");
}
int main(int argc, char** args) {
struct gdt_desc desc;
store_gdt_desc(&desc);
printf("First run, gdt base: 0x%X, limit: 0x%X\n", desc.base, desc.limit);
store_gdt_desc(&desc);
printf("Second run, gdt base: 0x%X, limit: 0x%X\n", desc.base, desc.limit);
store_gdt_desc(&desc);
printf("Third run, gdt base: 0x%X, limit: 0x%X\n", desc.base, desc.limit);
}
The result on my machine is:
Code:
First run, gdt base: 0xC039B000, limit: 0xFF
Second run, gdt base: 0xC039B000, limit: 0xFF
Third run, gdt base: 0xC039B000, limit: 0xFF
These values do not change if I run the program several times. It seems linux does not change the gdtr register.