 In the previous screencast, we saw how a system called is invoked from user space. In this screencast, we will see how the kernel handles it. We know that the interrupt service routines or ISRs are loaded into memory very early during kernel boob. The code that does this can be found in the following file. This is the same file that we looked at while tracing how the kernel boobs. Scrolling down this file, you can see that the interrupt service routines in particular the MIPS general handler is loaded pretty early during boot. Let's look at what these service routines look like. Crepping through the source code for MIPS general handler, we see that it's being defined in this file. Let's open up that file. Inside this file, we see that the MIPS general handler has only one line of real significance which is a jump statement to another function named common exception. Which can be found in the same file. Now common exception as a function contains quite a few lines of assembly. However, most of it can be summarized as follows. First, it saves all the registers into the stack and then it jumps into a function named MIPSTRAP. So let's quickly look at what MIPSTRAP looks like. Now the first thing of importance here is that MIPSTRAP as a function has one function argument or function parameter which is of type struct graph frame. Now the interesting question is how is this being passed to this function? The answer to that lies in how these registers were saved. Reading through the comments here, you will see that the order in which the registers are saved exactly matches the order of contents of the struct graph frame. Let me explain. For example, in struct graph frame, here we see that tfv0 is followed by v1 followed by a0 and a1. Looking at the assembly, we notice that the order is a1, a0, v1, v0. Which is in fact the exact opposite of what we have here. The reason why it is opposite is that stack is always pushed up. Which means while popping a stack, you always read it in reverse. This is how the arguments to the function MIPSTRAP is passed on to it. Now once we reach MIPSTRAP, we see that the code here is trying to identify what type of interrupt it is. For example, if it is an IRQ request, then it handles it as follows. What we are interested in however is if it is a system call which can be found here. So in case it is a system call, it invokes this function named syscall passing the trap frame over to it and proceeds to done. So let's look at what syscall does. The syscall function is defined under Kern arg MIPS syscall syscall.c. And here you can see that depending on the call number which is stored in register v0, there is a switch case statement which has in this case only two values sysreboot and systime. This is where you will be adding all your other system calls as clearly denoted by this comment here. So all your system calls will be living here. In case there is an error, you can see that the error value is loaded into register v0, signal and signaled by through register a3. In case of success, the return value of the system call is loaded into v0 and a3 stores 0 which signals that there is no error.