Executing a task

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Srowen
Member
Member
Posts: 60
Joined: Thu Feb 26, 2009 2:31 pm
Location: Genova, ITALY

Executing a task

Post 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..
User avatar
f2
Member
Member
Posts: 311
Joined: Mon Jun 15, 2009 10:01 am
Location: France

Re: Executing a task

Post 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.
"Open source seems to embrace the dark side of human nature." - Ville Turjanmaa
Srowen
Member
Member
Posts: 60
Joined: Thu Feb 26, 2009 2:31 pm
Location: Genova, ITALY

Re: Executing a task

Post 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..
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Executing a task

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Srowen
Member
Member
Posts: 60
Joined: Thu Feb 26, 2009 2:31 pm
Location: Genova, ITALY

Re: Executing a task

Post by Srowen »

So it's better to do a software context switch.. ok... thanks a lot!
Post Reply