Page 1 of 1

Executing a task

Posted: Fri Aug 21, 2009 2:56 am
by Srowen
I'm developing my os for the x86 architecture. I set up the TSS and the task gate descriptor in the GDT. I use the LTR istruction to set up the Task Register. But now i have to do the context switch. In the intel manual, it is written that i can do this in some different mode, for example "using an explicit call to a task with the CALL instruction". Ok, it is clear but.. what is the assembly code to do this?? thanks for reply at this noob question..

Re: Executing a task

Posted: Fri Aug 21, 2009 3:07 am
by f2
1) load the Task Gate Descriptor of the task with the LTR istruction.
2) do a far call to this Task Gate Descriptor.

Example:

Code: Select all

     mov  ax, 0x0028           ; 0x28 is the task gate selector
     ltr     ax
     call   far 0x0028:0x00000000
More info here: http://www.acm.uiuc.edu/sigops/roll_your_own/5.a.html.

Re: Executing a task

Posted: Fri Aug 21, 2009 4:25 am
by Srowen
i use this code:

Code: Select all

    asm volatile("movw $0x28, %ax");
    asm volatile("ltr %ax");
    asm volatile("lcall  $0x0,$0x28");
but while i try the lcall it give me a general protection fault..

Re: Executing a task

Posted: Fri Aug 21, 2009 8:42 am
by Combuster
1) load the Task Gate Descriptor of the task with the LTR istruction.
2) do a far call to this Task Gate Descriptor.
That's guaranteed to cause an GPF. (call to busy task)

to change hardware tasks (its slow, most people use software task switching), you can either ljmp, lcall, or iret to it. In any case, the jump only makes sense when the task is not the same as the one pointed to by TR. Both the ljmp and lcall will require an non-busy task, the difference is that with ljmp the original is set to non-busy, while lcall leaves it in the busy state.

Re: Executing a task

Posted: Fri Aug 21, 2009 11:23 am
by Srowen
So it's better to do a software context switch.. ok... thanks a lot!