‫Hello and welcome back, guys.
‫We are now going to implement the intro to script a table, so in our source directress just create
‫a new folder and we're going to call it for a script, a table.
‫We're going to create a new file ID and we're just going to set up that had a file.
‫Now we're going to create a file called IDs that see, and it includes the header file, and now that
‫we have our basic file structure done, we can start writing the code.
‫OK, so we are going to be implementing what we discussed in the last lecture when we talked about the
‫script to table.
‫We're going to be implementing everything I talked about there.
‫So if you haven't seen that lecture, go and watch it.
‫So we go to Editta.
‫We're going to define some structures here now.
‫So first, we are going to create our interruptive script to table this script to suggest to struct
‫in D.C. for the script.
‫OK, and we are going to pack this structure.
‫So first comes our first off set.
‫Now comes our selecter, so that would be the you know, we would set that, you know, the kernel code
‫selector basically.
‫So now comes a zero bytes.
‫Next, we implement the type attribute.
‫And now comes our offset up of its.
‫OK, excellent.
‫We now need to implement our ID tr descriptor.
‫Struct id tr descriptor.
‫Unit 16 Pty Ltd.
‫And then we're going to have a unit, 30 to 40 base.
‫OK, so that just points to the array basically, right, and this needs to be packed as well.
‫Just to be safe, OK, so if we just go to Austin, so I just want you guys to have something to cross-reference
‫with as you're going along as well as this, cos.
‫OK.
‫OK, so we can see here a value of 1000 Hajj means to injured Hajj interrupts.
‫So if we go here and we type in 200 Hecks, we should get five 12 decimal, which is correct.
‫So this is how many interests we can support.
‫Right.
‫So if we just go back here, we're going to create a new file in the source called Confect Hajj, which
‫is going to contain some configuration settings here.
‫Right.
‫So we're just going to go to find PCOS.
‫Total interrupts I will just FY 12 there all you can do Hecht's 200, whichever is best because it represents
‫a total no I'm just going to use the decimal equivalent I think is more clear that way.
‫So we go to ADT Dot, see, we're going to create a structure here now.
‫So we're going to go struct IGT, DGSE and then we're just going to go descriptors.
‫It descriptives.
‫And in here, we're going to include.
‫Confected outrage, and we're just going to go purchase total interrupts.
‫OK, now we're going to create another one struct EDT r descriptor.
‫I did see the script.
‫OK, so we're going to create a function called IDC in it which will set up the script, the table.
‫Now, before we continue any more, we need to actually create our own set function because we need
‫to nail all of these.
‫However, we don't actually have the functions to do that.
‫So we're going to have to create them ourselves.
‫So we're going to create a new folder in source called Memory.
‫OK, and we're just going to go memory Hajj F and F, memory H, define memory H and F, and now we're
‫going to go include S3 Deathstar, Hajj and we're going to go void pointer when we're sending a boy
‫pointer set.
‫Avoid pointer and it si size t size.
‫So now we're going to create a new file memory dot see and we're going to include memory dark Hajj.
‫Now, if we just go back to the Hajj, we're going to copy and paste this.
‫I'm just creating our own meme said here, guys.
‫Right.
‫So it'll will return a pointer, which is what it says on the C specification.
‫It just returns the point provided and then we're going to go char c pointer equals char Peter.
‫Four inch equals zero eye below size, eye plus, plus see pointer eye equals see, OK, and that that
‫should give us a nice memo said function to work with here.
‫So we should now be able to use meme's said.
‫So we go back to it to see we're going to include memory h memory photos, maybe memes that ADT descriptors.
‫And we're just going to set it to zero size of ice tea descriptives, OK, so I'll create a bunch of
‫NUL descriptors for us.
‫OK, so back to the documentation.
‫The limit here.
‫We're about to set up the idea.
‫The limit defines the length of the it invites minus one.
‫OK, so if we go back here then we're going to go into the scripter limit equals size of EITE descriptors
‫minus one Editta descriptor.
‫Double bass equals icy descriptors, so that should set that up correctly.
‫OK, so we're now going to create a tea set function which will allow us to set interrupts and the addresses
‫we wanted to go to.
‫So I said, why did it set Integer?
‫And this will be the Interop number.
‫OK.
‫And our here will go void address and you can call this if you want.
‫It might sound a bit cleaner, but I'll just keep it as in number to keep it simple for you guys.
‫So here, then we're going to go struct icey descriptor pointed to a descriptor now, right, DGSE,
‫this variable name equals itte descriptors.
‫And we're going to pass in the interim, no.
‫OK, so now we're going to go descriptor before I forget.
‫Guys, we need the address of that and of the value.
‫OK, so the address of this I scripter specified by the insured number.
‫So we're going to go to scripter offset one equals.
‫And before we go any further, go to Hajj and we just need to include a stint at the Hajj before I forget
‫to do that right.
‫My bad, because we need to resolve these types right now.
‫Go back to Aysgarth.
‫See, so scripter offset one equals.
‫Unit 32 t.
‫Address and we're going to we're going to use a bitwise operator here now, bitwise end, and we're
‫going to go zero zero zero zero zero f f f.
‫I know you can just do f f f guys, but I like to do the full amount because this is much more clearer
‫what's going on.
‫So we've successfully set off one of the descriptor for the Interop provided.
‫Next step is to select is to set The Selecter.
‫Now, this will be 008, I believe, but we're going to make an actual constant for this if we just
‫go kind of.
‫Yeah, we can see that I've set them here.
‫Right.
‫So eight is the is the code code select ten is the data selector.
‫I did call them Secchia for segment.
‫It's just easier to remember.
‫But yeah, technically they're selectors.
‫Right.
‫So if we go to configure IRH, we're going to go define Curnoe Code Selector 008 to find kernel data.
‫Select six ten.
‫OK, now we go back to Tazi.
‫We can now go and change the select from zero eight to kernel code selector so it's just nicer than
‫using magic numbers.
‫OK, so now we set our zero to zero.
‫Now technically it will always be set to zero because we set it here and we're not changing it, but
‫it's still best practice to put it here.
‫So if we go to Firefox here and we can see the entries here.
‫Right.
‫And how the bits should be stored like I showed you on the presentation.
‫Right.
‫We just got visual studio code here.
‫So we can compare the structures so you can see offset one.
‫Right, that is the bottom offset by here, right?
‫Zero to 15.
‫That's right.
‫Then we have our selecter.
‫OK, 16 to 31 bets, then we have at zero, so you can see us backwards, OK, just because of the way
‫the structure's stored in memory and now we have our type bits, forty to forty three, and then we
‫go straight for our offset to OK, the very top offset because if we add the bits together.
‫By hear from our type.
‫We do 47 minus 40, which gives us the full seven bits, right?
‫So we're now type attributes.
‫We can also add some additional information to said the DPL and the storage segment and so on.
‫So we open up hexed and we put in here, OK, and we put binary notice this pattern.
‫We can see that the first four bits, one one one zero, that's a 32 bit Interop gate, which takes
‫up our type.
‫That sets our type for us because we're working on the bit level right now.
‫These aren't individual bytes, right?
‫The type the storage segment does them present.
‫They all make up the one byte.
‫Right.
‫So we set that here, right?
‫Zero zero three.
‫That is our interest.
‫OK, but also the the upper the upper four bits of the type AHP, we are also going to set as you zero
‫eight, which, which will make that the two nibbles will end up making the U.S. OK, the U.S..
‫And the reason we're doing that is because obviously we need to set these extra bits here.
‫Right.
‫So let's just go through this with you so you understand.
‫So the storage segment set to zero of interest and trap gates and what we see here, a zero.
‫Next bit along.
‫This is our DPL, this takes up to two bits of descriptive privilege level.
‫OK, that's one one.
‫Now what is one one?
‫Well, let me show you, if I go to the terminal, I type Python B one one is decimal three.
‫OK, ring three, ring three.
‫So descriptive privilege level is ring three, which allows it to be called from use of programs in
‫userspace.
‫OK, and finally, our final bit here is the present bit set to zero for unused interrupts while we're
‫making an interrupt.
‫So it shouldn't be zero.
‫So we set it to one.
‫OK, so that's why what what we're now going to do, we're going to set the type to not deoxy but Zosi,
‫because we also need to take into account of setting these flags.
‫And it just happens to be the same values you see by coincidence because of the way we want to set this
‫up.
‫So, yeah, I hope that explains we're about to do and why we're not using 060 and we're using Zsuzsi
‫for the type.
‫OK, so what we're going to do then I'm going to go descriptor type, attribute equals easy.
‫And remember, the reason is not zero is because of what I just explained.
‫We have to take into account the will also set in the other bits in the DPL and so on.
‫So when I was going to go to script offset to equals.
‫Unit 32 t address shifted to the right by 16, and that's because.
‫The higher part of the offset, that's what it says here, which is why we have to do that.
‫Yeah.
‫So there we are.
‫We finished our IGT set function.
‫And now what we can do is if we go to ICE in it, we can do things like this.
‫It said zero and now we can put a function address here.
‫So let's just go.
‫It's OK.
‫And we're going to create a function of the top void.
‫It's zero and all it's going to do is print out and divide by zero error because interest zero is a
‫divide by zero exception.
‫If you remember, I explained this with the interactive table and real mode.
‫And yeah, there should be there should be fine.
‫We now need to obviously tell the process where the script table is, which we haven't yet done.
‫So we do this using the Allied T processor instruction so we can actually do this through C unfortunately.
‫So we create a new file called IDC ASRM in the IBT directory.
‫We're now going to go S.A.M. because remember this is an assembly section now and then we're going to
‫go it loads, OK, and here we're going to say Global Stilo.
‫So it exports the symbol.
‫Right now we're going to have to write some assembly language that's compatible with C.
‫If you don't know how to do that, you need to learn learnedness because I'm going to I'm going to do
‫it right now.
‫You might understand me if you don't.
‫You need to learn that because assembly is a requirement of this course.
‫So the first thing to do is we're going to push the base pointer.
‫OK, now we're going to pop base pointer and then we're going to return.
‫And now we're going to move the stack pointer into the base pointer so that we have a reference to our
‫frame.
‫OK, great.
‫Now everything inside in between these lines is basically our function, right?
‫So what we're going to do, we are going to say move SBX, EBP plus eight.
‫So that'll move the value from EBP plus eight into Ebix.
‫And the value is obviously the points that they provided to us.
‫So if we just did EBP without SBP plus eight, then that will obviously point to the base point.
‫We just pushed the stack.
‫If we did plus four, it would point to the return address of the function caller who called us if we
‫did plus eight.
‫Finally, it points to the first argument passed to this function that we were creating.
‫So that's why we do EBC plus eight.
‫But if you still confuse guys, you need to research the assembly language here because this is a requirement
‫of the course.
‫OK, so here we're going to go outside tiebacks and there we go.
‫That should work so that that that will load our script to table successfully.
‫We now go to E C we now need to actually implement the function prototype now so that our CECO can know
‫how to talk with it.
‫So if we go external void Aichi load void pointer.
‫It's that simple.
‫And now if we scroll down after we set up all our interrupts load the to descript table igt load and
‫we pass in the address of the igt id tr descriptor.
‫OK, and we need to pass in the address to that.
‫So the id tr the script remember is this one don't pass in the table by accident.
‫It needs to receive the Editta if you wanted to.
‫You could change this from void to a point to that.
‫In fact let's do it just to make sure no one makes a mistake like that.
‫Right.
‫So that we are that will provide a bit of a compile time security for us.
‫The.
‫OK, so we've now set up the table successfully.
‫We need to change our makefile to compile all these now.
‫And once we've done that, if we were to go in at zero or divide something by zero, it should call
‫our handler.
‫OK, so we're going to go to our makefile them.
‫We're just after here.
‫We're going to go forward, slash, build it.
‫Forward slash EDT.
‫Assem Dotto and in our bill directory, guys, we need to create a new folder here, so we're going
‫to go and create a EDT folder.
‫And we're also going to create a memory folder in the build as well, because we want to build files
‫to be structured correctly.
‫We don't want them all slapped in the same directory.
‫We don't want any conflicts later on if we name something similar or the same.
‫You know, we don't want any issues like that.
‫So make sure you create separate folders like I just did.
‫So now we're going to go forward, slash, build forward, slash memory, memory data.
‫OK, and we're also going to go forward, slash, build, idc, IDC.
‫Oh, OK.
‫So I did see Diesem that I will be our assembly file.
‫It'll be our CFO comp..
‫I mean.
‫And make sure the sections HSM, don't forget that, OK, so we are going to.
‫Go back to the makefile and we're going to start making these things, so we're just going to copy and
‫paste because it's easier.
‫So I've copied and pasted journalism.
‫I'm now going to change this to EDT EDT D'Allesandro Forward slash IDG IDC Daria Sam for IDC, idc jsm
‫forward slash EDT.
‫IDC assembled a nice.
‫So there's our I.T. assembly file compiled assembled.
‫I mean so now we're now going to copy the kernel C file here and we'll do the same.
‫IDG It although it does C because it's just easier to copy and paste it rather than do it every single
‫time.
‫You know, that's what I want done when a copy of the C file again.
‫Now we need to do memory so we're going to go build memory.
‫Memory O source memory memory dot c.
‫Memory, memory, dot, see?
‫Finally, memory memory Dotto OK, nice, so now ready to attempt to compile that and see if that can
‫pass successfully.
‫If it does, we can call it loud in Canada and see, OK, so we're going to open up the terminal, go
‫to PCOS.
‫And we're just going to go make clean forward slash, build that S.H. and there we are.
‫We can see there's a few compulsories with us.
‫No worries at all.
‫So firstly, a declaration of print.
‫That's because in Canada at sea, we need to export this function in a prototype, so just copy, copy
‫this and we're going to paste it in the header file.
‫OK, so we copy and paste our print function from Canada Sea into Canada and now we need to go into
‫C2C.
‫We simply include Canada Hajj.
‫So that's that problem solved.
‫And if we now build again, can see that errors come.
‫OK, now, as for this area, let's just go back to the Makefile a second, because there's one other
‫thing we need to do that I forgot to do in our eyes to see next hour includes we also need to do another
‫code for it for the ADT directory.
‫So then it goes into source edet and then it can resolve the THC.
‫So just do that, because then that allows us to just include things like I'd hate rather than I did
‫before I did.
‫So we're going to face the same here for memory.
‫OK, and we're going to do this for all of our C files that we make in the future.
‫We'll always have the include to its own directory as well.
‫So that includes so that it can include files of its own.
‫So we're going to go back to the terminal.
‫We're going to build that again.
‫Error assignment to you in it's 30 to T from struct ADT descriptor.
‫OK, that's no problem, go to see and all we have to do is just cast it to you and say to T because
‫it's a pointer, right?
‫But in our in our in our actual structure, we don't start as a pointer.
‫We start as an unsigned feature integer, which is fine, which is fine, really.
‫It could be a pointer, but that's OK because we don't use it as a pointer, the actual system does.
‫So I think it's perfectly comfortable to store that in the structure.
‫As an unsigned integer, that's OK.
‫So if you just cast that pointer here to you in a three to T, that should work fine because remember
‫in C when we access arrays, it returns appointed to that array.
‫Right.
‫When we access it like this without an index.
‫So if we now feel that again, we can see that works perfectly.
‫I'm just going to run that and we can still see hello world and test from last lecture.
‫So nothing's panicking by the looks of it.
‫And if we now go to Canada and see, we now need to include it forward slash Izidor and now in Col Meng,
‫we simply scroll down at the very bottom.
‫Here we go.
‫IDC in it.
‫Initialise.
‫The global no no initialised the interrupt to script the table and we go to Tazi, we need to put that
‫in the prototype as well as to just copy and paste it in it.
‫And just pasted in the header files, so we have a prototype, and if you now go back, we're going
‫to make clean build that S.H..
‫And we see how will test.
‫OK, so now what I want us to do is cause a problem.
‫So if we go to Colonel JSM.
‫And right, right by here, we're going to create a new label and we're just going to call it a problem,
‫right?
‫And without the underscore that even and we're just going to go movie zero and the reason we're doing
‫this, if we actually try to divide by zero in the source code, the compiler might notice we're trying
‫to statically do that and it might not allow us to do it.
‫So I don't want to I want to do an assembly just so we can guarantee that this is what's happening.
‫Without any fear of any optimisations or something, so here we go, movie zero, because the serious
‫issue, right, divide by zero.
‫So if we now go global problem, OK, Seattle exploded and now in Canada at sea, we're just going to
‫go avoid problem, OK?
‫And we're going to make that external.
‫And I just called problem by here, OK?
‫And if we now go back to the terminal and we make a clean bill that S.H., KDDI, Ben Kumu divide by
‫zero error.
‫So you can see our interests are set up correctly.
‫If we go back to Canada, Diesem get rid of this and we're actually just going to go in at zero to call
‫interest zero and the same thing will happen.
‫So we now try that again, divide by zero error, not just change this to in 32.
‫If we now go to Tazi and we change this from zero to thirty two, what do you think you're going to
‫still see.
‫Divide by zero error, so you can see you can now you can now easily set up entraps in the system without
‫it said function, just make sure you set them before you load the descriptor table.
‫Yeah.
‫So, yeah.
‫So that's how you do it guys.
‫So I'm just going to control zie that says back to zero because this is a divide by zero error.
‫Right.
‫And we're going to go to Canada Diesem.
‫We're going to get rid of problem because we don't want it there.
‫That was just for example.
‫And to get rid of the global label problem at the top, we are going to get rid of every problem and
‫we're gonna get rid of the function called the problem.
‫We now just compile that.
‫And tested, and now we see no problem outputted, so that concludes this lecture and thank you very
‫much.
‫You've now implemented entraps in your operating system.