idea for multitasking

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
unknown user

idea for multitasking

Post by unknown user »

i was thinking about something for writing my kernel to multitask. what if i disassembled each prog i was going to run and ran the asm commands one by one? i asked this on EH but nobody answered.
Tim

Re:idea for multitasking

Post by Tim »

No, don't (unless you're trying to write a Java VM). It would be veryveryveryvery slow. Assuming you're on the x86, you can do simple multitasking on the timer interrupt.
  • Give each task (thread or whatever) its own kernel stack
  • On every interrupt, store all registers on the stack (pusha and push each segment register).
  • On the timer interrupt, choose which task will run next
  • On the way out of every interrupt handler, switch to the current stack (mov esp, something)
For example:

Code: Select all

timer_handler:
pusha
push ds
push es
push fs
push gs

mov eax, KERNEL_DS
mov ds, eax
mov es, eax

; Centralised interrupt handler. Returns new ESP in EAX
call interrupt_hander
mov esp, eax

pop gs
pop fs
pop es
pop ds
popa
iret
unknown user

Re:idea for multitasking

Post by unknown user »

now how exactly would you put that into action. i'm new to asm and am writing this in C, so i'm kind of "iffy" on the whole thing.
Tim

Re:idea for multitasking

Post by Tim »

There's too much to explain on a board like this. Try browsing through the Cosmos source code:
http://www.execpc.com/~geezer/os/
Post Reply