Page 1 of 1
idea for multitasking
Posted: Wed Apr 10, 2002 5:21 pm
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.
Re:idea for multitasking
Posted: Wed Apr 10, 2002 5:42 pm
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
Re:idea for multitasking
Posted: Sun Apr 14, 2002 6:48 am
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.
Re:idea for multitasking
Posted: Sun Apr 14, 2002 10:18 am
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/