Page 1 of 1

Problems following the Brendan's Multi-tasking Tutorial

Posted: Sat Apr 18, 2020 1:22 pm
by Thpertic
I just started reading the tutorial (https://wiki.osdev.org/Brendan%27s_Mult ... g_Tutorial).
But I have not understood the following sentence:
Once you've created an initial data structure for keeping track of a task's information; create an "initialise_multitasking()" function. The idea here (initially) is that there's already a task that has been running since boot, and you only need to create the information for it by allocating some memory for the task's information structure that you just created and setting the fields in that structure as appropriate.
Here he is talking about a structure which holds the page directory and the kernel stack top.
I have a question for both of them:
- I'm using recursive paging so as Page Directory should I use 0xFFFFF000 or the address pointed by it?
- In the case of the first process (the one running from boot) do I have to use the ESP value or I have to allocate another 4K block as the other processes?

Re: Problems following the Brendan's Multi-tasking Tutorial

Posted: Sat Apr 18, 2020 3:50 pm
by bzt
Thpertic wrote:- I'm using recursive paging so as Page Directory should I use 0xFFFFF000 or the address pointed by it?
Use the one that in a task switch restores the same paging you're using now (the boot task's). I believe that should be the value in CR3.
Thpertic wrote:- In the case of the first process (the one running from boot) do I have to use the ESP value or I have to allocate another 4K block as the other processes?
I think Brendan meant the current ESP.

However I'd like to point out that Brendan's advice is not the preferred nor the only way to do multitasking. There are many kernel task switching designs which makes this whole initial task structure mess completely unnecessary. And it won't work with SMP anyway (there each core should have its own stacks, and to store different ESP you'll need as many task structures as number of cores at minimum).

For example in my kernel I use identity mapping for the boot task, and once I switch to the first real task, there's absolutely no reason to switch back to identity mapping ever again. Memory allocated during early stage in boot task is simply accounted for the idle task on the BSP. Hence my kernel doesn't need this dirty initial task hack at all that Brendan is talking about.

Cheers,
bzt