Syscall/Sysret works the first time, causes #IO next.
Posted: Sat Oct 05, 2013 9:49 am
Hello.
I've recently got Ring3 threads working in my scheduler, but right now I'm using iret and there is a noticeable lag/stutter/what have you.
So I'm looking into replacing that with Syscall/Sysret... and I believe i've gotten most of the thing figured out... except this.
As you can tell from the title, I can successfully perform a syscall and sysret... however, it fails with an Invalid Opcode exception subsequent times.
Here is the code:
Ring3 program:
quite simple. Here is the MSR setup:
And here is the actual code that gets called:
Anyone got any clues? All the register values look normal at the time -- the exception occurs on the 'syscall' instruction, the second time. Works 100% as far as i can tell for the first time.
Thanks!
I've recently got Ring3 threads working in my scheduler, but right now I'm using iret and there is a noticeable lag/stutter/what have you.
So I'm looking into replacing that with Syscall/Sysret... and I believe i've gotten most of the thing figured out... except this.
As you can tell from the title, I can successfully perform a syscall and sysret... however, it fails with an Invalid Opcode exception subsequent times.
Here is the code:
Ring3 program:
Code: Select all
while(true)
{
asm volatile("syscall");
}
Code: Select all
// setup MSRs for syscall/sysret
// modify STAR
mov $0xC0000081, %ecx
rdmsr
// msr is edx:eax
// simultaneously setup sysret CS and syscall CS
mov $0x001B0008, %edx
xor %eax, %eax
wrmsr
// now we modify LSTAR to hold the address of HandleSyscall
xor %edx, %edx
// TODO: Write handler for SYSCALL instruction instead of interrupt
// keep both options available.
// fill in address when ready/
mov $HandleSyscallInstruction, %eax
mov $0xC0000082, %ecx
wrmsr
// set SFMASK to 0.
mov $0xC0000084, %ecx
xor %eax, %eax
wrmsr
// Call our kernel.
call kmain
And here is the actual code that gets called:
Code: Select all
xchg %bx, %bx
push %rcx
pop %rcx
sysret
Anyone got any clues? All the register values look normal at the time -- the exception occurs on the 'syscall' instruction, the second time. Works 100% as far as i can tell for the first time.
Thanks!