What should be implemented before multitasking?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
mrjbom
Member
Member
Posts: 317
Joined: Sun Jul 21, 2019 7:34 am

What should be implemented before multitasking?

Post 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.
User avatar
AndrewAPrice
Member
Member
Posts: 2300
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: What should be implemented before multitasking?

Post 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.
My OS is Perception.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: What should be implemented before multitasking?

Post 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.
User avatar
mrjbom
Member
Member
Posts: 317
Joined: Sun Jul 21, 2019 7:34 am

Re: What should be implemented before multitasking?

Post 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.
User avatar
AndrewAPrice
Member
Member
Posts: 2300
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: What should be implemented before multitasking?

Post by AndrewAPrice »

I found the PIT very easy to use. It'll fire an interrupt on IRQ0.
My OS is Perception.
Post Reply