 In this screencast, we look at how sys161 boots your kernel. The program OS161GCC uses a custom linker script while linking the kernel together. This script can be found under Kern, Arc, MIPS, Conf, LD Script. However, instead of jumping straight to answers, we would be walking you through how we acquired this information. This will also teach you a few tricks on how to search through the OS161 code base. To really trace back how the kernel boots, we have to do a little bit of in-cuter backtracking. We know that at some point, the menu that you see here is displayed to us. We start with this small string for menu, which the kernel seems to print at some point. Let's find out which function actually prints this. So what we are trying to do here is we look for the string for menu through the kernel code base, searching through all files recursively. As you can see here, KREP returns this one file, KernIncludePron.h, and it also tells us there are two binary files that match this. Let's get rid of these binary results by adding the flag capital I. So now let's look at KernIncludePron.h, which has this string. As you can see here, the string is being defined as a macro with the name of kernel prompt. Given that this file does not give us any further information, let's look at what piece of code uses this macro. From the results, we see that kernel prompt is being used in Kern main menu.c. Let's open up this file. We search for kernel prompt to jump to the place where this macro is actually appearing in code, and we see here that kernel prompt is actually being printed out. But given that our goal is to trace how the kernel boots, what we really need to focus on is the function which calls this Kprintf. In this case, it's the function named menu. So now we need to look for what function calls menu. Let's try and do this. So searching for menu gives us quite a few results. Some of these are false positives, because some of these we don't care about, basically because they are not the function that we are looking for. However, we see that the function we are looking for is actually here. It's being called in Kern main main.c. As we can see, menu is being called within a function named K main. So let's try looking for K main. Interestingly, there seems to be no place where K main is being involved. Now, this is probably because of the string that I'm searching for, which includes this packet. So let's try and get rid of that and see where K main is being involved. So it looks like K main is being involved from a piece of assembly here, which is Kern Arc sys161 main start.s. So let's try and open up that file. So as before, we search for the string K main, which takes us immediately to the line where it's being called. And we see that this piece of assembly, which is probably very early on due to input, given that it's trying to call into the first C function we have, is appearing in this file under this label. So let me try and walk you through what some of these mean. So this line signals that the symbol underscore underscore start should be global, which basically means that it should be visible to the linker. This line signifies that the symbol start is of type function and this signals the entry point into this symbol start. This line here is just a label as normal labels are in C. And we see that the start function begins by setting up a stack frame. This stack frame is being used for the kernel. And here we see that there is some ask yard about how the memory is laid out in sys161 and it goes about moving. If you read through the comments, you will find that it goes about trying to copy the boot argument string so that it can set it up so that when K main boots, it can get the kernel arguments. And finally, once all this is done, we jump to K main. So what calls start? That's the next question. So let's try and grab for start as we've grabbed for other strings. Up until now we see that there are some results from user land, which we will ignore because we are focusing on how the kernel boots up. So we focus on these results. And in these results, we have seen through all of these except this one line, which is the LD script itself. So let's quickly open up the LD script. And here in the comments, we clearly see that this script basically tells sys161 GCC how to actually start the kernel. And the first line in here is entry start. So this sets up the entry point to the kernel to be this function or symbol name start.