software multitasking
software multitasking
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.
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.
Go here : http://alexfru.narod.ru/
Get "os.zip" its got a simple example coded with DJGPP
Get "os.zip" its got a simple example coded with DJGPP
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
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.
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.
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.
Why should that technique be particular to microkernels?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.
- Combuster
- 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:
Where? Where? i'll kill that articleiammisc wrote:And plus the wiki says so...
![Shocked :shock:](./images/smilies/icon_eek.gif)
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+...])
- AndrewAPrice
- Member
- Posts: 2309
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
No, not if you initialize the stack/heap first.Crazed123 wrote:Actually, now that I think of it, isn't jumping to a code segment with a higher DPL than the CPL illegal?
My OS is Perception.
woops. my bad,i was thinking of this article on osdever.net http://osdever.net/tutorials/soft_ts.phpWhere? Where? i'll kill that article *shocked*