Page 1 of 1

What should be implemented before multitasking?

Posted: Thu May 14, 2020 1:31 pm
by mrjbom
Hi.
I want to implement multitasking in my OS, but I don't understand what I need to do before that.
Now I can work work with the keyboard and I have a primitive physical memory manager (divides the memory into pages and allocate the desired number of pages), is this enough to implement kernel multitasking? Or should I do something else?
I think so, but it's better to ask.

Re: What should be implemented before multitasking?

Posted: Thu May 14, 2020 5:57 pm
by AndrewAPrice
Very close, you just need to implement interrupt handling. Return from the interrupt with a different set of registers (including the instruction pointer and stack pointer) to what you entered with.

Then, this interrupt could be fired from a timer or manually fired by a thread willing to give up control.

Re: What should be implemented before multitasking?

Posted: Fri May 15, 2020 12:52 am
by iansjack
I'd say that allocating memory as pages, rather than smaller amounts, is going to be a little wasteful. I'd recommend writing a memory allocator to hand out smaller chunks of (virtual) memory.

Re: What should be implemented before multitasking?

Posted: Fri May 15, 2020 8:26 am
by mrjbom
AndrewAPrice wrote:Very close, you just need to implement interrupt handling. Return from the interrupt with a different set of registers (including the instruction pointer and stack pointer) to what you entered with.

Then, this interrupt could be fired from a timer or manually fired by a thread willing to give up control.
I already have interrupts, I think I need to implement software interrupts somehow. I also need a timer with millisecond accuracy to switch between tasks. But I don't know what kind of watch will help me.

Re: What should be implemented before multitasking?

Posted: Fri May 15, 2020 1:31 pm
by AndrewAPrice
I found the PIT very easy to use. It'll fire an interrupt on IRQ0.