Problems following the Brendan's Multi-tasking Tutorial

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Thpertic
Member
Member
Posts: 56
Joined: Sun Sep 16, 2018 6:46 am

Problems following the Brendan's Multi-tasking Tutorial

Post 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?
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

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

Post 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
Post Reply