‫Hello and welcome, everybody, and in this lecture, we're going to start implementing ELF Loda, if
‫you remember in last lecture I showed you a presentation on the Al-Fadl format.
‫Well, we're now going to create an actual elf loader for our object files.
‫We will load them into memory and execute them.
‫So the first thing I want us to do is go to source.
‫We're going to create a new folder called Loda.
‫And inside here, we're going to create a new folder called Format's
‫and we're going to create a new file called After the Hajj.
‫So now we're going to go hash tag F and Def El-Hage to find FH.
‫And I know if we just go to Google.
‫And we search for our full specification.
‫And we can take this one here from the Linux Foundation.
‫And this is the entire specification that we're basing our floater off now, as you can see, it's a
‫lot of pages.
‫There's so much going on here.
‫In reality, we can right now Florida in under three hundred lines of code because our Florida will
‫only load static files.
‫In other words, it won't support Qaid libraries.
‫OK, so you can see everything in detail in this specification, explains what these variables mean,
‫explains what these types mean.
‫Now, I'm going to explain as much as I can throughout this lecture while we're implementing this.
‫However, please, please, please have this manual open next to you, because look how detailed it
‫is.
‫It tells you exactly what every field is doing, you know, so we can see that the EP offset.
‫This member holds the program tables.
‫The program had two tables falloffs.
‫It invites if the file has no problem, had a hold zero.
‫The specification is very detailed and it's a lot of pages.
‫OK, you don't have to concern yourself with most of this stuff unless you wanted to implement shared
‫libraries, which is a bit more complicated to get.
‫Right.
‫So go to Visual Studio code, then keep this specification open, OK?
‫And in Visual Studio Code, we're now going to start implementing some definitions and structures for
‫the file format.
‫So we're just going to go hash tag, define pf x zero zero one, OK, hash tag, define PDF WSYX CO2.
‫And you know, if you don't know what these are.
‫Check the manual, guys, because I could make a course on on the old format.
‫That's how detailed and complex it can get.
‫An entire course can be made on this.
‫And I'm covering this in, what, two lectures, two or three lectures.
‫So here we're going to opf are zero 004 to find null zero to find peaty load.
‫So these are those program had the types that we was talking about in the presentation.
‫Right.
‫Loved to find peaty dynamic too.
‫And yeah, we just copy and paste load here, go to the specification.
‫I teach you guys how to find out this information.
‫Just do control F and then we go paste that into the bottom.
‫What is peaty load.
‫The array element specifies a loadable segment.
‫There we go.
‫You see it explains that it's part of the program header.
‫So everything I'm doing, you can cross-reference with that manual.
‫And if you do need extra support, send me a message and I can help you.
‫So here we're going to go hash tag, define peaty interpeace.
‫OK, that's three to find peaty notes.
‫That's four.
‫Define Peaty S.H. Hleb five define peaty, be HDR six.
‫And now we're going to do the same for the sections to find null zero to find T that's one to find s
‫t symbol table.
‫Well same table to s y tab guys.
‫OK, make sure you don't actually write symbol table.
‫I just said that out loud.
‫So then we're going to go hash tag, define SAHD start tab for string table define SHC.
‫Well a four.
‫So that's a relocation there.
‫Define S t hash five.
‫Define SHC dynamic six.
‫Define SHC.
‫Note seven.
‫Define as nobut eight.
‫Define safety well as another relocation nine to find safety.
‫S.H. Labe ten define SHC, DBI and same four dynamic symbol I think eleven tag define SAHD low proc.
‫Twelve to find safety high proc 13, to find safety, low user 14, to find air safety, high user 15.
‫OK, so that's it for the simple definitions there.
‫So now we're going to go to find it none.
‫Zero to find E.T..
‫Well, one to find E.T. XY to define ETN five.
‫Now, that's three sorry, three, my mistake has to define Ebtekar four to find it, and I went 16
‫to find my class four.
‫And if you look at it and identify, that should be I and I don't not yet.
‫I indent guys.
‫So that was my mistake.
‫So make sure you change that.
‫And here we're going to go to find it eight to five.
‫And now we're going to find the outclasses hashtag to find Alpha Class None zero hashtag defined Alpha
‫Class thirty to one hashtag.
‫Define our class 64 to.
‫So these describe if it's a 32 bit program or a 64 bit program.
‫Right.
‫Hashtag define lth data none zero hashtag define alpha data to LSP one to find alpha data two must be
‫two.
‫So as you can see, there's a lot to be explained here.
‫This is an operating system development course.
‫It's not a course on the alpha format.
‫I could make a ten hour course on this one one specification.
‫I can't possibly cover it all here.
‫So once again, that manual will explain all of these fields.
‫If you want extra clarification, however, follow this course all the way through and you will have
‫an alpha coda.
‫So we're going to go to find S.H. and UNDEF zero, OK?
‫And now we're going to declare some types now.
‫So we're going to go typedef unit sixteen G of thirty two 1/2 and we need to just include acidy in it
‫up here guys include scd in it dot org.
‫OK, and we're also going to include seeds after the hatch as well guys.
‫OK, let's include both of those headers up here.
‫That'll, that allow us to access you in at sixteen t when you include Usted.
‫And so now we're going to go typedef unit thirty two T of thirty two word typedef in it thirty two T
‫Alpha thirty two Soad.
‫I know these are weird names guys, but these are all inside the alpha specification.
‫Let's copy and paste Alpha 32 sort.
‫We can search for it here.
‫And yes, you can see that they use it, OK?
‫And if you scroll all the way up, it tells you what these data types mean.
‫OK, so again, the manual has so much detail.
‫Any questions you have is probably in the manual.
‫But if you still have trouble, just send me the message, guys.
‫OK, so here we're going to go.
‫Typedef Unit 32 to of 30 to address typedef in it 32 out of 32 offset.
‫OK, so that's OK if not actually offset just off.
‫So now we're going to go struct of 32 HDR that's 32 program header and that contains our 32 word P type.
‫That's the first variable.
‫And as a matter of fact, just go to Firefox browser or whatever your specification is and just search
‫for program header in here, OK?
‫Might take a while to find the section, so, guys, I actually paused the video until I could find
‫this axis manual shoot, you might take you a while, but if you search for the variable name P type
‫that we just made, you'll find it straight away.
‫So you can see this is the program header.
‫OK, all of these are described P type offset CPV address.
‫OK, now one thing I wanted to note is if you look at the manual here, you will see they declared the
‫structure slightly different.
‫I've declared them in lowercase because this is my style of coding.
‫OK, I don't like using the Campbell case stuff.
‫So that's just something to be aware of when we continue this.
‫OK, it's all lowercase when you're working with the types we're creating.
‫So this here explains program header.
‫OK, so we need to declare all of these and you might be tempted to copy and paste.
‫If you want to do that, fine.
‫But just be careful that you don't lose track of the cost.
‫OK, so we're going to go back to Visual Studio Code and now we're going to go out thirty two off off
‫set of thirty to address P the address of thirty to address P P address of three two word P file size.
‫So that's P file S Z the that represents that of thirty two word P mem size that again it's an S Z on
‫the end of that array of 32 word P flags of 32 word P align.
‫And we're just going to pack that with actual impact as well guys.
‫OK, because whilst the compiler probably won't move these bits around because they're aligned properly,
‫it's best to you packed anyway just to be on the safe side.
‫So, yeah, if we look at the manual, we can compare those types.
‫So yeah, we can compare here.
‫Now we can see of the two would of three to offset a three to address address.
‫And then we have one, two, three, four forwards at the bottom.
‫One, two, three, four.
‫So yeah, it's perfectly correct.
‫We've defined the program header correctly.
‫So now we're going to go out of 30 to SAHD.
‫So this is the section had an arc of 32 words, S.H., name of 32 words, S.H. type of 32 word, S.H.
‫flags of three to address S.H. address of 32 to offset S.H. Offset of 32 words.
‫S.H. size of 32 word S.H. Link of 32 word S.H. Info.
‫And make sure you put that semicolon there that I missed.
‫Guys of 32 word S.H. address a line of thirty two word S.H. and sice entity.
‫So guys, I need you to make sure that you write this exactly as I'm doing.
‫If you use the wrong type, you're going to corrupt your entire offloads.
‫So I just want to point something out as well.
‫You'll see here the end to end Tresize, OK, and you'll see here S.H. Size.
‫So how do you know how many elements there are where the S.H. officer disappointing.
‫Why?
‫It's very easy.
‫You take the same size and you divide it by the entity size, OK?
‫And that will give you the total elements that the S.H. offset is pointing to.
‫So it's pointing to some sort of table of some kind that holds loads of records of some kind.
‫Then you calculate how many records there are by taking the size and dividing it by the entity size.
‫OK, so I just want to point that out to you and we're going to pack that.
‫I know you don't need to worry about that right now, but it's best to mention it because a little light
‫bulb will appear in your head at some point, you know, when you start to understand the format better.
‫So that's the section how to create it.
‫So now we're going to create the Elfreda's.
‫So we're going to go struct, Elfreda.
‫Unsigned Shah Ident, II and Ident, OK, so that is the signature essentially guys of the file.
‫So this is the very first thing in the file is the alphabet.
‫OK, the very at the very top at offsets here in the file is the header.
‫So we're going to go after two 1/2 E type of 30 to half a machine of 32 word E version of 30 to address
‫entry.
‫So that's our program entry point.
‫That's the virtual address of the entry point of thirty to offset mph of.
‫Of 30 to offset S.H. off of 32 worthy flags of 30 to half each size of 32 1/2 mph, E.A. size of 32
‫1/2, EBP.
‫None of that is you have E S.H. EMT size of 32 1/2, S.H., None of 32 1/2, S.H. Stia MDX.
‫OK, and that should be Elfreda.
‫And we're going to pack that as well.
‫OK.
‫And now we're just going to go struct of 32 simu no, no elfatih to DVM, well, implement the Devean
‫first of 32 sort detec union.
‫Now we make a union, OK, so the union won't really contain a whole lot.
‫Just put Duen by here as well guys at the bottom and the union will contain a word for Deval and a address
‫to the pointer.
‫And I'm sure you all know what a union is because you should be fluent in the C language before you
‫took this course.
‫However, just in case someone doesn't know what it is, I'm going to just quickly describe it.
‫The union basically shares the memory region.
‫So Deval and Pointer, they shared the same memory.
‫OK, so if you changed Pinay, you're basically also affecting Deval.
‫They share the same memory.
‫So that's all you need to be aware of.
‫So here we're going to pack this attribute packed.
‫OK, so now we're just going to go struct of 32 s y m.
‫So we're implementing the symbol definitions now.
‫We're just going to go archabbey packed.
‫And inside here, this structure, we're now going to go after each word as a name and as you know,
‫the name specifies an index in the string table, in this case, four symbols.
‫It's the dynamic string table in the DOT, DUI and star section.
‫OK, so this this points to an index in that string table.
‫And what is the name?
‫Well, it's the symbol name, so it will be the function name.
‫Stuff like that.
‫Right.
‫The all the exploded symbol symbols and the city name points to a string that represents the name of
‫this symbol.
‫So that's just an index in the dynamic string table in this case.
‫So here we're going to go out 32 address city value of 32 words, city size, unsigned char, astm fo
‫unsign each other.
‫And you guys should check the manual about these things after we've made the floater, because whatever
‫these values are depends on the type of symbol they are.
‫It is.
‫And there's lots of different reasons of when the value is different, whether it's a virtual address,
‫whether it's a relative address and the same for all of the values, really.
‫So you need to pay attention to the manual.
‫Don't make assumptions.
‫See if we're going to go out 32 1/2, S.G. S.H. Index.
‫OK, so that represents our symbol.
‫So we've defined all of the structures for Alef that we care about and all of the definitions that we
‫care about.
‫So that's good news.
‫So that completes part one of the L flow to series.
‫In the next couple lectures, we will start actually creating the loda.
‫Now that we have all of the head of files and definitions, we need to create the.
‫Thanks for watching POB one.