Page 1 of 1

Multitasking without paging

Posted: Mon Dec 14, 2020 5:40 am
by verynewbienoob
Hello,
Like in topic, is it possible? Every one guide that I see on osdev-oriented websites describe it but with paging already implemented. My goal is to first implement multitasking and then maybe in future implement paging.

Re: Multitasking without paging

Posted: Mon Dec 14, 2020 6:23 am
by pvc
Shouldn't be a problem. Just treat all your tasks just as you would treat threads of a single process. The thing is that you lose address space separation, so one misbehaving task can break others.
In the code, 2 major differences would be that
  • You have to be able to load any executable (and library) anywhere in the address space
  • You never swap address spaces (reload CR3 on x86)

Re: Multitasking without paging

Posted: Mon Dec 14, 2020 6:29 am
by bzt
verynewbienoob wrote:Hello,
Like in topic, is it possible?
Absolutely yes. Read viewtopic.php?f=15&t=37283 too.
verynewbienoob wrote:Every one guide that I see on osdev-oriented websites describe it but with paging already implemented.
Because that's simpler. Most implementations also switch address spaces, because it's easier to create tasks with separate address spaces (no task-specific addresses needed).
verynewbienoob wrote:My goal is to first implement multitasking and then maybe in future implement paging.
That could be tricky, but doable. You can make shortcuts if you implement paging first; and you can develop bad practices if not. The main difference is, without paging all tasks must use different addresses for their code segments, while with paging all tasks use the same address for their code.

Cheers,
bzt

Re: Multitasking without paging

Posted: Mon Dec 14, 2020 1:45 pm
by bloodline
My OS doesn’t use memory protection or paging. Feel free to browse the source code on GitHub and ask questions if you need pointers about how to do it.

Re: Multitasking without paging

Posted: Tue Dec 15, 2020 4:00 am
by thewrongchristian
verynewbienoob wrote:Hello,
Like in topic, is it possible? Every one guide that I see on osdev-oriented websites describe it but with paging already implemented. My goal is to first implement multitasking and then maybe in future implement paging.
If you're just doing threading in kernel space, such as you might do with an embedded platform, multitasking without paging is not only desirable, but also mandatory for embedded processors that don't have paged MMU.

One of the benefits of doing multitasking before paging is you can do so entirely in user space in a hosted process, and use regular host debugging tools to work on your multitasking implementation to get to grips with the details. Essentially, it allows you to model it as a user space threading library, then once you're comfortable, move the code you've written to bare metal.

Paging, however, is so fundamental to general purpose operating systems that it is worth understanding and implementing early. Apart from anything else, it makes management of free memory much easier, as you don't have to deal with external fragmentation, and once you move to user space with potentially multiple address spaces, it's the only sensible way of protecting those address spaces from each other (other protection mechanism exist, such as base/limit segmentation, but they're not portable.)

Re: Multitasking without paging

Posted: Sun Dec 20, 2020 4:35 am
by clementttttttttt
Well LDT exists so it shouldn't be that hard.