‫Hello and welcome, everybody, and in this lecture, we're going to change our start see fall so that
‫it's able to load health data.
‫OK, currently we can only load binary data.
‫We are now going to implement it so we can load elf data.
‫So the very first thing I want you to do, I want you to say wrasse equals process load elf.
‫OK, we're going to pass in the filename and the process.
‫We haven't created this function yet.
‫OK, here we're going to say if the rest is equal to minus E invalid format, then we're just going
‫to load the binary data because if it's not in our file, then it must be binary, right?
‫Well, I assume it's binary, so.
‫Well, first, try to load the file if it's not an elf file or if we can't load it for whatever reason
‫because it's a bad format, then we'll load that file as binary, which we'll just call this function
‫as we made before.
‫So yeah, if it is a vidale file, but it's an error, then obviously process lopatin we won't be called
‫and we'll just return that negative value here on line eighty nine.
‫Obviously that is set on line eighty three where process load elf returns some sort of error or something.
‫OK, now let's just check.
‫Status of the Hajj.
‫And we can see we haven't created the invalid format error in here, so we're just going to go define
‫it in format nine, OK, so that that should work fine like that.
‫And there we go.
‫We can see that resolves that conflict.
‫So not just by here, we're going to go static init process load lth const char filename
‫struct process process and we're going to go and address equals zero return address.
‫So obviously this function will be in charge of calling offload and loading that file.
‫But before we continue any further, I want you to just go to the outflow to again, because we missed
‫something very important on our validate load.
‫If you go here, you can see we return an E invalid argument.
‫This should be a E invalid format, OK, because if the if we file validation, then it can't be a valid
‫file that we can load.
‫OK, so we should just return e invalid format and on process start C we check for that on line 90.
‫OK, so if we change the invalid format, it just means it's a nail file that we can't deal with or
‫that it's not in our file at all and we should treat it as binary.
‫OK, if any of the error is returned then it won't load.
‫It is a binary and it will just return the error.
‫So yeah, just to offload that c make sure you use minus E in formats rather than minus E invalid argument.
‫OK on the L validate loaded function.
‫So back to process start, see then and we're going to now implement the process load malfunction,
‫so the first thing we're going to do is include the el-Fadl, uh, while they followed us.
‫So just scroll up to the top here and we're going to go include loda format's outflow to DOT Hajj.
‫OK, now, in a better implementation, we would have Stracke this out, would have some sort of loaded
‫C file and we would call program load or something.
‫Well, it wouldn't be called that because we have that in-process Stazi, but we're basically a function
‫that would choose the correct format and stuff like that.
‫It would be abstracted out much in the same way we abstract it out of virtual file systems.
‫But as I've already covered that with you before, you have the skills to abstract that further if you
‫wish.
‫So we're going to scroll down here now.
‫And process low for slop, we can see that cow's process load data which tries to load the file.
‫OK, so by here processed LoDo, this is where we need to be now.
‫So we're just going to go struct our file.
‫Our file equals zero.
‫If rest's below zero, then go to out and we'll have the output label by here.
‫You can also make an is error macro.
‫Have we already done that.
‫Yes, I think we have.
‫OK, so we can just go is there is there a race if you if you prefer to do that?
‫That's no problem.
‫And maybe that's a bit more clear for you.
‫We can just we can see that that just casts that to an integer and checks if it's below zero.
‫OK, so.
‫Yeah.
‫Is there a rest and go to.
‫That's exactly the same saying if the race is below zero, we know that it's an error.
‫If it is, uh, and yes, I've checked for the error, but we haven't called the function yet.
‫So online 85, we're going to go rascal's offload filename, ampersand our file.
‫OK, and then that's and then that's when the error check needs to happen.
‫So we call flow to try and load the file.
‫If it's loaded successfully, the file pointer variable will be set to point to that memory where the
‫alpha was loaded.
‫Otherwise, if there's an error, we'll go to out.
‫OK, so that's what happens there.
‫So if everything was fine otherwise, in other words, we don't go to out, then we're going to go process
‫file type equals file type.
‫Lf we haven't created these things yet, but we will create them.
‫Don't worry, process our file equals our file.
‫OK, so just go to process start because we're going to need to create these variables now and you will
‫see appointed to the physical memory here, we're going to have to make a union here so they share so
‫that they share the memory.
‫OK, and inside the union we're going to have our voice pointer, OK, so we don't need that one anymore.
‫We just need the one in the union and we're going to paste that there.
‫And unions, everything in a union shares the same memory space.
‫OK, so in case you didn't know that.
‫So here what I'm going to go struct.
‫I'll file.
‫OK, so the pointer in the file, they share the same memory.
‫OK, how do we know which one to use?
‫Because we set the tape here while we set the process taip process file type ECAs file type.
‫So go back to process start and just appear.
‫We're going to say typedef unsigned char.
‫Process type.
‫OK, and then here we're going to go define process type O as zero and we're going to say define process
‫type binary as one.
‫OK, and now just above here, we're going to say process type, uh, file type.
‫OK, so that's that's how that works, right.
‫So we'll even call this process file type.
‫OK, that sounds better.
‫Process file type and then here process file type lth process file type binary.
‫We've got a process Stazi.
‫Let's just change this here.
‫It's a process file type.
‫OK, so that's perfect.
‫Now, just here, when we say process low binary, we're just going to say process, uh, file type
‫equals process, file type binary and that's for the process lo binary function.
‫OK, so we just want to set the file type to binary online 70 for the and the file type 12 on line ninety
‫two here for process load of OK and then that's how we'll know which variable we're accessing the pointer
‫or the file because they share the same memory region.
‫We will rely on the file type to know which one to access.
‫OK, so that's perfect now so this should load the files successfully and set the process typed to the
‫process file type of.
‫OK, so you'll see here we have process mapped binary.
‫Well obviously this needs to be changed now because we need to map the alphabet differently.
‫So what we're going to say here is we're going to say let's switch process, file type, OK?
‫And we're going to say case process, file type Alaf.
‫OK, and in here, we're just going to say rascal's process map out.
‫I'm just going to pass the process in there and we're going to have another case for binary process
‫file type binary.
‫OK, we're going to break and we're going to say sequel's process.
‫My binary I'm going to pass in the process there, OK, and then here we're just going to check if it's
‫below zero and if it is, there was an error, OK, otherwise we'll map the stack.
‫Finally map the stack, which is what we're already doing by here.
‫OK, on line one three six.
‫So now we'll map the the process into memory differently, depending if it's an alpha or binary.
‫OK, now we'll have a default label here.
‫And if the if if the default tables called then obviously there was an invalid file type provided.
‫So in this case we can probably panic the system because we wasn't expecting this to happen.
‫So we can just say panic process map memory invalid file type.
‫OK, uh, you could return an error, but to be honest with you, it's pretty it's pretty obvious the
‫kernel program has done something wrong.
‫It's not by because of an argument passed to us, we've chosen an invalid value.
‫So panic is probably better.
‫OK, so you can just use your new line terminated there as well.
‫So when are you going to create the process?
‫Map our function.
‫So we're going to go in a process, map out struct process process and in here we're going to be in
‫charge of actually mapping the binary.
‫So we're just going to go in a rest sequence, zero return address.
‫And now we're just going to say struct L file L file.
‫You could do a check here to see if it is actually an F process pass to us, but we won't be accessing
‫this outside of the file, so it should be fine and we can even mark that is static as well.
‫No big deal.
‫So struct our file equals process our file and now we're just going to say gress equals paging map to
‫process task page directory and then we're going to say paging a line to lower page and we haven't created
‫that function yet.
‫It'll basically align the value to the lowest page for the value provided to to the next lowest page.
‫And then we're going to go f virtual base our file and then we're going to go Alaf physical base.
‫We're going to pass in the our father.
‫And we know that the physical base is page aligned correctly because of the way our heap works.
‫It only allocates memory on four thousand ninety six byte boundaries.
‫However, the virtual base stress, we don't know for sure.
‫So it's best to just align it to the lower page, which is why we call this.
‫We haven't created that.
‫As I said, we will get to that now.
‫We need to provide the actual end address to map for the physical and address.
‫However, that is not guaranteed to be four thousand eighty six by the line.
‫So we do need to align that.
‫We'll call paging a line address.
‫We've already made that function.
‫Obviously, we're going to say our physical end, OK?
‫And we're going to provide the file.
‫And I know a lot of these functions don't exist.
‫We will create them.
‫OK, guys.
‫So now here we're going to say paging is present.
‫Paging access from all I'm paging is rideable.
‫Now, you'll notice that we are basically mapping the entire our father's rideable, which is not so
‫good.
‫But we want to test this before we continue.
‫The better way will be to loop through the sections in the file and map them based on the flags shown
‫to us.
‫But we can implement that another time.
‫Let's just get something working right now.
‫So let me just go over this again so you can see.
‫So we go paging map to we pass in the paging directory for the processes task, we go paging aligned
‫to lower page, which will basically take the base address here.
‫And it will take us to the next lowest address, which is page aligned.
‫OK, we now go our physical base.
‫OK, this is the base address for the Alpha, basically the of memory.
‫OK, we haven't created that function yet.
‫Now here we go, paging a line address our fiscal end and that will give us the end address.
‫And then here we just provide all those flags.
‫OK, now what we could do is we could just ensure that it's aligned before they even load the file.
‫And we won't have to use this paging a line to lower page function.
‫However, for now, this is appropriate.
‫So we're now going to implement these functions.
‫So we're going to start with paging a to our page.
‫So just copy and paste that string there.
‫And we're going to go to paging Dot C and we're going to look for paging line address here call.
‫And we're just going to add our own little paging a line to our page.
‫So we're going to go void, paging a line to lower page and we're going to pass in a virtual address
‫here.
‫OK, or it might not even be a virtual address.
‫Could be any address, but we'll just call a virtual address.
‫That's no big deal.
‫So here we're going to go Unit three to T address equals Unit three to T Viotti.
‫So that will give us the actual in-store version of the address.
‫We could rename this really?
‫To be honest.
‫Yeah.
‫What will we rename it.
‫Change this to address.
‫OK, and that'll go in there to that cast.
‫And we're going to use this as an underscore address for the unit three to one.
‫OK, just make sure you don't make the mistake again.
‫I'm incorrect.
‫So here we're just going to go underscore address.
‫Minus equals and the second address modulus paging page size.
‫OK, and then we're just going to return void and the school address.
‫So make sure you use the underscore guys, because we cast the the original one without the other.
‫Scroll to the unit 32 t here.
‫OK, so let me just show you this quickly so you can understand if we go four nine six, OK, modulus
‫four nine six, what do we get.
‫We get zero.
‫OK, so if they pass us four nine six, the value they'll get is four nine six pass four nine seven
‫four nine seven minus four nine seven.
‫Modulus four nine six.
‫Gives us four nine six so you can see it takes whatever value provided and it finds the the next page
‫below it and it gets us that address because remember we can only we can only use page with page addresses,
‫page by the addresses.
‫We can't have offsets.
‫So back to post to start see then and that function is now implemented.
‫Now we need to implement our virtual base, our physical base and our physical end.
‫So just go to our file or offload or I should say.
‫And actually you'll see we've already implemented them.
‫They're just nine the header file.
‫So just copy and paste our virtual base and we're going to put that in our flow to dot org.
‫Copy and paste it into the header.
‫We're going to do the same for our virtual end.
‫We're going to do the same for our physical base.
‫And finally, we're going to do the same for our physical and.
‫Perfect, and now we're going to rebuild that file using builder S.H. and there might be a few SANCTUS
‫areas we did right a lot.
‫And that's OK.
‫There is a few, Sankt says in declaration.
‫OK, go back to Page and just see guys.
‫We need to put the paging aligned to lower page in the header file of paging DOT.
‫OK, so that it's accessible from outside.
‫So just put that in the headphone.
‫And we're going to rebuild that again.
‫And we can see that works, but it says undefined reference, so just go back to offloads, see?
‫And everything looks absolutely fine, so it's clear what has gone wrong, we forgot to put it in the
‫makefile, so just go to the makefile and we're going to just put it in here.
‫So what we're going to do is we're going to search for our thought.
‫Oh, did we put that in?
‫No, we haven't.
‫OK, so we need to put all of those in then.
‫So just by here, then we're just going to copy and paste this GDP dot o and we're going to post it
‫above there and we're going to change this to build loda format's l thought, oh, I'm going to do the
‫same here.
‫Source Loda format's of dot C.
‫We're going to pace this.
‫Over this one here.
‫OK, so, so slow that for myself to see and we're going to do the same for the object file.
‫Just pasted over that one.
‫So that's the output format.
‫Right.
‫So we compile our thoughts C to start out and you'll see this include directory.
‫This needs to be source loda formats.
‫OK, so yeah, that looks OK.
‫So we can see we compile after C in 12. and we're going to need to create a directory in the in the
‫actual build as well.
‫Guys are suggest here we're going to create a new directory called Loda and we're going to create a
‫new directory called Format's.
‫And then we're just going to create a key file as well if you're using it.
‫OK, so that's all fine.
‫And that should work OK now.
‫Copy and paste the object file into the dependencies at the top.
‫So we're just going to paste that here just to Colonel Dotto like that.
‫OK, and now we need to also do the same for the offloads to just copy and paste what we just made.
‫And we're going to change this outflow to Dotto the to see.
‫The formats include here can stay the same.
‫We're going to go out of our flooded out see by here.
‫And the output for the output file name will be offloaded.
‫Oh, so now we need to scroll up and we need to add the outflow of dot o to the file dependencies,
‫just as we did here.
‫So just copy and paste the one that we just made.
‫And this is going to be flow the data.
‫OK, so we can now try to build that.
‫So we're going to go build the research and we can see it's tried to compile the outflow, but there's
‫a few compilers, so that's OK.
‫Just go to offload that C and we'll fix those now.
‫OK, so we can see a few basic errors.
‫The first ones, very simple line 13, we use const char pointer array.
‫It should just be const char array.
‫OK guys, because this is an array of characters here.
‫OK, so there's no need for the asterisk there.
‫Otherwise you're making an array of pointers.
‫OK, we don't want that.
‫So that's the first error solved.
‫We can see on line one, two, four, we're using an address equals zero, but we're not using that
‫variable.
‫So just go to one, two, four.
‫And we can see in Nebraska, zero one not returning rest, basically, guys just returned refs here
‫on line one three one Alaf process, we had a return, a return address.
‫And we can see the another error is conflicting types for LTH process P header.
‫So if we just copy and paste that, we can see that that's how it should look.
‫OK, so just copy and paste the prototype, go to offload.
‫Org and we can't see anything here.
‫Where is it having conflicting types are.
‫That's where it is.
‫We named them both have process P had this should be our process P headers and this should be our process
‫P header.
‫OK, so that's the mistake made there.
‫And we can see on line one five three redefinition of rest.
‫So go to one five three.
‫Uh we can see we've, we've basically created the rest variable again here.
‫OK, so just get rid of this thing here and we'll just go rascal's our they loaded like that.
‫OK, so that's all fine.
‫We can see in declaration of process P headers uh on line one five nine.
‫So yeah that was just because we named them the same function.
‫But since we solved that on line one three three, everything should be fine now.
‫So let's try to rebuild that.
‫So now we're just going to go build that S.H. and we can see everything works as expected and that's
‫compiled.
‫OK, perfect.
‫So now that all of that works, we can finally try to load our health program and see if it loads successfully.
‫OK, so we're going to do now is we're going to go to kernel that C uh, and scroll down and where we
‫where we go process load switched blankest up m we're going to change that to blank out.
‫OK, and now if everything works OK we should be ok.
‫Just go make clean build that S.H..
‫And I was going to keep in GDB, break askaris CLX four, one, two, three, four, five, target remote
‫pipe that QMI three eight six dash HDR stop and dash cam video last dash gdb Stelio.
‫We're going to go see the continue and there was a little bag there, run that again, guys.
‫Sometimes that happens.
‫Might need to close kumu sometimes it doesn't give us the terminal.
‫There you go.
‫So just make sure you've broken on zero x 400000 again for one, two, three, four, five.
‫OK, got to continue.
‫And we can see it said fail to load blanked out.
‫OK, so we need to find out why
‫and try to avoid wasting your time.
‫I loaded the debugger and did it for you.
‫The problem is very simple.
‫F-stop one return zero.
‫That's perfectly acceptable.
‫Here we check if it's below equals zero it should be.
‫We should be checking is below zero, not below our equal.
‫OK, so just go to the airflow.
‫Did not see far and scroll down.
‫And yeah, just by here, line one or two we should be checking is below zero, not blow equal because
‫zero is a valid response to Half-Step.
‫So just close the kumu and we're going to try that again now.
‫So we're just going to make clean bill that S.H..
‫OK, so we're just going to go to the stage and then we're going to go in and we're going to just run
‫kumu like that just to check everything works, OK?
‫And we see no errors.
‫That's a good sign.
‫So now we're going to load GDB again and we're going to go break Astreus six four, one, two, three,
‫four, five.
‫And then we're going to target remote kumu systemised three eight six.
‫Testaccio stop in dush capitalist's gdb stadio.
‫What we can see, there's an area there that's some that's happened again, it's back with Kumu that
‫is, or with GDB one or the other.
‫So we're going to try that again.
‫So when are ready to proceed to continue?
‫And we can see that breaks on zero x 400000 do layout HSM and look at that.
‫You can see that that works, that runs our Today ESM program.
‫OK, we can see that that works correctly.
‫If you go to blank today, ESM, you can see here that it says that it will get the key and then output
‫the chart to us so we can see our program was loaded successfully.
‫You can just press to continue now.
‫We can press any key in Kumu and they will tell us the key that we pressed.
‫OK, everything now works as expected.
‫And if we just do control C and we delete the breakpoints and continue again, start typing, you'll
‫see that our program works just as it did in the binary fall.
‫Apart from now, we're loading in our file.
‫We do control C and we just add the symbol files here.
‫OK, and then we we've just resolved Simbo files now and then we say print process, current, OK,
‫print askaris process current.
‫I mean, you can see that it has a nail file and the file type is zero.
‫And when we have a file type of zero, that is a nail file, guys.
‫So congratulations, you just implemented the L format.
‫Now, this is not the best implementation because if you look here, we have data that's that can be
‫overwritten because we basically we map the entire process memory as writable for a nail file.
‫But there's no need to do that because the file comes with flags.
‫OK, so if I just close out of this so I can show you, we go to programs blank and we dump the file,
‫OK, we can see if we scroll up in here.
‫We can see that the flags for the code is Read-Only PPFA, but the flags for the day to locate a zero
‫x 400 1000 is readable and writable.
‫OK, so you can see that it supports different flags.
‫So we want to make the code readable only essentially.
‫Right, because I know I just said that we can override the data, but actually that's a little different
‫because we've put it in the data section, not the read-only data section.
‫So no, that's correct.
‫In this implementation, we should be able to override that data because of the sections I've used in
‫blank 37 section DOT data, for example.
‫But all of the stuff in the ASRM section of the code section, it should not be readable.
‫OK, and as you can see, we have a PDF here, meaning read only.
‫So we don't want to be able to to write to the code and change it.
‫OK, we want a read only page.
‫So in the next lecture will be focused on making the pages read only and we'll also be making writable
‫and readable pages.
‫But for now, this implementation is OK and you've successfully loaded your very first L files.
‫So congratulations.
‫And we did it in around 200 lines of code, a little bit more maybe to 200, 300 lines of code if you
‫include the header files.
‫So congratulations.