Page 1 of 1
Multitasking - How OS actually switch to a new task ?
Posted: Wed Apr 20, 2011 5:39 am
by osdevkid
Dear All,
I am go throughing about "create and start a task".
To create a new task, we have to create a new address space, and that address space should have a link on kernel code and heap area and we have to add that created task in to the task list and etc.,
my doubt is where exactly we are starting a new task ? because no special x86 instruction to start a new task. (
is there any special x86 instruction to start a created task ?)
The below link explains about how to create a new task and start a new task
http://www.jamesmolloy.co.uk/tutorial_h ... sking.html
But, I can't able to understand the function "read_eip()". just jumping to a particular address is an actual start of a task ?
Can you explain, how it is working ?
Re: Multitasking - Any x86 instruction to start a created ta
Posted: Wed Apr 20, 2011 6:27 am
by AJ
Hi,
Yes - to start a task, all you need to do is jump to the entry point.
Typically, you will do something such as: create the new address space and switch to it (still in ring 0), create a user mode stack, load executable code, jump to entry point (now switching to ring 3).
The new task will typically then do its runtime setup, so you may want to set up an initial heap, open stdin, stdout and stderr etc before calling main.
Cheers,
Adam
Re: Multitasking - Any x86 instruction to start a created ta
Posted: Wed Apr 20, 2011 6:37 am
by osdevkid
Yes you are right, however, in that URL (see it, in my first thread), they are in ring level 0 and they are creating an address space .... etc., and just juming to the code in ring level 0, how it will be task switch ?
Re: Multitasking - Any x86 instruction to start a created ta
Posted: Wed Apr 20, 2011 7:02 am
by AJ
Hi,
I've just looked through the link and understand what you mean...
That function is just a way of reading the
current eip.
Code: Select all
[GLOBAL read_eip]
read_eip:
pop eax
jmp eax
The explanation is in the paragraph immediately after the code snippet. What JamesM is actually doing is implementing fork(). If you have a look at how fork() works, you will see why he needs the current value of EIP. Later in his tutorial, he explains how the two tasks know whether they are child or parent prcesses and goes on to talk about the kernel multitasking code...
Cheers,
Adam
Re: Multitasking - Any x86 instruction to start a created ta
Posted: Wed Apr 20, 2011 7:12 am
by osdevkid
Dear Adam,
Thank you very much.
The ASM function "read_eip" is used to just read the instruction pointer where to start executing the child task. it is not an actual task switch.
Even we can use an another function with while(1) loop and we can assign this function address to task structure "eip" field, to start executing the child task. Am I right ?
The actual task switch happens at switch_task() function, not at "read_eip".
Please correct me, if I am wrong.
Re: Multitasking - Any x86 instruction to start a created ta
Posted: Wed Apr 20, 2011 8:18 am
by AJ
Hi,
That's correct, although what is actually intended with fork() is that you start at the same EIP and the child process then uses something like execve to execute the child process.
Cheers,
Adam
Re: Multitasking - Any x86 instruction to start a created ta
Posted: Wed Apr 20, 2011 10:30 pm
by osdevkid
Dear Adam,
Thanks for your reply.
I think, we understood wrong. Because JamesM clearly commented as below:
after the call to "read_eip" we could be in one of two states.
1.We just called read_eip, and are the parent task.
2.We are the child task, and just started executing.
So, JamesM starts his new task at "read_eip", now the question is how it is possible to start a child task by just simple "JMP" instruction?
Re: Multitasking - How OS actually switch to a new task ?
Posted: Thu Apr 21, 2011 12:36 am
by Combuster
Do you know how software task switching works?
Re: Multitasking - How OS actually switch to a new task ?
Posted: Wed Apr 27, 2011 1:23 am
by osdevkid
What is "pointy wizard hat" ?
Re: Multitasking - How OS actually switch to a new task ?
Posted: Wed Apr 27, 2011 3:45 am
by Combuster
You might have looked it up at the
hacker's dictionary but I can imagine you're not established enough to know of its existence.
Jargon file wrote:Pointy hat: See wizard hat. (...)
Wizard hat: Notional headgear worn by whoever is the wizard in a particular context. (...)
Wizard:
1. Transitively, a person who knows how a complex piece of software or hardware works (that is, who groks it); esp. someone who can find and fix bugs quickly in an emergency. Someone is a hacker if he or she has general hacking ability, but is a wizard with respect to something only if he or she has specific detailed knowledge of that thing. A good hacker could become a wizard for something given the time to study it.
2. The term ‘wizard’ is also used intransitively of someone who has extremely high-level hacking or problem-solving ability.
Looking up "wizard" in the
urban dictionary gives similar results (but also some NSFW ones near the bottom). "pointy hat" doesn't look up well there though (do not try at work).