Page 1 of 1

syscall/sysret in longmode

Posted: Fri Feb 16, 2007 3:22 pm
by os64dev
can somebody explain to me how to use syscall/sysret in longmode, because i've been figuring out how it works but bochs only gives me.

00001321150e[CPU0 ] interrupt(long mode): unsupported gate type 6
00001321150e[CPU0 ] interrupt(long mode): gate descriptor is not valid sys seg
00001321150e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting


i've set the GDT msr STAR and have the LSTAR according to the folowing code:

Code: Select all

    gdt[0].raw[0] = 0x0000000000000000ull; //- null selector.
    gdt[1].raw[0] = 0x0020980000000000ull; //- code64 selector ring 0
    gdt[2].raw[0] = 0x0000080000000000ull; //- data64 selector.
    gdt[3].raw[0] = 0x00209E0000000000ull; //- code64 selector ring 3.

    asm volatile("lgdt %0" :: "m" (pgdt));
    asm volatile("movl $lbl, %0;ljmp *%1; lbl:" : : "m" (myjmp.addr), "m" (myjmp));
    asm volatile("movq   $0x00000000C0000081, %rcx;"
                 "movq   $0x0008000800000000, %rax;"
                 "wrmsr;                           "
                 "movq   $0x00000000C0000082, %rcx;"
                 "movq   $0x0000000000008000, %rax;"
                 "wrmsr;                           "
    );
    asm volatile("syscall");
fyi, at 0x8000 there is a jmp. statement, so it should hang.

any pointers anyone?

Posted: Sat Feb 17, 2007 9:09 am
by os64dev
never mind, i found out already. there were several errors:

1) the memory page was supervisor mode only.
2) EFER.SCE was not set to 1.
3) MSR registers are address by edx:eax instead of full 64-bit registers.

when i fixed the above the syscall was working properly. yay now i can concentrate on system calls....
well maybe after setting up the IDT :D