Page 1 of 1

Clarifications on Brendan's Multi-tasking Tutorial

Posted: Thu Apr 16, 2020 12:10 pm
by leth
As I said in the title, I just started that tutorial (https://wiki.osdev.org/Brendan%27s_Mult ... g_Tutorial).

At the Step 1 I already got stuck. The problem is, though, I don't exactly understand this part:
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.
The task's informations are like the page directory and the kernel stack top.
I have a question for both of them:
1 - Using recursive paging, this will always be 0xFFFFF000 or the address pointed by it?
2 - Do I have to allocate a new block from the kernel heap for this or I just use the value of esp?

This are for the first process, but can be helpful if you want to share something on creating a new one... even if I think that the tutorial will talk about this.

Re: Clarifications on Brendan's Multi-tasking Tutorial

Posted: Sat Apr 18, 2020 11:26 pm
by Octocontrabass
leth wrote: 1 - Using recursive paging, this will always be 0xFFFFF000 or the address pointed by it?
It's CR3.
leth wrote: 2 - Do I have to allocate a new block from the kernel heap for this or I just use the value of esp?
You use the value of ESP, but it gets written when you switch to a different task so you don't need to fill it in with the correct value at this point.

Re: Clarifications on Brendan's Multi-tasking Tutorial

Posted: Sun Apr 19, 2020 2:54 am
by bzt
What was wrong with this thread which asks exactly the same question?

Cheers,
bzt

Re: Clarifications on Brendan's Multi-tasking Tutorial

Posted: Sun Apr 19, 2020 5:17 am
by klange
bzt wrote:What was wrong with this thread which asks exactly the same question?

Cheers,
bzt
This one was posted two days earlier by a new user account and was stuck in the moderation queue.

Re: Clarifications on Brendan's Multi-tasking Tutorial

Posted: Sun Apr 19, 2020 1:25 pm
by bzt
klange wrote:This one was posted two days earlier by a new user account and was stuck in the moderation queue.
Ah. I see. Thanks!

Cheers,
bzt

Re: Clarifications on Brendan's Multi-tasking Tutorial

Posted: Sun Apr 19, 2020 2:46 pm
by SpyderTL
The x86 CPU has registers and instructions specifically to assist the OS with multitasking/multithreading. However, I would recommend ignoring those features, and implementing multitasking completely in software, at least at first. You can implement a software multitasking system that manages task switching in probably 10 lines of code.

The key to a simple task manager is to push everything that you need onto the stack, and then store that stack pointer value somewhere safe, and then change the stack pointer to the saved stack value from the next task, and then pull everything you need off of the top of the stack.

Once you get this working, adding hardware support and more advanced scheduling can be added later, and you can verify that everything continues to work as you make those changes.

Good luck. Let us know if you have any more questions.