Page 1 of 1
software multitasking
Posted: Thu Mar 08, 2007 2:15 pm
by xyjamepa
Hi,
a month ago I tried to implement a hardware multitasking
but I found it hard, complex and slow so I decided
to implement software multitasking but I have no idea
about it so I think I need some explaint about software
multitasking and how it goes with paging
and how can I implement it(I mean here software multitasking),also
any links or tutorials are welcome.
my os sure 32bit protected mode and I'm using DJGPP
Thanx.
Posted: Thu Mar 08, 2007 3:14 pm
by Dex
Go here :
http://alexfru.narod.ru/
Get "os.zip" its got a simple example coded with DJGPP
Posted: Thu Mar 08, 2007 3:35 pm
by pcmattman
I cheated a bit in my soft multitasker... I basically have a resched function only called by the timer interrupt, which has all the registers, flags and segments in a convenient structure. That's passed to the resched function, which saves the old process data and loads the new data. When it returns, the timer interrupt continues processing and once that's done, the timer interrupt effectively returns to the next process.
Posted: Thu Mar 08, 2007 9:02 pm
by iammisc
most operating systems store a structure with a pointer to the stack for the process and the page directory. To switch tasks, you switch page directories(make sure that your kernel is mapped to every task!), and then you change esp to the new process's stack. Then you pop off all the registers from the new stack. Because your stack contains the return address whatever called the task switching function, on your next ret, control of the processor will be given back to the old process's state.
You will have to create a function that sets up the initial stack properly for each new task.
If you have a microkernel and want your task switching to go a bit faster and make the switcher easier to implement, you could just store all the registers and the cs:eip inside the process structure then to switch processes you would set the new page directory, restore the cpu state, and jmp to the old cs:eip.
While the microkernel one is easier to implement, it also has more liability to not work which is why i recommend for you to follow the first one.
Posted: Thu Mar 08, 2007 10:02 pm
by Crazed123
iammisc wrote:If you have a microkernel and want your task switching to go a bit faster and make the switcher easier to implement, you could just store all the registers and the cs:eip inside the process structure then to switch processes you would set the new page directory, restore the cpu state, and jmp to the old cs:eip.
While the microkernel one is easier to implement, it also has more liability to not work which is why i recommend for you to follow the first one.
Why should that technique be particular to microkernels?
Posted: Fri Mar 09, 2007 10:16 pm
by iammisc
That trick is limited for microkernels because it is only should be used for fast-switching contexts not really for a full-fledged multitasking thing.
And plus the wiki says so...
Posted: Sun Mar 11, 2007 5:05 am
by Combuster
iammisc wrote:And plus the wiki says so...
Where? Where? i'll kill that article
Really, the concept of software task switching is independent of kernel style. You can use either method for both types of kernels. The only essential difference is the use of PUSH/POP register instead of MOV register. (which you can even evolve in the other: you could temporarily point esp at the desired structure and push/pop, or you can load the registers from [ESP+...])
Posted: Sun Mar 11, 2007 12:05 pm
by Crazed123
Actually, now that I think of it, isn't jumping to a code segment with a higher DPL than the CPL illegal?
Posted: Sun Mar 11, 2007 6:21 pm
by AndrewAPrice
Crazed123 wrote:Actually, now that I think of it, isn't jumping to a code segment with a higher DPL than the CPL illegal?
No, not if you initialize the stack/heap first.
Posted: Sun Mar 11, 2007 6:37 pm
by Crazed123
Really? How so?
Posted: Sun Mar 11, 2007 11:08 pm
by iammisc
Where? Where? i'll kill that article *shocked*
woops. my bad,i was thinking of this article on osdever.net
http://osdever.net/tutorials/soft_ts.php