‫Hello and welcome to this lecture, guys.
‫So in this lecture, we're going to change the way interests are handled if we just go to it.
‫He did see and we scroll up.
‫You can see that in it, in it we have ideas, he said, this is currently how we set interrupts, OK,
‫we call it set and we set it to some assembly handler, which then calls the C function.
‫After its first push, the general purpose registers, then it calls the C handler.
‫OK, now this is a bit tedious because we're going to have so many assembly routines.
‫It's going to be a bit of a nightmare.
‫So I propose a better solution.
‫We create an assembly interrupt routine for every single possible interrupt and they all call one handler,
‫the handler they call they push the script number to that C handler.
‫So the C function will know which group was called because it'll be pastorate as an argument.
‫So obviously we don't want to create 500 different labels here.
‫So what are we going to do?
‫Well, we can create a macro and by creating a macro, we only have to write code once and we can make
‫a loop.
‫OK, so we're going to do that in this lecture and it will mean the handling of interrupts will be far
‫cleaner because we won't have to write an assembly routine for every interest handler we wish to create.
‫OK, so we're going to begin now.
‫And if you don't know what I'm doing here, you're going to need to research about macros in Nazeem
‫because that is unrelated to our step.
‫So just by here, we're just going to go %s sine macro interrupt one global in its.
‫Percent one in eight percent one, and we're just going to push aid to save those general-purpose registers,
‫we can copy and paste these comments here, guys as well, just to make it clear what's going on.
‫OK, so that's what that's doing.
‫Interrupt frame, and and we can push the static pointer at this point in time, and now we want to
‫push the interest number because like I said, the C program needs to know which intercept was called.
‫Right.
‫We're making a macro here.
‫And essentially when they call in three or 10 or something, we're going to need to know what intercept
‫number was called.
‫So we push that to the stack there.
‫And then in the C prototype, that will be like in in it interrupt or something in the C function prototype,
‫it'll upset the stack frame and the the interim number as an integer.
‫OK, and that's how we'll know what's going on here.
‫And we're just going to call intra Pannella, which we haven't created yet.
‫And now we're just going to go add ESPE eight, and this is to ignore these two values, we pushed to
‫the stack there and I we're going to just go pop and I get to return from the routine.
‫And I was just going to go percent and macro again.
‫That's a macro.
‫So that coat's not there because we haven't called it.
‫So what we're going to do now is we're going to say percent a sign I zero.
‫We're making a loop.
‫OK, we're going to go rep five hundred and twelve interrupt I.
‫OK, and then we're going to go present a sign I equals I plus one.
‫OK, so we go assign I, I plus one and I will incremented.
‫OK, so I know these macros are a little ugly, but this is a sembler.
‫OK, so the macro system is not going to be beautiful, you know.
‫So we have to deal with what we have here.
‫We're going through the pain of making these macro's now so it can be cleaner later on in the C-code,
‫so here we're just going to go percent and repp.
‫So, OK, what's happening here?
‫Then we create a for loop that loops through 512 times and it basically calls our macro interrupt.
‫I OK.
‫And that will essentially create this code, OK, and it will replace the Interop we we've done here
‫with Pesenti, with the Interop number we pastorate here I.
‫OK, so let's say it's on index six or whatever.
‫Right.
‫It would say in six.
‫So if we say interest six, what we're saying is, is global and it's six in its six label Pusztai word
‫six.
‫That's what we're doing.
‫OK, so this code is basically like copy and pasted like this.
‫Five hundred and twelve times.
‫So essentially this is looped through 512 times.
‫Encrypt I is called, which represents our macro that we make further up.
‫OK, you don't have to do anything, I was just controls in those copy and paste I did.
‫So yeah, that's what's happening here.
‫OK, we're doing interrupt.
‫I hear if we did interrupt sex, what would happen is this would say in it's sex, this will push sex,
‫OK?
‫And it literally is like copy and pasting.
‫It's like definitions in C.
‫OK, so once you've done that then we can go ahead and say that we are looking for that function, the
‫interrupt handler function.
‫So we'll go at the top here and we simply go extern interrupts Handler.
‫So OK then we're just going to go to I that c and just by here at the top here we're going to say void
‫interrupt handler.
‫Any to interrupt.
‫Struct interrupt free.
‫OK, and we can just call that frame, actually, so, yeah, this function here.
‫We'll get cold by these macro's, OK, and this macro will pass the correct integer, the intra that
‫was called to us because of the well, this one I mean, because we've done percent I so percent I is
‫replaced with whatever value you passed here.
‫If you do interrupt 20 like this, then it's going to generate a macro within it.
‫Twenty being the label and at twenty being pushed.
‫OK, so just, just understand that OK, so that's perfect.
‫We go to see.
‫OK, so before we fill this function in, there's some things we need to note.
‫The process is not magic.
‫It doesn't know that we've created a macro or 512 interrupts.
‫We need to update the descriptive tables using it.
‫Except now the problem is we don't know the addresses of these macros.
‫It's unfortunate.
‫I know.
‫So what do we do about this?
‫Well, we create an external pointer array.
‫That's what we do.
‫And we define the array in IGT, HSM.
‫So just follow me and you will understand what is going on.
‫So just by here, we're going to say external void pointer entry points a table, OK, and we're going
‫to put here Pekoe as Max interrupts OK, now if you just go to config dot, we're going to make that.
‫So we're just going to go define Peatross.
‫Max interrupts 512.
‫Make sure it's 512 guys because we've created 512 entries here in Australia.
‫So when we looked for five, 10, 12 times.
‫Right.
‫OK, so that's was all good.
‫Now, essentially in days and we're going to declare this array into a table.
‫That's why we've is external, right?
‫Using the external keyword.
‫We're going to fill that array in assembly with pointers.
‫So these interests that we've created here in our little loop by here in TRIPTI, in TRIPTI and so on.
‫Right interview into one inch or two, we've created five, 10, 12 of them in this four loopier.
‫Right.
‫We've got in TRIPTI and it's called an TRIPTI here and created 512 of these separate routines for each
‫and every interrupt.
‫So the idea is here we create this entry point to table in Australia and we we pointed to each and every
‫individual one that we've created here in this folder.
‫OK, so that's the idea because the C program can't possibly know about this.
‫Right?
‫So that's why we have to declare the array.
‫And I start I assume you will understand soon enough.
‫Just scroll down a bit here.
‫And just by here you will see we loop through PTW total interrupts and we set I to know interrupt.
‫OK, we need to change this.
‫It instead needs to be set to enter a pointer table I.
‫OK, and that will ensure the process is happy.
‫Now you'll see we've gone ptw into interrupt PTW total interrupts.
‫We now have two definitions saying the same thing so we don't really want that.
‫So this little definition we may, we're going to replace it with PTW.
‫Total interrupts actually and in config Hajj we can remove that definition we made.
‫I didn't realize we made one earlier on.
‫So if we go back twice to see it should look like that now.
‫OK.
‫OK, so just a quick overview.
‫We create an array called entry point to table.
‫This is external, which means we're not creating this memory.
‫We're saying to the C compiler, this man was created somewhere else.
‫We don't know where, but just treat it like void pointer array that can hold five, 10, 12 elements.
‫That's what we're saying here.
‫Now, the memories actually create nice today.
‫We haven't written it yet.
‫But, you know, I've told you, that's what we're going to do.
‫OK, so you're aware of that?
‫Good.
‫In it.
‫In it we loop through all of those total interrupts, OK?
‫And we set in the script table that I should point to entry points, table I.
‫That's what we say.
‫OK, so we've set up those points is now OK.
‫And now finally and that Asen we'll have a little pointer array OK.
‫Which will point to each and every interrupt here, which I've already explained to you.
‫So that's a brief overview of what's going to happen here.
‫So this is not so hard.
‫Scroll to the bottom here and in section, that data, which is going to go into a pointer table.
‫And we're going to go percent a sign I zero percent rep five June 12 interrupts Arae entry I, which
‫we haven't created yet.
‫And then we're going to go percent assign I, I plus one percent and rep and I just above here were
‫going to say macro interrupts oray entry one td in eight percent one and macro.
‫So can you see how this is working.
‫We've created that entry point a table that's that our C program sees as external.
‫Right.
‫It sees that as external as as I've already explained, we create the array here that point to table
‫here, OK, and we call the macro encrypt array entry which does a double what, which is four bytes
‫the size of an address and a 32 bit architecture.
‫Right.
‫And what address.
‫So we send it to.
‫Well, only in eight percent one.
‫OK, and as you know, the percent one is replaced with whatever value parts to it.
‫So that's how that's working.
‫If I was to go interrupt array entry five, that's going to be replaced with in five.
‫And what is the five label.
‫Well, the five label if we scroll up.
‫Is this it represents this.
‫I understand, because if I did interrupt five, then that's going to give me a label of it five, you
‫understand, because that's how macros work.
‫This is created five million, 12 times because of our loop and so is our point.
‫That table is created five, 10, 12 times.
‫Well, the entry we have five new 12 entries.
‫OK, so we let's we have literally in just assembly created a table of pointers pointing to our intra
‫service routines.
‫So it's nice to see if we now access the entire point to table where actually accessing the memory here
‫on line 112 where we where we call the interrupt array entry macro.
‫OK.
‫It's appointer to end it one and two and three and four and so on, and that's the same reason why we
‫have to loop through all of the pointed table and do I just said, OK, because that updates the descriptive
‫table so that it points.
‫So these macro's, OK, so that's how that is working guys, and I hope that makes sense because it's
‫quite difficult to explain this stuff when you haven't worked with macro's before.
‫So if you're still confused, you need to research by the macro's before continuing this course.
‫So, yeah, now that we have done that, if we want to run this, any interest that happens, that we
‫have an override ID, we've overrides everything here.
‫You see Xerox 21, Xerox, Xerox and any Interop, we have an override ID.
‫It will call this interim Tangela here.
‫So it really is that that fascinating that we've just simplified this so much now that we can see the
‫exact interruptive was called the Interop number, which is fantastic.
‫We can have a switch statement, we can have an array of function pointers and we can work with those
‫in troop numbers.
‫OK, so this is a this is a really good thing that we've abstracted it out like this.
‫If we decided not substract that, I would like this, we would have to use it set on some assembly
‫routine, which then calls the C handler would have to do that for every single instrument that we wanted.
‫Now, that's that's a lot of work.
‫This little micro implementation simplifies the whole thing, although we have to do is use an if statement
‫on this interim number was the incorrupt and SREP five.
‫OK, then do something for five.
‫You see what I mean?
‫It's that simple now because we've abstracted this out.
‫So just go to Tarsem because we're not quite done.
‫We need to now make this table exploded.
‫So just copy and paste the label into your points table.
‫Scroll up and we're just going to say global and we're going to paste that in global entry points table.
‫OK, I'll give it a global and a 21 H because we don't want that anymore.
‫We're just going to delete that.
‫OK, we go to Tazi and we're just going to look through here a second, whereas in SREP 21 handle at
‫the age of twenty one.
‫Hey Chandler, we no longer want that or I just delete that.
‫OK, and copy and paste outby zero twenty six twenty and paste that in the interim.
‫Tandler because remember the programmable Interop controller requires an acknowledgement, as I've already
‫explained, when we were first implementing these handlers.
‫OK, it requires an acknowledgement.
‫So we have to give it an acknowledgement.
‫OK, so we're now ready to test this.
‫So we're going to compile this and we're going to put a breakpoint on this line and see what the number
‫says.
‫So just go to the terminal and we're going to go make clean build that, S.H..
‫And we see a little error on line 54 and 65, I see JSM, so just go to line 54 and we can see what
‫I've done here.
‫I've done a percent, I, I should have been eight percent one.
‫Guys, that was a little mistake because I was using the eye here in the loop.
‫Change that from percent eye two percent one.
‫And we're going to scroll down and we're going to do the same on line 64.
‫No, no, that was the only one.
‫OK, recompile that now.
‫And there we are.
‫That works fine, you can see undefined reference to any 21 page, line 57.
‫That's because we just deleted that.
‫So if we just could start see line 57, uh, and we're going to delete this one here.
‫This is she said Xerox 21 k delete that because we've created the handle on how to handle that.
‫Right, with the macros.
‫So build again.
‫We can see that works absolutely fine.
‫We're going to go Cribben GDP and we're going to test this to see if it works.
‫So we're going to go add single file filled kernel full todo Xerox one.
‫One, two, three, four, five.
‫Target remote kumu system i3 eight six dash hastier showstopping dash capsulize JP GBE Studio.
‫OK, and we're now going to break on the interrupt handler.
‫We're going to proceed to continue and look at that.
‫We can see in thirty two, OK, and if we print the frame, we can see the general-purpose registers
‫pressie to continue.
‫Now we see in Europe one one eight C to continue in 32.
‫OK, so you can see we have now created our very own generic intercept handler and it tells us the number.
‫And can you see the potential with this?
‫We have a switch statement if statement point of function or anything we want because we now know the
‫Interop number.
‫Now, this is something that the processor doesn't tell you.
‫As you know, we we know which Europe was used because we made a macro of 512 different interrupts,
‫OK, that it literally created 512 different Interop labels.
‫And if we scroll down, we created our pointed table here, which also points to the addresses of those
‫five 12 interrupts.
‫What are the addresses?
‫Simply the labels.
‫So in it one and a two and a three and a four, so on.
‫And they push themselves, they push their own interim number to the stack.
‫And that is how we get to know exactly which Interop was called.
‫So congratulations, you've now abstracted out your interest handlers.
‫This was very important step in writing clean code.
‫That little extra effort goes a long way.
‫So thanks for watching.