WEBVTT 1 00:00:02.639 --> 00:00:13.889 William Cheng: Hey, this is the second part of lecture seven. So we just finished talking about procedural context switching and now we're going to see how to do threat switching. Okay. 2 00:00:16.800 --> 00:00:24.300 William Cheng: Alright, so now we're sort of connect what we just talked about can also draw the threat control block. 3 00:00:25.020 --> 00:00:32.670 William Cheng: So normally, you know, the threads there. So the independent media each other. They sort of running parallel, you know, and they can run in different CPU if where multiple CPUs. 4 00:00:33.300 --> 00:00:49.380 William Cheng: So they don't directly interact with each other. Okay. So as it turns out that one of those sort of a common technique that people do that when they implement operating system is that the threat can be made to be aware of each other and they will be able to see the transfer control. 5 00:00:50.400 --> 00:01:00.030 William Cheng: From one site to another. OK. So the idea here is up once there is inside the CPU. So what it will do is that in order for it to give the CPU to another threat. It's going to make a function call. 6 00:01:00.690 --> 00:01:05.910 William Cheng: Okay. So, this function is known as a co routine because it's a function that's used by, you know, 7 00:01:07.410 --> 00:01:11.700 William Cheng: It's used to transfer the CPU from one thread to another threat. 8 00:01:12.270 --> 00:01:20.760 William Cheng: Okay, so they sort of come up with this, this term called co routine. It's a routine. That's kind of used by two threads or that's shared by to threats as we're going to see exactly what this looks like. Yeah. 9 00:01:21.480 --> 00:01:26.340 William Cheng: The picture that we saw before. Over here is that this is what sleeping dress look like if a thread is sleeping. 10 00:01:27.120 --> 00:01:34.200 William Cheng: Very well. That means that that's what it's not executing code, right. So the third control blog and we saw before, in chapter one that inside my control blog. 11 00:01:34.680 --> 00:01:40.200 William Cheng: There's some kind of a context area and you know the contract area save all the registers. 12 00:01:40.680 --> 00:01:46.710 William Cheng: Okay, so one of the register over here, we saw before the three important register yeah i p i, p pointed a tech segment. 13 00:01:47.310 --> 00:01:55.530 William Cheng: ESP points at the top of this target EDP point to the middle of the top stack rank. Right, so, so, so the same content over here. If your thread. 14 00:01:55.950 --> 00:02:02.790 William Cheng: That goes to sleep. We're going to save all the register into the you know the same context area is that instead of three control bar. 15 00:02:03.330 --> 00:02:14.640 William Cheng: Okay, so one of the, you know, one of the register that you have to say what we hear is going to be the stock pointer or the SP pointer over here. So, because it was sort of draw a. So your job is pointer. So they will point to where the current top of the stack is 16 00:02:15.240 --> 00:02:22.800 William Cheng: OK, so for Thursday over here. Here's what it is address space look like. And if this is the top of the stack. So when we put through as asleep. 17 00:02:22.980 --> 00:02:30.060 William Cheng: Then instead of saved contacts data structure, instead of threat control blah, there's a start point here that will point exactly what the current top of stack is 18 00:02:30.600 --> 00:02:40.770 William Cheng: Very similarly, if I be sleeping right here. So we're kind of walk you through it is also sleeping. So that means that all the register are saved. So if this is the current you know if this is the the top of the stack. 19 00:02:41.130 --> 00:02:52.470 William Cheng: Went through I be fall asleep. So therefore insider threat control blah instead of say contacts area. There's a stat pointer over here that will point to exactly when that you know exactly where the stock is when that fell asleep. 20 00:02:53.460 --> 00:03:01.320 William Cheng: Yeah, so, so this is what sleeping so. Okay, what about the third that's running why you know we we saw the code before where you are running 21 00:03:01.770 --> 00:03:08.760 William Cheng: The you know that you will be executing the code inside of a function like the main function itself function do we update the thread control block. 22 00:03:09.660 --> 00:03:15.300 William Cheng: When clearly we don't. Right. So, therefore, if you are thread running out of CPU, then we don't really touch control, blah. 23 00:03:15.930 --> 00:03:23.790 William Cheng: OK, so the 300 why you always keep track of threads, you know, we hear is that easy. It's keeping track of the register for the thread or has fallen asleep. 24 00:03:24.450 --> 00:03:30.870 William Cheng: Okay, if you're a threat is actively running out of CPU then then the threat control blog doesn't track the register inside the CPU. 25 00:03:31.470 --> 00:03:39.870 William Cheng: Okay, because the CPU is really busy is executing code over here is not going to modify the third console log say oh I changed yet. So this guy Chin Ups. It is about you. It doesn't do that at all. 26 00:03:40.590 --> 00:03:50.910 William Cheng: Okay, so for the third that's falling asleep, you know, insider threat control blog in reflect this. The exact state when this fallacy. Yeah. The third that running out of CPU, it's a different story. Yeah. 27 00:03:52.560 --> 00:04:01.080 William Cheng: Alright, so, so what does it says contacts. Right. You know, so, so, you know, all the register over here is the part of those contacts and also the address space. 28 00:04:01.410 --> 00:04:09.030 William Cheng: Inside the address space over here. Currently, the stack pointers pointy here and that's exactly what my threat fell asleep. So, therefore, that is part of the contract work through it. 29 00:04:09.390 --> 00:04:17.220 William Cheng: Okay. So as it turns out, the standpoint over here is going to be sort of the most important part, because we also know that inside the stack rank, we still other register value. 30 00:04:17.880 --> 00:04:29.610 William Cheng: Okay, so some of them is season is so so yeah the the the context of a thread is stored all over the place. The current CPU contacts and stored inside the same contacts over here instead of 300 blog. 31 00:04:30.150 --> 00:04:35.730 William Cheng: But you know the function that call this the last one sheet over here again, lots of information are stored inside a Saturday. 32 00:04:36.720 --> 00:04:45.870 William Cheng: OK. So again, the context of the threat. Some of them are in satisfactory. Some of them are insider threat control blah right when the sweat. You know what was when they were false. Yeah. 33 00:04:47.580 --> 00:04:54.750 William Cheng: So we're gonna we're going to store that means that if that control blog so again for control God's a little tricky because that can be implemented the kernel or implement the user space. 34 00:04:54.930 --> 00:05:04.950 William Cheng: So implementing the user space, then select control blog. It's a user space data structure. It's good to implement. Is that a colonel one in that case. That's right. Good job lines going to be the colonel data structure. Okay, so keep that in mind. Yeah. 35 00:05:05.400 --> 00:05:13.800 William Cheng: All right, to transfer of control on one side to another. It's equivalent to copying the 300 block of the target threat into the current contacts right so 36 00:05:14.460 --> 00:05:27.630 William Cheng: When we look at the simple case where it's where there's only a I should be the only case that we look at. We look at a case where there's only one CPU okay when there's only one CPU, then you can only execute one threat right so we're going to call this threat. The current threat. 37 00:05:28.980 --> 00:05:43.200 William Cheng: That. So, therefore, if you want to, you know, so, so, so, so, so, so, so it will connect catchy is a global variable to represent. Well, you know, what is the current threat. So what we try to execute a threat. Well, in that case, we're going to make that threat the current threat. 38 00:05:44.580 --> 00:05:55.350 William Cheng: Right, so, so, so let's say that you know we're running. So I see three C's going to give up the CP, two, three. So in that case, what, what, in that case what what to do. Well, what do we do that, it will make a the current threat. 39 00:05:56.550 --> 00:06:03.900 William Cheng: Okay, so it's something you said that's all you have to do, right, once you start running, we can actually restore the context and then threat is going to pick up exactly where you 40 00:06:04.920 --> 00:06:08.220 William Cheng: Guys are going to see exactly how this is done. Yeah. Alright. 41 00:06:09.330 --> 00:06:18.030 William Cheng: So the code that we're going to look over here. So, so I guess, in this case a threat is running out of CPU so 30 days right here. I say is running out of CPU over here. 42 00:06:18.240 --> 00:06:23.100 William Cheng: And then we're going to give the CPU to thread be right. So sorry. It's a little different from the previous picture that we had before. 43 00:06:23.490 --> 00:06:33.210 William Cheng: In the previous teacher API both sleeping so now is one instead of CPU right so what it will do is it will call a function called switch to give the CPU to to to be 44 00:06:33.600 --> 00:06:43.470 William Cheng: There. So therefore, in this case, the argument over here is going to be thread be and then over here, even though it's the threat the threat identifiers and this guy was sort of think about it. That's actually the factual block. 45 00:06:43.950 --> 00:06:52.800 William Cheng: In this example, you know, maybe threads are implementing the user space. Okay. So guys, you know, over here, we're just going to assume thread t is actually the threat control bar. Yeah. 46 00:06:53.580 --> 00:07:08.460 William Cheng: Alright, so, so, so, so A is going to cause cause switch to to to to give to to to to to give the the the CPU. This might be now so therapies that control block has the exact contact of be 47 00:07:09.510 --> 00:07:14.310 William Cheng: Fair. Be right before right before fallacy. Right. This is exactly what we talked about before, right. 48 00:07:14.850 --> 00:07:24.840 William Cheng: Over here right before I before I fall asleep while we were saving the entire state, some of the information going to the stack rank. Some of the permissions on a story inside of our control blog. 49 00:07:25.050 --> 00:07:29.670 William Cheng: And now if you're going to restore all this information that then there will be, will be able to run that 50 00:07:31.320 --> 00:07:41.730 William Cheng: All right, so, so, so, so, and also the contact information is through a strict control blog over here is going to be outdated. Okay, so three will be here is running inside of CPU. 51 00:07:42.810 --> 00:07:45.510 William Cheng: So he's not a threat control blah what sees that a third hundred bucks for a 52 00:07:45.990 --> 00:07:51.960 William Cheng: While we mentioned before, what cities that have 300 block, right. So there are a lot of stuff and then the one we know appears that three identifier. 53 00:07:52.140 --> 00:07:58.470 William Cheng: Also, the threat return at six. Oh, I mean clearly thread is still running software is not dead yet. So the return exit code is still valid. 54 00:07:58.770 --> 00:08:05.880 William Cheng: Okay, there's always going to be the contact area over here and the contact area is not update it. So everything inside of contracts area over here will be out 55 00:08:06.900 --> 00:08:15.330 William Cheng: Will be out of date. Okay, so what I do here, I draw a question mark. Oh, here's a, I have no idea what this data structure is is pointing to, right, because it is running out of CPU. 56 00:08:16.410 --> 00:08:25.140 William Cheng: But I know exactly where threat be fell asleep right over here, it says the stock point oh point right here. There's a bunch of stack right right below the exactly as we saw before that. 57 00:08:26.550 --> 00:08:33.300 William Cheng: There's also a global variable called current through. So the current through it right now, since we are running thread inside of CPU current will well what 58 00:08:33.480 --> 00:08:38.910 William Cheng: Is the current that while currency is going to be thread. So, therefore, this is simply a pointer to global variable. Instead, you know, 59 00:08:39.570 --> 00:08:43.650 William Cheng: Instead of 30 implementation that point, who, who is the current thread that's running out of CPU. 60 00:08:43.890 --> 00:08:55.260 William Cheng: Okay, the yellow part over here is the CPU. Right. So what is the CPU point to the IP points of the tech segment ESP point to the top of the stack of the stack rank and the EDP pointed the middle of the box that 61 00:08:55.650 --> 00:09:00.450 William Cheng: pops up. Right. Right, exactly what we talked about in the first part of today's lecture. 62 00:09:02.100 --> 00:09:07.020 William Cheng: Alright, so now we're going to execute the assumption over here. So here is the actual assembly code. 63 00:09:07.530 --> 00:09:15.000 William Cheng: If you look at it, you know, push our GDP, right, so we're not going to go over this code in the assembly call but we're going to go over this call, as if they're sequel. 64 00:09:15.810 --> 00:09:22.830 William Cheng: Okay, because if you look at the secret. The secret is really simple. If I want to give the CPU for threaded throughout be it's only three lines of code. 65 00:09:23.730 --> 00:09:27.660 William Cheng: Okay, so what is that telling you is telling you that these three lines of code must be really tricky. 66 00:09:28.140 --> 00:09:35.010 William Cheng: Okay, so. So, therefore, you know, if you look at the assembly code you're going to notice that this assembly code is a little different from what we saw before. 67 00:09:35.700 --> 00:09:42.690 William Cheng: Okay, when we see the main function and the sub function, you know, the upper the both option they start with enter and then they end with lead 68 00:09:42.810 --> 00:09:52.260 William Cheng: So if you look at this car, very, very carefully, you'll see that at the beginning. Over here is the two lines of code that exactly the same thing as the enter. But the bottom line. The bottom part over here is not leave 69 00:09:53.160 --> 00:09:57.360 William Cheng: Okay, so what does that tell you is telling you that this function is not generated by the compiler. 70 00:09:57.870 --> 00:10:06.120 William Cheng: Okay, this function is actually written by some very clever programmer. Guys, I do, is we're going to go over the secret over here because it's a lot easier to understand. Yeah. 71 00:10:06.960 --> 00:10:11.400 William Cheng: Right so so SRE. Oh, because it's gonna cost which what is there a cost to switch 72 00:10:12.180 --> 00:10:20.370 William Cheng: Okay, because Ray wants to give up the CPU. Why does he wants to give out the CPU. Well, maybe, for example, I said I copied me time slot and the meat, which is not available. 73 00:10:20.880 --> 00:10:32.640 William Cheng: Right. So in thread a, you know, three copies me taxonomy has no not available. What Is there supposed to do, right. So again, inside the Citadel scenario, we don't have one CPU is a new text is not available, you have to go to sleep. 74 00:10:33.150 --> 00:10:40.170 William Cheng: Okay. So, therefore, what it will do is that it will add itself to the new tax queue. And then what do we do that, it will cost switch to give up the CPU. 75 00:10:41.040 --> 00:10:52.410 William Cheng: Okay. So this guy is what do we do that, it will look at to see which thread is eligible around and find our thread be over here is our job right so what it would do that. It will call this function and the argument will be happy to give the CPU to be 76 00:10:53.670 --> 00:10:57.510 William Cheng: Alright, so, so, so what are the other reason that thread I can give up CPU. 77 00:10:58.170 --> 00:11:06.240 William Cheng: You know, maybe other function copy that condition where or something like that. Right. Well, maybe to make the system called something like that. So there are many reasons, it will give up the CPU. 78 00:11:06.540 --> 00:11:17.160 William Cheng: Okay, so when you give up when it's ready to give up the CPU, it will cost which we can also you can call function like sleep right you sleep when you go, usually we don't give up the CPU. So again, you will call this function. Yeah. 79 00:11:18.570 --> 00:11:23.100 William Cheng: Alright, so, so I guess the reason is that important. So over here, it was sort of draw the function right so so 80 00:11:23.310 --> 00:11:30.390 William Cheng: If you look at the stock space inside thread thread A. Here's a snack space over here. We start out with the startup function is gonna call man gonna go, whatever. 81 00:11:30.570 --> 00:11:37.290 William Cheng: And eventually it's going to copy them the tax law we tax is not available. And now what it will do is it will cost switch. That's why when you call switch 82 00:11:37.530 --> 00:11:42.540 William Cheng: While we saw the code before we're going to build a stack frame for switch right and then we're gonna start calling this function. 83 00:11:43.110 --> 00:11:50.130 William Cheng: Okay. So, therefore, you know, we are ready to enter switch we build a stack on top of it. So that will look like this. 84 00:11:51.000 --> 00:11:56.280 William Cheng: Guy's ESP point to the top of the stack rank EDP pointed the middle of the top stack frame. 85 00:11:56.610 --> 00:12:04.260 William Cheng: Right, so again ABP point right here. The linguist link all the stock brings together. And now we're ready to execute sequel, even though we know this is my sequel. 86 00:12:04.560 --> 00:12:17.910 William Cheng: But now we're in a scene function. So, therefore, you know, we're ready to execute the code in the middle. We know that yes people at the top of the stack brand new order Sacra linked together. The EDP point to the you know the point where it's supposed to point you in the top separate 87 00:12:19.290 --> 00:12:24.330 William Cheng: Alright, so now we're going to execute the code in the middle, in the middle of your again three lines of code that are very simple. 88 00:12:24.570 --> 00:12:33.330 William Cheng: The first line of code says current threat right arrow SP, right. Correct. There's a point to the point of the standard structure right SP is going to be this SPP right here. 89 00:12:33.750 --> 00:12:46.320 William Cheng: Okay. So sp stance was a stock pointer. I mean, yes, P is the register name for Intel CPU. So over here on the coast. So I'm going to copy the the SP register inside the CPU and a store the images memory location over here. 90 00:12:47.310 --> 00:12:55.680 William Cheng: That's okay, I'm saving the contacts or other than, you know, for, for the current where I'm going to save it inside the inside the state of structure is that right 91 00:12:56.940 --> 00:13:04.500 William Cheng: Now, guys. So again, what you will do is that you will go to your current SP sp. So, so what's current SP SP is over his point right here. 92 00:13:04.770 --> 00:13:10.170 William Cheng: Now, so basically you're going to copy that the value of ESP, and then copy into this memory location. 93 00:13:10.650 --> 00:13:16.170 William Cheng: OK. So again, well you copy point to the end are pointing at the same place. So when you finish doing that. What's going to look like. Right. 94 00:13:16.500 --> 00:13:24.720 William Cheng: At the SP pointer inside instead of say contacts area instead of flight control Rachael Ray is going to point to the same place at the top of the stack. 95 00:13:26.040 --> 00:13:33.510 William Cheng: Okay, so, so this thing structure when it finished executing will look like this, right, the SP pointer over here now point to the same place as ESP 96 00:13:34.740 --> 00:13:39.270 William Cheng: Then we're done. My very simple instruction. Right. Yeah. So next instruction over here. 97 00:13:39.660 --> 00:13:49.770 William Cheng: Can I be even simpler occurrence, where it goes next to our next word is this guy over here. So we're going to remove this pointer right here and then point to the Fremantle blah after I beat 98 00:13:50.250 --> 00:13:55.950 William Cheng: Okay, so they will look like this. Nice. Okay. Very simple instruction right next instructional video is also very important. 99 00:13:56.430 --> 00:14:00.960 William Cheng: Very simple sp, which is the SP instead of CPU is going to equal to current 100 00:14:01.260 --> 00:14:10.500 William Cheng: Sp current clients right here sp. Is this the spirit over here. So what we're gonna do. We're going to copy this value into the ESP register inside of CPU. 101 00:14:10.680 --> 00:14:17.250 William Cheng: So again, when you copy pointer overhearing going to end up pointing to the same place. So once I do this ESP over here so so so 102 00:14:17.730 --> 00:14:25.650 William Cheng: Okay, this picture is very important. Right. Yes. P used to point right here for now. I remember what it was pointing to, bye bye bye copy that value into threat as 103 00:14:25.770 --> 00:14:32.910 William Cheng: A control blog over here. So now I can remove this pointer. Right, so I can remove this pointer over here and then point to where this guy is pointing right here. 104 00:14:34.110 --> 00:14:38.340 William Cheng: Okay. So the third instructions over here also very, very simple. So first, which is actually pretty simple. 105 00:14:39.780 --> 00:14:46.350 William Cheng: So when I finish over here either will look like this. And there's a USP over your point to the same place as you know the 106 00:14:47.070 --> 00:14:58.500 William Cheng: The same context of where the stack pointers pointing to. And now here's a surprise right when I applied the pointer right here, I will see that for thread be the top stock plan is also switch. Why is that 107 00:14:59.520 --> 00:15:05.460 William Cheng: Well, because when thread be fallacy of how this might be fall asleep. He also call the switch function to give up the CPU. 108 00:15:06.240 --> 00:15:15.780 William Cheng: Well, that's the basic guy over here is that once you have this function, then you can call to give up the CPU every threat when they need to give out the CPU, they will all call the switch function. 109 00:15:16.290 --> 00:15:21.480 William Cheng: Okay, so they have a window. What a third fall asleep while the top stock room over here has to be the switch back right 110 00:15:21.900 --> 00:15:27.870 William Cheng: Now, so as soon as I do that ESP point over here. I know is that, you know, the top staffing over here you switch 111 00:15:28.800 --> 00:15:37.500 William Cheng: And then. So this guy is also. So what about UDP well. So over here, the picture look really weird right end up spending right here right it's pointing to the fact that, you know, 112 00:15:38.040 --> 00:15:49.290 William Cheng: It's pointing to the stack insert a USP is pointing to the top of the stack in thread be current site over years, pointy into his point of therapy. So who was executing this call right now. 113 00:15:51.360 --> 00:16:02.940 William Cheng: I mean, you know, so in the beginning of a cost which right. Okay, I'm sorry, is it giving called one article to Article article and now I'm confused because I don't know when I'm executing code for three or four be 114 00:16:04.620 --> 00:16:08.850 William Cheng: Okay, so, so, so, so over here who is executing that Israel so Abby. 115 00:16:10.140 --> 00:16:15.480 William Cheng: I mean, there's really no no no. Correct. Yes, sir. Okay. Right. So, so the question over here is that doesn't really matter. 116 00:16:16.560 --> 00:16:23.700 William Cheng: Then why do you have to know when is it when it's cold therapy sessions. You mean, clearly, I see a calling this function over here. So, 117 00:16:24.150 --> 00:16:36.120 William Cheng: Continue the CPU. But what about that be, is that what it was I be doing okay so be is in the middle of waking up right when you start waking up at someone's not that actually didn't call what is so happy. Excellent. In this code already 118 00:16:37.470 --> 00:16:48.600 William Cheng: Guys good current third point of therapy or so of course revenue is running. But I came into this function. That's right. So when I give the CPU to be I'm no idea. I know when this happens over here says it doesn't really matter. 119 00:16:49.620 --> 00:16:56.100 William Cheng: Okay, what about the IP well over here for both this function, they're executing in the middle of the switch function. 120 00:16:57.390 --> 00:17:12.570 William Cheng: Okay, so yeah. P is plenty of the right place for both A and B. Okay. So over here, the revenue over here you can interpret them as the threat AZ IP okay interpret them as Mr P z IP. It's very difficult to argue exactly which one you know which perspective is 100% correct 121 00:17:13.980 --> 00:17:18.840 William Cheng: Okay. As it turns out, maybe doesn't matter. Okay, because this is how fast, which you work. 122 00:17:20.760 --> 00:17:25.470 William Cheng: Guys is low, we're, you know, so, so if we continue to execute code, what's going to happen right so now 123 00:17:26.130 --> 00:17:29.490 William Cheng: It looks like this over here the next instruction over here is going to is going to be returned 124 00:17:29.730 --> 00:17:36.930 William Cheng: While we saw what return is going to do right so return over here. Again, I'm going to pop the stock frame over here. I'm going to return back to the previous you know that stepping over here. 125 00:17:37.200 --> 00:17:44.820 William Cheng: When we return back to the previous diagram over here. We're going to restore the MVP pointer. At some point, even if he's gonna sell point to the next great 126 00:17:45.510 --> 00:17:49.110 William Cheng: Okay, so one thing that we know for sure is that when you return from this function. 127 00:17:49.740 --> 00:17:58.470 William Cheng: Okay EDP will start pointing to the saffron, right, because we know that once this is done and we finished executed the returning structure because of the first part of the of the today's lecture. 128 00:17:58.740 --> 00:18:08.160 William Cheng: We know that it will look like this. Right. Yes. He's going to point to the top of suffering over here HTTPS colon point in the middle. Let's start from over here and all the staff friends over here and linked together in linguists 129 00:18:09.180 --> 00:18:13.560 William Cheng: That. So therefore, we know that when we finished returning false of the switch function. 130 00:18:13.770 --> 00:18:23.340 William Cheng: We know that we're going to completely instead be assured, not what we're here right current state appointed sweat be over here. Yes, P point to the top of the stack over here for. So I'd be and we don't know what this function. So, 131 00:18:23.580 --> 00:18:32.730 William Cheng: This function could be you sleep. This function could be a piece of new timeslot this function could be peaceful condition where whatever those functions are whatever thread be decided to to give out the CPU. 132 00:18:33.000 --> 00:18:45.150 William Cheng: You know the one of the function that the way it was executing that a VP of our punter the starkest pops like rain or the Cybermen linked together. So we know that when you're done with switch you you you actually, you turn that you tend to be 133 00:18:46.080 --> 00:18:56.310 William Cheng: Okay, but we're not sure exactly, you know, when stress switching happen. And my argument over here is that maybe it's not that important to know exactly where this happened okay it's okay to not to know 134 00:18:57.030 --> 00:19:03.450 William Cheng: Okay, so as long as you know that somewhere in the middle here something funny happened. As it turns out, switching. It's kind of funny. Yeah. 135 00:19:05.850 --> 00:19:20.130 William Cheng: Oh, so you know so. So if the third one third one over here, our user space data structure right these are user space data structure, then what is current that are currently is going to be alive as the cursor over here is going to be a global variable inside your address space. 136 00:19:21.210 --> 00:19:26.100 William Cheng: Okay, so we can actually switch on one side to another without going to the operating system. 137 00:19:27.030 --> 00:19:33.600 William Cheng: Okay, so this function over here. So again, if threats are completely implemented user space the switch function is not a system call 138 00:19:33.990 --> 00:19:38.790 William Cheng: Okay, because you can give the CPU from one side to the other by staying completely in user space. 139 00:19:39.720 --> 00:19:45.450 William Cheng: Okay. So yeah, this is really where you don't need the operating system. How to do. So switching. As it turns out, that's actually true that 140 00:19:45.690 --> 00:20:00.030 William Cheng: Also, does not over here. Sp field insider threat control blog be over here, no longer truck ESPN inside the CPU. We're going to see that inside my control back over here the SP feel inside the same complex area. What is the point to it points to garbage. 141 00:20:01.440 --> 00:20:09.420 William Cheng: Okay, so this is where we started with that error. I thought I would put a question mark over here. Where was that we have no other words, pointing to it might be pointing to garbage. And now we can see exactly how 142 00:20:09.810 --> 00:20:17.670 William Cheng: How, how, how should I be this particular point of your point of garbage, right, because now you know the therapies running out of CPU. The top of the stack of he's gonna go crazy because 143 00:20:17.850 --> 00:20:27.510 William Cheng: It will make function call will return a call function to return or something like that. So, therefore, we know for sure is that instead it's a control volume. So I'd be over here, all these pointers over here, they might be outdated. 144 00:20:27.930 --> 00:20:34.200 William Cheng: Okay. They might just happen to be pointing in the right place, but also they might they might need a totally coverage that 145 00:20:34.950 --> 00:20:36.750 William Cheng: All right, very important to understand this. Okay. 146 00:20:37.530 --> 00:20:46.410 William Cheng: All right, so this is a real we have function rather typically all the function that you have seen and see what pumps you that you have ever written. Right. You know, the third that cause the function as a student, I returned 147 00:20:46.950 --> 00:20:54.450 William Cheng: Okay. So in this case, it looks. We're happy to swear a call this function over here who is watching the return or threat be actually returned from this function. 148 00:20:55.620 --> 00:21:10.500 William Cheng: Okay, so, so, so, is that really what happens. Okay, so, so, you know, again, we were I was stepping on this call with solar winds inside. Inside of running set to CPU when this function return. Sure enough, he's running out of CPU. 149 00:21:11.340 --> 00:21:18.510 William Cheng: Okay, so one question you can ask to say, well, who's prospective business who is looking at this, this, I also is running out of CPU therapy is running. 150 00:21:18.780 --> 00:21:20.580 William Cheng: Later on therapy is running out of CPU. 151 00:21:20.880 --> 00:21:28.770 William Cheng: That the answer. Over here is that if you look at this from the systems perspective. So what does the system by system could be the operating system could be the pizza library. 152 00:21:28.980 --> 00:21:34.530 William Cheng: Could be, you know, the user is looking at the machine to say oh right now. So it is running out of CPU. Oh right now therapy is running out of CPU. 153 00:21:35.160 --> 00:21:44.970 William Cheng: Okay, so from the outside perspective we switched from A to B. Okay, but what about if you asked for a Robin Wright phase one, I call the function. He said, Well, 154 00:21:46.200 --> 00:21:57.750 William Cheng: I mean, you put a microphone in front of thread and say, tell us what happened, I guess, various and say, you know, I was running out of CPU I call I call the switch function and then I fell asleep. I have no happen after I fell asleep. 155 00:21:58.830 --> 00:22:03.330 William Cheng: That if he asked to be to say, Well, what happened over here in the middle of the 156 00:22:04.050 --> 00:22:15.210 William Cheng: Of the switch function well said. He says, you know, I remember a long time ago I cost switch for some reason right and I fall asleep. I have no idea how long have I been sleeping, and then at some point I start running. I woke up in the function switch 157 00:22:17.310 --> 00:22:23.400 William Cheng: Okay, so, so, so again, these are different perspective right for the systems first perspective you switch on 32 three be the from 158 00:22:23.640 --> 00:22:39.030 William Cheng: His perspective is simply fall asleep, then it doesn't know habit. Right, so he knows that long time ago, you know, many, many, many, many months ago, it fell asleep, and then when he wakes up, he saw running out of CPU and then he will return on fest which okay what did you ask the CPU either 159 00:22:40.800 --> 00:22:49.620 William Cheng: Okay, so here's the CEO says. It says, I did what I switch a thread. No, no, no I didn't. I CAN PROMISE YOU I did not switch a threat. By the way, what's the threat. 160 00:22:50.670 --> 00:22:54.360 William Cheng: That the CPU doesn't know that there's such thing called a threat. 161 00:22:55.530 --> 00:23:03.780 William Cheng: Okay, so, so the CPS is I'm just minding my own business. I actually three instruction, you know, the data structures, you know, I'm going to copy the ESP point to into a data structure. 162 00:23:03.960 --> 00:23:14.370 William Cheng: I changed the global variable and then I copy a data structure of the memorable dish, what you're putting out of CPU register and I continue to execute code. I promise you, I did not. I did not switch any threats. 163 00:23:15.990 --> 00:23:24.840 William Cheng: Okay, so what is really going on over here, so get over here is that is just an abstraction CPU doesn't know about threats. Right. So if you look at the the Intel, you know, 164 00:23:25.200 --> 00:23:39.210 William Cheng: You're 36 manual right is the x86 CPUs over here, one of the old manual going to look at in colonel in the colonel assignment. It's called the Intel a 386 manual in three to six manual. There's no such thing called thread inside the entire manual 165 00:23:40.380 --> 00:23:51.990 William Cheng: That CPU is just hardware. It doesn't know about threats okay model Intel CPU, right, you probably heard about you. If you try to buy, buy, buy, buy into CPU. There's three there's IFI there's I seven 166 00:23:52.320 --> 00:24:03.060 William Cheng: By seven there's hyper threading. So actually I seven they know about threats. Okay, but what about three I never heard of you asked I three is this. I have no idea what it says. 167 00:24:03.660 --> 00:24:12.330 William Cheng: Okay, the more modern the modern CPU, they saw us. So if we focus on Sixth Edition Unix. I mean, clearly at that point CPU has no idea what a threat is because thread. 168 00:24:12.540 --> 00:24:19.080 William Cheng: Is just an abstraction. So now we're sort of know the meaning of what what does it mean to be a thread as and I trust you because CPU doesn't know about threats. 169 00:24:19.350 --> 00:24:24.900 William Cheng: OK. So, again, from all these perspective, from a system perspective, the, oh, there are threats Australia. There's Wetherby 170 00:24:25.080 --> 00:24:34.140 William Cheng: If you astray 30 says, Yeah, I'm a thread, you know, I was running out of CPU I fall asleep. If you're so happy to say, Yeah, you know, you know, I fell asleep and later I got woken up in the middle of a switch function. 171 00:24:35.160 --> 00:24:41.970 William Cheng: Okay, so sort of seems like they are you know they're alive. They're aware of these kinds of stuff. But in reality, the CPU. There's no that's 172 00:24:42.990 --> 00:24:48.420 William Cheng: Not right. So, so get this is very important concept to understand that a threat is just an abstraction. Yeah. 173 00:24:49.230 --> 00:24:56.940 William Cheng: Alright, so I hope you agree that this is an elegant way to switch, switch threads. So, therefore, you know, also, as will come here to switch to another threat. 174 00:24:57.900 --> 00:25:04.080 William Cheng: Right anytime you want to give up the CPU right you find not a threat and you give that the threat of CPU. So the assumption that 175 00:25:04.590 --> 00:25:12.810 William Cheng: This curve is incomplete. Right. What if next thread over here is no okay if you are a single threaded process, you only have one thread. How do you give up the CPU. 176 00:25:13.170 --> 00:25:20.460 William Cheng: So this guy's next right over here is no. So if you say, you know, no over here, right arrow sp, you can get a segmentation volume profile get killed. 177 00:25:21.060 --> 00:25:26.250 William Cheng: Right. So clearly this code is he completed so they don't in chapter four. We're going to address this issue that and also 178 00:25:26.610 --> 00:25:36.330 William Cheng: In this example, we will only show you how to save that the the stock pointer. What about all the other register all the other he has to be safe, right. Why do all the other register have to be saved. 179 00:25:36.720 --> 00:25:47.040 William Cheng: Right, because you are giving up the CPU. Not all the other thread, they will complete mess up the CPU. So next time when you run if you don't save the register, while the next level you are you going to end up with GARBAGE GARBAGE CP registered 180 00:25:47.910 --> 00:25:55.860 William Cheng: Okay, so therefore we only show you how to say the stock pointer, but you should sort of think about is that we, we also need to save all the other register values now. 181 00:25:56.640 --> 00:26:08.430 William Cheng: Right. So then we're going to revisit revisit that in chapter five, we talk about what is the real way to implement threats. Right. So right now we just give the introduction to give you a flavor of why we say threat is just an abstraction. Yeah. 182 00:26:09.720 --> 00:26:18.210 William Cheng: So this is southwest region. So again, you know, if you look at the assembly call this is enter, but the bottom over here is not leave because it's cold, it's handwritten 183 00:26:18.600 --> 00:26:21.660 William Cheng: So somebody actually have to rewrite this function in assembly code. 184 00:26:22.200 --> 00:26:29.250 William Cheng: There so. So again, you know, you know, in order for everything to work. You know, sometimes you have to write assembly code. Okay. We can't just write everything and sequel. 185 00:26:29.790 --> 00:26:42.750 William Cheng: Then right so just if you want to implement atomic operation. How did it really implement Hamid operation right that's still a mystery. We talked about the contest concept of atomic operation, but in chapter five will sort of show you exactly how these things implemented that. 186 00:26:45.270 --> 00:26:54.750 William Cheng: Spark of a different kind of switch function, you shouldn't be surprising because their CPU architecture is completely different. Right. Okay, so, so, so, so we're done with us a threat switching 187 00:26:58.590 --> 00:27:03.180 William Cheng: So the next thing we're going to look at is system caller ID. And what does the system called the user threat become a colonel. 188 00:27:03.870 --> 00:27:11.940 William Cheng: The Colonel is going to do something. Is that a kernel and when it's done is going to return back into the user space, right. So how does a context switching happen from a user threat to Colonel threat. 189 00:27:13.950 --> 00:27:21.990 William Cheng: Alright, so, so a system called right involved the transfer of control from the user koto koto koto koto as far as this class is concerned. 190 00:27:22.860 --> 00:27:27.900 William Cheng: Okay, so again, there are different events architecture, you know, the more modern architecture over here. 191 00:27:28.350 --> 00:27:38.610 William Cheng: So the way we sort of think about is that the user threat become a colonel threat is still the same threat is still belong to the same process. So in this case, there's no threat switching because it's still exactly the same threat. 192 00:27:39.120 --> 00:27:43.020 William Cheng: Okay, so it's not like you're a threat. A over here. You come inside the Colonel, you become a threat. He 193 00:27:43.230 --> 00:27:49.080 William Cheng: They are still exactly the same threat right there is simply a context switch you switch from a user three contacts to a current 194 00:27:49.290 --> 00:28:00.300 William Cheng: Contacts, you still have your still the same through as okay what does that means that you are the same threat. Now if you look up the flight control block the Colonel's and the user. So I had exactly the same as our control block because the same threat. 195 00:28:02.130 --> 00:28:05.820 William Cheng: Okay, so. So again, that's very important to understand over here. Well, you know, in this class. 196 00:28:06.090 --> 00:28:12.480 William Cheng: You know, most of the time when we talk about system call you are still the same throughout your user to simply change personality. And so the Colonel. 197 00:28:12.660 --> 00:28:23.010 William Cheng: And now when it goes out of Colonel, you can do all kinds of stuff, right, because now it again privilege when it goes that occur at all. And now he can, you know, can you tell us hardware, he can, you know, go to the bus to all kinds of crazy stuff. Yeah. 198 00:28:23.670 --> 00:28:30.090 William Cheng: Right, so, so, so, so it depends on the implementation. So again, you know, there are modern operating system over here. 199 00:28:30.450 --> 00:28:37.260 William Cheng: You know so so but but but we're going to sort of stick to the sixth edition abstracting over here, we can simply view this as a status change. 200 00:28:37.650 --> 00:28:49.890 William Cheng: You know, we would go from the user user mode into the privilege right sort of getting them over here settings that a CPU. So there's so he's got a CPU, there's going to be a switch that we're going to flip that you are in user mode over here and now he comes out of Colonel and now 201 00:28:51.570 --> 00:28:53.640 William Cheng: Now, now you're in the privilege that 202 00:28:54.570 --> 00:29:02.700 William Cheng: All right. And once the inside of the privilege small you have all kinds of problems you can execute operating system Co. You can go to the bus. You can talk to the hardware or this kind of stuff there. 203 00:29:03.060 --> 00:29:10.140 William Cheng: Alright, so you reality is a little more complicated, right, so we're gonna sort of talk about what's actually involved over here where you go from the, the user to our contacts. 204 00:29:10.470 --> 00:29:16.500 William Cheng: To the kernel for context. Right. And then when you're done with whatever you're doing, is that a current. Oh, you know, talk to the devices all the kind of stuff. 205 00:29:16.680 --> 00:29:25.410 William Cheng: And then you need to go back into the user space. Okay. It's only a status change your kernel threat and there you go through some weird stuff and then eventually you become users, right. Okay. 206 00:29:27.090 --> 00:29:30.690 William Cheng: All right, so most system. I will provide everything 207 00:29:31.290 --> 00:29:39.900 William Cheng: We don't have one threat, but this will have two stacks. Okay. One, we are one in the user space, right. So, so what does that. What does that look like 208 00:29:40.170 --> 00:29:49.590 William Cheng: What we already see that stack. Right. That is the stack. That's the inside the address space guys remember inside the address space every thread has your own stack space. 209 00:29:50.160 --> 00:30:04.560 William Cheng: Okay, so therefore every thread has a user stack space. So, yeah. Yeah, every cell has a user space right so that's why in the user space. And we also saw the picture when companies are the colonel colonel every third also has a stack. 210 00:30:05.820 --> 00:30:11.520 William Cheng: Okay, so why do you know what, why do we actually provide two stacks and one of the user space and wanting the current. What can we just use one of that. 211 00:30:11.910 --> 00:30:17.490 William Cheng: Right, you're going to use one of them. Which one, which one do you have to use. Well, you can use away inside the Colonel, because when you are 212 00:30:17.730 --> 00:30:30.240 William Cheng: We running the user space, you know, therefore, you can't really touch anything that Colonel. So if we only have one stack, then that will be the one that user space. Okay. And then when you make a system called coming out of Colonel, should the colonel user user space back 213 00:30:31.380 --> 00:30:35.070 William Cheng: Well, the answer is no, because the colonel doesn't trust the user space program. 214 00:30:35.550 --> 00:30:42.090 William Cheng: Right, we mentioned before, the colonel needs to be isolated from the user space program. So if you come into the kernel you continue to use the user space. 215 00:30:42.540 --> 00:30:51.120 William Cheng: What are the user space that has no space left. Well, so in this case he's out of control. If you make a function call, you're going to end up with a stack overflow and you're going to crash the Colonel. 216 00:30:52.050 --> 00:31:00.840 William Cheng: Okay, so therefore that's not allowed. So therefore, when you come into the corner. We have to switch to the colonel stack. Okay. Because the colonel doesn't trust the user space for that. 217 00:31:02.520 --> 00:31:09.810 William Cheng: Alright, so when I saw this picture over here. Again, which are horizontal line over here on top is the user space on top button inside is the Colonel. 218 00:31:09.960 --> 00:31:15.840 William Cheng: will only have one side over here. The threat is actually Nicole right here with the red arrow. The arrow signifies ESP 219 00:31:16.050 --> 00:31:22.290 William Cheng: We're going to have a user start over here. I'm going to have a colonel stack. So when you're running in the user space. The Colonel stack clearly is empty. 220 00:31:23.280 --> 00:31:31.260 William Cheng: Okay, so, so if you're actually encoding the user space forward, right. So again, main going to call some function and it's going to call Prague, or something like that. And then the, you know, 221 00:31:31.770 --> 00:31:36.270 William Cheng: Continue to make function call all this time the colonel start over here is completely empty. 222 00:31:37.230 --> 00:31:45.450 William Cheng: Then alright so. So in this example, are the, you know, our plans going to call the racism call right. So how do you call the racism calls. Okay, we saw that already in the first part of 223 00:31:45.750 --> 00:31:51.930 William Cheng: You know lecture seven. We're going to build a stack frame over here. And then we're going to start executing code right here. So it's never like this. 224 00:31:52.770 --> 00:32:04.710 William Cheng: Now, so again, right, is a system called cynicism part is is a thin wrapper around a track machine suction nice over here. We're going to set off of the trouble of the year. We're going to involve the truck. When we invoke the trap what happens 225 00:32:05.280 --> 00:32:08.700 William Cheng: Okay, something funny is going to happen right because we're hoping is that 226 00:32:09.120 --> 00:32:10.980 William Cheng: Later on we're going to start executing started Colonel 227 00:32:11.250 --> 00:32:19.440 William Cheng: Okay, so we're going to sort of talk about how you actually get there, but the eventual goal over here is that when you start, you know, making a trump system call you're going to come again for Intel 228 00:32:19.710 --> 00:32:34.740 William Cheng: The trap machine structure is basically implemented a software interrupt right for entirely constructed this end is zero, x to you mentioned before, over here, it's a software guy. So therefore, when we come inside the Colonel. We're going to be executed kind of an interrupt service routine. 229 00:32:35.910 --> 00:32:47.070 William Cheng: That. So at some point over here. We're going to start executing the interrupt handler right here that we're going to sort of start executing this call, almost as if we are basically a current visit was executing the CO as a colonel threat. 230 00:32:48.750 --> 00:32:54.150 William Cheng: Right, so, so we start executing a time machine instruction and boom, we're inside the current. Oh, we're gonna do something funny. 231 00:32:54.660 --> 00:33:06.360 William Cheng: Okay. Eventually the goat over here is to start executing sequel inside the kernel that so what we're gonna do is we're going to write the interrupt handler over here inside a colonel using the override this function as a see function. 232 00:33:07.500 --> 00:33:18.810 William Cheng: That. So this case, we need to find out what kind of environment. It is it a hallway, you know, Roberts is a software interrupt. Oh, in this example over here. This one is direct to you over here. So, therefore, in this case it's going to be a system call 233 00:33:19.470 --> 00:33:29.280 William Cheng: Okay, because the software interrupt over here, there's gonna be a system called. So in this case, we're going to check if the internal code over here, equal to system, a system called which is zero, x to be here right because mentioned before, the right to it. 234 00:33:29.460 --> 00:33:37.920 William Cheng: It's a troubleshooting structure or making a system call. So therefore, we're going to call another function which is also written in C and this one is called a simple handler, which is right here. 235 00:33:38.250 --> 00:33:48.000 William Cheng: Okay, so in this case we're going to, we're going to handle the truck call because in this guy's going to have 256 different system Hall. I go from zero to into 123 all the way to zero FF 236 00:33:48.510 --> 00:33:57.300 William Cheng: There is a devil, we're going to take the trump card over here and try to find out which system call it is because we need to find out, well, you know, which functioning to the user. One of the colonel to to help you with 237 00:33:57.720 --> 00:34:06.120 William Cheng: Oh, as it turns out that the you know the user program want want want want to perform the right system call. So in this case, a truck code over here will be equal to the code for the racism call 238 00:34:06.330 --> 00:34:12.090 William Cheng: Right. So again, one out of 256 choices over here. And then finally, you're going to call the right hand of the right, what is the right hander. 239 00:34:12.540 --> 00:34:18.990 William Cheng: Right. So again, Chapter while I call this the kernel version of the right so I call the K RY as on this side over here. They call it the right handler. 240 00:34:19.980 --> 00:34:31.680 William Cheng: That. So again, how they're all these things supposed to do, right. So once you're inside the corner over here. You're making function call the function call you make over here I exactly the same as you know the function call, you're making the user space. 241 00:34:32.040 --> 00:34:35.250 William Cheng: Why is that well because the kernel is also written see 242 00:34:35.970 --> 00:34:45.000 William Cheng: Okay, so therefore the function to call the function that the issue is that a kernel. They are just like regular see function right when you start working your Kronos I mean going to be very, very disappointed. 243 00:34:45.690 --> 00:34:50.550 William Cheng: Okay, you're gonna look at the kernel code to say well this looks just like the user space school and you will be 100% correct 244 00:34:51.090 --> 00:34:57.330 William Cheng: Right. So, therefore, you know, it's over here. We're gonna start actually going to try out machine, starting at some point we're going to start executing the interrupt handler. 245 00:34:57.450 --> 00:35:03.510 William Cheng: So what would that look like right so we start executing code right here we're going to build a stack rank will interrupt handler. So they won't look like this. 246 00:35:03.870 --> 00:35:15.930 William Cheng: Okay. Yes. Sorry, I will look like this ESP is going to fit right here, HTTP is going to part right here. Okay. And he is, he's gonna part right here. So this code over here is inside the Colonel's the Colonel's tech stack, man. 247 00:35:16.680 --> 00:35:28.650 William Cheng: You guys are there. The only differences over here is that he IP over here, point to the kernel stacks admin ESP pointed the colonel staff and the EDP over here pointed the middle of the middle of the top Colonel stack rank. 248 00:35:29.940 --> 00:35:40.500 William Cheng: OK. So again, the idea of here is exactly the same. But now you're just pointing to a different portion of the address space. Okay. So, this you know this this data structure of this data structure or do they belong to the same address space. 249 00:35:40.950 --> 00:35:45.450 William Cheng: Well, yeah, because there are still the same process, there's still the same thread so therefore they belong to the same address space, right. 250 00:35:45.690 --> 00:35:57.870 William Cheng: We mentioned before, the Colorado space, you know, start at 00000000 so this that space over here is is between this number and you know Xerox F, F, F, F, F, F, F. 251 00:35:58.890 --> 00:36:04.200 William Cheng: Okay, that's all there is. But otherwise, they look exactly the same there and I'm start executing this code over here. And then I'm going to make 252 00:36:04.980 --> 00:36:12.180 William Cheng: A call the system call. Hello. Yeah, yeah, I'm going to build a stack rank for, and then exactly what we saw before the beginning of lecture seven and that's going to happen. 253 00:36:12.450 --> 00:36:19.830 William Cheng: And we're going to, you know, say I'm staggered over here. Yes, piece of the pie right here up piece right here. Yeah, he's gonna part right here. And then we're going to call the right hand that are going to 254 00:36:20.910 --> 00:36:28.050 William Cheng: build another step for a transfer control to the right function over here. Yes, P point here ABP point here and now we're in the middle right hand over here. 255 00:36:28.770 --> 00:36:34.470 William Cheng: So what does right handler do or the right hander is going to, you know, you make a racism called you going to write some data, you know, 256 00:36:34.710 --> 00:36:41.460 William Cheng: You're going to write some data into a device, right. So whatever it is that we need to find out what is the data that you want, right to the device what device you want to 257 00:36:41.820 --> 00:36:51.090 William Cheng: Talk to you. And then we would use it, it will communicate the device over the bus and then, you know, and then tell the device to go ahead and write that data into the device and now you're Colonel, so I will fall asleep. 258 00:36:51.360 --> 00:36:54.270 William Cheng: Waiting for the inner I'll come. I'll completion interrupt. 259 00:36:55.230 --> 00:36:59.280 William Cheng: Okay, so when the I O completion interrupt hopping over here are Colonel says going to get woken up 260 00:36:59.460 --> 00:37:08.970 William Cheng: When they will call it says to the outer the iOS device operation is done. So therefore, the right is completed, unless you try to write a lot of data that you have to write write write write write 261 00:37:09.300 --> 00:37:19.590 William Cheng: Write to the device. Many, many time. Eventually, everything is going to be written to the desk written to the internet written whatever the device you want written to the screen when you finish doing that what you do, you're going to return from right 262 00:37:20.640 --> 00:37:30.210 William Cheng: Okay, so how do you return from right you do exactly the same way as the beginning of lecture seven again. Right. You know, just like subs going to return to me over here. Again he already started. Colonel you do exactly the same thing. 263 00:37:30.480 --> 00:37:35.280 William Cheng: Okay. So, therefore I'm going to return on the right system called Beyond I'm gonna go back to the phones, you know, we here. So in this case, 264 00:37:35.430 --> 00:37:40.410 William Cheng: I'm going to execute the next line of code right after the right handlers are some of those like this tip is gonna right here. 265 00:37:40.650 --> 00:37:47.190 William Cheng: I'm going to return from the right hand, though. I'm going to pop up the stack frame over here. I'm going to, you know, go back to what it was before. I'm going to return right here. 266 00:37:47.940 --> 00:37:55.230 William Cheng: And then finally going to be tough on interrupt handler. So whenever we drove on the phone. Hello again, I'm going to pop the stack. Right. But where does it go to 267 00:37:56.370 --> 00:38:04.710 William Cheng: Okay. I mean, clearly there's something else below this okay and something magical is going to happen. And then eventually, boom, you got it back into the user space. 268 00:38:05.340 --> 00:38:11.040 William Cheng: Right. So we're going to talk about the magic. Pretty soon. Right. But now we're going to talk about all the other stuff that that we already know what will happen. 269 00:38:11.820 --> 00:38:15.270 William Cheng: Is that you know there's something at the bottom over here that will take you back into the user space. 270 00:38:15.450 --> 00:38:23.640 William Cheng: When you go back to the user space, or in this case, you know, you will be right here right after the machine Saracen right so they will look like this. And now the colonel stack is completely empty. 271 00:38:24.780 --> 00:38:29.010 William Cheng: Because again, if we started out like this. And now going to end up exactly the same thing like this. And now we return for the 272 00:38:29.190 --> 00:38:35.910 William Cheng: Machines rushing over here. We're going to set up the return value for right over here. And then we're going to return right here. So we're going to pop off the stuff that the right stock for him. 273 00:38:36.180 --> 00:38:43.230 William Cheng: I'm going to go back over here ESP point right here at the bottom here, I'm going to continue to execute the data see home inside our program. 274 00:38:45.420 --> 00:38:56.610 William Cheng: Alright, so, so, so everything else over here we're talking about here is exactly the same thing as we covering the beginning chapter seven. So now we need to talk about what actually happened. You're starting from the machines judging how do you get into the handler. 275 00:38:57.690 --> 00:38:59.310 William Cheng: That. So that's what I'm talking about next. 276 00:38:59.670 --> 00:39:09.660 William Cheng: Okay, so that that will be the trigger over here to switch from a user through our contacts to external threat attack around when we start executing call we, here we are basically executing, you know, as the colonel flat. 277 00:39:10.200 --> 00:39:20.850 William Cheng: Now when I say the closer we know where we will, we know what does the next function call. Now, right. So we just not clear how do you actually get there. Yeah, right. So we're gonna take a look at that. 278 00:39:22.170 --> 00:39:30.990 William Cheng: Okay, so here's the detail of the machine Chechen right there's multiple step over here. So, so the first thing that happened when you're talking to the colonel we execute the 279 00:39:31.800 --> 00:39:36.510 William Cheng: Track the other machine code over here is that we got the Submariner up 280 00:39:37.380 --> 00:39:43.860 William Cheng: Okay and and also we're going to soon as we do that with us. We're gonna say the process a process or mode to be the privilege mode. 281 00:39:44.400 --> 00:39:49.980 William Cheng: Right. As soon as you execute the traumas. She is Josh and boom, you're inside the current already. Okay, so that means that you're in the privilege. 282 00:39:50.340 --> 00:40:02.820 William Cheng: So we're here without a set to CPU multitude of privilege and also we need to disable the internet. Why do we need to disable interrupt that because now we're going to use the data structure inside of Colonel that's shared by all the interrupt service routine. 283 00:40:04.440 --> 00:40:14.250 William Cheng: Okay. And also, we just coming out of Curt overview, you know, traveling instructor and tribe, we saw before. It's in zero x to eat. So it's a software interrupt so definitely this is, again, we are executing interrupt service routine. 284 00:40:14.610 --> 00:40:24.210 William Cheng: Right now over here for the software interrupt so definitely this case we're using a shirt data structure inside of Colonel that's share among all the interrupt service routine. So they have all we have to disable you know 285 00:40:24.390 --> 00:40:27.180 William Cheng: Because if you know it goes off, or they can compete with the same data. 286 00:40:28.050 --> 00:40:36.480 William Cheng: Guys are therefore these two separate very important. You have to disable rainbow up and then you need to, you know, set to CPU most privilege, because now we need to execute kernel code. 287 00:40:36.780 --> 00:40:42.420 William Cheng: Okay, in the clinical you're actually going over here. It's actually interrupt service routine co write the service teams for the software interrupt now. 288 00:40:43.230 --> 00:40:55.950 William Cheng: Right over here. The next thing over here says the hardware abstraction layer is going to save, save IP and SP into the temporary location over here. So we're going to say the user space contest into a temporary location in the kernel space. 289 00:40:56.940 --> 00:41:00.510 William Cheng: Okay, so this is the shared data source of that talk about for all the interrupt service routine. 290 00:41:00.810 --> 00:41:07.080 William Cheng: Okay, so, so whatever they were doing instead of CPU over here in order for us to come inside the current Otter. Excellent job so today. 291 00:41:07.290 --> 00:41:15.000 William Cheng: The first thing we have to do is to say the CPU contacts and we're going to save it into this temporary location in the kernel space that's shared by all the interrupt service routine. 292 00:41:16.620 --> 00:41:21.030 William Cheng: Okay, so, so, but the, what is the hardware abstraction layer. And so, as it turns out, you know, 293 00:41:21.990 --> 00:41:35.760 William Cheng: What we want over here is that, you know, we saw the user space as a couple over here. And then we have the kernel. And then we have a hardware at the bottom over here. Okay. As it turns out, what we want to do is that we want to be able to write our kernel code in a CPU independent way. 294 00:41:37.230 --> 00:41:43.740 William Cheng: Okay. Wouldn't it be nice if our kernels CPU independent right so this one will we need to go to a different CPU. We don't have to change the kernel code. 295 00:41:44.130 --> 00:41:57.330 William Cheng: Okay, so this is what do we have to do, right, we need to introduce another layer right on top of the hardware over here and this one is called the hardware abstraction layer it abstract away all the hardware features. So this way, our Colonel can be independent of the CPU. 296 00:41:59.250 --> 00:42:00.960 William Cheng: Okay, so we call it the whole abstraction layer. 297 00:42:01.500 --> 00:42:10.800 William Cheng: Sounds like a cop out. It sounds like you know you just don't want to do this in the opportunities that. But again, if you do this in operating system. Every time you need to change to a different CPU, you have to, you have to change your operating system. 298 00:42:11.580 --> 00:42:16.980 William Cheng: Okay, so it would be nice if our current all of our operating system again sixth edition units. The current on the iOS seven, same thing. 299 00:42:17.460 --> 00:42:25.230 William Cheng: Okay, so we want our colonel and opportunities and to be CPU independent that right so we come with this thing called a holler professionally over here. 300 00:42:25.680 --> 00:42:31.560 William Cheng: So in this case, we're going to say, you know, IP sp. What does actually save all the CP register. I think that's because you know we're in the user space. 301 00:42:31.740 --> 00:42:42.780 William Cheng: We need to save all the CP legend over here into the temporary location of us that have kernel space right again. We typically would point out the important register right yeah IP yes PvP all these kind of register over here because they are more important now. 302 00:42:43.620 --> 00:42:50.310 William Cheng: We're going to talk about how abstraction layer because the whole abstraction layer by definition is hardware dependent 303 00:42:51.600 --> 00:43:02.760 William Cheng: Okay, different CPU needs to have a different hardware abstraction layer, so therefore it's outside the scope of this class, right. So if you want to know about the horror abstraction layer. What class do you have to take you have to take a web class. 304 00:43:03.210 --> 00:43:11.790 William Cheng: Okay, so he they they're the one they implemented CPU is and therefore they can talk about, you know what, what does it look like. Okay. So as far as we're concerned, you know, 305 00:43:12.240 --> 00:43:14.940 William Cheng: You know, below the colonel between the current a horror abstraction layer. 306 00:43:15.390 --> 00:43:24.570 William Cheng: This like between the code on the hardware, there's going to be a horror stretching layer. So our Colonel can be hard. We're independent. So, most of the time to sort of focus on the kernel, which is the hardware independent part 307 00:43:24.870 --> 00:43:32.670 William Cheng: Okay, but once in a while. I mean, like what we talked about ESP up, are we are we being highly dependent. But of course, because we're talking about the Intel CPU. 308 00:43:33.390 --> 00:43:42.420 William Cheng: Okay, so that's why the typos textbook will talk about the Intel CPU and also talk about the spark CPU. So this one we're going to see that, you know, some parties are the colonel is actually CPU independent 309 00:43:42.750 --> 00:43:47.100 William Cheng: Okay, but some part of our has to be CPU dependent. For example, the switch code. 310 00:43:48.030 --> 00:43:53.550 William Cheng: Okay, can we switch copy CPU independent. Well, no, it's not possible because we're saving CPU register over here. 311 00:43:53.790 --> 00:44:03.480 William Cheng: So in that case, yeah, maybe what we can do that instead of switched over here. We're going to make a function call. So that function will be will be a hardware abstraction layer function that was saved all the CP register into a data structure. 312 00:44:04.080 --> 00:44:15.150 William Cheng: Okay, so again, maybe that's what we'll do. We'll, you know, we'll have the operating system or the piece or a library to be independent of the CPU and we're going to make a hardware abstraction layer call to save all the CP registered inside of data structure. 313 00:44:16.320 --> 00:44:24.060 William Cheng: Right. So again, we're not gonna, we're not going to talk too much about the horror stretching layer. It just had the operating system will use that to to to to talk to the real hardware. Yeah. 314 00:44:25.710 --> 00:44:30.600 William Cheng: So, so what is the job of the whole abstraction layer over here so so so once you say, well, this information is not a hollow 315 00:44:32.070 --> 00:44:40.500 William Cheng: The hollow abstraction layer is going to be the one that was switch us to the colonel threat contacts and there's, how would it do that. Okay, so first of all he needs to find the colonel stack. 316 00:44:41.910 --> 00:44:50.130 William Cheng: Okay, so how do you find the colonel stack. Right. Well, actually, it's pretty simple, right, because we have a global variable know as Quran threat right so if your thread I implement. Is that a colonel. We hear 317 00:44:50.370 --> 00:44:58.680 William Cheng: The current there is going to be a colonel data structure. So he's not a carnal so that you will know where the current, the current status. OK. So in this case, what you would do. 318 00:45:00.030 --> 00:45:11.700 William Cheng: Is that you can you can find the colonel stack. And then the next thing that you will do is that all the information that you save over here about the user threat contacts you will save it at the bottom where the colonel stack. 319 00:45:12.210 --> 00:45:21.060 William Cheng: Okay, we saw the but the coolest over here before, right, the coast. I go over here is completely empty. So what we're going to do that we're going to save the user threat contest at the bottom of the Colonel. The Colonel sat 320 00:45:21.420 --> 00:45:25.440 William Cheng: There and we're gonna actually sort of barrier. So nobody else can actually see it. 321 00:45:26.760 --> 00:45:36.930 William Cheng: Okay, so as far as, you know, our current affairs is concerned over here, you know, they're actually using the bottom of the colonel stack, but actually right underneath them. We actually we have buried treasure. 322 00:45:37.470 --> 00:45:45.120 William Cheng: At the bottom of the Colonel, sir. Okay. And in this case, what we will have is that you know all the same registry that we say from the user space program, we're gonna 323 00:45:45.840 --> 00:45:47.940 William Cheng: We're gonna actually buried at the bottom with kernels that 324 00:45:48.900 --> 00:45:54.990 William Cheng: Yeah, so we hear, you know, so, so, so, so the hall over here is going to set the IP to point to the colonel stack over here. 325 00:45:55.230 --> 00:46:02.820 William Cheng: Designated to be the corresponding user threat over here and then it will save all the stuff that we mentioned before, we here to save it into the bottom across that right 326 00:46:03.030 --> 00:46:08.700 William Cheng: It will copy the user IP and sp from the temporary location and push them onto the colonel stack. 327 00:46:09.150 --> 00:46:13.500 William Cheng: Okay, once they finish doing that now they are ready to become a colonel threat. 328 00:46:13.800 --> 00:46:22.290 William Cheng: Okay. So, therefore, what it will do is that in order to become a colonel over here, you need to re enable interrupt because now you're ready. You're going to be running inside a thread contacts. 329 00:46:22.590 --> 00:46:32.310 William Cheng: Okay. And also we can re enable interrupt because now we finished using all this data structure there are shared by all the interrupt service routine right because would copy them out and we push them under the colonel sec 330 00:46:32.730 --> 00:46:45.480 William Cheng: Okay, so now the temporary location over here, we're ready to handle another you know up. Okay. So, therefore, at this point, we're going to re enable you know up there. And now, what happened is the RD will start executing code inside interrupt handler, as we just saw before. 331 00:46:47.340 --> 00:46:56.970 William Cheng: Go. So over here are the steps that we saw before. Over here 1231234 over here. That's how you go from the machine instruction to the beginning of the interrupt handler. So you start actually when 332 00:46:57.330 --> 00:47:02.160 William Cheng: You grow up while we're in the lab is enable and we're actually using the code as external threat. 333 00:47:04.620 --> 00:47:09.960 William Cheng: Now, right, so, so, so, you know, so we again you can sort of think about exactly when do you switch to a kernel for that. 334 00:47:10.890 --> 00:47:19.800 William Cheng: Okay, um, it's not really clear I you come to you. You're a user threat. You come inside the current all going to the interrupt to go into the inner contacts over here because you're actually interrupt service routine car. 335 00:47:20.250 --> 00:47:22.770 William Cheng: Once you enable you to have up here. Boom, you're a colonel threat. 336 00:47:23.700 --> 00:47:31.890 William Cheng: OK. So again, there's something magical happen and it's maybe it's really important to pinpoint exactly what you become a colonel threat. Are you a colonel three right before you enable you know 337 00:47:32.640 --> 00:47:38.550 William Cheng: Well, I don't know. Okay. Yeah, because you know once you point your start pointing into the kernel stack or maybe at this point, you're a colonel threat. 338 00:47:39.480 --> 00:47:46.500 William Cheng: Okay, so okay exactly when this happened is really not important. And because what you need to understand over here is that we're experiencing over here is context switching 339 00:47:46.680 --> 00:47:55.680 William Cheng: And context switching is a kind of a funny thing in the middle, you know, you might not know exactly whether you are users or your parents or your three years where be and this is what happened during context switching 340 00:47:56.940 --> 00:48:02.730 William Cheng: Now alright so now. So now again we're going to do everything that we talked about before, and we're gonna, you know, 341 00:48:03.270 --> 00:48:09.300 William Cheng: Eventually, go to the kernel version of the right IoT device can authorize them to go to sleep. And eventually I will complete you're 342 00:48:09.720 --> 00:48:16.440 William Cheng: Going to wake up the colonel through I'M GOING TO RETURN RETURN RETURN. And then eventually, when we return from the interrupt handler over here. And then how do we return back in the user space. 343 00:48:17.250 --> 00:48:20.760 William Cheng: There. So in that case, we're basically going to go exactly the reverse direction. 344 00:48:21.540 --> 00:48:27.540 William Cheng: Okay, so on return from the trap handler over here, we need to go exactly the opposite direction. So, therefore, again, 345 00:48:27.900 --> 00:48:34.560 William Cheng: That we've got the club at this over here. The first thing. Oh, yeah. The last thing that you do was re enable interrupt so now you need to do reverse, you have to disable interrupt. 346 00:48:34.800 --> 00:48:41.850 William Cheng: Right. So again, why do I need you to say, well, you know, because I need to use this data structure that are shared by all the interrupt service routine. So therefore, I need to disable you know 347 00:48:42.240 --> 00:48:44.400 William Cheng: So that nobody can interfere. What, what I'm doing over here. 348 00:48:44.760 --> 00:48:53.760 William Cheng: That. So when I decided, you know, and now I need to go back over here. The last thing that we did before was to hide all the will to bury all the Treasure under the the colonel stack. 349 00:48:53.970 --> 00:48:59.610 William Cheng: And now we need to put all the thing at the bottom of the Colonel's that and then copy that back into these the temporary location. 350 00:49:00.450 --> 00:49:05.970 William Cheng: Okay. And then in that case. And then we need to continue to go up over here. Once we copy all that thing. 351 00:49:06.630 --> 00:49:12.330 William Cheng: Into the temporary location over here. And now we need to do the reverse of the track machine instruction. 352 00:49:13.290 --> 00:49:19.530 William Cheng: Get on the Intel CPU. There's one machine instruction that's very, very powerful that would do the last step over here on one shot. 353 00:49:20.040 --> 00:49:26.010 William Cheng: Okay, it's okay. That's the opposite of in zero x to eat, and that one is called the I return on x86 354 00:49:26.310 --> 00:49:30.630 William Cheng: Okay, I returned stands for return from interrupt or I return, return from, you know, I interrupt return 355 00:49:30.900 --> 00:49:37.770 William Cheng: Okay, it's one machine instruction. So once you set everything up. So again, this particular instruction is in the hardware abstraction layer right 356 00:49:38.250 --> 00:49:45.090 William Cheng: Okay, because the CPU independent is that this this instruction CPU dependent. If you're you're running the spark CPU, they have a different structure. 357 00:49:45.660 --> 00:49:56.520 William Cheng: That. So for the entire you know instruction over here. This is part of the whole abstraction layer. So again, we come inside you know will come out of Colonel by going through the horror attraction there now. When we return, we need to go in the reverse direction. 358 00:49:57.120 --> 00:50:01.230 William Cheng: That. So we're going to go to this one instruction over here. And this is a very powerful instruction. 359 00:50:01.410 --> 00:50:13.020 William Cheng: what he would do is that it will take everything inside the template location over here, put it back inside the CPU change the CPU mo to the user Mo and then we will enable interrupt all in one atomic operation. 360 00:50:14.400 --> 00:50:21.390 William Cheng: Okay, so I turned over here. It does a lot of thought put a lot of stuff back inside of CPU over here. And then he would change the CPU multi user mode. 361 00:50:21.600 --> 00:50:27.000 William Cheng: And then he when they wake up and then you will go back and then in that case you will return from the tribe and used to execute and call right here. 362 00:50:29.340 --> 00:50:34.740 William Cheng: Okay, so, so, so, so again, this is what happens when you go in the reverse direction. 363 00:50:35.250 --> 00:50:44.160 William Cheng: There's a little comment over here the similar sequence that to happen in hardware, you know, this is a software vendor. Ah, what about how interrupt me Holly no upsell flying around, they all come to the same place. 364 00:50:45.360 --> 00:50:52.590 William Cheng: Okay, so yeah well you get a hallway interact with and disable you around. And then you're going to go, you know, the change CPU mode to the privilege Mo, you're going to go to the house, especially here. 365 00:50:52.770 --> 00:50:57.390 William Cheng: So I guess Sephora hiring rub, they all come to the same place right because over here you see the call. We are the, you know, 366 00:50:58.260 --> 00:51:01.260 William Cheng: This you know handler handle both software interrupt interrupt. 367 00:51:02.190 --> 00:51:10.260 William Cheng: Okay, this in zero x to it, it goes to the system call handler. If there's a whole you know I was gonna go somewhere else. So, therefore, this is the common entry point for all interrupts 368 00:51:10.740 --> 00:51:16.560 William Cheng: Okay, so therefore right before there's, you know, our panel over here. Where, where, where are you, you're in the hardware abstraction layer that 369 00:51:18.150 --> 00:51:25.140 William Cheng: Alright, so then context switching. So get your peak oil you Robin is over here is that when you make that system, but when you actually the machine structure. 370 00:51:25.380 --> 00:51:31.830 William Cheng: Right before you do that, right, the, the, the user step look like this. And the colonel stuck over here is completely empty. 371 00:51:32.820 --> 00:51:38.370 William Cheng: Okay, and then evolving this out where you are. When it comes out of Colonel where you're ready to execute the colonel threat call 372 00:51:38.550 --> 00:51:49.170 William Cheng: What is the current cycle guy right so now the user. So the user side of us is going to get suspended and also all the users right contact is going to be stored at the bottom. The Colonel staff. 373 00:51:49.710 --> 00:51:54.180 William Cheng: Okay, so therefore you will look like this guy here, you know, to the car and start over here is 374 00:51:54.600 --> 00:52:02.070 William Cheng: Go to a different look over here at the bottom of the colonel start we're going to store the user threat contracts, again, have you know basically what ESP wanting to 375 00:52:02.520 --> 00:52:06.990 William Cheng: Be peaceful. I don't know all the CPU radio show up here, they all going to be set at the bottom of the colonel stack. 376 00:52:07.200 --> 00:52:15.810 William Cheng: And then start building stack for me is that a kernel. And then again, when you go to the right system called the top of the stack as well go crazy as the colonel threat make function costs. 377 00:52:17.370 --> 00:52:21.780 William Cheng: Alright, so again, this is what happened during a system called right and then and then in the end, will you return from 378 00:52:21.930 --> 00:52:32.670 William Cheng: The Colonel stack up here will be empty, you take all this information over here. You're going to restore that back inside of CPU and you're going to go back to exactly where we were before, and now the Colonel's a stock will become empty, empty. Yeah. 379 00:52:35.220 --> 00:52:42.870 William Cheng: So again, you know, the system was kind of funny right because something happened in the middle of the system called over here, right. We started out to the users that contacts and you 380 00:52:43.200 --> 00:52:51.240 William Cheng: Actually go to try out machine instruction in order for us to get into the kernel threat contest. Where do we go through, we actually, we go through the internal contacts. 381 00:52:52.140 --> 00:52:58.320 William Cheng: Okay. Because over here where he's not interrupt service routine. So in order for you to go from the user threat contacts to the colonel contacts. 382 00:52:58.530 --> 00:53:01.890 William Cheng: We have to do something funny in the middle, by going through the internal contacts. 383 00:53:02.130 --> 00:53:13.980 William Cheng: Okay. Similarly, when you go from the colonel three contacts into the user account is what do you have to go through. You're going to reverse direction, you still go into your contacts and this guy's again you are going to be executing hardware abstraction layer code that 384 00:53:16.200 --> 00:53:25.680 William Cheng: Alright, so sort of a summary slide for some of the context switching over. Yes. Okay. We haven't talked about the interrupt our contracts with chain right but we talked about the function or the procedure context switching 385 00:53:26.250 --> 00:53:34.800 William Cheng: The first switching also the system call kind of switching that. So again, what we need to pay attention to. Over here is that, how do you save the context. And where do you save it. 386 00:53:35.580 --> 00:53:44.790 William Cheng: Okay, well, you may proceed. Your call you save it inside the stock frame. You know what you switch on one side to the other. You save some of the stuff inside of soccer and you say some other stuff inside the third hundred block. 387 00:53:45.330 --> 00:53:50.820 William Cheng: When you go from the user threat to the Colonel, you actually, you say stop by hiding them at the bottom of the colonel staff. 388 00:53:51.510 --> 00:53:59.280 William Cheng: Writer as, as I mentioned before, you know, context switching. You know, it's complicated because you you save your contacts all over the place. 389 00:53:59.670 --> 00:54:07.080 William Cheng: Okay, so, so again we see, you know, the things I say in three different places. Already we three when we saw three different kind of context switching that 390 00:54:07.890 --> 00:54:12.120 William Cheng: And also, you know, when we tried to save all these contacts will try to save as little as possible. Right. 391 00:54:12.420 --> 00:54:18.660 William Cheng: Well, when you make the function or when you make the function call. We want to save as few register as possible because we want to be as fast as possible. 392 00:54:19.110 --> 00:54:29.310 William Cheng: Okay. Will you switch from, you know, one side to the other, you know, the picture that we saw say oh maybe all you have to do to save the standpoint or of course, in reality, also have to save the other CPU registered 393 00:54:29.730 --> 00:54:38.010 William Cheng: Okay, well, you go from the users the space of the Colonel. Again, we need to copy stuff more than wise, we need to copy the CPU state into temporary location. 394 00:54:38.220 --> 00:54:42.630 William Cheng: And then we copy need a copy of again because we don't we don't want to use that they've started inside the cardinal 395 00:54:42.990 --> 00:54:52.590 William Cheng: Because other interrupt service routine will have to use the same data structure. So, therefore, again, we need to find a place for it and then push them into the kernel stack Enoch is going to take much longer than the than the other context switching 396 00:54:54.690 --> 00:55:01.650 William Cheng: And also the says, Okay, you know, so, so for every kind of context switching. We're going to sort of try to try to save as few things as possible. 397 00:55:01.860 --> 00:55:08.370 William Cheng: Do we have to save the entire address space. Well, we don't have to save the entire address ways we're going to assume that the address space is going to be exactly the way it was. 398 00:55:08.580 --> 00:55:18.060 William Cheng: When we finish our system call will we go from one function to another or we switch on one side to the other guy. So it's a job, the operating system to also maintain that the rest of the contacts. 399 00:55:18.810 --> 00:55:23.070 William Cheng: Okay, we also mentioned about the extended address space, right. So we do stress switching when we 400 00:55:23.340 --> 00:55:28.260 William Cheng: Make system call, we don't really, you know, I guess, I guess we don't really touch the he said the address space. 401 00:55:28.500 --> 00:55:34.710 William Cheng: Unless we're executing the colonel flicker. Well, in that case, we're going to explicitly manipulate the extended extended address space. 402 00:55:34.950 --> 00:55:45.390 William Cheng: So yeah, we don't know what that could look like. And they don't get to see more of the implementation is that a colonel. What do you have to do exactly to to to to to to to implement the extended address space. 403 00:55:47.130 --> 00:55:57.810 William Cheng: And also in general is very, very difficult to make a clean context switch right we saw before, will you, will you make a procedure context switching function A his main function is going to cause up 404 00:55:58.410 --> 00:56:03.600 William Cheng: Okay, so there will be places, you know, that, that, you know, so again, when we think about, you know, 405 00:56:04.110 --> 00:56:12.330 William Cheng: Making a function call, we're thinking about making a see function call. Right. So you're in the sea function may you're going to call the sea function, you know, self in the middle of 406 00:56:12.720 --> 00:56:18.120 William Cheng: The out that the software is half built right so therefore, in that case, we're really not sure whether we're, you know, we're 407 00:56:20.640 --> 00:56:22.830 William Cheng: So, so, so, so like I since the stock or if 408 00:56:23.220 --> 00:56:34.020 William Cheng: It's not bill. We are sort of neither in 13 in the function may or in the fund himself right because in order for us to be in the function man over here. The requirement is that ESP so points to the top of the stack for 409 00:56:34.500 --> 00:56:43.170 William Cheng: The SAS base and all the sacraments, the link together in order for us to be completely inside the function itself again yes be so point to the top of the stack and it takes time to build the stack rank. 410 00:56:43.860 --> 00:56:51.690 William Cheng: Okay, so definitely in the middle of the context switching you know something sort of funny happened there. And we can also see that you know we switch on one side to the other. 411 00:56:52.260 --> 00:56:57.150 William Cheng: Okay, it is possible that you're sorting in the context of two threads, but you don't really know which one. Which one are you belong to 412 00:56:58.080 --> 00:56:59.460 William Cheng: Okay, and also finally we see 413 00:56:59.820 --> 00:57:08.190 William Cheng: Making a system call you all, you know, in order for you to switch from one context to another call back, you have to go through and you have to actually go through another contract that you know contacts. 414 00:57:08.430 --> 00:57:13.350 William Cheng: Right. So when you're going through the, you know, contacts, clearly you are neither in the users that kind of ties into kind of like our next 415 00:57:14.490 --> 00:57:23.040 William Cheng: Alright, so again context switching is funny because some of these things are just abstractions. So now we sort of see a little more detail of how these things are getting implemented now. 416 00:57:23.340 --> 00:57:37.980 William Cheng: Alright, so I'm going to stop right now. And the third part our lecture seven. We're going to look at how to handle interrupt context switching and also we're going to talk a little bit about, you know, how, how do you actually deal with IoT devices. Yeah.