it's long time ago i succeed loading tss. recently i'm working on smp so i have to copy or rewrite a lot of my previous work. This piece of code:
Code: Select all
void cpu_init(){
......
// load gdt and tss
ulong gdtptr[2] = { (sizeof(me->gdt)-1)<<48, (ulong)&(me->gdt) };
__asm( "lgdt (%%rax)" : : "a"( (ulong)gdtptr + 6 ) );
__asm( "ltr %%ax" : : "a"( X64_SELECTOR_TSS ) );
[b]// if i add some, maybe any function call here, it will work properly.[/b]
}
so the #PF, have no reason to happen, i'm very sure about it. and the following situations proved it.00034055736e[CPU0 ] exception(): 3rd (14) exception with no resolution, shutdown status is 00h, resetting
if i add some function right after the ltr instruction, it will work. ( i found this because i succeed at the begining, with a print function there to say "success" . ) but some more inline asm will not solve.
and if i replace the inline asm with a asm function call ( fun is in a separate file), it will also work:
Code: Select all
void cpu_init(){
......
// load gdt and tss
ulong gdtptr[2] = { (sizeof(me->gdt)-1)<<48, (ulong)&(me->gdt) };
__asm( "lgdt (%%rax)" : : "a"( (ulong)gdtptr + 6 ) );
//__asm( "ltr %%ax" : : "a"( X64_SELECTOR_TSS ) );
loadtss(X64_SELECTOR_TSS); [b]// a assembly function also works.[/b]
}
so i'm thinking if it is the problem of gcc, when i put an inline asm at the end of a function, it generated wrong code or sth?