1 00:00:00,000 --> 00:00:01,725 Glad to be here everybody 2 00:00:01,725 --> 00:00:04,350 and have a chance 3 00:00:04,350 --> 00:00:06,405 to share this work I've been doing. 4 00:00:06,405 --> 00:00:09,210 So I've created this crate I 5 00:00:09,210 --> 00:00:10,695 call the pluggable interrupt 6 00:00:10,695 --> 00:00:12,120 operating system. 7 00:00:12,120 --> 00:00:13,650 Here are the goals I had 8 00:00:13,650 --> 00:00:15,060 in creating this great. 9 00:00:15,060 --> 00:00:17,340 I've been teaching operating systems and 10 00:00:17,340 --> 00:00:19,830 rust for four semesters now. 11 00:00:19,830 --> 00:00:22,680 The most recent time I ran it, 12 00:00:22,680 --> 00:00:24,000 I really wanted to get students 13 00:00:24,000 --> 00:00:25,575 reading bare metal rusts. 14 00:00:25,575 --> 00:00:27,705 And this is how I went about it. 15 00:00:27,705 --> 00:00:30,510 So my goals were to enable 16 00:00:30,510 --> 00:00:31,980 students to read a 100% pure 17 00:00:31,980 --> 00:00:33,645 rust bare metal code. 18 00:00:33,645 --> 00:00:35,775 There's no rust experienced 19 00:00:35,775 --> 00:00:37,590 prior to the OS course. 20 00:00:37,590 --> 00:00:39,600 Now, earlier in the course, 21 00:00:39,600 --> 00:00:42,025 before we use this utility, 22 00:00:42,025 --> 00:00:44,060 I have students implement a bunch of 23 00:00:44,060 --> 00:00:45,230 Unix utilities 24 00:00:45,230 --> 00:00:46,400 in order to start learning or us. 25 00:00:46,400 --> 00:00:50,255 So Ls are MCP and so forth. 26 00:00:50,255 --> 00:00:52,924 Then I have them write a Unix shell 27 00:00:52,924 --> 00:00:54,664 and a web server. 28 00:00:54,664 --> 00:00:56,045 The web server, the 29 00:00:56,045 --> 00:00:57,740 main goal there is to really get 30 00:00:57,740 --> 00:00:58,760 them understanding 31 00:00:58,760 --> 00:01:01,775 concurrency as well as possible. 32 00:01:01,775 --> 00:01:04,670 Then what I wanted to do was for 33 00:01:04,670 --> 00:01:06,320 the bare metal part encapsulate 34 00:01:06,320 --> 00:01:08,015 code from the blog, 35 00:01:08,015 --> 00:01:09,710 writing and OS and rust, 36 00:01:09,710 --> 00:01:12,185 which is an absolutely phenomenal resource. 37 00:01:12,185 --> 00:01:14,660 I had a goal of no unsafe blocks 38 00:01:14,660 --> 00:01:15,905 and my student code, 39 00:01:15,905 --> 00:01:17,990 and I want it straightforward abstractions 40 00:01:17,990 --> 00:01:19,190 for setup for 41 00:01:19,190 --> 00:01:20,930 the VGA buffer or 42 00:01:20,930 --> 00:01:23,270 interrupts and background code. 43 00:01:23,270 --> 00:01:26,090 So here's our curricular contexts. 44 00:01:26,090 --> 00:01:28,835 I teach at a small liberal arts college. 45 00:01:28,835 --> 00:01:30,950 We have a limited number of courses 46 00:01:30,950 --> 00:01:33,740 we can require for a major about 11 or 12. 47 00:01:33,740 --> 00:01:36,530 So where our is structured 48 00:01:36,530 --> 00:01:37,970 all CS majors and minors 49 00:01:37,970 --> 00:01:39,890 take a two semester sequence. 50 00:01:39,890 --> 00:01:42,605 Foundations of computer science in Python, 51 00:01:42,605 --> 00:01:46,220 data structures in Java setup so that all of 52 00:01:46,220 --> 00:01:47,390 our upper level courses 53 00:01:47,390 --> 00:01:48,920 students are eligible to take once 54 00:01:48,920 --> 00:01:52,040 they've completed the data structures class. 55 00:01:52,040 --> 00:01:53,720 So like I mentioned, 56 00:01:53,720 --> 00:01:56,885 I've taught OS using Rust four times so far. 57 00:01:56,885 --> 00:01:58,280 I develop this crate and 58 00:01:58,280 --> 00:01:59,720 the most recent incarnation, 59 00:01:59,720 --> 00:02:01,040 I'm going to teach it again 60 00:02:01,040 --> 00:02:02,885 in spring of 2022. 61 00:02:02,885 --> 00:02:05,000 Super excited about it. 62 00:02:05,000 --> 00:02:07,549 He background ideas. 63 00:02:07,549 --> 00:02:10,310 So what do I mean by bare-metal programming? 64 00:02:10,310 --> 00:02:11,750 No running code beyond 65 00:02:11,750 --> 00:02:13,115 what the student writes. 66 00:02:13,115 --> 00:02:17,270 No OS services provided, but no hesitation. 67 00:02:17,270 --> 00:02:18,845 Provide library falls, 68 00:02:18,845 --> 00:02:20,990 lots of libraries and so forth. 69 00:02:20,990 --> 00:02:22,250 But the full code 70 00:02:22,250 --> 00:02:23,660 that's running is fundamentally either 71 00:02:23,660 --> 00:02:25,730 what the student wrote or the student 72 00:02:25,730 --> 00:02:29,975 called running this on the X86 architecture. 73 00:02:29,975 --> 00:02:31,640 That's in part of course because writing 74 00:02:31,640 --> 00:02:33,770 an OS and rust is targeted to that. 75 00:02:33,770 --> 00:02:37,445 It's also easily emulated using a chemo. 76 00:02:37,445 --> 00:02:40,985 For output, we use the VGA buffer, 77 00:02:40,985 --> 00:02:43,205 which on the X86 is 78 00:02:43,205 --> 00:02:45,905 memory-mapped in a character-based way, 79 00:02:45,905 --> 00:02:47,525 which is really handy because 80 00:02:47,525 --> 00:02:48,890 the fonts are just available 81 00:02:48,890 --> 00:02:50,285 straightaway in hardware. 82 00:02:50,285 --> 00:02:54,080 And it really saves a lot of effort. 83 00:02:54,080 --> 00:02:55,970 And then finally, interrupt, 84 00:02:55,970 --> 00:02:57,860 interrupts or code blocks 85 00:02:57,860 --> 00:03:00,065 triggered by specific hardware events. 86 00:03:00,065 --> 00:03:01,700 The two types of interrupts that 87 00:03:01,700 --> 00:03:03,320 I'm focusing on in this work, 88 00:03:03,320 --> 00:03:07,170 our timer interrupts and keyboard interrupts. 89 00:03:07,240 --> 00:03:10,985 My views on unsafe relative to this work, 90 00:03:10,985 --> 00:03:12,710 unsafe as essential for 91 00:03:12,710 --> 00:03:14,255 interacting with hardware. 92 00:03:14,255 --> 00:03:17,330 If you're going to be invoking a low level 93 00:03:17,330 --> 00:03:19,010 machine instructions and doing 94 00:03:19,010 --> 00:03:22,385 direct memory access is you're using unsafe. 95 00:03:22,385 --> 00:03:23,990 There's no getting around it. 96 00:03:23,990 --> 00:03:25,850 That said the way that 97 00:03:25,850 --> 00:03:28,160 unsafe is talked about in the writing 98 00:03:28,160 --> 00:03:30,680 and OS and Russ block really allows 99 00:03:30,680 --> 00:03:32,300 its uses to effectively 100 00:03:32,300 --> 00:03:34,265 be scripted, so to speak. 101 00:03:34,265 --> 00:03:37,145 That isn't always looks the same every time. 102 00:03:37,145 --> 00:03:38,870 So it's code that 103 00:03:38,870 --> 00:03:40,910 readily lends itself to abstraction. 104 00:03:40,910 --> 00:03:42,650 Now one of my concerns here 105 00:03:42,650 --> 00:03:45,395 is after one semester of learning Ross, 106 00:03:45,395 --> 00:03:46,790 I don't necessarily think 107 00:03:46,790 --> 00:03:47,960 students should 108 00:03:47,960 --> 00:03:49,520 think they're ready for unsafe. 109 00:03:49,520 --> 00:03:50,570 That is, I really want them 110 00:03:50,570 --> 00:03:52,310 immersed in Rust for awhile. 111 00:03:52,310 --> 00:03:54,380 Understanding what's safe mode 112 00:03:54,380 --> 00:03:55,895 gives you and rely, 113 00:03:55,895 --> 00:03:58,580 learning to rely on those guarantees and not 114 00:03:58,580 --> 00:03:59,900 be so tempted to just start 115 00:03:59,900 --> 00:04:01,595 jumping into the back doors. 116 00:04:01,595 --> 00:04:05,150 And so that philosophically 117 00:04:05,150 --> 00:04:06,290 as part of what lay behind 118 00:04:06,290 --> 00:04:07,670 that design decision, 119 00:04:07,670 --> 00:04:09,560 it is important that students are 120 00:04:09,560 --> 00:04:11,120 aware of the issues and the 121 00:04:11,120 --> 00:04:13,340 unsafe within the crate 122 00:04:13,340 --> 00:04:15,505 is discussed at length during lecture. 123 00:04:15,505 --> 00:04:17,960 So three key examples from 124 00:04:17,960 --> 00:04:20,990 lecture are on a keyboard interrupt 125 00:04:20,990 --> 00:04:23,780 whenever you hit a key that causes 126 00:04:23,780 --> 00:04:25,850 a key code to be 127 00:04:25,850 --> 00:04:28,895 stored at a specific address in RAM. 128 00:04:28,895 --> 00:04:30,785 So I show students how to write 129 00:04:30,785 --> 00:04:32,690 the unsafe code that just reads 130 00:04:32,690 --> 00:04:34,415 that straight out of RAM, 131 00:04:34,415 --> 00:04:36,320 initializing the interrupt. 132 00:04:36,320 --> 00:04:38,360 So telling the interrupt hardware, 133 00:04:38,360 --> 00:04:40,880 these are the functions 134 00:04:40,880 --> 00:04:42,830 to execute when the interrupts happened, 135 00:04:42,830 --> 00:04:45,770 of course, requires an unsafe block. 136 00:04:45,770 --> 00:04:48,260 And then when an interrupt ends, 137 00:04:48,260 --> 00:04:49,070 you have to tell 138 00:04:49,070 --> 00:04:50,240 the interrupt controller that 139 00:04:50,240 --> 00:04:52,655 you're done and that also needs an unsafe. 140 00:04:52,655 --> 00:04:54,290 Now, those are a lot of 141 00:04:54,290 --> 00:04:55,985 code in an unsafe block. 142 00:04:55,985 --> 00:04:56,900 And it gives students 143 00:04:56,900 --> 00:04:58,370 a sense of this is where 144 00:04:58,370 --> 00:04:59,929 unsafe is really necessary 145 00:04:59,929 --> 00:05:01,895 for interacting with the hardware. 146 00:05:01,895 --> 00:05:04,520 So I'm gonna begin by showing what I'm going 147 00:05:04,520 --> 00:05:06,785 to call a hello world example of the crate. 148 00:05:06,785 --> 00:05:08,720 Very simple little program. 149 00:05:08,720 --> 00:05:10,310 It's got an interrupt handler for 150 00:05:10,310 --> 00:05:11,570 clock ticks that just prints 151 00:05:11,570 --> 00:05:13,085 a period on each tick. 152 00:05:13,085 --> 00:05:14,600 It has an interrupt handler 153 00:05:14,600 --> 00:05:15,680 for keyboard events, 154 00:05:15,680 --> 00:05:18,365 it just prints the type character and it has 155 00:05:18,365 --> 00:05:19,970 a mean that defines 156 00:05:19,970 --> 00:05:22,100 these and then launches the handler code. 157 00:05:22,100 --> 00:05:24,530 So this is literally 158 00:05:24,530 --> 00:05:27,020 the entire mean for 159 00:05:27,020 --> 00:05:28,730 a minimal use of the crates. 160 00:05:28,730 --> 00:05:31,865 So couple of compiler directives, 161 00:05:31,865 --> 00:05:33,485 a couple of imports. 162 00:05:33,485 --> 00:05:34,730 And then from here. 163 00:05:34,730 --> 00:05:38,015 It defined a function to, 164 00:05:38,015 --> 00:05:39,620 this is what happens on a tick. 165 00:05:39,620 --> 00:05:42,470 You print a defined 166 00:05:42,470 --> 00:05:44,135 a function for dealing with 167 00:05:44,135 --> 00:05:45,830 a key that's using 168 00:05:45,830 --> 00:05:47,390 this PC keyboard library 169 00:05:47,390 --> 00:05:48,830 that has the decoded keys, 170 00:05:48,830 --> 00:05:50,825 which is pretty nice because 171 00:05:50,825 --> 00:05:53,465 it's got a nice enough for encoding them. 172 00:05:53,465 --> 00:05:54,740 And then we just go ahead and 173 00:05:54,740 --> 00:05:56,450 print those out as they arrive. 174 00:05:56,450 --> 00:05:59,720 And then here's the setup basically. 175 00:05:59,720 --> 00:06:02,840 So you define a start method 176 00:06:02,840 --> 00:06:05,780 that of course does not terminate what? 177 00:06:05,780 --> 00:06:07,760 I've created a data structure 178 00:06:07,760 --> 00:06:09,185 called a handle or table. 179 00:06:09,185 --> 00:06:10,820 You set up with its constructor 180 00:06:10,820 --> 00:06:12,170 and using the builder pattern, 181 00:06:12,170 --> 00:06:14,555 you say dot keyboard, 182 00:06:14,555 --> 00:06:15,965 Here's my keyboard handler, 183 00:06:15,965 --> 00:06:18,320 that timer, here's my timer handler 184 00:06:18,320 --> 00:06:19,685 and then dot start. 185 00:06:19,685 --> 00:06:23,000 Let it run and let it do its thing. 186 00:06:23,000 --> 00:06:25,325 And that's a minimal program right there. 187 00:06:25,325 --> 00:06:27,080 So one screen full, 188 00:06:27,080 --> 00:06:29,615 we actually have a running kernel. 189 00:06:29,615 --> 00:06:30,800 Now obviously it's not 190 00:06:30,800 --> 00:06:32,495 an enormously functional kernel, 191 00:06:32,495 --> 00:06:36,770 but it is legitimately a kernel code that is 192 00:06:36,770 --> 00:06:39,005 either student authored or 193 00:06:39,005 --> 00:06:41,315 called by a student from a library. 194 00:06:41,315 --> 00:06:42,440 Talk a little bit about 195 00:06:42,440 --> 00:06:43,910 the handler table datatype 196 00:06:43,910 --> 00:06:45,830 that I illustrated on the last page. 197 00:06:45,830 --> 00:06:49,729 So it's got four data fields. 198 00:06:49,729 --> 00:06:52,130 An optional timer function, 199 00:06:52,130 --> 00:06:54,680 an optional keyboard handler, 200 00:06:54,680 --> 00:06:56,750 a startup function which is optional, 201 00:06:56,750 --> 00:06:59,010 and then a CPU loop. 202 00:06:59,440 --> 00:07:02,150 Cpu loop is main code 203 00:07:02,150 --> 00:07:03,650 that runs in the absence of interrupts. 204 00:07:03,650 --> 00:07:04,940 And if you don't give it anything, 205 00:07:04,940 --> 00:07:08,045 it just executes an X86 halt instruction. 206 00:07:08,045 --> 00:07:09,260 So at that point just all 207 00:07:09,260 --> 00:07:09,980 the running code is 208 00:07:09,980 --> 00:07:11,825 from the interrupts themselves. 209 00:07:11,825 --> 00:07:14,540 So behind the scenes 210 00:07:14,540 --> 00:07:16,235 to set up the interrupts, 211 00:07:16,235 --> 00:07:18,770 we create a global variable of 212 00:07:18,770 --> 00:07:19,865 the handler cable type 213 00:07:19,865 --> 00:07:23,045 using lazy Static, right? 214 00:07:23,045 --> 00:07:24,770 There are some interrupt handlers 215 00:07:24,770 --> 00:07:25,820 that relay interrupts to 216 00:07:25,820 --> 00:07:27,635 the appropriate data fields 217 00:07:27,635 --> 00:07:29,630 of that global object. 218 00:07:29,630 --> 00:07:31,760 All the unsafe code again 219 00:07:31,760 --> 00:07:34,129 is inside those provided handlers. 220 00:07:34,129 --> 00:07:35,900 The bulk of the code is 221 00:07:35,900 --> 00:07:37,895 from Philip opera men's blog, 222 00:07:37,895 --> 00:07:39,770 the bridge code, the handler table. 223 00:07:39,770 --> 00:07:41,510 I wrote a lot of packages, 224 00:07:41,510 --> 00:07:43,310 but in many ways the bulk of 225 00:07:43,310 --> 00:07:45,140 the crate is from his blog. 226 00:07:45,140 --> 00:07:47,570 And he was pretty I mean, 227 00:07:47,570 --> 00:07:48,530 he gave it under 228 00:07:48,530 --> 00:07:51,140 a pretty unrestricted license, 229 00:07:51,140 --> 00:07:53,210 but he's still pretty 230 00:07:53,210 --> 00:07:54,665 generously blessed to the project. 231 00:07:54,665 --> 00:07:56,690 When I contacted him about it. 232 00:07:56,690 --> 00:07:59,330 The VGA buffer code is almost 233 00:07:59,330 --> 00:08:01,520 entirely taken from operations codes, 234 00:08:01,520 --> 00:08:02,780 especially he wrote 235 00:08:02,780 --> 00:08:04,535 very nice print and print line macros. 236 00:08:04,535 --> 00:08:06,410 I did add a plot function so you could 237 00:08:06,410 --> 00:08:08,750 directly uptake columns and rows though. 238 00:08:08,750 --> 00:08:10,400 These memory accesses are 239 00:08:10,400 --> 00:08:12,680 concealed behind buffer and writer object, 240 00:08:12,680 --> 00:08:14,660 which conceal the unsafe blocks 241 00:08:14,660 --> 00:08:15,710 that are wrapped around 242 00:08:15,710 --> 00:08:19,295 the memory map output for the VGA buffer. 243 00:08:19,295 --> 00:08:21,620 So big assignment at 244 00:08:21,620 --> 00:08:23,270 the end of the semester is students, 245 00:08:23,270 --> 00:08:26,030 right? Cooperative multitasking kernel. 246 00:08:26,030 --> 00:08:27,500 This is a screenshot of what 247 00:08:27,500 --> 00:08:29,105 it looks like once it's running. 248 00:08:29,105 --> 00:08:32,240 So in the VGA buffer, 249 00:08:32,240 --> 00:08:33,680 I have the students set up for 250 00:08:33,680 --> 00:08:35,645 Windows and they select 251 00:08:35,645 --> 00:08:37,310 a function key to decide 252 00:08:37,310 --> 00:08:39,350 which window is active. 253 00:08:39,350 --> 00:08:41,000 And by active, I mean receiving 254 00:08:41,000 --> 00:08:42,890 keyboard events that can then 255 00:08:42,890 --> 00:08:45,020 choose to run one of two programs, 256 00:08:45,020 --> 00:08:47,615 a program to compute averages. 257 00:08:47,615 --> 00:08:50,120 You can kinda see an example of it down here, 258 00:08:50,120 --> 00:08:52,385 or a program to compute pi. 259 00:08:52,385 --> 00:08:54,230 And you give it a tolerance and then 260 00:08:54,230 --> 00:08:55,370 it'll run a certain 261 00:08:55,370 --> 00:08:56,570 number of ticks in the background. 262 00:08:56,570 --> 00:08:58,130 A little side here tells you 263 00:08:58,130 --> 00:08:59,270 how many ticks each of 264 00:08:59,270 --> 00:09:00,650 these processes are run. 265 00:09:00,650 --> 00:09:02,105 So they actually get to write like 266 00:09:02,105 --> 00:09:04,235 a nice little multiprogramming 267 00:09:04,235 --> 00:09:05,900 operating system 268 00:09:05,900 --> 00:09:08,120 with two built-in programs. 269 00:09:08,120 --> 00:09:10,655 So like I mentioned in the last slide, 270 00:09:10,655 --> 00:09:12,410 up to four processes we 271 00:09:12,410 --> 00:09:15,200 compute pi view of power series. 272 00:09:15,200 --> 00:09:17,210 Most of the process actions, 273 00:09:17,210 --> 00:09:18,830 keyboard inputs and output to 274 00:09:18,830 --> 00:09:20,930 the terminal and perform 275 00:09:20,930 --> 00:09:22,835 one step of an algorithm. 276 00:09:22,835 --> 00:09:24,920 So what Handel or 277 00:09:24,920 --> 00:09:26,570 table does for this one startup, 278 00:09:26,570 --> 00:09:27,815 it clears the screen, 279 00:09:27,815 --> 00:09:30,725 the timer updates the system clock count. 280 00:09:30,725 --> 00:09:33,260 The keyboard seems most recent key pressed. 281 00:09:33,260 --> 00:09:34,900 The CPU loop released 282 00:09:34,900 --> 00:09:37,460 the most recent key press to the kernel. 283 00:09:37,460 --> 00:09:39,635 So it looks in an atomic cell, 284 00:09:39,635 --> 00:09:41,120 refreshes the screen when 285 00:09:41,120 --> 00:09:42,560 the system clock updates and 286 00:09:42,560 --> 00:09:43,820 advances the currently running 287 00:09:43,820 --> 00:09:45,980 process by one step. 288 00:09:45,980 --> 00:09:50,575 So here's the kind of the main code for that. 289 00:09:50,575 --> 00:09:52,900 So there is a data structure 290 00:09:52,900 --> 00:09:54,220 just called the kernel that's 291 00:09:54,220 --> 00:09:55,930 doing all of 292 00:09:55,930 --> 00:09:58,210 the organizational work, so to speak. 293 00:09:58,210 --> 00:10:00,430 But this is how it gets bridge with 294 00:10:00,430 --> 00:10:02,950 the pluggable interrupt OS library. 295 00:10:02,950 --> 00:10:06,175 What we have is a tic function 296 00:10:06,175 --> 00:10:10,180 that updates this ticks atomic cell, 297 00:10:10,180 --> 00:10:11,710 does a fetch add just to 298 00:10:11,710 --> 00:10:13,465 increase it by one every time. 299 00:10:13,465 --> 00:10:17,575 We have a key handler that 300 00:10:17,575 --> 00:10:20,710 updates the last key atomic cell 301 00:10:20,710 --> 00:10:23,560 with the most recently received key. 302 00:10:23,560 --> 00:10:26,500 Then within the CPU loop, 303 00:10:26,500 --> 00:10:27,550 at the beginning of the loop it 304 00:10:27,550 --> 00:10:30,360 creates a kernel object. 305 00:10:30,360 --> 00:10:32,420 What's up a local variable also 306 00:10:32,420 --> 00:10:34,370 for the last tick. 307 00:10:34,370 --> 00:10:36,470 And then it just goes into an infinite loop 308 00:10:36,470 --> 00:10:38,915 where each time it finds out, 309 00:10:38,915 --> 00:10:41,765 is there a key to load and if so, 310 00:10:41,765 --> 00:10:44,225 it stores it a none, 311 00:10:44,225 --> 00:10:45,470 because we've now read 312 00:10:45,470 --> 00:10:47,735 the key and then tell us the kernel about it. 313 00:10:47,735 --> 00:10:49,700 Then it finds out what's the current tick 314 00:10:49,700 --> 00:10:51,680 if it's advanced since last time, 315 00:10:51,680 --> 00:10:54,454 it does a redraw of the screen. 316 00:10:54,454 --> 00:10:55,880 And then finally it tells us 317 00:10:55,880 --> 00:10:57,590 the kernel every time through the loop, 318 00:10:57,590 --> 00:10:59,120 regardless of what happens with 319 00:10:59,120 --> 00:11:01,160 the interrupts to run one instruction. 320 00:11:01,160 --> 00:11:02,869 And this is the basic structure 321 00:11:02,869 --> 00:11:04,340 of the program the students 322 00:11:04,340 --> 00:11:05,900 are asked to write. 323 00:11:05,900 --> 00:11:09,260 So kinda, as I mentioned earlier, 324 00:11:09,260 --> 00:11:10,670 user selects the one with 325 00:11:10,670 --> 00:11:13,115 the function keys and the currents. 326 00:11:13,115 --> 00:11:14,600 Selected window is either blocked on 327 00:11:14,600 --> 00:11:16,100 input or it executes 328 00:11:16,100 --> 00:11:17,375 one step of the algorithm. 329 00:11:17,375 --> 00:11:17,990 Did a couple of 330 00:11:17,990 --> 00:11:20,660 other little assignments for this. 331 00:11:20,660 --> 00:11:22,985 To kinda set them up for this, 332 00:11:22,985 --> 00:11:26,735 I had them implement a little VGA video game. 333 00:11:26,735 --> 00:11:27,890 So in other words, they had to write 334 00:11:27,890 --> 00:11:29,405 a program that had 335 00:11:29,405 --> 00:11:30,920 animation controlled by a 336 00:11:30,920 --> 00:11:34,070 timer interrupt and controls 337 00:11:34,070 --> 00:11:35,540 with from a keyboard interrupt. 338 00:11:35,540 --> 00:11:37,280 And I gave them an example of 339 00:11:37,280 --> 00:11:40,670 my own creation which I call ghost hunter. 340 00:11:40,670 --> 00:11:42,440 I'll leave it to your imagination. 341 00:11:42,440 --> 00:11:45,335 What exactly inspired that? 342 00:11:45,335 --> 00:11:47,420 Then the next assignment is they 343 00:11:47,420 --> 00:11:48,590 actually create what I call 344 00:11:48,590 --> 00:11:49,805 a video game kernel. 345 00:11:49,805 --> 00:11:51,740 It's kinda like a video game console 346 00:11:51,740 --> 00:11:53,330 where you've got a menu of games, 347 00:11:53,330 --> 00:11:55,290 which are games they wrote actually. 348 00:11:55,290 --> 00:11:58,360 And you can choose a game to run, 349 00:11:58,360 --> 00:12:01,345 pause it, have multiple ones paused, 350 00:12:01,345 --> 00:12:02,620 kill them and so forth. 351 00:12:02,620 --> 00:12:03,010 Flowers, 352 00:12:03,010 --> 00:12:04,750 they learned about process management 353 00:12:04,750 --> 00:12:07,060 from reading that video game kernel. 354 00:12:07,060 --> 00:12:09,700 So from here, some things 355 00:12:09,700 --> 00:12:11,230 I'm looking forward to doing. 356 00:12:11,230 --> 00:12:13,165 I'd like to figure out, 357 00:12:13,165 --> 00:12:14,830 and chemo has a capacity for this. 358 00:12:14,830 --> 00:12:16,690 I just haven't studied it in detail yet. 359 00:12:16,690 --> 00:12:18,220 Tattle RAM, disk or disk 360 00:12:18,220 --> 00:12:19,960 simulator sometimes so that they can 361 00:12:19,960 --> 00:12:24,265 have experienced if a file system. 362 00:12:24,265 --> 00:12:26,830 The code I wrote enabled 363 00:12:26,830 --> 00:12:30,205 preemptive mole, cooperative multitasking. 364 00:12:30,205 --> 00:12:32,710 Learning how to let it do preemptive, 365 00:12:32,710 --> 00:12:34,645 I think would be interesting. 366 00:12:34,645 --> 00:12:36,880 Develop some more model assignments 367 00:12:36,880 --> 00:12:38,690 and maybe handled interrupts. 368 00:12:38,690 --> 00:12:40,985 I am actively interested 369 00:12:40,985 --> 00:12:43,730 in collaborating if anybody's got 370 00:12:43,730 --> 00:12:46,460 ideas or concepts for expanding on 371 00:12:46,460 --> 00:12:49,340 this list of URLs 372 00:12:49,340 --> 00:12:52,820 here of some of the resources I created it, 373 00:12:52,820 --> 00:12:54,770 but a couple of them already in 374 00:12:54,770 --> 00:12:56,840 the chat for your reference. 375 00:12:56,840 --> 00:12:58,640 And I will share all of these in 376 00:12:58,640 --> 00:13:01,850 the zoo lip chat as well. 377 00:13:01,850 --> 00:13:05,870 So that's my presentation. 378 00:13:05,870 --> 00:13:08,045 I'm going to start looking at 379 00:13:08,045 --> 00:13:11,660 the chat to see what questions 380 00:13:11,660 --> 00:13:18,050 might have arisen during its forth. Okay. 381 00:13:18,050 --> 00:13:20,039 Let's see. 382 00:13:20,680 --> 00:13:24,030 Sorry, I'm just scrolling through it. 383 00:13:26,530 --> 00:13:27,935 Okay. 384 00:13:27,935 --> 00:13:29,090 We're starting with command 385 00:13:29,090 --> 00:13:30,650 line Unix utilities, 386 00:13:30,650 --> 00:13:33,980 inspired by the book on this topic. 387 00:13:33,980 --> 00:13:38,300 I'm not really, I was inspired by that just 388 00:13:38,300 --> 00:13:39,260 because I thought they'd be 389 00:13:39,260 --> 00:13:40,460 easy to code and it'll be 390 00:13:40,460 --> 00:13:43,190 a nice on-ramp into rust. 391 00:13:43,190 --> 00:13:44,870 It also kind of dovetail 392 00:13:44,870 --> 00:13:46,430 with the overall philosophy of my class, 393 00:13:46,430 --> 00:13:49,490 which was start with the OS at 394 00:13:49,490 --> 00:13:50,420 the level students have 395 00:13:50,420 --> 00:13:51,530 been interacting with it and 396 00:13:51,530 --> 00:13:53,975 then gradually dive downward. 397 00:13:53,975 --> 00:13:58,940 So it was pretty useful in that way. 398 00:13:58,940 --> 00:13:59,990 But here this be hard to 399 00:13:59,990 --> 00:14:01,580 adapt to an alternate ISA, 400 00:14:01,580 --> 00:14:03,880 for example, an arm board. 401 00:14:03,880 --> 00:14:06,564 That's a really great question. 402 00:14:06,564 --> 00:14:08,290 Part. 403 00:14:08,290 --> 00:14:10,600 I'm relying a lot on some of 404 00:14:10,600 --> 00:14:12,295 the fairly high level 405 00:14:12,295 --> 00:14:14,770 hardware support that you get on the X86, 406 00:14:14,770 --> 00:14:17,530 most especially the VGA buffer. 407 00:14:17,530 --> 00:14:18,550 So if you're going to adapt 408 00:14:18,550 --> 00:14:20,110 to something like arm, 409 00:14:20,110 --> 00:14:21,070 there might need to 410 00:14:21,070 --> 00:14:22,930 be some additional plumbing 411 00:14:22,930 --> 00:14:25,060 put in place to handle out. 412 00:14:25,060 --> 00:14:26,470 But that said if you're doing something 413 00:14:26,470 --> 00:14:27,940 like on an Arduino or whatever, 414 00:14:27,940 --> 00:14:31,000 that would be less of a concern. 415 00:14:31,000 --> 00:14:33,370 So I think it would be a fair amount 416 00:14:33,370 --> 00:14:34,780 of work to adapt to arm, 417 00:14:34,780 --> 00:14:36,535 but it'd be really interesting to do. 418 00:14:36,535 --> 00:14:37,930 And actually I've always been a fan 419 00:14:37,930 --> 00:14:40,190 of the ARM architecture. 420 00:14:40,320 --> 00:14:44,455 Where is the print macro defined? 421 00:14:44,455 --> 00:14:46,130 In? For example, 422 00:14:46,130 --> 00:14:52,580 the print macro is fairly deep in the Cray. 423 00:14:52,580 --> 00:14:57,360 Let me bring it up here. 424 00:14:58,450 --> 00:15:01,950 Just a second. 425 00:15:02,500 --> 00:15:06,815 So if you go into 426 00:15:06,815 --> 00:15:15,530 crates and click there, 427 00:15:15,530 --> 00:15:17,480 if you go into 428 00:15:17,480 --> 00:15:24,089 the repository and the source code, 429 00:15:24,580 --> 00:15:29,015 it's not there in 430 00:15:29,015 --> 00:15:33,725 VGA Buffer dot RS specifically. 431 00:15:33,725 --> 00:15:35,945 So yeah, there's a lot to it. 432 00:15:35,945 --> 00:15:37,910 It follows pretty closely 433 00:15:37,910 --> 00:15:40,325 from the fill opera moon blog, 434 00:15:40,325 --> 00:15:41,330 but that's where you would 435 00:15:41,330 --> 00:15:43,520 find it in my code. 436 00:15:43,520 --> 00:15:45,620 So Bart mentioned is 437 00:15:45,620 --> 00:15:47,810 an alternative architecture would replace 438 00:15:47,810 --> 00:15:49,580 cp loop with a man that was required to call 439 00:15:49,580 --> 00:15:51,665 the kernel housekeeping inside the loop. 440 00:15:51,665 --> 00:15:55,530 What are the trade-offs here? 441 00:15:56,470 --> 00:15:59,075 So that's an interesting question. 442 00:15:59,075 --> 00:16:01,430 I've been pondering this a little bit. 443 00:16:01,430 --> 00:16:03,860 One thing I like about having the students 444 00:16:03,860 --> 00:16:06,199 write explicit interrupt handlers 445 00:16:06,199 --> 00:16:08,480 is it forces them to think clearly about 446 00:16:08,480 --> 00:16:11,180 the concurrency issues that are involved. 447 00:16:11,180 --> 00:16:13,400 I've imagined a variation 448 00:16:13,400 --> 00:16:15,845 on this in which students 449 00:16:15,845 --> 00:16:19,070 would just provide a kernel data structure 450 00:16:19,070 --> 00:16:20,240 and it would kind of relate things 451 00:16:20,240 --> 00:16:21,425 to them automatically. 452 00:16:21,425 --> 00:16:23,270 But it would detract from what I 453 00:16:23,270 --> 00:16:26,135 want to do in that regard. 454 00:16:26,135 --> 00:16:29,000 Does the OS do virtual memory management? 455 00:16:29,000 --> 00:16:30,155 Not really. 456 00:16:30,155 --> 00:16:32,060 I mean, X86 requires you to 457 00:16:32,060 --> 00:16:33,860 do it just as a matter, 458 00:16:33,860 --> 00:16:35,330 of course, but what I did with 459 00:16:35,330 --> 00:16:37,430 it was really pretty trivial. 460 00:16:37,430 --> 00:16:39,800 There's been some interesting work 461 00:16:39,800 --> 00:16:41,570 done in, gosh, 462 00:16:41,570 --> 00:16:43,445 I forgot the name of the kernel, 463 00:16:43,445 --> 00:16:46,145 but the author is named Kevin booze. 464 00:16:46,145 --> 00:16:47,810 He was a PhD student at 465 00:16:47,810 --> 00:16:49,969 Rice University who constructed 466 00:16:49,969 --> 00:16:52,005 a rust based operating system. 467 00:16:52,005 --> 00:16:53,755 What the underlying principle 468 00:16:53,755 --> 00:16:54,790 that you don't necessarily 469 00:16:54,790 --> 00:16:56,050 need to use a hardware 470 00:16:56,050 --> 00:16:57,580 mechanisms for virtual memory, 471 00:16:57,580 --> 00:16:59,500 given that you're doing everything in Rust, 472 00:16:59,500 --> 00:17:01,240 you can let the language mechanisms 473 00:17:01,240 --> 00:17:03,070 ensure process isolation. 474 00:17:03,070 --> 00:17:03,850 So I haven't actually 475 00:17:03,850 --> 00:17:04,750 gotten to really thinking 476 00:17:04,750 --> 00:17:07,105 about virtual memory management yet. 477 00:17:07,105 --> 00:17:09,370 What are the biggest learning challenges 478 00:17:09,370 --> 00:17:11,365 induced by using no standard? 479 00:17:11,365 --> 00:17:13,270 Great question. 480 00:17:13,270 --> 00:17:15,700 I tried to give students an awful lot of 481 00:17:15,700 --> 00:17:18,055 hand-holding in this regard. 482 00:17:18,055 --> 00:17:20,650 So for my own sake, 483 00:17:20,650 --> 00:17:24,940 I would say learning which crate, 484 00:17:24,940 --> 00:17:28,000 which libraries you had to import, 485 00:17:28,000 --> 00:17:30,595 I think from rather than 486 00:17:30,595 --> 00:17:34,920 std was kind of annoying. 487 00:17:34,920 --> 00:17:37,010 And then just figuring out, 488 00:17:37,010 --> 00:17:38,570 okay, what are all the pieces? 489 00:17:38,570 --> 00:17:40,280 What's all this stuff I need to lay down like 490 00:17:40,280 --> 00:17:44,730 print line in order to get anywhere really. 491 00:17:44,950 --> 00:17:47,240 And how far to students come in 492 00:17:47,240 --> 00:17:49,700 this course compared to similar courses? 493 00:17:49,700 --> 00:17:52,850 And see, man, that's a great question. 494 00:17:52,850 --> 00:17:54,290 To be blunt. 495 00:17:54,290 --> 00:17:56,390 I only really was ready to teach 496 00:17:56,390 --> 00:17:57,290 this class when I was 497 00:17:57,290 --> 00:17:58,520 able to teach it and Rusk, 498 00:17:58,520 --> 00:17:59,810 because the thought of teaching it and 499 00:17:59,810 --> 00:18:02,030 see was kind of a nightmare based on 500 00:18:02,030 --> 00:18:04,190 my own memories as an undergrad taking it and 501 00:18:04,190 --> 00:18:06,380 see just the endless 502 00:18:06,380 --> 00:18:08,315 memory errors and so forth. 503 00:18:08,315 --> 00:18:10,310 So bottom line is, 504 00:18:10,310 --> 00:18:11,690 I think we've got just about as far 505 00:18:11,690 --> 00:18:13,385 as if I were teaching it and see, 506 00:18:13,385 --> 00:18:15,199 because things like concurrency 507 00:18:15,199 --> 00:18:16,670 errors get pointed out to them. 508 00:18:16,670 --> 00:18:18,680 Compiler and aren't the subject 509 00:18:18,680 --> 00:18:22,130 of three-hour sessions and office hours. 510 00:18:22,130 --> 00:18:25,070 So that's something I've really, 511 00:18:25,070 --> 00:18:29,255 really appreciated about Rust. 512 00:18:29,255 --> 00:18:31,550 Yes, Theseus OS was the one. 513 00:18:31,550 --> 00:18:32,630 Thanks Arthur. 514 00:18:32,630 --> 00:18:34,565 That was the one. 515 00:18:34,565 --> 00:18:36,560 Totally check that out. 516 00:18:36,560 --> 00:18:37,940 Well, I think that's probably 517 00:18:37,940 --> 00:18:39,080 time on my session, 518 00:18:39,080 --> 00:18:40,280 so thanks everybody for 519 00:18:40,280 --> 00:18:41,599 all the great questions 520 00:18:41,599 --> 00:18:44,570 and interactions I'm active on the tulips. 521 00:18:44,570 --> 00:18:46,550 So if you're interested in any of this stuff, 522 00:18:46,550 --> 00:18:48,005 please reach out to me. 523 00:18:48,005 --> 00:18:50,000 And like I said, if you want to collaborate, 524 00:18:50,000 --> 00:18:52,670 anything, think about extensions or whatever. 525 00:18:52,670 --> 00:18:53,315 I am. 526 00:18:53,315 --> 00:18:54,080 All ears. 527 00:18:54,080 --> 00:18:55,715 I've had a lot of fun with this, 528 00:18:55,715 --> 00:18:57,410 and it's been a great theater workshop. 529 00:18:57,410 --> 00:18:59,160 Thanks everybody.