‫Hello and welcome, everybody, in this lecture.
‫We're going to create a print command, so what is a print command?
‫Well, essentially, the U.S. program will be able to push the address of null, terminated string to
‫the stack and set the command to command one, which means print and then issue.
‫And it's your ad.
‫And guess what will happen?
‫It will print a message to the terminal.
‫Now, if you really wanted to do this the proper way, you would abstract this out a lot more.
‫We would use, write and read functions instead for IO operations.
‫There wouldn't be a kernel command for print.
‫But, you know, this is you guys are learning.
‫So this is important that we keep this simple.
‫But I'm letting you know this so that after this course you can make a clone of your of the coursework
‫and and you can essentially go off and abstract things out by yourself based on the ideas that I'm telling
‫you.
‫So, yes, to keep things simple, we want to implement the read and write functions.
‫At least now at least we will just create a print function directly.
‫So, yeah, well, we're going to do then let's start by rewriting our user program here and then we
‫will implement the command in the kernel.
‫OK, so let's start by getting rid of all of this stuff here because we don't need that now.
‫And just below our infinite jump, we're going to say section that data.
‫I was simply going to go message TV equals Hello, World.
‫And we're going to put a null terminated at the end, because this is not the C programming language,
‫guys, so, you know, this is we need to put zero at the end of our chat sequences.
‫Otherwise it won't be it will not be null terminated if we do not do this.
‫OK, so you must put a null terminated.
‫So up here then we're just going to go push a message just like that, OK?
‫And we're going to say move X one, which will be the print command in it zero eight, which will invoke
‫the kernel and then we're going to go add ESP four because we've only pushed one item into the stack
‫here.
‫OK, so that should print Hello World to the terminal.
‫That's what should happen when we run this.
‫So let's just make clean and build a minute just to make sure that use programs.
‫Correct.
‫We can see that works absolutely fine, so that's no big deal, good, and we've now implemented the
‫use program, so now we need to head over to the colonel and implement the actual command.
‫OK, so let's head over to isolate the directory.
‫I want to create a new file.
‫We're going to call it iodized Hajj, OK?
‫And we're just going to go if and if I saw any Hajj I Hajj to find Izadi Hajj, Hajj hashtag indef,
‫OK.
‫And we're just going to go struct into a frame voie pointer pointer eighty Hajj command one print and
‫that's going to accept an interim frame as an argument.
‫OK, and put your semicolon here on struct in your frame.
‫So we're going to copy and paste come one print into iodized C.
‫And we're going to include iodized Hajj, so, yeah, guys, just make sure you created the iodized
‫CFR here, OK, and paste that command in here.
‫OK, so we're just defining it.
‫OK, perfect.
‫And we're just going to return.
‫Zero print will always return zero.
‫OK, so, OK, we have a little prototype and now we're ready to start writing some code for this.
‫So we're going to go voi pointer userspace message buffa.
‫OK, and we're going to go equals task, and you'll notice we don't have this function, so we're going
‫to have to include the task ahead of us.
‫So we're going to include task tasks on Hajj.
‫And that should be right.
‫Yes, it is good, so we're going to go TASC.
‫Get snack item and we're going to put in test current in here and zero for the index, so that will
‫pull the first element pushed.
‫So to the task stack, as you know.
‫And we know that that is the.
‫Hello, message.
‫OK.
‫So in an easy world, we would just be able to cast this Turca Pointer in print straight to the terminal.
‫Unfortunately, as I've explained before, we can't do that.
‫The reason we can't do that is because they're the pointer to the message.
‫You see 400000 something, 600000, 15 or something away in the kernel page.
‫So while that's going to be a disaster, you understand.
‫So the correct thing to do is to copy from the userspace buffer into a kernel buffer.
‫OK, that's the safest solution.
‫So we're going to go chop one or two for this does mean string will only be to be a maximum 1024 bytes
‫long.
‫All the other characters will be discarded, but never mind.
‫And this buffer will hold the message that the user pushed to their stack, because we're going to copy
‫it.
‫We're going to copy this buffer from the user space into kernel space, into this buffer, OK?
‫However, as you can see, this is only 1024 bytes long.
‫Unfortunately, this means that the string can't be bigger than that, but that's absolutely fine.
‫Who writes strings longer than that?
‫Right.
‫And if they do write longer than that, it won't cause an error.
‫It'll just only print up to one thousand twenty four bytes.
‫OK, so the next step is to go copy string from task.
‫This is the function we made earlier, guys, and we're going to test current.
‫And we're going to copy from the userspace message Buffa into the Colonel Buffer, and it'll be a max
‫of size of buff, OK, which will be maximum 1024 bytes if we just click on copy.
‫If we just control left, click on copy string.
‫Fantastic.
‫It'll take you in here and just refresh your memory.
‫A few lectures ago, you know, we we make some memory that both the uses of pages and Colonel Page
‫can see.
‫And then, you know, we switch to the user page, we copy into the into that memory.
‫And then finally, when we're back in the kernel page, we copy to the physical memory, the physical
‫buffer provided to us.
‫OK, so you know, that's what that's doing, guys.
‫It's just manipulating the pages so that we can copy from the virtual address, because we all know
‫that this userspace message buffer is going to be zero x 400000 something because that's where user
‫programs are loaded.
‫Now, obviously, many processes share the address x 400000 something, you know what I mean?
‫Many processes.
‫So obviously this this this address only contains the message when we are on that tasks page.
‫OK, when we're in it's page directory, I mean, when the processor is pointing to its page tables.
‫So, you know, that's why this function is pretty essential because we need to copy from the task back
‫into kernel space.
‫OK, so once you've done that, we can now safely print out that buffer.
‫So how do we do that where we just go print stuff?
‫And obviously we need to include kernel dot Hage because that's where the print command is.
‫So it's as simple as that.
‫And now we have our print command.
‫OK, so we do need to register the command.
‫So just go to Izadi Stazi and we're just going to include iodized here, OK, and we're going to go
‫ISO 88 register command system command print and we don't have this command yet and it's going to be
‫exciting.
‫Page command, one print.
‫OK, so if we just go to the header file Izadi and then we can just add some, add a new enum here system
‫command one print and make sure you put the comma there ready for the next one so that we don't have
‫sanctus errors.
‫It's so easy to forget that in later on guys.
‫So if you put it in now you won't make any mistakes later when we when we add new commands to this.
‫So yeah, we can see that that hasn't resolved it because we need to do come on one system command one
‫print not system command print system command one print.
‫OK, perfect.
‫So now let's go to the Makefile and we're going to add that file to the Makefile, the IOC that we just
‫created.
‫OK, so if we just scroll through this file, you'll see this.
‫This may make commands here.
‫Just copy and paste that.
‫That's for the miscalled O for ISSI DH.
‫And we just want to change this one here to IADB.
‫Oh OK.
‫Iodized see the include here can stay the same.
‫We're going to put iodized C in here and finally the output file will be biodata so builds.
‫Hey I'm just copy and paste that build guys because as you know we've done this a thousand times.
‫We need to paste in the make files, object files at the top here.
‫The files I guess you just pasted in there so that it can be seen.
‫OK, now that you've done that, just go back to blank today because I forgot something here.
‫You'll notice we have the section data at the bottom.
‫We have the sections ITSM at the top.
‫However, this is a huge problem.
‫Go to Link LD and what you see here, tech section comes first, then the data and our Assam's at the
‫bottom.
‫That's no good because that'll mean that are ASRM.
‫For once it is output, it is a binary.
‫The data hello will will come before the actual assembly data.
‫We really, really don't want that to go to link Aldy here and blank.
‫I assume we're going to copy and paste the diesem at the bottom here and we're going to put it just
‫below the text now, make sure it's below the text as sometimes having the RASM above the text can cause
‫alignment issues in real binary files.
‫So make sure it's below by here.
‫OK, OK, now we've done that.
‫We are ready to build this whole program and see if it worked.
‫So just go make clean build to that stage.
‫And I we're going to go Cribben and we're going to run Kumu.
‫And look at that, we see the hello world, you can see hello from earlier that pointed out in the Colonel,
‫but you see the hello from the USA program.
‫Now we just press control.
‫See, let's change this message.
‫So we're going to say I can talk with the colonel, OK?
‫And we're going to run that again.
‫We're going to make a clean bill that S.H..
‫So remember its top forward slash Baghdad, S.H. guys, Cribben, Qumu, and now we see I can talk with
‫the colonel.
‫Excellent.
‫So, yeah, by the way, in case you don't know the shortcuts I'm doing on the keyboard, if you press
‫control, are lasu you to do a reverse search?
‫If you then juku, you'll see our old command from earlier and even just enter the run that OK, just
‫want to make that clear to everyone.
‫So OK, we're just going to clean some things up now.
‫We're going to get rid of the I will test this printed out in our.
‫So just go to Colonel Dot.
‫See.
‫And scroll up and we're going to get rid of the Hadleyville test just after terminal initialise, because
‫that's just getting in the way now and I'm just going to make clean build again.
‫See how that looks.
‫And yeah, I can talk with the colonel, we can see that works perfectly excellent guys.
‫So regarding that issue I showed you in the link of how earlier, we also have the same thing in the
‫main Col's Hlinka file.
‫Now, this this could be a problem waiting to happen, so I'd rather not risk it.
‫So just copy and paste that and we're going to put that just under the text as well.
‫OK, because that just ensures the data doesn't corrupt the alignment of the HSM file.
‫OK, and we keep the same file beneath the text section here while the H.M.S. beneath the text section,
‫I mean, we keep that under there to make sure it doesn't corrupt the alignment of the c the text alignment
‫here, because we're putting this is all binary, OK?
‫And we know the CECO will be aligned correctly.
‫The binary output for the code that will be aligned correctly.
‫Can we really trust the we're going to align our assembly correctly.
‫OK, so make sure it's below the text because you're going to run into problems otherwise.
‫So yeah, keep that, I assume, above the data and that should ensure we don't correct the alignment
‫in our HSM files because of the data not being aligned.
‫OK, perfect.
‫So yeah, this wouldn't really be a problem if we were outputting as an alpha file or something, but
‫we're outputting as binary, so everything's condensed together.
‫So alignment issues do happen.
‫So you do need to be aware of these things.
‫OK, so yeah, congratulations on finishing this lecture.
‫You should be proud of yourselves to have got to this point.
‫I know it's taken many hours to even get to this point, but you can see just how how intense operating
‫system development actually is and kernel development.
‫The most important thing is you've completed all the major internals that matter for the for the skeleton.
‫So you can easily build on this as we go forward.
‫So in the next few lectures will be implementing the keyboard and some sort of shell.
‫So, you know, you'll be able to load programs from the terminal, the literally essentially be able
‫to type into the terminal.
‫Let me just show you.
‫Into this terminal here, you you're eligible to just go testing one, two, three, you know, and
‫it'll it'll be appearing here, OK, much like the terminal here where we can things you'll better at
‫the command center here and your programs will load and so on.
‫OK, so thanks so much for watching, guys, and take care.