‫Hello and welcome, everybody, in this lecture.
‫We are going to implement the invoked system command command that we briefly started making a couple
‫lectures ago.
‫So essentially the use of land is going to pass us some command documents and then we're going to inject
‫those into the process like we did in Colonel see by here, OK, where we go inject arguments.
‫OK, so that's what we're going to be doing here today.
‫So, yes, let's begin.
‫OK, so just go to process start see in Izadi Hajj.
‫By here and we're just going to go struct command arguments, arguments equals task, virtual address
‫to physical task current and the virtual address will be the task at Stack Item.
‫And we're going to go to Task Current and we're going to take the first index on that task stack.
‫So, again, this does exactly what we do on the process arguments here.
‫It gets a virtual address of the command documents and returns as the physical one that the colonel
‫can access.
‫OK.
‫And guys, it's not cool command arguments, it's called command argument.
‫So that was my mistake, that just make sure that you double check that, OK?
‫And what we're now going to say is we're going to say, did they pass us a no variable?
‫Like if they pass us something now and we're also going to say, did they pass us an argument that is
‫zero in length?
‫So just to strengthen their OK.
‫Because if they did either of those things, then there's nothing we can do because they've passed us
‫a command that has nothing and we can't deal with that, it's impossible.
‫OK, so check for both of these things and we return zero if that's the case, OK?
‫So by here, we know that we at least have one argument.
‫OK, so we're going to go strike command argument.
‫Real command equals arguments zero.
‫Now, this is the program that should be run, OK?
‫Because think about it.
‫They've passed something like blanked out of one or two, something like that.
‫Right.
‫So Blank Elf is the root command argument.
‫So in fact, call it root command argument.
‫You know, blank trough is through a command argument.
‫OK, argument is this second argument two is the third argument.
‫And just to an ampersand argument, zero here to get the address of that, guys.
‫OK, so we know the root command argument contains the program to load.
‫OK, so if we just go const char program name equals rule command argument and we go argument there.
‫OK, we know that contains the program name now.
‫OK, so that's the program to launch.
‫OK, we're going to go shabbath no no char path and we're just going to go max path here, OK.
‫And we're going to copy the program name into this path but not before we copy the drive number.
‫So remember I told you before how you should use some sort of environment variables in a better implementation
‫so that you can have path variable and stuff like that while I still stand by that.
‫But as we have it implemented, then this kernel, we're just going to pretend we already have path
‫variables and we're going to put the drive number into here into our path.
‫OK, zero column forward slash and then we're going to copy the program name just after that.
‫So it becomes something like this zero blank.
‫OK, so then it's a valid program to load.
‫So what we're going to do then we're going to go string copy or string and copy, I should say path
‫plus three program name size of path.
‫So this is important.
‫The reason we do plus three is because we've already put three bytes into the buffer and we want to,
‫you know, copy just after that.
‫So once we finally do this, we should end up with something like that.
‫So it'll be outdrive zero, it'll be drive zero and then the program name OK, or whatever it is.
‫OK, so that's where the path will be equal to after this.
‫Now, once we've done that will now be in the situation where we're able to load and switch to the process.
‫So just go start the process.
‫Process equals zero process load switch and we're going to pass the path for the filename and ampersand
‫process for the process.
‫OK, and we're just going to say an address equals process, load, switch, and we're going to say
‫if the rest is below zero, return address.
‫OK.
‫And as a matter of fact, by here where we return zero, we should even reach an error here.
‫OK, so it'll be in e invalid arguments minus the invalid dog.
‫OK, and we only return zero and success.
‫OK, guys, now the invoked system command, because we don't have multitasking yet, it is going to
‫have to block.
‫OK, so because of that we're never going to be able to return from here.
‫There's some VOC system command.
‫We're going to have to literally switch to the next task here because we don't have multitasking.
‫Right.
‫So that does mean we'll never return from this command if it was successful.
‫OK, it's not a big deal, though, because as I already explained before, when we entered this interrupt,
‫when we entered into 680, we save the registers of the task that is calling this vote system command.
‫So whenever the process are launching terminates and we switch back to the other task, it will be as
‫if it returned from this function.
‫But it is technically never did return.
‫We just redirect the execution flow when we're done with the other program and we do that just by doing
‫the tasks next and dropping into the usual.
‫And again, so it's not so difficult, but returning arguments from here will be very difficult to do,
‫but actually switching to the process and inject in the arguments not so hard.
‫So we're not going to worry about returning a good result.
‫We'll have returned zero there, but just no, it'll never actually be returned.
‫We're just satisfying the compiler that wants us to return something.
‫OK, so what we now do then is.
‫We go tasc switch and we pass in the process task that we just created, and that will ensure that we
‫switch to the task, OK, and now we need to actually drop into use the land again.
‫So we go tasc return and we go process task top registers, OK?
‫And that will ensure that we actually start executing, using land again for this new task we just created.
‫So task switches, you know.
‫It just switches the paging to use the land, OK, and tax return will actually end to use the land
‫using the assembly code that we wrote in tax today.
‫Same here, the tax return.
‫So, as you know, it does this by persons of the stack.
‫Change in the second registers the strong general purpose registers and then using an IRA.
‫OK, so just to remind you all for a couple years ago.
‫So, OK, so that should work perfectly fine.
‫That's starting a new process, but it doesn't inject command argument.
‫So let's do that now.
‫So just above tax, which we're going to go process, inject arguments and we're going to pass in the
‫process and the command argument
‫just like that, OK?
‫And that will return whether it was successful or not, to just go rascal's process, inject arguments.
‫If it's below zero, just return
‫less than just return.
‫Yes, that'll be absolutely fine.
‫We are going to have to cast some of these things, guys.
‫So here we go.
‫Return an invalid argument.
‫We want to go return error.
‫OK, and if we look in error.
‫We can see that just Kasit to avoid avoid Pintor, OK, because we are actually returning to avoid what
‫we are supposed to be returning of our point of here.
‫OK, so you do need to take that into account.
‫So just go return error wrests.
‫It's an era where, OK, and then we can return zero down here, we don't have to cast that to avoid
‫point of sale, OK, so that should work absolutely fine.
‫So, yeah, you can check if you've done that correctly now by going make clean bill to that stage and
‫we can see that that compiles without any problems.
‫OK.
‫So that's how it should look.
‫OK, so, yeah, once you've done that, we're ready to go into the standard library to make a function
‫that invokes this kernel Command seven, OK, so just scroll up here, go to a study of some suggest
‫between Command six and eight, which is going to go Void Peatross system, and that's going to accept
‫a command document pointer.
‫OK, and we can actually call that argument's.
‫OK, so this runs the system command based on the arguments, and we're just going to go our system
‫here.
‫We're going to push the base point to move the stack, point it to the base point and move seven to
‫the Hicks register for command seven, uh, runs the system command based on the arguments.
‫OK, uh, when now going to go push the word EBP plus eight, and that is verbal arguments.
‫We're going to go in at 060, which invokes the colonel.
‫We're going to restore the stack pointer, guys.
‫OK, pop the base point and finally return.
‫OK, so that's the assembly for Command seven and use the land for invoking command seven in the kernel.
‫Scroll all the way up and we're going to explore this function.
‫OK, like that.
‫Scroll all the way down and we're going to copy and paste the prototype here, OK?
‫And it should also be inside you guys inch by there, OK, because the DEA ROJDA contains the return
‫result after the Zaidee.
‫Now we will have a result returned to us in the case that there was an error.
‫Otherwise the register won't be changed.
‫So it'll actually be equal to seven if everything went OK.
‫And we return from this eventually, because technically, whenever returning from it, as I've explained,
‫if we go into use the land, then our registers are saved somewhere and when it switches back to us,
‫it'll stop running from ADP fault, but it never actually returns.
‫OK, you understand, never returns from the routine itself.
‫So because of that X register won't be changed.
‫It will remain a seven.
‫So, you know, these are things to consider.
‫OK, guys, so what we're going to do then we're going to copy and paste this into PTW page.
‫Just like that.
‫So now we have a system command, which is really, really useful, right.
‫So we're also going to make another command here, one of the functions, I should say.
‫We're going to basically go in it Peatross system command, that system run, and that's going to take
‫a kind of command.
‫OK, and this is going to be a C function.
‫So just going to start C scroll all the way down and we're going to paste that in like that.
‫It's going to return zero here for now.
‫And what we're going to do is we're going to say Peatross parse command and we're going to pass in the
‫command there and the maximum size of the command.
‫So we don't actually know the maximum here.
‫So what we'll do is we're going to go chop off one thousand twenty four and we're going to go string
‫and copy buff command size of baff.
‫And this allows us to know the maximum size.
‫Right.
‫So then we can pass in the buffer instead of the command and we go size of buff, OK?
‫And that shows everything's always in bounds because string and copy will only copy up to 1024 bytes
‫of the command provided.
‫OK, so here we're going to go struct command document, command document while route command document
‫I should say equals Peatross parse command.
‫OK, and what we're now going to say is, is if the command document is null then just return.
‫An error is invalid argument.
‫We don't have one.
‫We don't have that.
‫OK, just return minus one and something like that.
‫You guys can also include the status file if you want to contains all those definitions, you can make
‫one for use land if you want to, minus one from here, because that's pretty straightforward for you
‫guys to understand.
‫I don't have to show you that.
‫So rather than returning minus zero or something, we'll just return minus one.
‫So yeah, if the root command argument was parsed correctly, then we're going to go Peatross system
‫and we're going to pass in the root command argument and we're going to return.
‫OK, and you can get rid of this return zero now.
‫So that's how that looks.
‫OK, so basically now in our shell we'll be able to go Peatross system run and it should launch, blanked
‫it out for us and pass some arguments to it.
‫So let's just make it clean that now.
‫So we go make being built at S.H..
‫And see, that works absolutely fine, perfect.
‫OK, we're ready to use PTW system run.
‫OK, so we're going to scroll up to Shell Soft that see, so what we're going to do is we're going to
‫get rid of this post a slow start because we're now going to use the system run command and we're just
‫going to go a system run and we're just going to pass in the buffer for the command that they entered.
‫So when I was just going to go to start, see, there's one thing we forgot to do here.
‫You'll see above is 1024 bytes.
‫But if you go to the picturesque parse command, you can see that we check if the max is above equal,
‫the size of command and what's the maximum we allow?
‫It's one four bytes.
‫Just change this to one thousand twenty five, OK?
‫And that should allow us to have a thousand twenty four by buffer then.
‫Otherwise it's going to return minus one here because we'll fail to create the command argument.
‫So just had to come that C because we're also starting blank today, not shelter health.
‫Change that to Sheldon Alpha because obviously we want to run the shell now.
‫So we're just going to go make a clean bill that S.H..
‫CD, Ben, we're going to run Kumu.
‫And now we're going to go blank that our testing and what do we see, we see blank out did this work,
‫which is exactly what we expected, because if we go to Planktos C, we can see Prince Aragvi zero.
‫So that's perfect.
‫Guys, we managed to do that.
‫Run that again.
‫And we're just going to type Lanctot s.
‫And we can see the program still works and now it only has zero not argument as well.
‫So, yeah, we can see that that works really well, actually.
‫Go to show that.
‫See, after we read the line, we just want to make a new line before we actually call ourself, before
‫we run the program.
‫I mean, and that will make the terminal a bit cleaner.
‫So what we're going to do now is we're going to loop through all the command arguments for in Chaika
‫zero epilog C C++ and then we're going to go print Igby I.
‫OK.
‫And as a matter of fact, print F percent.
‫S new line.
‫And we're just going to pass the aragvi in like that.
‫And we should find now that all the arguments we pass will be put on new lines.
‫So try that to build S.A.G. again.
‫Citibank, WAMU.
‫So now if we go blanked out, what a great day this is, like what we see, Lanctot, of what a great
‫day this is.
‫So congratulations, guys, you've now been able to make programs, have arguments.
‫You're welcome to take this a step further if you want and have quotes, you know, so that they can
‫so that you can do something like this, so you can go blank health and you can have quotes by Hello
‫World, you know, something like that.
‫If you want to take it a step further, you can do that.
‫You'll just need to change your parsing algorithm a little bit and also allow the use of shift in your
‫keyboard.
‫So, yeah, I hope that that makes sense.
‫And congratulations on implementing program arguments.
‫I know that I know that that was a big one, but it was an important one.