‫Hello and welcome back, everybody.
‫In this lecture, we are going to create the ability to handle colonel commands and to register them.
‫So the very first thing we want to do in last lecture, we made this little prototype.
‫Uh, this should return a void pointer, not a void.
‫OK, so that's the very first thing to do.
‫So what we're now going to want to do is we're going to want to go to Hajj and we're just going to create
‫a TYPEDEF at the very top of this file, which is going to go typedef Voit Isaw Hadi Isaw 80 Hajj Command.
‫Strapped into a frame frame, and we just need to forward to clear the frame at the top here as well,
‫guys.
‫OK, so typedef void I 8h command and it upset say frame.
‫As you can see here, it also returns a void pointer.
‫I also just want you to put an asterisk by here, OK, to signify that this is a pointer.
‫OK, so void askaris bracket asterisk.
‫All right.
‫That's how it should look so at defining a Isaw 8h command typedef here so that we can just basically
‫goes things like this on one, come on two.
‫And these will be pointers to functions that accept interim frames and return a void pointer.
‫OK, that we pointis function pointers.
‫OK, so once you've done that we'll go back to Tazi, scroll to the top.
‫And I would just by here, we're going to say static, I saw a command, I saw 80 commands, and here
‫we're going to go Peatross Max, I saw 8H commands.
‫OK, now we're going to copy and paste this and we're going to go to config.
‫Don Hage, and we're just going to paste that in here, hashtag to find pictures, Max I 80 commands
‫and that's going to be, let's say, 1024, that that seems like it will be plenty.
‫And then we go to Aysgarth.
‫See, we can see that that is now resolved successfully.
‫No problem.
‫OK, so scroll back down to the Izadi Channel Command function and we will continue from here.
‫OK, so we're simply going to go void results equals zero return results.
‫OK.
‫Now, inside here, we're going to say if the command is below equal zero or the command is above or
‫equal.
‫Peatross Max, I, I assume, are 80 commands.
‫So if it's out of bounds, basically, yeah.
‫Then we're going to return zero here and violate command.
‫And some people in the past have asked me why we use integers here and not unsigned integers.
‫What one?
‫We don't plan to go below zero.
‫The reason for that is because this is the best practice possible.
‫It's good practice to use integers by using integer over unsigned.
‫It ensures we don't accidentally mix the types and result in unexpected values or having to cast or
‫something like that.
‫Right.
‫Unsigned numbers have their place.
‫I would use them when I'm loading raw data from a file, for example, raw binary from a file and I
‫know it's unsigned.
‫Then I would use unsigned integers for things like this where they're passing us integers to us like
‫that.
‫We should be using integer here, not really unsigned.
‫OK, so now I want you to go iso a command command function equals Isaw 8H commands command and we're
‫going to go.
‫If the command function is no, then that command doesn't exist.
‫The the basically what's happened in this situation use the land has tried to invoke a kernel function
‫that doesn't exist.
‫Now, obviously, we need to handle that situation.
‫So how do we handle that situation?
‫Is it an error?
‫Of course not.
‫They use the land may have been written for our lady colonel version, and it's trying to be run on
‫a version that doesn't have this colonel command yet.
‫There's many reasons why that might happen.
‫It's not an error.
‫It's just something we can't process.
‫So all we do is return zero and that's that.
‫And the user, Lambiel, will receive zero upon returning from the interrupt.
‫That's will happen Yucel and will just c0 in the register, you know, because it's called the command
‫that didn't exist.
‫It's no big deal.
‫We just can't handle it, unfortunately.
‫So what we do here is we go result equals command function frame.
‫So again, this is a point to a command function, OK?
‫And we pointed to the command function stored in the isolated commands array.
‫And this is an array of pointers.
‫OK, it's an array of pointers and the pointer type is simply a function pointer to Isaw 80 commands.
‫So any function we store in this array, it needs to accept a frame pointer and it needs to return a
‫type of void pointer.
‫OK.
‫So that is our Izadi handle command function completed.
‫OK, so we still need to actually set by here to point to our.
‫Saw 80 Rappa function here, so I just want you to copy and paste this, I mean it from ITSM, the Assadi
‫Hajratwala, and we'll get to the rights to see.
‫And I just want to scrub to the top.
‫We're just going to go extern void.
‫I'm going to paste that in, OK, because this is our Rappa for ISIS that's defined in the assembly
‫here, OK?
‫And we need to change the ID to point to this for Zaydi.
‫OK, so that is defined then.
‫I would say see prototypes.
‫So make sure you do that.
‫And just in Idit in it we're going to idjit.
‫He said Zaidee and we're just going to point it to I saw Aidi wrapup and this way then whenever someone
‫does a zaidee from use a land it'll come in, it'll call ISIS Rappa and that will call our C function
‫Isaw 8H handler passing the frame and so on.
‫And that then will run ISI, the handler which will run ISI d.H Handler Command, which will call our
‫function pointer for registered command.
‫OK, so just make sure you do that and everything will work as expected.
‫OK, so the next step now is to create the ability to register commands.
‫So just go void.
‫Isaw LDH Register Command and command ID.
‫I saw a command command so that's the function point to the notice.
‫We don't use an asterisk for this function pointer.
‫That's because we did it here where I've highlighted.
‫OK, so that's why we don't have to do an asterisk here because we did it right here.
‫OK, so now inside here we're going to say once again, if the command is below our equal zero or the
‫command is above our equal, show us Max Isaw 8H commands.
‫Now, in this situation, this cannot be an innocent mistake because this is registering commands.
‫This is called from Colonel End.
‫And if the if the colonel and sets up the commands incorrectly, it could be disastrous.
‫So if we're unable to register the command because they've given us something below zero or above the
‫maximum commands, then we will panic and say that the command is out of bounds, OK?
‫And that will ensure that we deal with that problem.
‫And no nasty surprises there.
‫We also need to check guys that the command is not already take OK, if the commands already taken and
‫this is in command.
‫So this guys, this is commanded, OK, just copy properly the prototype properly.
‫So command ideas below zero.
‫All the command that is above the maximum commands.
‫So yeah, now we need to see if the commands already exists.
‫So if this is not zero then the command exists.
‫So we're going to go panic.
‫You're attempting to overwrite an existing command because they've basically tried to register a command
‫with the command that's already being registered.
‫OK, and we don't want that because only one command should bind to one command.
‫You can't have multiple commands in the same command idea.
‫OK, so now we just go inside commands.
‫Command ID equals command.
‫So you can see all the command ideas is basically just an index in this array.
‫OK, and that's our register command.
‫And I want to copy and paste that, by the way, and we're going to put that in the head of all of it.
‫I'd hate just to the bottom here like that.
‫Perfect.
‫OK, so that is all of that.
‫So we're now going to go to the terminal and we're just going to go make a clean bill to the stage.
‫And we can see two errors here in Declaration of Function Task, Colonsay, say, and test page.
‫So just scroll to the top here.
‫We haven't included the task pedophile.
‫That's what's happened.
‫So we're going to go to task task to include task test on just rebuild that.
‫Now are we can see that it's absolutely fine.
‫We now try to run that.
‫We can still see how low will test.
‫And remember, you run the operating system with this command here, kumu system I six.
‫How to stop him.
‫OK, so, yeah, we can see that we've now implemented that core functionality.
‫In the next lecture, we are going to actually be creating our very first command by calling SCADA Register
‫Command and the command we will make will be very, very simple.
‫It won't do a lot.
‫It'll just be a simple command to test the kernel functionality.
‫Maybe we will make a kernel function that just sums two numbers together.
‫And by the way, you would never write something like that in a real kernel.
‫The kernel commands should be reserved only for a very strict kernel.
‫Operations for things that you can do in userspace, you absolutely should example commands.
‫There would be kernel commands the command to exit the program.
‫For example, if a program wants X it out of itself, something like that.
‫So yeah, we're going to be creating our very first kernel command next lecture.