Clarifications on 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
leth
Posts: 1
Joined: Thu Apr 16, 2020 11:58 am

Clarifications on Brendan's Multi-tasking Tutorial

Post 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.
Octocontrabass
Member
Member
Posts: 5575
Joined: Mon Mar 25, 2013 7:01 pm

Re: Clarifications on Brendan's Multi-tasking Tutorial

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

Re: Clarifications on Brendan's Multi-tasking Tutorial

Post by bzt »

What was wrong with this thread which asks exactly the same question?

Cheers,
bzt
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

Re: Clarifications on Brendan's Multi-tasking Tutorial

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

Re: Clarifications on Brendan's Multi-tasking Tutorial

Post 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
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Clarifications on Brendan's Multi-tasking Tutorial

Post 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.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Post Reply