‫Hello and welcome, everybody, and in this lecture, we're going to start changing our identity functionality
‫and we're going to essentially be implementing interrupt zero eight.
‫As I said in the presentation, this will be the Interop that will be used for communication from use
‫of processes to the kernel.
‫So the very first thing we're going to want to do is we're going to want to go to ID assembly and source
‫it, ID JSM scroll all the way down here.
‫I'm going to go Isaw 8H Rappa and we're going to clear the entraps.
‫We're going to push ahead.
‫OK, so as you know, push and push is the general-purpose registers.
‫To the stack, OK, now, as you are already aware that I explained in the presentation, one an interest
‫Zwick's 80 is invoked while our interests he said he wanted to invoke from Yucel and the actual process
‫will push a lot of the same things as we push to get to use land in the first place.
‫There will be slight differences because some of those registers will be different now, such as the
‫program counter, for example, the IP register where they are, the current instruction being executed.
‫So that's important to know.
‫So I'm just going to outline them now, just so you know.
‫OK, so there's an interrupt frame start, and I'm just doing this so you can see, OK, because you
‫might get confused later down the line.
‫So these are already pushed to us by the process upon entry to this entrance.
‫OK, so they go as follows.
‫We have Unit 32 T IP.
‫We have a unit three to six units, three to three flags.
‫And don't forget the comment there, guys.
‫We have a Unit 32 to stack pointer Unit 32 t stack segment.
‫So that's what's pushed to us.
‫OK, these are pushed to us automatically.
‫And then we push the general purpose registers to the stack as well.
‫So the X, X, X and so on.
‫OK, because these are these are the registers, the general purpose registers as they were in the user
‫program at this time because we haven't changed anything yet.
‫The only thing we've done is change the flags here, OK, by issuing a Seelie instruction.
‫And we don't actually need the KELLYE instruction because because of the type of interrupt this is we
‫go to it does C and we see IDC said yes because of the type attribute being what it is, the interrupts
‫will be disabled automatically upon entry to this function anyway.
‫So we don't actually need to clear the interrupts here.
‫So yeah, we can actually get rid of that clear interop flag and we can get rid of all of these, by
‫the way.
‫So I gave it a clear here and gave it a stay here.
‫Clear here.
‫Stay here.
‫OK.
‫Perfect, because we we just don't need them to be honest, it's just extra code that we didn't need
‫because of the type of interest that says the process will automatically disable the interrupts to stop
‫motion troops coming in anyway.
‫So it's no big deal.
‫OK, so here the interim frame ends.
‫And now we need to push the stack pointer, OK, push the stack pointer so that we are pointing to the
‫interim frame.
‫So as I said, the stack pointer at this point in time.
‫OK, it has all of these on it and it has this.
‫OK, so if we push the stack points and now we can cast it to a C structure later on and we'll be able
‫to access all of these pushed to the stack.
‫OK, so that's why we're pushing the stack pointer here, because this is the perfect address right
‫now that shows us the entire enter frame.
‫So that's why we need to push here.
‫If we push the stack pointer later, we're going to have corrupted data, you know, and intel architectures,
‫as you know, the stack grows downwards by default.
‫OK, so that's why we can push the stack point here and have access to all of this.
‫OK, that's why.
‫So we're now going to go call Isaw 8H Hans-Olaf and now we're going to move the response into a temporary
‫variable, which we haven't created yet, called temp response.
‫And we're going to pass the into that, OK, because as you as you're aware, see functions, they return
‫their values in the register.
‫If the value can fit into an integer, that is OK.
‫So it doesn't matter if we're returning a pointer type audience to type X register here will be felt.
‫OK, so only when you are returning much larger data when the X register is not used.
‫OK, so that's important to know since ISSI the handler will only be returning void.
‫Pointis then this is absolutely acceptable.
‫So we just basically after we finish calling the interrupt ISI d.H handler to seat the CI handler written
‫in c, x, e will have the value for the return result from this function call.
‫OK, so that's why we're putting it into the temp press, which we haven't created yet.
‫OK.
‫And one of the thing guys, I forgot to push the command codes as well, so that's important.
‫So just above the Israeli handler, we need to go push X because remember what I said, X will contain
‫the commands that are function that are colonel should should invoke.
‫OK, because remember, I showed you in the presentation last lecture, I showed you how that example
‫code, right where we're setting the electricity two to one because we want to print.
‫And in this in this hypothetical kernel, one means print to to the screen.
‫OK, so that's what I'm trying to say here.
‫So we need to push that stack because our CI function is hand.
‫The handler needs to be able to see what that command was.
‫So X holds our commands.
‫Let's push it to the stack for a handler.
‫Perfect.
‫So yeah, once again, we set the result here, which we've already done on this line.
‫Good.
‫We said ten press to that result and now we need to adjust the stack because we push these here.
‫Right.
‫We push the stack point at any X so we can either do something like PBX, PBX or we can just go add
‫to the stack pointer by eight, because as you know, in 32 bit operating systems, the R word is four
‫four bytes in size.
‫OK, so when we push like this, we're pushing for bytes.
‫So if we push twice, that's eight bytes.
‫OK, so we add to the stack pointer by eight, which will return our stack pointer to as it was before
‫we push these two elements to the stack.
‫So now we're going to restore the general purpose registers for use land.
‫Very easy, we just go pop.
‫OK, which basically pops all of this off the stack again, these general-purpose registers that we
‫post here.
‫OK, as you know, you guys understand at least enough sambi damage to this cause.
‫I can only assume so.
‫You're perfectly aware that the stack pointer has to be has to be as it was before this push on line
‫fifty seven for this pop had to work correctly.
‫OK, that's why we add to the stack pointed by eight bytes.
‫So the final step then is to move the result back into the X registers.
‫So we go move X and we're going to go to press and then we're just going to go in at the OK, which
‫will return from the interrupt.
‫So why do we even use this temp, register them?
‫My concern is, is if we ended up using the X register at some point down the line, we might forget
‫that we're relying on that for the return result and that that would obviously be very bad for us corruption.
‫Right.
‫So by storing it in a temporary area of memory here, we at least show the programmer that we need to
‫save this for later.
‫OK, if we I know we're not changing X here.
‫If we didn't do that and we and we seem to at some point down the line, we forget that the X contains
‫the return result.
‫You're going to spend a lot of time debugging and trying to figure that out.
‫So it makes sense just to do this.
‫And in that way, then it's clear what's going on.
‫OK, so we need to find out.
‫Temp rests now.
‫So just down here, we're going to go temperatures and we're just going to go through, OK?
‫So stores, the service will say that inside here is stored the return results from ISIS d.H handler,
‫perfect.
‫OK, so we have our assembly scroll to the top and we're going to just go global ISIS d.H rapper.
‫We called it.
‫I think it is, yes.
‫RAPPA And we're also going to say extern, I saw 8H Handler.
‫So we need to create Isaw 8H handler in the Cifas now in Ijtihad, see.
‫Oh, and before we do that, guys, quickly go back to the title Rasim.
‫Scroll down.
‫This needs to be in the data section, so just go section that data because this is data, OK?
‫All right, so back to Tazi and we can continue this just at the bottom of this file, which is going
‫to go void Pintor, I saw 8H Handler is going to accept a command and an interim frame.
‫Now, I did.
‫I haven't forgot.
‫We need to actually declare the interim frame here.
‫So we go to see how we can do that.
‫So we're just going to go here and we're going to go struct into a frame.
‫Unit 32 T Eddi, Unit 32, ATSI, Unit 32, TBP, Unit 32 T Reserved Unit 32 tiebacks unit three to
‫T IDEX Unit three two Cheek's Unit three two Tax Unit 32 type units to Cheek's Unit three T Flagg's
‫Unit 32 T E.S.P.
‫Unit three to T Assess and we need to pack that guys.
‫Just two attributes packed, OK, because we don't want the compiler doing anything fancy with these
‫bits.
‫Not that I would have a reason to their aligned correctly, but nevertheless at prepacked guys to be
‫on the safe side here.
‫OK, so we just go to Google and we search for PUSCH and.
‫You can see that that pushes X, X, IDEX, SBX, E.S.P, EBP, BSI and Eddi, and it pushes all of
‫those to the stack.
‫Right.
‫So that's why we have this Ediacara, EBP and so on.
‫OK, for that reason and you'll notice here we have a variable call reserved.
‫This is because that's the stack point that the Poshard put on on the stack.
‫But we don't care about that stack pointer.
‫We only care about the stack point that the processor provided to us during the interrupt.
‫And it's this stack pointer here, which is the uses stack pointer.
‫OK, use a line stack pointer.
‫That's what we care about.
‫OK, so if we now go to I don't see again and we can now continue this function, you'll see the frames
‫now resolved because we just created it.
‫So we're going to go void.
‫REST's equals zero.
‫We're going to switch to the kernel page.
‫OK, uh do we have that function yet?
‫Let's just search for that here.
‫Did we create Col Page.
‫We haven't created the kernel page function yet.
‫OK, that's no problem.
‫We will need to create that very soon.
‫And as a matter of fact, we can create that in a moment after we finish this function.
‫So the next step is to save the current task status.
‫So we're going to go test current save state and we just pass the frame and this will basically just
‫save the registers from this frame into the task, OK?
‫And the reason for this is for multitasking purposes.
‫If we wanted to switch to another task at any point, that would be achievable so long as we've saved
‫the old tasks state but that we're talking about multi threading.
‫Now, that's more complicated.
‫However, having these foundations in place will make it easier to implement later on.
‫So we're going to go sequel's ISI d.H Handle Command and we're going to pass the command in here and
‫the frame.
‫So as I showed in the presentation, I showed the flow of how this is working.
‫OK, so you should watch that again if you're confused.
‫Essentially, we call Society Channel Command that finds the correct command first based on command
‫number here and execute said, OK, that's how that works.
‫So the next step is to switch back to the tasks page and then return the response.
‫OK, so that's a function.
‫You can see there's a lot of functions here we haven't yet created.
‫Do we even have tasks page yet?
‫Yes, we did create tasks page.
‫So that's good.
‫We have tasks page.
‫That's that's good news.
‫So we need to implement Col Page task can't save state and we also need to implement the AP to handle
‫commands and register commands.
‫OK, so we're going to start by implementing Col Page.
‫So just go to Canada that see and we're going to create a function here called Col Page.
‫So void Colonel Page.
‫And as you as you're probably aware, this will switch the page directory to the COL page directory,
‫OK.
‫And it will also change the registers to the COL registers.
‫So we're going to call Col registers, which we haven't created yet, and we're going to go paging switch
‫Colonel Chunk.
‫OK, and I will switch our page directory to point to the colonel's page directory here, the page and
‫forget about Schunk.
‫So the entire memory is seen by the colonel, essentially.
‫OK, essentially the way the memory's mapped in this COL chunk is how the memory will be mapped after
‫we call Colonel Page.
‫OK, so then the colonel can access all of all of the memory because the colonel chunk is basically
‫linear.
‫So each virtual address points to its equivalent physical address and we want that by design.
‫OK, so that's why we need the COL page function here.
‫So we've got a Colonel Diesem.
‫We're going to create colonel registries now.
‫OK, so just after this infinite jump, we're going to say Colonel registers
‫and we're going to go move X ten.
‫We need to now settle the segments.
‫So we're going to go move DCX, move East X, move GSA X and move FS X, and we're just going to return.
‫So that changes all the segment registers to points of the kernel data segment.
‫OK, so that's pretty important.
‫And now at the very top of the file, we're just going to go global kernel registers.
‫OK, so now back to kernel that C and we're going to take the prototype kernel page and we're going
‫to put it in Canada.
‫OK, and we're also going to put kernel registers in this file as well.
‫OK, so that is perfect.
‫That's the Col page function now completed.
‫OK, so the next step is to go back, try to tazi and we now need to implement Tarsa current safe states.
‫So we're going to go to test Stazi and we're going to create void TASC current safe state dysfunction
‫and that's going to accept an interim frame.
‫Now this function, guys, absolutely needs to be called from Colonel and the colonel pages.
‫We need to the page needs to be sent to the Colonel Page before you call this.
‫If you call this without that, it's not going to be so good for you.
‫OK, so what we're going to say now is we're going to say if TASC current is equal to zero, then panic
‫and no task, no current task to save as just a little bit of assertion there.
‫OK, and we can get rid of the equals equals zero.
‫Just put an explanation, Mark, at the start of the save statement.
‫OK, so if we don't have a task then there's no current task to save.
‫OK, and we'll panic the whole system because something really bad has happened for us to call Tasco
‫and save state and there be no task existing.
‫Something really bad must have happened.
‫So we just panic the system.
‫OK, so we're now going to go struct task task equals task current and then we're going to go task save
‫state task frame.
‫OK, so that will save the current task state.
‫We do.
‫We do however need to also now create task, save state.
‫OK, creating task save state is quite easy.
‫We just go into task save state struct task task.
‫Struct Entropa frame frame and as a matter of fact, that can actually just be a void.
‫You don't really need to return anything here.
‫Uh, and what we're going to do is we're going to say TASC registers dot IP equals frame IP.
‫OK.
‫And you'll notice that it can't resolve the frame.
‫So we need to include that guys.
‫Right.
‫So just scroll up here and we're going to say include.
‫Uh, I, I see that Hajj and this is check that's right here.
‫Yes, it is.
‫OK, so back down, then scroll all the way back down to where we were.
‫And.
‫Here it is.
‫And we're just going to carry on, so we're going to tax registers, Todd says.
‫He was Frank's task registers double flags, frame flags.
‫So notice what we're doing here, right?
‫We're saving the state the task.
‫And if we know the state of the task, we can we can resume from that state at any time that we like,
‫which is perfect because we can pose tasks, do something else and then resume them later on, because
‫that's all that's all the process state is.
‫It's just the state of the registers.
‫When you paused the program, that's all it is, guys.
‫So we're going to start task registers.
‫Espie was framed E.S.P.
‫Task registers.
‫SS EQUASS Frame, SS task registers thought e x equals frame X task registers dot Ebix.
‫No, no no doubt sbp because frame eppy.
‫Tax registers Dybek, he frame CBX tax registers, so X equals framework's tax registers, Eddi equals
‫frame Eddi, don't try and be smart and do some sort of meme copy
‫the I can't remember of the order of the frames.
‫The same order is registered structure and task.
‫But just do it like this because it's much more clear what's going on.
‫Right.
‫And sometimes clearer code is more important than fasta code.
‫OK, so tax registers X equals Frain ADEX tax registers s.i equals frame s.i.
‫OK, that's perfect.
‫So look, look, you can right click for my document on Visual Studio guys to clean it up for you.
‫So look, look what's happening here.
‫This is very simple.
‫We passing the task and we pass in the interim frame.
‫It'll save all the registers from the frame to the registers of the task.
‫And you've just saved it, you've literally just saved the task, right?
‫You can go and do anything you like and you can come back and it will resume without even knowing that
‫it was paused, so long as obviously things like memory was still the same and you didn't tamper with
‫the process in any way.
‫But yeah, the registers, they determine everything here.
‫OK, so we've now implemented Tascon and say state, I want you to copy and paste task Colonsay State
‫into the task header file, uh, at the bottom here.
‫However, we also need to forward declare interim frames.
‫So just go to the top here and we're just going to go struct interrupt frame, OK?
‫And that'll just resolve that little dependency problem here.
‫We're basically saying to the C compiler, we'll tell you what it is later.
‫So basically what we're saying here say if we scroll up and we go back to iced tea, that C we can see
‫we now need to create Isaw 8H handle command.
‫So we're just going to go void Isaw 8H handle command and that take in the command and an interim frame.
‫Now, as you saw in the screenshot, this now needs to go through, it needs to find the command from
‫an array that we haven't created yet, and then it needs to invoke that and return the result.
‫So we're going to have to create the ability to command and handle them here.
‫However, that's for the next lecture, because we have implemented ISIS, DHEA now and the ability
‫to register commands, handle commands deserves a lecture in itself.
‫So we'll leave this lecture as it is and we will carry on with this next lecture.