‫Hello and welcome, everybody, and this lecture, we're going to start implementing some of the usual
‫and functionality.
‫So what I want to do is in the task directory, in your source directory, we're going to create a new
‫file called Task Start Azem.
‫Now we're going to set the bits to thirty two.
‫That's the very first things.
‫Just go scoping study to up here.
‫We're going to set the section to section DSM and we're going to create a function called Restore General
‫Purpose Registers and whatever.
‫We're going to just go push EBP movie VSP, Move SBX, SBP plus eight and this will all be explained.
‫Move Eddi SBX move essi SBX plus four, move pbp SBX plus eight.
‫Move idex ebby Ebix plus 16.
‫Move SBX SBX plus 20.
‫Move X SBX plus 24 and finally move SBX SBX plus 12.
‫And we're now going to go pop E.S.P and return.
‫So this little function here restores the general registers.
‫So it looks like this OK, void the star general purpose registers struct registers red regs.
‫So that that is how that looks, guys.
‫OK, uh, so we access the point and we just go through it.
‫And if we go to tests at Hajj, this is the red structure that we are accessing, OK, in our assembly
‫code here.
‫So let's go to test stage and we're now going to create some prototypes, including a prototype we just
‫made for four star general purpose registers.
‫OK, so we're just going to go void's restor, general purpose registers, struct registers, regs,
‫OK, and go to task today s.m again.
‫Just by here, we're going to go global restor general purpose registers and that objects spotted in
‫the object file so that it can be used elsewhere.
‫So we just go to task tonight.
‫Again, I want to create a new prototype.
‫We're going to avoid task return, OK?
‫And that is also going to take in registers and what this task return function will be.
‫It'll draw us into use a land, OK, based on the registers we provide here and the IP.
‫OK, so it'll actually drop us in the U.S. and we are going to create that function.
‫Tester DSM now to go back to test the DSM.
‫So we're just going to go TASC Return, move EBP VSP, OK, and I'm going to put some rules here for
‫us.
‫So the first thing we need to do is push the data segment.
‫Uh, SS will be fine.
‫OK.
‫Next thing we need to do is push the stack address.
‫Next thing we need to do is push the flags and next thing we need to do is push the code segment, finally
‫push the IP.
‫OK, now as I said before in the presentation about Use the Land, I explained all this to you in this
‫function we're creating now, uh, essentially we will issue an IRA instruction once we've pushed all
‫this to the stack.
‫Uh, the the processor doesn't know any different.
‫It doesn't it'll treat us as if we're returning from an interpreting.
‫It will pop everything we pushed here and push us straight into, uh, use the land.
‫OK, so that's what's going on.
‫So let's access the structure, uh, pass to us.
‫That's the first thing.
‫So to do that, we go movie A, B plus four.
‫OK, next we're gonna go past these words,
‫SBX plus forty four.
‫So push the data stack select.
‫OK, so we're basically pushing the data segment.
‫What the SS register here.
‫OK, and now we push the stack pointer push would word SBX plus forty.
‫And guys, these aren't just random numbers I'm picking here.
‫Right.
‫You need to realize they've passed us a structure registers here.
‫OK, as a matter of fact, I'm going to copy this and paste it here to make it more clear for you so
‫you can see.
‫So they're passing us this register structure and we're basically accessing each of the fields, OK,
‫by offset because we're in assembly.
‫So they're not random numbers.
‫OK, so the next step is to push the flags because if I just go to test one second.
‫You know, you can see SS E.S.P flags, SS, you know, we're just offsetting them correctly here,
‫OK?
‫That's what's going on.
‫So we're going to push the flags now.
‫So we just go push chef.
‫OK, we're now going to pop the flag since the register, we're going to order on that bit that I was
‫talking about in the previous presentation, which will enable interrupts once we issue and I read instruction,
‫OK, because we're enabling that bit in the flags.
‫OK, so when I want to push the flags back to the stack, now that we've done that, now the next step
‫is to push the code segment.
‫So we do that by going posti what SBX 30 to and now we want to push the IP to execute the IPS, the
‫program counter guys, the address in memory we wish to execute.
‫And yeah, this is this will look for a virtual address, OK, because we have paging enabled, so just
‫don't forget that.
‫So we're now going to go push the word Ebix twenty eight.
‫OK, and now we want to set up some segment registers.
‫OK, so we do that by going move X PBX plus forty four.
‫We're just going to go move these X move esx, move FS X move to X.
‫OK, that's what we're doing there now.
‫We cannot change the stack segment here because we're still relying on the stack, OK, and we don't
‫need to worry about changing the stack segment because when we issue that I read instruction, the processor
‫will deal with that for us.
‫So we also need to restore the registers to the ones in the register structure pass to us.
‫This is not so difficult.
‫We just go past with EBP plus four and now we're going to call Restor general-purpose registers below
‫by here.
‫So basically just passing that pointer to this function, OK?
‫And we now need to restore the stack and unfortunately we're unable to pop from the stack because we
‫risk we risk corrupting a register.
‫OK, so we're just going to go ADP four and then that gets around that whole problem.
‫Why do we need to do that?
‫Because we just pushed for bytes here to the stack when we pass this register structure to it.
‫Final thing to do is I read these let's leave kernel land and execute in use the land.
‫There we go.
‫And that is that is absolutely it for that function.
‫Little dropsonde to use the land.
‫So basically we're basically falsifying a interrupt stack frame, essentially, OK, we are pushing
‫all the stuff that the processor would usually push when it calls an interrupt.
‫We are pushing all that manually, pretending we're in an interrupt.
‫Right.
‫And then we just do an IRA to leave that fake in Europe.
‫That never even happened.
‫But the processor will react the same as if it was an interrupt.
‫It's going to go and pop all of these values off the stack and it's going to drop us into use the land
‫and basically take us to where this IP is in this register's structure.
‫So that's good that we've done that.
‫Now let's export it.
‫So we're going to go global task return.
‫OK, so go back to test, I hate you have another function we need to make here.
‫So just under here, just go void, use the registers, OK?
‫And now back to test ideas and we're going to create that down here.
‫Use the registers and all of this function is going to do is change all the segment registers to the
‫user data segment registers.
‫So we're just going to go move X zero x 23, move D X, move s X, move FS X and move GSA X, and we're
‫just going to return.
‫And that said, obviously the code segment isn't changed.
‫It only affects the data registers.
‫This one does and it just changes the address to zero.
‫It just changes the value the selector to zero x 23, which which is the user data segment.
‫OK, so that's what that's doing.
‫So.
‫Yet scroll up and we're going to just explore that, so we're going to go global use registers.
‫OK, and now you've implemented that one as well.
‫OK, so go to task, Ötzi, because we have some CECO we need to right now.
‫We're not ready to just load the process yet.
‫There's still more things that need to be done.
‫OK, guys, so we're just going to go in it tasc switch struct task task.
‫And what this function will be responsible for is switching the current task that is running.
‫It'll change the current tasks that's running and it will change the page directories of the process
‫to point to the task we've provided here.
‫OK, so that's what this functions for.
‫So to do that, we're just going to go kind of task was task.
‫Paging Switch task page directory, and I was just going to return zero, so it's nice and easy, OK?
‫We now want to copy and paste this into tests on this prototype.
‫So it's accessible out of the test of file.
‫And we're now just going to go in it.
‫TASC page user registers tasks which Curran's task.
‫So what does this do?
‫Task Page takes us out of the kernel page, page directory and loads us into the task page directory.
‫That's what that does.
‫OK, so one, there's an interest in the kernel.
‫We are responsible for switching to the kernel page and then back to the task page.
‫OK, the page directories.
‫So that's why we create this function here in a task page, because after we after when there's some
‫sort of interest in the user LAN program, the process, the kernel will be called again.
‫OK, and we want to access the kernel page at this point in time.
‫OK, and now when we're done, we obviously want to switch back to the tasks page so that when we return
‫from the interrupt, the user process can see the memory as it saw it before it called the kernel.
‫OK, so that's what that's false.
‫So that calls our user registers function, which we just made, which will set all of the second registers
‫back to the user land.
‫And it calls tasks which which we've just made, which switches the paging directory to the tasks page
‫directory.
‫So that's what that does, guys.
‫OK, we're just going to return zero here as well.
‫I want to copy that prototype and just put that in the header as well.
‫OK, we've almost finished this user LAN functionality.
‫However, we need to create a function that will run the very first task.
‫So we're just going to go void task, run first ever task.
‫And this will be responsible for doing just that, running the very first task.
‫So just copy this.
‫I'm going to paste it by here.
‫So void task run first EVA task.
‫The very first thing we're going to do is we're going to make sure that there is a current task.
‫All right.
‫So if there's if there's no current task in the system, then we're going to panic.
‫Right?
‫Because what we need we need that no current task exists because that's very, very important that we
‫do this.
‫Check, guys, if we don't do this check and someone calls this a panic system, the task has to be
‫loaded before we call this.
‫So now we're going to go tasks which task ahead.
‫And we know that there's a task ahead because we just checked there was a current task and now we're
‫going to go to task return task head registers so you can see that this function should only be called
‫for running the very first task in the system.
‫So you call this and it will run the heads essentially.
‫How does it run the heads?
‫It switches the task and then calls the task run a task return, I mean, which will drop it into use
‫the land.
‫OK, so before we go any further, I want you to know that our current system is single threaded.
‫There's no ability for multiple tasks to be running at once.
‫However, the way we've written this code allows for it to be implemented more easily later on should
‫we decide to implement multitasking here?
‫Because once again, remember, I said the multitasking is just flipping the registers back and forth
‫like that.
‫OK, Task one registers task choose registers, task one's registers task choose registers.
‫You do this every time that there's an interest to some kind, maybe a timer and to interrupt something
‫like that.
‫And that is how you do it.
‫OK, and by flipping the register so fast, it gives the illusion of multitasking even though there
‫was never multitasking going on because there's only one.
‫We're only working with one processor call, but it gives the illusion multiple things are running at
‫once.
‫OK, so if we just go to the Makefile, we're going to add that task today is in this file so we can
‫see tests to assess today.
‫Sentido, just copy that and we're going to post that here.
‫I want to change that.
‫The task force assembled a task to this task today is task today assembled out.
‫Just copy and paste the task today assembled.
‫And we're going to put this in the object file.
‫OK, just like that.
‫And we're just going to make clean build that S.H. and hopefully everything compiles.
‫Uh, OK, we can see missing argument, one of paging switch.
‫That's no problem.
‫Go to task 106.
‫And we can see it's looking for a directory point and we gave it a page directory, so we need to give
‫it the actual directory entry guys, because that is what it is looking for the directory entry.
‫OK.
‫So if we now believe that, I can see that Bill is absolutely fine.
‫Are we going to see we still see the messages, so there's no panicking going.
‫So, yes, the fix to that Complera guys will pass in the directory entry, not the page directory structure.
‫OK, so we've now implemented this use functionality.
‫So let me tell you where we go from here.
‫Well, essentially, we load the process.
‫That's the first thing we do by loading the process.
‫What it does is it creates a new task.
‫OK, by calling task run first of a task, that task will get run.
‫So that's what's going to happen.
‫Guys, we're going to use the process low for slaughter, process, load function.
‫And then finally, we're going to call task first of a task and that will run our task.
‫However, we don't have any programs to run right now, so we will obviously need to implement those
‫first.
‫OK, so thanks for watching this lecture.
‫Guys were very close to having used the programs now.