whoa we're streaming are we streaming am I live can you hear my silky smooth can you hear my voice it sounds like you can it sounds like you can and uh we're just gonna go for it uh let's make some announcements uh-huh add notice hey look I already typed it that way I don't forget it okay uh oh that's not don't worry about me I'll be fine we are live I think I do a red circle too and then we're gonna do OS development hey fog hey it's the correct link I was worried okay yeah in case the uh the title didn't spoil you that announcement just did welcome to the first OS stream who knows how it's going to go it may be horrible we will see uh we're gonna completely build a charade what's up we're gonna completely build lenser OS uh from scratch so we're just gonna get clone it and then we're gonna go from there and follow all the steps and uh you can see exactly how to build lenser OS sorry it says apparently I joined 100 seconds into the Stream yeah pretty much it's been a minute 40 now storage says minus a hundred not a hundred oh oh I read it wrong you're right hey Rue Arc my favorite twitch stream is live fog champ hey fog champ to you what's up Roark how's it going thank you for tuning in surrade you as well thank you for tuning in so uh let's just get it going we're doing a streamer and we're just doing a git clone uh there are many ways to do this I could just run a shell command get clone I'm going to use maggot clone which is just a an Emax plug-in which runs git clone for me but uh you can see it just acts it I almost said it axed it asks us for a URL path local URL or bundle this is a URL here's the URL we're going to put in uh what is it colon slash slash github.com uh we'll do code bird dot org slash lens plays games slash lenseros dot get I'm pretty sure that's correct so raid says did you see my pull request oh no I did not did you make it on uh codeberg or GitHub probably GitHub oh it's probably on codeburg says on codeberg you're a legend sorry thank you so if you don't know uh development of the OS is currently happening mostly on codeberg which is a uh a little not-for-profit or non-profit based in Germany I believe and they are basically hosting their own giti instance and as long as your projects are free and open source then you are completely cool to use it so that's what I'm doing I do have a new pull request make scripts executable nice nice that's good so on Windows I write the shell scripts for Linux and then use WSL to run them this makes them executable with the Linux command that I can't really run on Windows it doesn't I don't have permission from WSL to alter the execution Flags ruark says I think it's in Berlin actually so where I live maybe I should visit them that's awesome maybe you should that'd be sweet you can make them executable in WSL as far as I know can you really I couldn't figure it out it said permission denied all the time and then I looked it up and they said you can't uh alter like Windows files I think the shell files themselves would have to be in the WSL file system not in the mount the windows mount which is where everything is now but you're probably right you're probably right I can probably do it I'm just not good enough uh I don't know how uh make scripts executable it I'm pretty sure it's fine all of them have zero changes they're just executable now I'm that's perfect we're just gonna merge this bad boy uh what's the last commit let me make sure yeah hopefully fix stuff so we're good so I'm just gonna rebase and fast forward this is what I want to do right this will just add this commit I'm pretty sure I'm pretty sure I'm gonna set a due date for you this has to be done that's so funny I had dependencies what does that even mean is that like issues oh if you can add issues oh that's cool I don't know what all these are but this is cool what are all teams My Toot to raise awareness on the get to open letter [Laughter] oh okay I don't know why this makes me laugh so hard it's so dumb I don't know what all this stuff is but uh oh no oh no no no no no no no I'm dying oh no it's canceled nothing please I'm just gonna select My Toot I don't know what else well I can't change it back oh man don't click that button sorry it's just rip we're just gonna rebate some fast forward hopefully nothing broke I guess we gotta wait for that open letter now I'm pressing escape delete backspace nothing works man I guess we gotta pick something first time chat from edible monad you can't merge it now resolve the toot the shoe first oh why is this I don't even know what these are your project will forever have my toot to raise sorry it's a brilliant UI almost as intuitively as I'm not letting you access comments from the commits page oh by the way thank you so much for tuning in edible monad you have a great name you like Haskell I'm gonna just refresh the page yes changes may not be saved thank God [Laughter] we're good we're good we're toot free and we're gonna keep it that way oh ruark asks the Eternal question I'm learning Castle right now what's a monad oh no oh I feel so bad for you Rourke says two three I like that this this OS needs to be two to three so ridiculous Serene says a monad is a monoid in the category of endo functors duh he's right oh audible monad says monad is the monoid and the fategory of in hunger oh it was a good day today edible monad thank you so much for the follow ing luckily we're toot free you don't have to eat any any toot monads we we've we've smitten it out of this out of this OS I'm gonna just do it I'm laughing too hard oh God he are merged welcome siraid as a contributor to lenser OS I think you're the you're the third now okay clone two yeah lenser OS uh sure so now that we clone this edible monad says this PR was a roller coaster it was rough man it was uh oh man it's like that keemstar intro the other day I almost died okay so now we have our uh lenser OS that's good that's here and uh here's the directory this is what you get and we're going to take a look at the readme and we're going all the way to building lenser OS yes there's a ton of stuff to do I already have all the dependencies that I do need so we are good to go oh man Roark says toot toot I like trains sorry it says welcome to Haskell so good Okay so there's effectively four steps one of them is downloading dependencies which we've done so there's three steps we gotta build the bootloader and if you don't know the bootloader is basically the thing that uh your system boots into so like for example grub canoe grub that's a very common one for Linux and on Windows it's obviously Windows specific and on lens or Os it's lenser OS specific it's a UEFI based bootloader 64-bit so we just uh boot right into long mode which is pretty sweet we don't have to do any uh build the 16-bit page tables switch to 32-bit protect mode build the 32-bit page tables switch to 64-bit long mode build a 64-bit page tables then we can start we just get to start at the 64-bit which is luck Village is lucky which is lucky thank you UEFI so if we take a look at the bootloader instructions it's going to change blah blah I made my own bootloader we're going to use it eventually you can check it out on GitHub in any case in any case the bootloader is an EFI application which runs in the ufi Shell which is basically what replaced bios at some point so what comes on your motherboard will be able to run this bootloader and then we basically have to use pe32 plus executables with the proper subsystem for an EFI application all of this is handled by a make file uh so yeah now we just have to build the bootloader with make it's not too complicated I think I'm going to use e-shell for this stuff I should have opened a new window first but uh you can see I have my shell open on the right side now and what we can do is just literally run what's over here on the left right here sorry it says I'd recommend make Dash j instead nah you'll see it's quick uh and now that we're in here I'm on windows so I'm going to use WSL and just you can pipe any command into WSL from the shell just by running it uh passing it as arguments so now we can just use WSL make sorry it says that's true the bootloader doesn't take long to compile I'm pretty sure it would take longer to set up all the threads we've done it so uh we now have it that only never has to be done once from here we can actually build the bootloader executable by typing the bootloader what you mean for getting WSL by the way is there a way to find it I gotta use fat okay I can't hit uh home I gotta hit Ctrl a usually I hit home with my right hand don't at me so it says Now setting up threads is faster than that you could be right it could be right uh so yeah now we just make the bootloader so it says if it's not you have a bad OS La Mal that was the bootloader by the way it's very simple one file so all we have to do by the way if you're curious this is just regular GCC on Linux they pass in some uh specialties but it's really not that different you know what I mean and then uh you just object copy and you basically just rearrange the entire file right here it's pretty funny but yeah you can just do this by hand if you really want if you are confused at what all this make make bootloader stuff is if you're interested it's not too complicated you can definitely do it by hand it's just not uh Pleasant to write commands like this as you probably know Rourke says that was quick claw yep that was the bootloader so now we can see oh man uh now we can see that we have I think OS bootloader nope that's just uh the source files it's LS x8664 bootloader and now we have main.efi so if we do a a little file test on that you can see that it's a pe32 plus executable an EFI application for x8664 with a stripped of debug info for Microsoft Windows that's just because it's pe32 plus but this is exactly what we need sir Ed says my internet connection sucks so I'm going to Benchmark how long it takes just to compile GCC oh that's really cool I'm very interested it's it's going to take us two hours I'm not even joking we're gonna be sitting here for two hours very soon because if you don't know the next step hint is uh what is unclear The Next Step intent is uh a little rough now we have to build the tool chain and the kernel the tool chain is a special version of the gnu compiler collection this is needed because it needs to know where to look for things like libraries like system libraries and system headers and it basically has to know what your lib C is and how it works and uh if you don't know I wrote the lenser OS has its own lib C so you also are gonna have to build that if you really want King bun says I'm excited hey King buns what's going on I'm so glad you're here thank you for tuning in I'm glad you're excited I'm excited this takes a long time and it takes like five gigabytes of hard drive space or more it's like seven these days so this this is the 15 to 90 minutes uh step you know what I mean so if you can really if you can use a pre-built lenser OS dual chain I really recommend it they're not going to be up to date but you don't have to wait a long ass time if you do want to wait a long time and you're okay with it here's all the things you're going to need I already did this so uh on Windows you need to do this in WSL and on Linux you just run this command or on dbn I should say anyways then you just run toolchain.sh and while toolchain.sh is running we're going to be talking about what it's doing y'all ready so oh yeah CD bull chain so you can see that we have here let's open this can I do this this is a good idea one second I'm setting something this will look better uh yeah ping bun says I started it oh onwards trust Stead lamou so can I make this bigger I can look at that look at that how beautiful perfect so you can see that this is now our thing and if we look in the tool chain directory you can see that there's some stuff mostly toolchain.sh and uh what we're gonna do is run that oh it does a lot I recommend looking at what it does before you run it charade says it prompts me for a file to patch when I run the patch command by hand are you at home King bun says no always run shell scripts without looking ruark says it's too big that's better nice kingbun says trust Steed that was rough trusty nice onwards trusty Steed that makes more sense I like onwards trust stead is much better sorry it says never mind I think I was in the wrong directory yeah you have to run this from the tool chain directory if things will break so right says yeah it works now King buns you may be in the wrong directory are you in the tool chain directory he says he pasted a make error I've seen that before King bun says I am I don't know we'll see if we get it whoa so we're gonna first download gnu Ben utils this includes things like uh tar the archiving program and it may just can include R not tar but don't worry about it But it includes most importantly LD the gnu Linker so we've downloaded it that wasn't too bad luckily my internet's uh obliging King buns we will uh I've ran into that issue before I'm pretty sure it was just uh the wrong directory but I'm sure there's multiple causes for it so I will think about it and if we run into it I will really think about it you can always do everything by hand if you really want we download gnuben utils and GCC source code again this uh this tutorial that's written out is older we're using GCC 12.1.0 now and basically extract the archives to get the source code yes you use tar extract the exit files that you downloaded which is all the source code for bin utils and GCC we patched them which is a way to update their the code with certain changes and this allows GCC to actually recognize lenser OS is the OS that it's running on and it can look in the proper places for lib C headers and Lipsy libraries and Etc and also have all the proper configuration you also have to create a sys root this hasn't happened yet we're still extracting bin utils which is going to take forever extracting GCC is going to take even longer because it's like 100 000 files maybe 300 000. I don't even know at this point no rule to make Target all GCC stop make no rule to make Target all target libgc so if we take a look at the tool chain script you can see that basically what it does it says download if this doesn't exist already download extract and Patch Source archives if they haven't been which is uh what these sections do here kingbun says is wrong window whip LS wrong window I'm confused so now we've extracted and patched bin utils that's good kingbun says I typed King boom says oh I typed LS and twitch chat LMAO I get it now wrong window that's that's so good that's so good so now we're downloading the the new compiler collection Source archive we are right here using curl and uh eventually we will get to creating a sys root which we have a whole nother script for as you can see it's quite complicated it has to do with the lib C headers because you have to compile GCC with all of the libsy headers that it's going to be using and they have to be like in the proper hierarchy that they will be on the destination OS that it will run on so in lenser OS the sys root basically is a mimicked copy of the lenser OS root file system and this is needed so that we can compile uh GCC with the proper sys root and it will look in the proper places for system headers and everything like that I love that you typed LS in twitch chat that's pretty legendary why are my directory showing what's going on but yeah oh this is going to take probably 10 minutes uh so while we extract it let's talk about it what we're going to do next is do something called configuring and then building if you don't know Auto configure is like this whole ecosystem of tools and they basically have scripts that you can run with certain parameters and it'll alter how the final build process uh happens for example we can disable W error which means that even if we're compiling with W error which is forced in some places we can actually disable it in this configure script and even though we compile with W error it won't error out on a warning which means that your 30 plus minute compilation won't stop because of a warning which is a big deal right kingbun says it CDs into gcc's 12.1.0 build in the bash script but aren't the make files in GCC without the build no the make files are generated by the configure this is correct I promise I'm pretty sure siraid said it works he may have done it by hand but I'm pretty sure he said uh tooltrain.sh worked for him that doesn't mean it works for you I'm not saying it's your fault sorry it says it works on my end so we got Windows confirmed and Linux confirmed because I built it yesterday charade says both toolchain.sh and By Hand Works legendary so let's try and help King buns what do we uh what do we think is going on it no rule to make Target how could that happen in make how could that happen in make so you're down here you've already configured that the configure script didn't make the proper targets maybe it can GCC string may have been set wrong I don't even know I'm trying to figure it out so I'm gonna take a while so let me look up let's just bring up this and uh yeah we can do this one sec yeah in my GCC build directory there's only a config.log yeah that would be the issue then so the configure didn't run probably didn't pseudo the bash script yeah I shouldn't need to shoot it shouldn't need sudo but you can try at your own risk I wouldn't I don't think it needs it unless a charade has something to yeah sorry it says you don't need to pseudo it that's what I was thinking as well uh so let's see make no rule to make Target stop so why would configure not be run sorry it says I'm building GCC right now so the instructions are working all right that's good that's good uh King buns can I recommend something just try and run this configure manually maybe tool chain dur like maybe PWD or dur name is different on your system and it didn't work uh how it's expected which is fine it's kind of expected but uh so maybe this tool chained replacement didn't go well in this GCC string may have not gone well as well so try and run the configure script by hand so what that would look like is you could go into the uh into the lenser OS tool chain and then you said you already have the GCC build so you can just CD into the GCC Dash build right wherever that is and then once you're in there you can do dot dot slash 12.1.0 configure with all the options so it says except that I changed the GCC version from 11.2 to 12.1 in the hand instructions nice yeah that's just because I haven't Rewritten them I could honestly just do a search and replace but yeah you should be able to configure by hand really make sure to get all of these arguments they're all very important and you may have to set Target and prefix and figure out what they are it's not going to be the easiest I I'm sorry but it's definitely doable and you could run the configure script by hand like that and then see if that works or if the configure script is spitting out errors that aren't being shown by the toolchain.sh siraid says you didn't escape the past shame on you oh no And by you I mean lands it always from always surround shell expansion with double quotes otherwise it'll break if pass contains spaces that could be king buns's issue then that could definitely be king buns's issue because I didn't do that anywhere I don't uh so I just copied verbatim the the scripts from OS Dev the little bits and then I made them into this larger script like I collected this from one page this from another I actually wrote that myself all the downloading and extracting stuff but this stuff where you configure and make bin utils and GCC I just copied it I don't trust King bun says my paths most definitely never have spaces oof okay so it's not that so it says so you should really do something like this yeah probably sorry so it's time for another PR then I'm pretty sure my shell script linter will scream at me when I open this file probably by the way it's completely normal to have this take a long time it's uh it's a lot of files in case you didn't know like if we look at it so far foreign Ty 76 000 files and 4 600 folders and there's more so like I said it's a large extraction it takes a while charade says you can do tar xvf to see a progress report that way you know it's actually doing something that slows it down tremendously because all of the files it's extracting are tiny they're like a kilobyte they're all the test cases and like that from gnu so the thing is by printing out or taking the time to print out each of the file names it takes longer sorry it says extracting took five seconds on my system with xvf good for you good for you I'm Jelly I I wanna I won't lie so it says I always do xvf and I don't think it's that bad to be honest when extractions on your system take this long there it's that bad it's a big difference it used to be like 45 minutes that's also when I'm SSH into a server oh Christ again 10 year old Hardware gotta go easy on me boy King bun says what flags does that enable um extract verbose and here's the file that you're about to uh here's like the archive file that you should extract that's what Dash f I think Dash X actually puts it in exit mode not extract so the dot Tara XZ alrighty we are we are halfway through I'd say the extraction of GCC we're running the shell script on the left that I wrote takes a long time but uh it's much easier than running things by hand if we were doing things by hand we would be right at about this step you can also find the stuff on codeberg or GitHub all these files are up there this is the readme.md and the tool chain subdirectory of lenser OS charade says I'm pretty sure Dash X is extract but I could be wrong we're programmers we figure it out uh Dash X Dash X uh there's no depth checks oh here it is Dash X extract we did it you are correct yep extract update list add replace create I don't think I've ever used anything other than c and x what do these do what does add replace and how is it different from update foreign why are there hashes hmm suspicion yeah here's here's what I was remembering it's Dash Z that's the one desk J for XC is that really true amazing there you go and that's tar sorry it says I always do cxvf and zxvf for tar.gz files nice czvf nice both c and x at the same time doesn't make sense though I was wondering so create and extract yes oh man alrighty but yeah this is doing a large thing we are basically extracting all of the comp hey we did it hey that was perfect timing we've extracted we're done extracting we are now downloading gnu compiler collection prerequisites how about that libgomp libma prefer libmuka what is that lib MPC or is that lib impica it's not really a a usual Sim syllable but muppafar is definitely one of my favorites libgomp always just makes me think of Super Mario 64. all the uh bomb hey so now we've patched GCC now we're bootstrapping the system root now we're configuring the new bin utils so we just uh blasted through a couple of these steps and we are now building and installing gnu bin utils so again gnu bin utils contains things like R the archiving program uh LD the gnu Linker things like this also I really have to fix how all these are written this is horrible uh I should just write them in latex provide PDFs Serene says all right I'm done rip yeah I'll see you in four hours when I'm done King bun says checking Target system type invalid configuration x86 underscore 64-lenser OS lens are not recognized running manual config I get that that means the patch wasn't applied to your GCC you have to patch your GCC then because to recognize lenser as a Target you have to patch the source code I'm so sorry King buns I wish it was easier for everybody but something as complex as an OS is just inherently going to be rough rpwh says Yeehaw what's up rpwh how's it going thank you so much for tuning in so right so stats are in general hopefully Discord still works my CPU is beginning to burn we haven't okay we've dropped frames Panic okay we're fine we only dropped 700 frames we're good we're good fam kingbun says yeah no worries that makes sense but I'm so sorry but it seems like the patch was not applied so if you run patch with all the the files that should work and make sure you you switch it to 12.1.0 because 11.2.0 King bun says I'm learning a lot I'm running the patch now nice and make sure to switch everything to 12.1.0 the 11.2.0 patch may not work it's been literally like a year since I've tried it we switched to 12.1.0 right when it came out in uh what was it July oh no negative 60. La Mao yes even though the first one here build stats extracting venue Tilson GCC five seconds bruh that took me 10 minutes configuring vineyutils one second pretty much you you didn't include the CIS route building Ben utils because it's probably a millisecond building bin utils 21 seconds that's where we are right now are we building GCC I think we're right at the end of bin utils in the background now yeah cr.o so we're we're doing a bunch of compilations okay now a bunch of compilation and linking object copy hey strip new hey elf edit hey address to line ran lib strings oh I just closed don't shake too hard pretty good so that's all happening in the background this took three minutes for suraid and it's been it's been it's been a while it's been I'm pretty sure like 20 minutes for us King bun says reversed or previously applied patch dissected but assume Dash are no what do I enter here lamal I would enter no so that means maybe the patch was applied you'd have to either re-extract JCC or you'd have to and reapply the patch make sure it's again 12.1.0 and not 11.2.0 the 11.2.0 uh patches may have been nuked in a commit on accident thanks to emacs before save hook untabifying things which I fixed last yesterday in 12.1.0 but I didn't go back through the old the old patches I'm so sorry I wish I could help more but I I also have had that exact error message happen all the time during development but it basically just means that it's trying to apply the patch and it's going hey the the changes that we're going to make are already there did you mean to make these changes to the other file instead Is It reversed do you want to apply the patch to the source instead of the output okay we're dropping more frames we are now building GCC or maybe configuring it either way my I can hear my computer ramping up like a jet engine the system I used to build it oh my yeah I don't I don't have I don't have this oh this just hurts my soul I just I King bun says apply anyway no yes two out of two hunks failed saving rejects so that looks exactly like the the problems I was getting yesterday and it was it had to do with tabs and spaces I'm so sorry but that exact error message would only happen oh my that exact error message would only happen when uh the patch was already applied or if the patch has an invalid path so if like GCC 12.1.0 if it's trying to patch from a file that doesn't exist it'll go hey I don't know what to do me oh no encoding overloaded can you still hear me chat ground control to Major Tom are you there oh no sorry it says we can still hear you oh good good good good yeah this is uh It's Beginning this is what building a very large gnu project looks like by the way it's endless checking for this checking for this checking for this checking for this charade says building llvm is way worse than this by the way I know I can't do it on my system it's physically impossible I don't have enough RAM sorry it says it takes like 20 minutes on my system that's it llvm is seven times slower than GCC confirmed because it took three minutes right hey feel free to move on to the next step if you have the tool chain built if you're uh computers faster than than I I'm scared to use emacs at this point I don't really want to mess with anything because I keep getting encoding overloaded messages and uh I haven't dropped frames yet but it keeps saying encoding overloaded we're doing good siraid says building took two minutes 30 seconds oh my God I'm pretty sure we've already done double that checking whether this printf is declared config.status creating make file so the general build of GCC is build everything there's a lot of stuff by the way you see all those warnings that just happened yeah it's a killer when those stop the compilation that's why we disabled W error disabling native language support may be a bad idea if you want like German or Japanese or any other language output but uh it makes it about 20 times slower I'm not joking I tried it once I it never finished I gave it a day and then I was like yeah no sorry it says it also doesn't help that you're running this in Emax Emax is not a particularly fast terminal kingbun says each element that might be slowing it down too maybe from what I've uh experienced eshell does lag behind but it doesn't actually halt the program it just it takes forever to read standard out so you're seeing like old output it's taking a while to print it but uh the actual program I've never seen slowed down we could do tests we should do tests because I'm I've done this for a long time I've done it both in Windows terminal and eshell and I've never noticed a margin like a difference but again that's not benchmarking that's just me noticing things and I'm not I'm not one to known to notice things uh it looks like when we just okay so we just built a lib and now we're starting to build another you can tell because it changed from all the the command line commands to checking for blah blah blah so we are now configuring another dependency or part of GCC this may be checking for Pearl checking for PDF to HTML oh no checking for package config an uninstalled package config Dash I so it says if you're using an old compiler that'd slow it down too right so it says by the way what compiler are you using now so what compiler you use to compile GCC is uh is a big one sorry it says I noticed a huge Improvement in build times going from GCC 11 to 12. so it says I use gcc-12 and it worked on Linux if that works that's dope I couldn't get it well I guess that was like months ago when I tried it was in July I tried in July to use GCC 12 on uh windows and everything went horrible did not work sorry it says why wouldn't it I got a bunch of Errors I don't know it just uh it would not it complained about uh like CIS root stuff like the CIS route wasn't working I couldn't figure it out I'm passing I'm passing I'm passing with sis root to the configure but it just would not work it kept in trying to include Windows headers when they weren't in a freestanding so right says Windows problems oh yeah it was Windows specific for sure Linux usually has harder to track down problems but they make more sense Windows is just like oh it's just because it's Windows Linux is like well there's actually this really complicated problem behind it this was just our solution I know there's problems but this is the best we could do on Windows it's just like yeah let's just uh we don't do that why I don't know King buns the story of his life when replying to Windows Problems by siraid oh no oh no I'm gone I'm gone no can you hear me stream buffering or is it just me uh can you hear me please I'm so sorry the stream is dying my CPU is burning alive that's right it says back now hey can you hear me I'm so sorry it went down to zero we dropped all frames for like 10 seconds this is so bad oh no oh I'm gonna take a picture I gotta show this foreign ever tried to use like Discord in a browser and attach a picture on mobile I'm back I'm so glad oh I'm gone okay 3 400 dropped frames and Counting it's going up oh no okay oh no it just went red again okay I'm back sorry it says you're gone for like 10 seconds yeah cool now this is so bad this is I'm just hoping it works I'm just hoping it works oh no Kingman says frames never heard of her okay we good again we're back to configuring oh no we oh no foreign oh no my phone died it's in my hands and I'm typing on it and it dies I was trying to send you guys a picture of my uh my dropped frames how they just it has begun so right it says do make-j Purl Dash e print and proc Dash print n proc minus one next time to leave a thread for the stream lol and yeah I just used Pearl in a shell command because I can't think of a simpler way to subtract two numbers but I was wondering can't you use a exec or a test or something I remember doing that in bash a while ago yeah that's a better idea I'll have to alter the uh the tool chain I'll make a stream toolchain.sh that leaves some some goddamn threads for the uh for the stream hell it's dying again oh no okay I'm back that we only dropped a few hundred frames oh it's gone again are you there it went red and it's back green it's back green we good we good oh and it's red again this is like the the biggest roller coaster of my life and I'm sure this is gonna be the the least popular stream in existence it's literally just a terminal I just I'm laughing at how uninteresting what I'm doing is I'm staring at a terminal just running a program but I can't do anything because my computer's dying so there's just nothing I can do Matt sorry it says I think uh in parentheses in parentheses and proc minus one or something like that works in bash but I usually use Pearl for arithmetic because arithmetic in bash is awful and easy to get wrong that's right it's not arithmetic it's arithmetic King bun says bro I'm on my way to get some of what you're smoking I need those Giggles in my way uh just get really embarrassed you'll you'll you'll be great at it this is nervous laughter this is not laughter of joy oh no sorry says by the way I know you like your toolchain.sh script but how much would it upset you if I made a cmake script for this instead it literally used to be like that and that way we'd have one top level cmake script for everything or maybe you want to do that I don't know I do not want to do that there's a reason why the kernel is in cmake and everything else is separate but you'd have to test if it works that's fine if you make a branch and I can clone it that's totally cool that's kind of sorry it says which is simpler for me to do just saying feel free to do it make the top level cmake script if you feel like you understand it but I warn you it's already very complicated just I'm like look at the kernel cmake script and you will understand like okay there's a lot here you know what I mean there's uh it's sorry it says test if it works means you'd have to build GCC again oh I know I do this all the time that's why I know how long it takes it takes so long oh don't zone out emacs no Jesus Christ oh no I'm dropping him no can you still hear me I'm dropping frames boys I'm going I'm gone oh no 15 frames what are we gonna do what am I gonna do average time to render frame is 30 milliseconds this is Diet this is going so horribly I love it sir it says you're still here hey but yeah I do this all the time I have about 10 lenser os's just on my system right now and they all work I don't know why but I just have to make a new one to test it and then I don't delete it and then every once in a while I go back there and I pull and I I do everything there sorry it says casual 470 lines of cmake I've seen worse you can imagine if that warning we just got made us fail by the way oh it's going bad again oh no so many dropped frames oh no oh it's oh it's very bad oh it's very bad you're gonna run a run out of disk space at that rate lamel I literally have hundreds of gigabytes of Windsor OS it's horrible it's an addiction at this point oh no 15 FPS I'm so sorry boys this is going bad frames missed due to rendering leg 4 000 skipped frames due to encoding laying four thousand eight thousand one hundred and ninety two dropped frames oh no that's like over like over a minute isn't it oh no kingbun says lenter OS is bigger than my porn folder oh sorry it says Ah you know you're doing low-level stuff if you have to use the dash M Flags oh yeah oh yeah the dash lowercase M flags are scary man the documentation on them is horrid sorry it says other than MRH equals negative that's the common one yeah that's true people would like to do that and be like look I'm I'm optimizing it it's fancy it's like well yeah it's faster that's it build a Canadian cross compiler and then and then get back to me we're doing a Canadian cross right now I don't think you can hear me right now because everything is red on OBS and it's screaming at me it's saying please stop uh but hopefully you know hopefully it's going well hopefully I'm not just silent historian says also your kernel cmake script can be as long as you want it to be La Mao so right says I'm just gonna do add subdirectory LOL and we can hear you just fine all right that's good that's good everything is red in OBS it's just everything's red it's bad we'll tell you when you disappear again bless I appreciate it I'm gonna need it it's everything's just constantly red now that's really funny oh my this is so bad just everything's red it's so scary this is everything I don't want to see as a streamer OBS is screaming at me encoding overloaded consider turning down video settings or using a faster encoding preset FPS is 20. average time to render frame is 30 milliseconds and there's 20 000 dropped to the network there's 10 000 drop frames due to encoding and 10 000 skipped frames due to rendering this is the worst me this is literally the worst it could go this is so awesome I mean I guess the stream is still going it's not the worst that's right it says 30 milliseconds per frame is more like 30 FPS I think average time to render frame 45 milliseconds 117 milliseconds jumps around 115 38. 32 plus the FPS is also stopped by rendering and coding and uh Network King bun says bro streaming from a toaster basically at this point I should probably have a fan on it's going bad all right you ready to see this boys okay I'm taking a picture one sec oh no foreign I always find it funny to just sit there and watch it when I build big projects LOL I don't what's b top I'll have to look into that also suraid in the Discord you said I love my CPU I love your CPU too I wish I could have it pretty sure you can just do sudo apt install b-top and WSL if you're interested y'all get right on that as soon as this uh compilation finishes you know I'm pretty sure if I try to do anything like I haven't even clicked out of emacs I'm scared to do anything I'm pretty sure it'll break my computer the CPU is most definitely just at 100 usage but I don't want to open task manager and find out that's what's classified as around if I don't want to find out I don't want to find out rocks is still compiling bro oh yeah oh yeah we're still going I I told you it's going to take two hours while we're streaming I'm not I I have an idea of how long these things take so it says I put a screenshot in general okay I'm gonna try I'm gonna alt tab into Discord yoink criminal switch OBS oh boy udes oh that's nice is that it do you see how slow this is this is really pretty that's really nice I'll have to try this ruark says okay I'll be lurking for another hour I guess yeah no we're oh we're almost done this okay we're actually almost done here's another a screenshot very nice should try this out this is really cool is it gonna like leak my IP is there any networking thing ignore my RAM usage oh no 22 gigs okay we're actually near the very end of the compilation when you see this Echo time stamp this is one of the last thing that has to happen I don't know why it takes so long but uh sorry it says it'll only leak your local ipu all right then we good then we're good as long as ipv4 is fine oh no we're dropping more frames oh no that's right so you can turn that off though I I we'll take a look how long did this take by the way I'm pretty sure it took 40 minutes right we started like 20 minutes into the stream with this tool chain.sh that was a 45 minute compilation there's not much to do after this this is why I'm saying this look at my CPU number by the way it's all the way up at seven I've never seen that have you seen seven for the CPU usage in emacs that's insane I how high did that number get I just recognized it it may have been higher before that's insanity oh May okay we're dropping more frames encoding overloaded the dang CPU I'm just happy you're still going I'm happy you're still going we're doing it so at this point we're all the way at the bottom we are making all of these GCC targets and I'm pretty sure this Echo timestamp is one of the last things to do in install Target libgcc as you can see libgcc is what we were building so hopefully all we're going to do is uh after making libgcc we're just going to install them and then we which is basically just copying files takes like 10 seconds and then we go and hopefully at some point my CPU will will relinquish control back to me and uh we will be able to do things once more just to see how slow Discord was I've never seen that animation lag just for opening an image yep there's our big link that was taking the long time we have little bits that we got to deal with now Liberty what is liberty for I always have fun saying it libgump Liberty Liberty what I don't know what LDL is that's probably something I should know sorry it says I usually build llvm with 30 or 31 threads rather than 32 because of that oh nice nice yeah here's it it's doing all the installing beautiful stuff you can see all five make threads make jobs happening there what are we doing now okay there's more No it should be done really soon yeah we're oh we have to compile libgcc with no Red Zone due to x8664 so we're compiling another version of libgcc that way we can actually have the uh the stack not killed so it says because if I don't I can't use my PC for like 20 minutes yeah that's where I'm oh we dropped many frames again foreign like every five seconds my OBS just everything turns red the bitrate red for FPS red average time red CPU usage red and then I get encoding overloaded warnings OBS is yelling at me also we're on 3.6 megabytes of standard out that's a good point that's incredible I think we're going to get to 4.2 just run like a token on it Toki what is it called so it says or million lines I don't know that's definitely megabytes you can see the amount of lines here on the left 13 000 lines and this is like this is without verbose on can you imagine if we had verbose on can you imagine if we had verbose on I don't even also we did it it's done oh my God chat it happened yay give me a Pog champ we did it that took like 40 minutes oh my God that was rough sorry it says yeah three megabytes of standard out just sounded so absurd that I had to do a double take little pug 3.7 megabytes should have timed it that's true hindsight is 20 20. well there's that done to uh ensure that it works you can uh just test out in here there should be a bunch of things see all these are executables so we can test out G plus plus oh look at that 12.1.0 oh look at that sorry it says no problem that you didn't time it oh you're the best right thank you just do it again in time at this time oh no no you had me in the first half not gonna lie may also Daniel B with a Pog champ shout out Daniel B thank you so much for being excited because I'm excited but yeah we have everything here so now we have the whole gnu tool chain for lenser OS uh so if we do something like what is it don't machine it's not dump machine what is it I don't remember what it is maybe that's not the uh G plus plus is that to the new tells I don't even remember anyways we have a cross compiler so what does this mean we built this compiler on Linux and it also runs on Linux does that make sense so Linux is where it will run Linux is where it was built and then the programs that this compiler will compile will run on lenser OS does that make sense it's a little confusing I know there's three separate things which is Target host and uh build it's GCC Dash dump machine duh oh rip I never do it there it is look at that it's correct it's not just the name of the executable it's actually what GCC thinks the machine that it is on it is on lenser OS baby oh that's so good to see by the way that's so good to see we did it we have done it it works we built an entire tool chain for lenser Os from scratch patched with by the way I included this Auto dereferencing dot so in C when you use this compiler the programs that you compile can actually use dot on pointers to structs or unions so you can have like struct Foo with stuff in it right and then you can say struct Foo pointer equals new Foo or whatever let's call it C plus plus and then guess what also I think I have to do that all you have to do is say Foo dot stuff whatever's in here you can just use the dot it doesn't matter it's Auto dereferencing ain't that cool ain't that cool little patch to GCC do you want to see how simple that patch is by the way can I open read only find file read only perfect I don't I just don't want to screw up the patch in case you didn't couldn't tell uh here's the patch here it is in GCC that makes it so that dot can be Auto dereferencing it's a complicated diff it ain't it that's it right there Isn't that cool I just think it's so cool how something that seems so complicated like Auto dereferencing is like this diff Roark says wait we are done we actually are partially done we're done with the tool chain so now we can as uh you can see we can run our tool chain we got the version it runs it's it's a it works get the works so now we're done with the tool chain and if you remember from way back when we came here from here we're supposed to be building the kernel ruark says 13 for 546 lines I like that yeah yeah that's where we at that's where we at baby it was also 3.7 megabytes of standard output how do you like that serrade says also seeing as you've implemented a mini lib C in lenser OS I sort of feel the urge to try and add some Cindy optimized mem copy implementations Etc yes sorry that would be sweet that would be amazing so right that would honestly be so cool having an optimized mem copy is like well and since lenser OS is x8664 only that's like that's perfect that's literally perfect Rourke says holy yeah yeah it was some it was some some killer some killer Vibes anyway this is where we were if you remember we were just building the tool chain once the tool chain is usable continue on here boy that took a while I recommend taking a look at config.cmake and seeing what there is to fiddle with but going with the defaults is just as well let's take a look also I can use my computer again yay so the kernel has a configuration charade says compiler intrinsics time hey as long as it works it's GCC only so who cares I mean the the kernel itself should be able to be used with clang as well I'm pretty sure it says uh or assembly time I guess of compiler intrinsics don't work but I'm assuming they do yes we still have all the compiler intrinsics of GCC we have we should have all of them so it says the intrinsics are an Intel standard we may not have them we may we definitely may not have them I don't know if they work on Linux in the Linux kernel then I would assume they work in the lens or Os kernel because the GCC setup is very similar that's the image Trend header and Friends I immediate intrinsics okay King bun says at least this wasn't rust compile times it's true it's true it was only like 40 minutes how bad is that you know really uh so what this says is settings and options may be set during project configuration like so you can use again your regular cmake generation command but with Dash D and then the option and then equals to whatever you want to set it to so this will eventually allow us to change architecture which I don't even want to think about doing nothing would even know you can set the machine to vbox this is because virtualbox is very buggy and has a lot of issues where like the hpet timer doesn't work at all but in qimoo it works fine so if you're using kilimu go ahead and change list Q email I recommend that heartily but uh feels like vbox and if you're wondering what you can change it to there's a list here in case you were curious sorry it says didn't I show an example of me using AVX intrinsics on Discord the other day of memex or 32 in my networking Library that's right you did with the 256 byte operations we talked about that you can hide the uart color codes so if your terminal doesn't support the color codes and Escape sequences the output looks horrid because it's just riddled with Escape sequences that's meant to be color so you can hide the color codes uh by default which means that there's actually no color in the output and then kuimu debug which starts killing me with dashes-s flags halting startup until a debugger has been attached I use this to attach GDB to kiwimu and then you can actually uh debug your kernel as as it boots up which is nice so right says I routinely just put Escape sequences in the source code LOL I did and then I wrote a function that removes Escape sequences and doesn't print them so it says also here's the function I was talking about I'm gonna check it out I click on links from survey I'm a simple man uh-huh okay so oh boy so if you have ABX we do have ssc2 and AVX but it takes a while for us to set them up in the kernel so you'd have to make sure that we actually set up sse2 and AVX using CPU ID I think we have to do some complex stuff in kernel stage one like the middle of Kernel stage one is when we actually set up AVX and SSE and enable them so I mean that's definitely doable I don't think we even do MMX I think it's so old or just nah fun fact if the memory isn't aligned properly for simdi it's seg faults that's true oh man AVX 512 I don't think the kiwimu supports AVX 512 but we have AVX at least with 128. cool this is very cool but I think something like this definitely may work in lenser OS there's just gonna have to be a switch where we use one mem copy before k-stage one and one mem copy after or after a certain part of Kernel stage one okay let's actually build our OS huh we can now just use cmake so let's do that so we can now go back to the top level I'm also just going to clear a little bit and uh what we're going to do is run exactly the command that I see there how about that that's right we got to use WSL don't be dumb like me uh I probably have to remove the file the folder now yeah uh remove dash RF kernel slash build that's scary BB kernel move Dash RF build cd. that's better uh cmake Dash build blah blah blah WSL no cmec 3.2.0 is or higher as required you're a running version 3.16.3 no uh if this work we're gonna try it did not work it's probably waiting for me to enter a password but it didn't flush uh like that okay so we're gonna go to a real terminal King bun says WSL pseudo lamal uh pretty much so CD dot dot okay so I was like I thought I knew it cmake is already the newest version well that's a rip ah also reminder to try installing b-top if you're interested it's a good idea I'll just do it okay bye guys I'm pretty sure me switching you guys unable to locate package b top perfect what is beat up it's this thing in the Discord you should check it out this thing it's very cool it's like h-top but fancier lamou so many drop frames it's so bad three to four browser windows with 30 tabs total oh Jesus Java moment what is our issue cmake 3.20 or higher is required what was the original I could not find something using the phone named blah so everything's going fine in WSL except for that we don't have a high enough cmake version do we have to build cmake I don't remember how I did this C9 3.20 when did it come out I don't even know just change the cmake version well that's what I want to see what they add why do I why is it set to that we'll try it I'm pretty sure we need the newest version I don't know it unknown command C make path yeah there's there's the kicker also you can just download the latest cmake binaries for Windows we're doing a Linux build uh cmake.com download so it downloads I can never remember cmake okay it's apparently downloads the dot org it's probably.org yeah download we did it okay what do we do uh-huh so can I download this on Windows does that make any sense what version are you using in WSL how do I even know foreign how do you know which version of Ubuntu you're using I don't know what command to run figure out what WSL is I'm pretty sure I just clicked the Ubuntu on the stupid windows store I've gone there once so this should be Linux Source if we just get executables we should be able to run them this is binary distributions run LSB underscore release Dash a why do I not trust that it's just it looks sketchy what am I releasing Dash a looks like an all flag it's a little scary says yeah it's safe trust me Kappa oh man it looks correct it looks correct I usually trust Serene but uh when I see release Dash a it weirds me out a little uh we did it it's 20.04 LTS horrible we should just update Ubuntu on stream foreign says okay you're using the older Ubuntu version I mean it's it was the one that came up maybe specifically install the 2204 app on the Windows store it might be easier that sounds like a yikes okay also you can't update the version what does that mean you'd have to set up WSL again that's fine I didn't set it up really and I know how annoying that is I just I literally clicked one button and that's all I've ever done Lando XD said wait lens actually read my suggestion after about six messages wow I'm sorry there's so many chats going on right now Lando XD says can't believe I nearly missed the stream I have cmake 3.22 on Ubuntu WSL are you using 2004 or 2204 sorry Lander your name is the same color as Sir AIDS I literally thought you were the same person it's exactly the same color we're just copying uh some stuff in the background right now don't worry about it perfect that thing uh Slash Mount slash d slash program bin slash cmake pretty good uh cmake Dash G units make files dash s kernel Dash B kernel slash build we did it yeah blender XT is that better he changed his name to bright red that's much better actually that's nobody else is red right now Roark says lender should add a chat box so he doesn't have to read all the chats but then what would I say sorry says it's written in C plus plus so just run make Dash J sorry it says oh and that was also unrelated but you can download b top and build it manually let's do it roarx is not all of them though I mean read them out loud but then what would I say lender XD says well he still needs to read them to get our ideas exactly I don't have any ideas sorry it says please just Alias that to cmake LOL I'm good build b top in a proper terminal though all right we'll use like Windows terminal I'm pretty sure I can open WSL in it is this an insult C plus plus it's not actually they have really fancy build output with colors and everything I mean eshell supports colors I just type the URL of the lender OS git repo and forgot to type git clone you just open it in the browser ruark says Windows terminal it's better than CMD are you kidding me blender XT says do I have dementia Maybe were you here for the 40 minutes where we were compiling a compiler it took so long okay so we now have done it we can now run cmake Dash build dash dash build I should say about all this configuration crap and uh we have to specify a Target as well if you uh didn't know so our Target I'm pretty sure if we just do this it'll tell us the target huh here's all of our targets you can see each file gets its own Target so you can build each file individually but you can also you see there's some some things here we have image GPT image ISO image Raw how about that hmm how about that uh so what this is is basically the OS is now able to be built but building it just gives you an executable so that's not that helpful really when it comes to an OS so we have these uh targets to specify to actually build boot media in some certain way so GPT stands for good partition table ISO means make an ISO a disk file and raw means just make a bootloader like raw disk file with everything that lenser OS needs pretty sure I should go image GPT says okay it's better than CMD but both of them are windows not like this I'm sorry for hitting on Windows but it's Windows okay no need to be sorry Spirit there's no need to apologize for hitting on Windows exactly Roark says okay that now and look we've now generated this hard drive which has a start LBA and end LBA by the way I wrote the program create GPT I wrote this program I had to isn't that fun Lander XT says how can you be a C C plus plus programmer and use Windows uh stubbornness Rex is right but look we did it we built the target it's a 48 megabyte hard drive boot Drive I should say this is so bad they made WSL to literally run Linux I mean you're not wrong so look at that look at that GPT stands for good partition table ISO stands for make and ISO I see how it is you don't know what ISO stands for no International suck off I don't know that's not that it's not that Rook says ISO stands for ISO that's correct brewark knows what's up ah so as you can see we now have an executable which if we look at we can just say what are you and you see it's literally just an elf 64-bit executable because that is what we built in our bootloader in the lens arrest bootloader we built an elf executable Builder like Runner it loads and executable and runs it in the bootloader and this is what it does and then that's been encoded into honduras.bin that's the lender OS top-end not kernel that man I was like what that doesn't exist and you can see that it is a Dos MBR boot sector so this is a fat 32 good partitioned thing which has a start and end here blah blah blah with an extended partition table at the end how beautiful is that Sarita's tell me about it compiling my stuff for Windows is the bane of my existence sometimes especially networking code yeah networking code on Windows can die in a hole so you can see lensaros.image this looks like it's the actual FAT32 itself uh disk so this is the actual file system just raw in a file 48 megabyte file system with the lens OS executable the fonts that it needs stuff like that ISO files are international organization for standardization apparently iOS what lender said surely that's iOS though that's what I was just what are you sure press X to doubt thread says no.iso the internet says ISO it is ISO but International Organization for standardizations iOS the file format is literally named after the iso limo you mean the iOS the ISO file format is named after the iOS the organization for standardization lamou and its International standards organization Omega Scenic do I have on Windows I have a good seat let's try and do the same thing don't think I need quotes yeah what happened could not find CMA compiler so I'd have to build it for Windows that's fair in any case I should be able to run kiwimu uh somehow so Scripts run hda.bat okay so we have we have where we've arrived this is going to try and load ovmf and from lenseros.bin which we did do so all we have to do is run this little batch file so we're just going to take you here we're going to say Scripts onehpa.bat it's been so long since I've done this oh my God it's working chat chat fog oh wait wait oh hey we did it I'm loving it we did it chat this is Linda OS we did it oh my God I didn't know if it would work but we did it chat we did it lender XT says what I know we did it it only took an hour and a half charade says it's only chf-138 oh Christ which is like 139 dollars Roark says the boot sound POG champ we're OS fog champ that's right it says bog yes do a barrel roll this is so awesome welcome all to Windsor OS uh that's a big nose so good also it's I don't know how to fix this bug if anyone actually cares when I press the down arrow it disappears please tell me why it's so confusing every other way works left right up but down and it disappears and then reappears you can hold up you can hold left you can hold right by holding down no it's taken so long for me to do that okay uh along with typing all the ASCII characters do not try to type something that's not ASCII you may break things uh by typing ASCII characters you can get uh everything we have some symbols which were hand coded into the kernel most likely your down arrow code is just slow okay is that a challenge is that a challenge no I'm kidding let's take a look at it uh yeah keyboard.cpp or sir so when we draw the cursor here here it is it's right at the top of keyboard.cpp also yes egglet I understand please shut down all you're gonna freak out at this Lando XD says I have an idea rewrite it in Python that'll be faster yeah we'll just Port the entirety of python right on over to lenser OS foreign also I'm really happy these are staying aligned that's good you can see that since we compiled with vbox oh I have I have colors I forgot I can draw with the mouse oh what should I do I don't want to go against the toss I can't I can't be tossed lender XD says yup makes sense so even lens OS users can experience slow code lamal uh what do we do let's Draw Something so this is just using a very simple drawing mechanism every time you get an event that the mouse moved to a position we just draw a box there and if you right click it randomizes the color using a what is it linear feedback shift register randomizer and you can make uh just crazy things keep switching colors I like going outside so you just make it a little layered foreign oh yeah this this guy's looking nice I'm gonna give him a nose his nose is going to be all the colors oh no how about that so it says draw the C plus plus logo LOL I don't even know what that is I'm uncultured lender XT says copyright contributors to lenser OS you act like that's not just you and charade that's literally not Lander you you are a part of that you you are one of them this is yours just as much as mine according to the license which means we're never re-licensing because I'm not tracking all you down for a real license so hopefully GPL V3 remains legally enforceable or any later GPL I think we have GPL V3 or later it says built-in support for dotted lines nice yeah Lindo XD says my incredibly rough licensing code you needed to fix in seven separate commits pretty much listen your code was not bad I want to it I do want to iterate on that your code is not bad at all the reason I had to change most of it was because of an OCD thing and I was like the the C plus plus comment style isn't uh we usually put stars in front of all the lines right but there were no stars so I just added the Stars that's pretty much all of the commits the other ones were just like uh the shell the shell files and stuff in subdirectories that you missed like the storage and memory subdirectories so we basically what do we do cursor down uh keyboard scan code translation hey look ASCII uh this is a really good idea I gotta use this pattern more this is like a map but a static map that's easy to initialize in C plus plus I gotta take my own ideas so we translate a scan code where do we actually call Translate from nice search room yeah so we call translate here after handling a character so we parse a scan code and if we get arrow down we do cursor down where's cursor down probably in here so it can be inlined also ignore the errors charade says should be const experts shaking my head the compiler is probably optimizing that for you anyway but still yeah I wrote all this code six months ago or more I did not even know const expert was a thing I promise Linder XD says how do I deal with being famous I have one GitHub follower foreign that's funny that's really funny uh I don't know you're gonna have a hard time man it's really troublesome so if size and character is y minus amount is less than it seems like this is wrong so if the size and characters minus the amount we would like to move wouldn't that be cursor up am I insane how does this code make any sense if amount is greater than cursor position what no no okay kill me if I I know I wrote that kill me that doesn't make any sense I don't think I'm surprised it works so when we go to the bottom I mean it just stays at the bottom if we go to the top it just stays at the top I don't know how this works that code is so you don't underflow the cursor I see I'm getting it now I'm getting it now I easily don't go up more lines than there are I'm yeah so cursor up means y goes down because we're top left coordinates that's what was getting me I was like wait how is cursor up aren't these backwards I was like doesn't this have to be here but yeah cursor is going up I mean why their y position goes down so if it's greater then it's just going to be set to zero this makes a lot of sense now cursor down we basically say if the total size minus the amount is less than cursor position okay so that basically means that at the very bottom minus how much we want to move if the cursor position is uh in between that then obviously we can't move that far down we just go to the bottom so that's what that does it caps us off at the bottom okay this is starting to make sense I just looked at it like how does this work this does not seem like it makes any sense same thing with left and right so there's cursor down uh which is called here so after we do that we break means Gotti zero equals false and then we can pop out to here so it says also I like that you're using u64 Etc yeah I did I did like it the problem is that if you want to make some I did I used u64 where I should have used you size you know what I mean I'm pretty sure we have it in integers.h yeah so here you can see all of our integer declarations also I don't know why I didn't use a type def yeah you size is good to have we're just going to add it uh I should be using usz more I really should too s64 though that's a bit cursed honestly why I prefer I-64 how does that make any sense to you so you have a signed integer and an unsigned integer and you're going let's abbreviate them yeah this makes sense let's abbreviate them I-64 and u64. let's use this one and this one why why you and John Blow are the only people I've ever seen use s64 everyone uses I-64 why if you can explain to me why this would be I-64 why do we use int instead of signed and unsigned they already start with different letters just use them unsigned uh signed uh sorry it says because it makes sense it doesn't make sense this makes sense it's readable signed 64-bit integer is implied unsigned 64-bit integer that's how you'd say it it's how you'd write it it makes sense this is like integer 64. how does that make any sense lender XD says it makes about as much sense as my life you can also use int and in64t and not signed and signed 64t true signed as the default that's why it just says I why do you have to specify I that's my question like if you're going to say oh assigned integer is the default then just just have it be like oh 64. is the that's a 64-bit into the default baby if you want to write numbers you gotta affix that lender XT says you just had nothing to say about that well life doesn't make sense none of us really have anything uh down uh yeah looking good so I really should put an upper bound on parse character I mean I guess they can only go to 255. but if this a draw cursor code is truly just too slow when going downwards versus upwards I would be surprised I tried to optimize it as much as possible that's why I have all these Vector multiplications and things like that it really helps you know optimize it so it says I don't know you got a benchmark it I was just being sarcastic bro it's not optimal at all don't forget to download and compile b-top okay again why not OS is running stable also that's today we're using the RTC correctly I'm pretty sure that's broken on virtualbox download and compile b-top let's do it I'm going to put dollar signs in this guy's eyes really quick I don't like that how about that I don't know why I like that so much but I do don't forget to download and compile b top and yes I'm going to keep using eyes even if it doesn't work on Twitch not using eyes would severely limit my ability to communicate well also it works eat the works eyes work it's a better TTV Emoji apparently I agree with you you though I I do that a lot he says just do make that Shay I've already tested it I it uh where do I download it to yeah oh by the way we didn't look at the debug output of lenser os at all look at this beautiful beautiful debug output um oh yeah beautiful so here's where the bootloader starts let's also get another WSL thing going oh no it's going to leak my IP oh no that was close oh my God that was so close it literally just leaked my IP as soon as I clicked away it literally just leaked my IP I I saved myself so fast holy it should only leak your local IP though nope this is this is definitely not my local IP it's uh I think it has to do with uh the virtual like virtual box creates new network uh new network drivers and stuff that was so close All the nervousness the nervousness uh yeah it doesn't start with 192 or 10 then it's not the local IP lol it was not the local IP oh anyway just double checking my screen okay we're good we are back oh I love uh I love little moments like that to really get your blood flowing as a programmer oh okay that was good that was good goddamn virtual box maybe it's Hamachi maybe Hamachi did it I don't even know okay so why does it even list all the your IP like your ethernet connections it's I don't care it's fine everything's fine we're gonna do a git clone I'm literally writing this from by hand because why not uh from github.com aristocratos so it says because it's a server OS that's probably why it lists the IP La Mao probably right Arch doesn't do that I gotta get Arch is there an arch WSL hopefully this is fine just in the home directory by the way I'm trusting you oh nice that's awesome this is really cool required Flags standard C plus plus 20. oh no what build system is this did he do this by hand and make is he insane oh my really nice build output okay we're stealing this how did how did this happen rip I forgot I'm not on Windows the executable is in bin b top all right it's going to leak my IP I just I have a feeling okay it only leaked the local IP I think we're good I'm still gonna how do I disable it okay you press Q to get out of it is there a way to uh hopefully this works okay so there's no non-networking stuff there probably in it huh you can type 3 to turn off the networking okay oh la Mal cool well that's dope you can see my horrible CPU specs now it's abysmal I'm just comparing it the serrades output it's a joke mate it's a joke your terminal apparently doesn't support the fancy formatting what fancy formatting mine looks fancier if you compare them what a flex goddamn charade ooh yours does look much fancier I'm sure I just don't I I have a different CPU as well foreign like bars yeah I don't have any of that what is four this is process so this would only catch processes in WSL which would work for our compilation Jesus four is processes oh no I clicked one I didn't I didn't know I could select things I thought this was oh no uh or okay just go away I'm scared so they have the C drive as the root apparently and then we have a swap file crazy two is memory and disks e coolness this is a lot the time I kind of just want to leave this up like full screen this should just be my desktop I only ever come up and open emacs anyway fancy this is really cool we'll definitely have to look at this the next time we compile and I think just running this may break my computer though it may be rough sorry it says it's nice to look at in it it is it really is can I save preset is that what that means okay there's the local IP it only updates every two seconds by default so it's gonna be fine yeah it could be do you see how much RAM is available it's not good running this while running the compilation may just it well it may just break everything what is tree well that's fun R is reverse her core filter oh you can search oh no if you have four open while compiling it's just gonna be all CC1 Plus or clang processes depending on what you use CC1 plus baby foreign that's awesome this is very cool uh I really recommend downloading and building this that's easy and fun and uh it's I'm sure it's useful very cool let's turn on color output for lenser OS let's go draw a big smiley come on give me a brighten there we go yes the creepiest smile the dollar signs foreign it's pretty good are you feeling it now Mr Krabs so it says if you're using Linux and it's up to date you can probably just install the b top package at least that's what I do uh building it and running it from source is much more fun and you learn a lot more plus I think that that build system is worth it to point people to I think their build system is really just a fancy make file if it works it works me b-top looks simple enough where uh that's okay but I'm sure the make file is horrid look at our beautiful lenser OS our time isn't that far off normally these are so hard to keep uh in track and it really depends like which one do you use do you use real time or do you use the pit most people tend to use real time and keep updating the pit based on the real-time clock so basically like every two seconds the pit timer would be reset to the the RTC and keep counting from there so it says now we want to make a build system that's equally fancy LOL I mean lenser OS fun compiler anything you want to do let's do it no it can be for anything I'm not saying you have to do it there's one of my projects I'm just saying that uh it's a great idea they look great but yeah this is lenser OS you can't do much in it can you but uh it sure is fun to open and uh play around with and look at the code see how it works and let's get our color output and then go through all the debug output uh it means I have to go into emacs and build again I think uh what do I gotta do the WSL yeah that one so I want to build an image GPT but I want to reconfigure first so where's the configure yeah that's the one I tried there we go and now I basically want to set the option remove it hide uart color codes equals off should be good can we move not found on your system image not found on your system skipping image vdi Target generation blah blah basically if you have kiwimu you can make more media and then we can run our build again with GPT rebuilding the kernel here there it goes now we're building the hard drive using Create GPT a program that I wrote it's available on GitHub I don't know if it's free and open source I don't know if I licensed it yet but I should you can see the size is 48 million bytes and we have a FAT32 partition on there which is what this guide means or you would charade says Port the fun compiler to lenser OS next fall I mean you're joking but it's actually going to be easy once we get uh an actual like user space desktop environment going down it's going to be easy because lenser OS uses very basic C or not lens or west a fun compiler uses very basic PRC with no dependencies so it's basically just going to be you know that's it it's just gonna be porting C library which filling in the details so it says time to make insert language name here the native language for this OS LOL we'll just take over yakt is what we'll do I'm gonna be like thanks Serenity OS for like building this for us we're going to use it now and you can see we've rebuilt the kernel we enter again everything's the same except for look at all this colorful output look at this we got rainbow the Rainbow Road let's take a look at all of this from the very beginning from bootloader to use well sort of user space we are in user space right now if you didn't know it's just not uh clear sorry it says nice nice nice colors yes basically the first thing that we do is the bootloader prints out a bunch of stuff and it says okay kernel has been found if the kernel isn't found on the file system the UEFI file system it'll error out here and say hey the kernel wasn't found you ran the lens arrest bootloader but the kernel not here so not sure what to do default font loaded successfully we load a font from the file system as well as the kernel executable which means that if this doesn't show up you get a corresponding error message hey there's no fun what are you doing uh then we basically verify the kernel format we make sure it's an elf file and we make sure it's executable and we make sure that basically we're not just running a text file or some other thing that shouldn't be executed then we build the uh the elf program so we actually load the kernel segments uh at one megabyte is generally the standard is that one megabyte I don't even know what that is something like that and you uh you load it there because there may be like bios and stuff or like CMOS uh data access in the lower RAM values and you don't want to screw things up down there so you put the kernel somewhere up high so that it doesn't get in the way also of the bootloader itself which is going to be somewhere so we just guessed that one megabyte and hope hopefully there's nothing important there for the bootloader again it's a very uh naive bootloader we load the the kernel because we loaded the two program segments then we have to load GOP is the graphics output protocol of UEFI every bootloader has some stage of this this is basically collecting all the data about monitors and frame buffers that you can write to and actually draw to the screen so literally at the lowest level you just get a frame buffer in memory and that when you write things there that shows up on the screen that's the deal and it says here's where it is here's how big it is anything you write here that will go onto this screen it's this big blah blah blah then we have to parse the EFI memory map so EFI is basically this uh boot environment that it's the replacement for bios if you know what that is and UEFI passes a memory map to the bootloader that says hey here's where all the memory we're using as UEFI is here's the memory you can use and not get in the way of everything so to do that we basically have to parse it and do some special stuff you see that we find a root rsdp table but the checksum's wrong so we have to find one with the correct checksum that one got me for so long there was like a straight week of getting that to work I swear because checksums are also hard to calculate or know if you're calculating it correctly uh we set up the kernel entry point which is Ox blah blah blah it's not shown here but there's actually all F's to the left of this so this is ox ffff or something like that FFF yeah ox 8fs and then this and that's basically our kernel entry point in the virtual memory because that's like way up in the memory out of the way of everything else but the actual entry point because we loaded it at a specific memory address is this which is all of that ffff FFF eight we basically just remove that section and take this lower part because that's where it's actually loaded craziness right Linker script fun and then we calculate the kernel entry point we exit boot Services which means like all this UEFI stuff you can actually allocate memory with UEFI and like do a bunch of stuff there we don't do much of that you can also set up like networking and stuff like that which we'll have to get into but then once you exit boot Services that's like you're done with uafi you can't call it anymore until you reset the system and then we finally enter the lenser OS kernel and we say hey welcome to lenser OS blinking we're like hey we made it we set up the uart driver which is how we're actually putting this debug output onto the screen this is a uart hardware chip so this is a Serial Communications Hardware driver that we initialize and then we can uh detect which actual Hardware chip we are inter we're communicating with and we communicate it to it in the proper way and then it says okay we can talk to the user now we initialize the driver which is what this is proof of and we're saying okay you're booting into it now here's where it's going to get dicey we map the physical memory identity wise in the kernels page table what does that mean so basically every Ram address in x8664 has something called physical addresses and virtual addresses and this can be like ox000 null May map to something like ox1000 and then when a the actual program attempts to access for example load byte at ox1000 this is very rudimentary but bear with me loadby.ox1000 this will actually this actually loads at 0x000 due to this virtual the physical mapping so the physical memory at ox000 is available at this virtual Ram address does that make any sense so anytime you access RAM and C or anything like that you're actually accessing the virtual memory the hardware memory you have no idea where you're actually where it is the user Space Program does not know which is a large part of the point in the kernel however we map the memory the physical memory 0 to 0 and 165 a zero zero zero zero to one six five eight zero zero zero zero so accessing zero actually gets you the address at zero this is called identity mapping and it allows for the kernel to have full control over all of the RAM on the machine ain't that fun so we can fill it with all ones fill it with all zeros we could do whatever we want and it would access one to one on the hardware in the kernel the problem is the kernel is in here right so what you can do is create another mapping to the same address but a different virtual address so now if you load ox1000 or 2000 this actually loads ox000. does this make sense and in doing this means that we can map the kernel to a really high address range it's literally like in the terabytes if this was actually bytes it's so huge right it's insanity but we map it way up in the address range so that the actual Ram can be identity mapped we can access all of it we can actually we can also execute in this other area which means that we can actually Mark all of this Ram as not executable and Mark this as executable which means the kernel is only able to run itself and not anything in Ram given to it for example by a user space ain't that cool ain't that cool and it uh it knows like it's self-evident it goes okay where am I loaded at okay so I'm loaded here so which means we're here so then we map this range here into this range here you can even see the exact section mappings where like all of our code is stored which is 88 kilobytes of code technically Kibby bytes but whatever then data read-only data and BSS we can probably get BSS to be smaller and we only lost 3377 bytes to page alignment which is good if that's bigger than one page AKA 4096 bytes then that would mean we're laying out everything incorrectly but this is pretty good layout in memory to keep everything adjacent and usable we could probably put the RO data closer but it's uh it's not up to us I don't really care we'd have to then change our link or script a bunch so after we set up our physical memory and we go okay I get it now our physical memory is this big this is how much RAM we have we set up an allocator so if we look in Emax where are we we set up in memory uh physical memory manager it's what we call it and this manages you may have guessed it already the physical memory and it does that with a big giant bitmap so we get a bitmap of all the bytes not all the bytes all the pages in physical memory storage says does the does the colonel use your lib C because the Linux kernel doesn't no it doesn't it has its the kernel is self-contained it uses no libraries everything is written from scratch uh but as you can see in memory we have this page map which is our bitmap and this is actually all of our pages whether they are free or not so when we allocate a page we can lock it in this bitmap which basically means we just set it and we can keep track of how many are free and used and uh stuff like that so locking Pages you can lock a bunch of subsequent Pages stuff like this and this is how we allocate memory oh man it's been so long since I looked at this and uh yeah so when we actually are initializing what you're seeing is in it physical being called from K stage one I think so we have kernel.cpp this is where we actually enter the kernel K Main so K main is actually our entry point and this is called by our bootloader so our bootloader basically calls into here it doesn't it calls into our pre-kernel but uh if you want to figure out how this stuff works you can it's very complicated and hurts my brain any questions let me know so right says also since you have your own lib C and since this is an operating system that means I can use underscore underscore identifiers POG I like the underscores that's awesome it's the small things right and you can see that hey main once we get here from our pre-kernel which I don't even wanna Jesus I don't even want to get into it pre-kernel is straight says I don't know why I I know why I know why you like the underscores they look awesome you're not wrong it looks very technical and sweet also everyone you should get up and stretch my back hurts I'm gonna stretch right now should I get a webcam oh okay so okay stage one basically you can think of it that K main is like our regular main entry point for our C program K main is where we enter and it immediately just says K stage one and after that's done you have now booted into lenser OS and k-stage one is incredible uh ye sorry it says I I'm gonna get up and get something to eat real quick then great idea great idea I'm just gonna go over the basic uh structure of lenser OS because it's awesome hi there [Music] oh man there we go that went wrong there how do I go backwards of color I keep coming out the right side yeet I'm just doing this because I I'm standing finally feels much better to be standing I don't I've never found any drawing program that actually draws like this it looks so unique to lenser OS because these types of dotted lines that are just like random based on how fast you move your mouse and how fast the events are coming in they interrupt it's like it's actually really rare to see drawings that look like this you couldn't do it by hand and you can't unless you're using like chalk on a Blackboard it works okay so in lens or Os case stage one oh you can see that it basically does everything all of these are used and these are all pieces from the kernel like the CPU EFI memory and the elf loader fat definitions for FAT32 file allocation table file system and uh k-stage one is a monstrous function which does an insane amount of stuff which disables interrupts if they weren't already that's what this does that's right inline assembly how about that so with this inline assembly clear interrupt flag this basically sets the r Flags register if you know how x8664 works it sets the flags register interrupt bit and it clears it so this means that you're clearing the interrupt flag and that means that interrupts just won't happen we will not be interrupted ever this is the code that will run atomically on the CPU does that make sense hopefully that makes sense so we disable interrupts we ensure boot info pointer is valid because we kind of need boot info and if it is not valid that's a huge issue what we should eventually do here is a check sum that's passed all the way from the bootloader and then we can ensure that the boot info checksum is correct which basically is a much better validation but we're not there yet that's just a security change we could make in lenser OS uh let me just close this uh x86 specific we load a global descriptor table in the interrupt descriptor table so what this is if you see setup gdt that's actually an assembly file believe it or not set up gdt basically assigns I don't know why this isn't uh static I can probably just make this static in any case we set up the global descriptor table and uh This is complicated here's how how it breaks down there are different privilege levels and different axises and limits based on different uh Flags in This Global descriptor table so for example to enter user space you actually just enter ring three which has different as you can see different access and limited Flags not limited flex but Flags so the access and flags are very different between all of these which means uh for example you can't execute data you can only execute code and you can't uh execute kernel code from user space and you can't execute oh you can't access kernel data from user space things like that the TSS is called the task State segment if I remember correctly and uh this is effectively there to make it possible to switch between the different uh Rings more easily for different tasks like process switching multitasking does that make sense and it's the size this is what got me for literally again a week the TSS is the size of two gdt entries isn't that killer so the gdt entry see how it's uh it it's regularly just this size right 32 uh bits I'm pretty sure maybe 64 because of this I can't remember it's a certain size the TSS is double that for like no reason it doesn't even need to be double it it's just for fun oh and then where are we not there okay stage one so after we set up the gdt basically initialize it we probably don't even need to do this we can make this easier we set the size to the size of the gdt which is a page it's in 4096 and we set the offset to Virtual to physical GG DT so we need the physical address in this actual place but we only have the virtual address when we get this as you know the program works in Virtual addresses sir 8 says by the way does lenser OS support copy on write Pages it can but not yet because if it does you can optimize mem copy quite a bit if performing assist call that just copies the mapping that's what glibc does on Linux yeah that's definitely doable we have the whole system in place for that but we I didn't Implement copy on write pages because it's hard but we do when we Fork a program we are just going to copy and then uh copy the pages but then once they write to it we have to again that's exactly what you're describing copy on right it's just we haven't done that yet we're not that far into user space sadly also I just saw your mem move implementation I don't even know what that is I know what Memu is but I didn't know I wrote it I think that's going to be the first PR I don't even have where do I use mem move I don't even know where is it by the way then move I don't even see it it's not here it uses a variable length array I don't where is my move where'd you find it string.cpp oh that's why it sucks you're in lib C that's in the lib c yeah libsy I literally wrote in one day in case you're wondering I wrote this in one day I just went through and did everything that I could possibly think of that I would need in the C library in one day so they're probably very likely incorrect oh no oh no should I really write that me oh sorry it says rep move SB that's one way of doing it I think that's a good example of when assembly is slower than C well yeah honestly rep move SB sped up sped it up a lot the frame buffer used to lag everything but uh it works okay now like a 1920x1080 frame buffer used to be undoable it would just lag but currently it's not too bad but yeah this is for user space mem copy so whatever user space should uh should do do that I don't know uh yeah this is this is I just uh yeah feel free to make a PR I don't think anyone will complain that this is gone but I did write it in one day maybe two pretty sure one because I I don't even remember writing it siraid says the kernel and user space mem copy should be different functions than I take it uh the user space one in lib c will end up with very many it should have a lot of validation checks that the addresses it's accessing are actually accessible by the program that's asking for the mem copy user space is going to be filled with security kernel is going to be efficient so in the kernel you can actually go to memory.cpp and this is the mem copy that we use here mem compare memset that's actually not a bad memset volatile read it could definitely be better don't get me wrong but it's not bad charade says I think it should be the other way around if anything why would the kernel make a bad mem copy call that's what I don't get mem copy and the kernel will only ever be called by the kernel Liberty mem copy shouldn't really have to check anything if it's not accessible the kernel will just seg fault your program well yeah you can do that too there's other things to rely upon like we don't have to check that it's not accessing kernel memory but we could check that it's accessing memory that's actually like uh where it comes into play again is the like mem copy has to deal with in user space doesn't have to deal with validation I'm pretty sure I could be wrong mem copy in the kernel is just supposed to take two addresses and just copy that many bytes just do the job this is such a weird unrolled loop I don't know how I came up with this it is faster but it's such a weird Loop so red says yeah but I think only the kernel should be able and should have to check if something is mapped to a process Maybe I'm pretty sure it's I'm pretty sure even on Linux you have like uh in the proc pile doesn't it specify I don't know I could be wrong if you mem copy to an invalid address in user space it'll just issue a page fault and the interrupt handle will segment your program at least that's how Linux does it I mean we could do it like that that's that's not preventative it's reactive but it's still okay it just means the program will crash instead of saying this place at this spot had a big deal which well we could also have like a a non-crash scenario handled by the interrupts so in the interrupts uh we could have what are we talking about so when we get a page fault this has a long way to go by the way I know uh the page fault checking every memory do reference would be infeasible Imo all right if if you think it's not worth it I don't care I'm not the one that's gonna get hacked I don't think any exploits for lenser OS will even get made but yeah we Panic if things go very wrong as you can see here or here but uh in any case we could not panic basically we're saying if it's user super you're trying to it's not present or you don't have so we would instead of panicking here we would end the user process that caused the page fault and then we would have to somehow or we could try and somehow recover it and just give the process all zeros that what it read from and spit out an error message to the user so it says the CPU takes care of checking out for you using page fault so if you get a page fault then you check then you check what went wrong I'd say I mean we already do that it just means that uh again it's reactionary versus preventive it's fine it's not I think it's totally a way to go not too bad but yeah basically just instead of panicking here we'd say hey shut down the the process and do a make a big deal about about it or just get feed the process all zeros whatever it was trying to read but if it's trying to write and causes a protection fault that's a big deal so that'd probably be something else not bad not bad okay also I'm pretty sure these are broken if you want to take a look at them if you know what's wrong here I would love to know these don't work on virtualbox at all I think killing the process or signaling a seg fault is better than just giving it zeros why though otherwise the program will keep running thinking that the read succeeded and it'll break I'll check the volatile functions later bless but I'm pretty sure I've I've narrowed it down bees don't work on virtualbox and I'm pretty sure it's because of this exactly right here we need memory barriers but I don't know how I don't know how I'm not smart enough for memory barriers M fence anybody infants that's a complicated way to say we load the gdt we set up x8664 we prepare our interrupts which uh pretty where is it you know prepare here it's got to be somewhere it's probably just above yeah so we remap the pick chip iot is out of the way of General software exceptions what does that mean software exceptions basically come in the form of all these page faults and stuff and they are actually thrown by with this number here and this number refers to the uh the type of exception that it is so What's Happening Here is we're saying all the things that are mapped currently in the the pick chip we're going to remap them up and out of the way of all of these so past uh Ox whatever I think Ox 20 is what it's passed we create the IDT the interrupt descriptor table using an interrupt descriptor table red register or something like that and uh we basically install a bunch of interrupt handlers I'm sure you're familiar with this or it's similar to like binding events that we did in C note and then we flush which just means hey actually update this thing and what that calls I can't remember what that calls actually gidt into somewhere so the IDT you can see here you can see to flush it we load the IDT which is the memory address of this we may want to use Virtual the physical here I'm not sure we'll see obviously it works uh but yeah there we are so that was the pair interrupts we set up uart to initialize so this is when we set up our driver this thing here as you can see that's where we print this with debug message s which is just a string and we init physical and in it virtual memory which here and then we initialize the Heap so you know when like in C plus plus when you use new and delete yeah we set that up so now we can use new and delete after calling init Heat in the kernel and that's because we set up a little Heap way up at this virtual address and uh it's basically just allocates Pages as needed so it says also would you be fine with me maybe starting to implement part of the C plus standard Library no I would not be fine with that I feel like that could be useful since we're using C plus plus anyway you know that's not the type of code we're writing [Music] this is meant to be like the lowest level C plus imagine that it's c is what you should do sorry imagine that it's c with new and delete and static cast also don't use static casts like I did all over the place use regular C casts it doesn't really matter that this is static does that make sense just just use parentheses I did I did this thinking it would be better it's not better it doesn't matter the compiler knows better than I do just use functional style casts yeah exactly int value exactly you you have it right with the parentheses just like that first time chat from buffer ox55 hello are you a bootloader are you the last two bytes of a of a of a bootloader sector I recognize those those bites uh but yeah so after we end at the Heap then we can create the system which is like the system so this is the kernel Heap by the way but uh the system itself just keeps track of quite literally everything it keeps track of all of our CPUs all of our system devices so Hardware that's connected all of our file systems that we have set up and uh found and then all sorts of other stuff as well file systems devices we have so much stuff all stored in a singly linked list isn't that your favorite but serate I'm scared of uh like C plus plus standard lib stuff I don't think we need any of that we're sticking to c-lib stuff buffer oxa a55 so some sort of lamal but yeah so we init the Heap and then we debug it you can see this is where it starts and ends this is how big it is and this is a our actual addresses so you can see we have one thing in there it's one header it's free and it's 40 71. heat metadata versus payload ratio in used regions negative nine percent that may be a little broken it may be using uninitialized memory a bit so that's just in memory Heat it doesn't matter it's just the debug stuff but when we heat print debug here's Malik by the way and free only heat print debug and do this little metadata thing this is definitely broken used space efficiency starts at zero 1 minus 0 over used count times a hundred this doesn't even make any I don't I'm not convinced this is correct used count what is that is it just a zero are we dividing by zero we would get an error it's being added here if it's not free but if that never happens then this is zero and we just divide by zero lamal sorry it says C plus plus standard lib stuff can be a bit hard to read sometimes but it's not that bad I just feel like having standard string and standard Vector et cetera might be useful at some point and uh I'm good sorry it says before that I'd have to implement Malik though LOL we already have Malik it's in here it's right here Malik little part of the Heap spirit says by the way is there a burke subirk or a map syscall or something like that yet no honestly I barely know what those do as a Windows user so no sorry it says not in lib C we're not in lib C but Malik and Lipsy is not implemented I see what you're saying I was like we're not in the scene yeah Malik and Lipsy is definitely not implemented because we're gonna have to create a whole nother Heap a user space Heap I think the plan is to just make a new Heap for every program honestly rather than do it the traditional way where there's one big Heap and all the programs get it why not just have each program get its own Heap maybe it's a huge issue and we'll run into like memory usage problems but I don't think it's a problem sorry it says I see that's why you're using a vla though uh what probably because of Berk's a burke or a map uh but yeah so you can see that we have our Heap set up we definitely have some things going wrong and then we print out 64 bytes per char and if it's an underscore it's free and if it's a Stars used so you see our little header takes up a little a little space at the beginning but other than that it's completely unused baby about that how about that either way memo can be implemented without a temp buffer yeah you just have to check if one's bigger than the other and then go one way or the other you're exactly correct and it's a much better idea we then uh as you can see from k-stage one we initialize the real-time clock so the real-time clock gets initialized here as you can see by the way you can see the color codes coming into play uh and debug message faithful faithful debug message and we basically just say hey here's a bunch of things here it is and uh buffer ox55 says I just checked your YouTube channel man it is a gem please keep continue as much as you can thanks thank you so much I really appreciate that I recommend joining the Discord you can get announcements every time I go live and you uh you'll never miss another another stream baby and we also talk about crazy stuff like Linguistics and uh b-top and uh you can get code review if you want to see show off your code you can get help if you're having troubles I really recommend it it's a ton of fun charade says what's the difference between debug message and debug message s debug message s underscore s just takes a string so you can't actually pass in like things here this won't work you can't pass in formatted code debug message is formatted debug message S no formats just a string sorry it says IC it was it's basically just to get around the fact that there there isn't any way to tell whether this is just a string or just or one of these and it's really slow to print things out character by character to the uart driver it's much better to print out buffers at a time sorry it says that's definitely an interesting naming convention I don't think there is a naming convention honestly I think I just made it up as I went I didn't this was again the first thing I ever wrote in C plus plus that actually I put time into before this was like being angry that I can't get a GUI program to link correctly with libraries I'm gonna it I'm gonna writing an OS from scratch it it uh it definitely was a good idea but yeah so after we set up the RTC we print out what time it is which is a cool now we know what time it is the naming convention is the function name ends with f if it formats and if it doesn't end with F it doesn't format so print and printf basically I don't really care about that this is just for debugging if you're a developer you can learn to use debug message and debug message s it's fine it's literally I'm pretty sure it's all in one file you can literally just go here and look at what it does ah debug message C debug message s you get message buff debug message debug message debug all the overloads all right and then debug message V which is a VA list and then finally debug message rainbow which is one of my favorites that's how we get this rainbow output it's fun though draw boot Graphics this is just a function up in case stage one and we say draw some stuff uh this actually uses the global renderer to draw to the screen so in lenser OS if when we're booting up if you look right here like in this area here there's a face and that's drawn right here this draws a face you can see the left eye left people right eye right people mouth programmatically drawing a face is not easy but it's it's doable buffer Ox a55 asks how long have you been programming uh a year I I mean it depends on what you want to call it 10 years to a year Alexi just slid into the server what's up Alexi uh that may be buffer Ox a55 who knows who knows in any case yeah I've basically started programming seriously like a year ago I started this OS uh and uh it's kind of all blossomed from there as you can see on the YouTube channel I made a text editor after the OS because I got kind of burnt out on the OS I'm just getting back into it now buffer 0x855 says yeah it is me hey shout out to Lexi for joining the Discord buffer x8855 you're the best thank you I appreciate it we're gonna have a great old time also sir a did you know about this do you know about this horribleness I don't get x8664 sometimes but this is like one of the one of the places that's like how is the world still functioning the OS has to provide 512 bytes otherwise FX save and FX restore will crash the system and cause it to infinitely reset which means restart charade says oh God context switch instructions lamal yeah yeah an OS is all it is is context switching that's all you're doing constantly after we get through this little bit so you can see we've prepared memory the real time clock the renderers both the uh drawing pixels to a linear frame buffer and the basic text renderer which is a specific type of renderer which is better it uses the global renderer the global basic render to actually draw text and the cursor and yeah it handles keyboard input and stuff this is the bane of my existence determining cash information about CPUs it's scary also we set up random number generators I didn't mention that but that's done here this is just for fun I literally just I just implemented random number generators for fun in the kernel they we really don't need them at all they're just for the colors when you right click that's literally it but it was fun to write them siraid says and yeah in this case the naming convention doesn't matter haha it's just that underscore s gives me PTSD because of Microsoft's stupid open S functions and all of that nonsense but F open is deprecated [Music] I know exactly what you mean I scream at my visual studio every time I open it like it's F open is fine I promise oh it kills me it kills me so shut up egglet you ain't right okay so yeah this is like one of the worst things in the world uh it's it's so bad so we have to store the feature set of the CPU so we create a CPU description which will describe a CPU and we call this the system CPU this is basically thread zero is what we're trying to figure out what can we do on thread zero but here's the thing CPUs have more than one thread now so CPU descriptions actually has a whole thing in it foreign as you can see it it is used to create an actual CPU and what we're going to have to do is create many CPUs do you see what I'm saying here currently we we have thread zero basically getting set up we have to do this for every single core on the or thread I should say every single logical core foreign and we have to use CPU ID yeah you know that CPU ID that that assembly instruction that's literally what we use to figure out this stuff isn't that terrifying we literally just call okay call CPU ID with this here's the string we've we've done it and then we just call it on Reg isn't this horrible anyway we have to do a bunch of multitasking stuff for when we want to set up uh actual you know multiple threads multiple cores multi-threading we're already multitasking so we're good there buffer Ox a55 says did you write your own bootloader uh I didn't I didn't I didn't I didn't currently lenser OS uses the gnu EFI bootloader from like 1990. it's old okay but it's it's somewhat open source there's no license and it's been distributed everywhere with no problems so it's mostly open source siraid says I mean you don't have multi-threading but look at it like this no threads no Deadlocks no race conditions that's the problem there are still Deadlocks and we still have to do spin locks because of Hardware interrupts I'm sorry there are race conditions you're right there are no threads but there are still race conditions because of context switching also this is incorrect now it's not oh I broke everything oh no okay it's fine everything's fine so yeah first thing we want to do is say if FX save and FX restore are supported then try and support as much as you can try and support FPU and SSE does this make sense so uh again there's links if you really want to know what to do in the code so if a feature is present its features flag is set in system CPU this is what we're about to do in the giant if statement so if ethics save restore is enabled then we can set FX saver store capable in the system CPU then we have to actually initialize FX save with our memory address did you know fxsave could take a memory address I did not anyways then you say okay now it's been enabled so not only are we capable of it but it is ready to be used it is enabled and what this will be used for is like when CPU ID is called by a user space process we can say if it's enabled we can use it if it's capable say we weren't able to set it up but your CPU is capable of it sorry and then if it's not capable we say hey you can't use these instructions your CPU isn't capable so sell the CPU keeps track of that stuff if FX save and FX restore our supported setup FPU this is floating Point Unit this is like floating Point arithmetic I think is from x86 and basically if it's enabled you have to do this crazy FN init thing after setting up uh these right so cr0.em ifset FPU and Vector operations will cause a UD so we have to clear this bit and then TS and cr0 is Task switched ifset all FPU and Vector Ops will cause a a non-maskable non-maskable interrupt fault I don't know I don't even know I don't what is Hash NM I forget in any case you can't do it it'll cause a problem so we clear these bits otherwise there's big issues cr0 if you don't notice the control register zero of x86 and it basically has a bunch of flags that have to do with how the computer is operating and what's allowed and after we enable it then we say okay it's now enabled we should probably do like tests or something I don't know FPU not supported ensure it is disabled so this ensures the opposite of this is true the opposite of what this does which means that if they are attempting to be used it'll say hey that's undefined Behavior hey this is not okay non-maskable I don't even know what that stands for as I said then also after setting up the FPU or after trying try and set up SSE SSE is like uh 128 bit operations I'm fairly certain sse2 at least which is what this is so if SSE is allowed then we say okay we're we're we can do SSE and then we have to set all these because if we provide a XM exception Handler if we provide FX save FX restore functionality and then co-processor monitoring and emulation coprocessor emulation basically makes a single core act like all of the cores so even if I'm pretty sure so you can have the core Zero act emulate other cores there's so much there's so much to do no this isn't cores this is co-processor so this is for like servers with two CPUs and stuff like that it's saying which one should handle things anyway there's that SSE there's also other than FX save FX restore there's X save and X save saves a bunch of registers that have to do with very large bit operations capable only through AVX basically operated on only through AVX so what we do is say if we have X save then we're capable enable X Save which means we have to set the bit OS provides something's missing there but I'm pretty sure this is OS provides a uh I love that it's just not there OS provides the XM exception Handler as before but I could be wrong uh we enable it and then if SSE and X saver supported then we can set up AVX I'm not sure if this is correct I remember I couldn't find enough data on this like can you have AVX without having SSE is that a possibility I don't know but uh this is how it currently works and then basically we enable AVX if we are uh able to and that is all of the CPU craziness isn't that insane all of that just to figure out and set up like oh floating Point operations and context switching commands Torrid we basically then create our CPU from our description of our CPU and then we say Okay system CPU has this CPU again we're gonna have to do like Numa domain stuff and that stuff here but we'll get there we'll get there so at this point where are we CPU ID is supported you can see CPU vendor ID is authentic AMD so our Q emu our emulator is running an AMD CPU with these capabilities we have no X saver AVX but we do have all the others and we were able to enable them so that's good and then you can see cpu000 what that actually refers to is it here where is it do I have CPU it is CPU uh basically that gets a CPU ID string that's not what I want to do where is it it's got to be somewhere here where's the CPU itself so CPUs have a logical core number a physical core number a pneuma chip number and a pneuma domain number and an apic ID for the local apic all of these identify the CPU based on chip domain physical core and logical core so you can figure out which actual Processing Unit you're talking to with all those numbers which is why we save them in the CPU class this is where they're printed out craziness right and then we look for this thing called the memory mapped configuration space the acpi table so acpi is a standard that has basically a bunch of tables that can all have different data within them and there's a whole bunch of different ones and uh so to find a table you use the header and a signature and you basically say looking for blah table if you're debugging we say how many entries are there okay for every entry iterate over each one and get the standard descriptor table basically each table starts with the standard descriptor table all of these are tables this standard descriptor table header is at the beginning of each uh time you iterate and then you can just use this to determine what type of table it is who made it why it's there how big it is stuff like that and one of them that we in particularly need is rsdb2 so what we do is where are we there we are we acpi initialize which if we check this out you can see it's right here and we say from the root system descriptor pointer remember our bootloader actually found that for us if you remember up here and it saves that in the boot info passing it to the kernel to be used here and we use that to get our root system descriptor pointer and our extended system descriptor table which is stored in the root system descriptor pointer table right and then we basically uh fill out these Global variables with our rsdb and xsdt so that's our initialization then we look for the mcfg and the mcfg stores PCI devices so storage devices like ahcis will be detected here which is good that means we can start to talk to hard drives so with that we use the uh what is it whoops enumerate PCI oh boy this is a good one are you ready so to enumerate the PCI you basically look in your mcfg which we found from find table in the acpi and this mcfg contains all the PCI devices and uh they're stored in what's called device configs of acpi and we basically get a device config address and then the device config itself just through a cast and then we basically iterate over it from its start to its end and enumerate each bus within this device config so a bus a device config is basically a thing that can hold a bunch of devices and all it has is a list of buses and each of these buses may be used by numerous devices themselves so for each bus we enumerate the bus then we do some math to uh keep track of where we are I used to have to map it we no longer do because of identity mapping uh we used to have to map and unmap it then you'd basically just Loop over the bus for all of the devices which there are 32 of in each bus 32 possible devices and here we do have to memory map it because uh these are generally not in the proper place uh like they're in some Hardware mapped memory which is generally has some crazy address that isn't actually within regular Ram which is all we have mapped in the kernel so we map it and then we say okay get the header there if the header is invalid like we should skip it then unmap the same memory that we just mapped which means we don't actually have to uh you know we don't actually have to keep this mapped for no reason we can free up some memory which is always good but if it does exist then we enumerate all of its functions which there are eight of isn't this insane and then each device Having Eight functions you enumerate the function and each function basically stores a PCI device header so this is where you actually get to the functions that the PCI device implements if that makes any sense and uh oh boy oh boy basically when we enumerate a function we get an actual device this function means okay we have a device this is something we can use and you can see we have to do cache human readable information with device and device tree that's a good idea but currently we have get vendor name get device name get subclass name and get progif name we can use those to get the actual PCI values what these are are actually telling you what they are so if we go what do you know if we look at PCI descriptors you can see that there are different device classes right get device name which is vendor ID and device ID and all of these are different classes of devices and then within each of these classes there's actual specific Hardware that each has their own their own you know ID this is such a horrible way to do things but honestly it's not bad but yeah you can see there's a lot of Hardware you know there's a lot and uh what we're most interested in most of the time is HCI because what this means is that there are actually hard drives SATA hard drives talk through ahci controllers so what we do is say okay if it's a mass storage controller and if it's SATA and if it's an HCI 1.0 well hey we know how to deal with that we're saying okay create a storage device uh with the proper system numbers system device identifying numbers we know what it is and then we basically say we store the PCI device header and data 2. and then we set flag that major storage search true so what this means is that if it's major storage and this flag is set we should search it for a file system does that make sense so if for some reason we shouldn't search a major storage device for a file system we can skip it here and set this to false or set it to false later for some other reason and then we don't have to search it which takes a lot of time and then we add our device to our global system this is like our CR Hardware system right so now we have this storage device cool huh that's what enumerating PCI does again there's a lot more to do there you can handle graphics cards you can handle net network cards you can handle pretty much everything and it's all through PCI ain't that fun then we probe for a storage devices so all those storage devices that we just found yeah we're gonna we're gonna do some stuff to them so we basically I love this for each by the way we basically for each of the devices if the device is a major storage and a HCI controller right if it's a storage HCI controller and we should search it this flag is not zero then we can say okay we're probing this HCI controller lump after we discovered all our devices and then you can see that we uh we do some complicated stuff here with the a bar what this basically means is we're creating a place in or not creating we're using a place in memory that can be written to by the HCI controller the actual Hardware that will overwrite this data so we mapped that and then say Okay using this data that we just got in the first port then what we're going to try and do is create a port controller to control the port and basically do that if it's a SATA device then we want to make sure that we should search it further for partitions and file systems stuff like this again we set this in multiple places but it doesn't matter because this is important then we add the HCI Port as its own device into the systems list so each the HCI controller itself is a device and so are each of its ports because uh that's just how we have to make things work with inheritance and everything and we're saying basically uh where are we at why why we set it to Major storage search to false right this is because we have already found all the ports that would make sense so if the dev flag storage search is not zero we search it and then don't search it any further like don't search it again if we somehow happen to do that right make sure it's zero on the device whereas the HCI Port gets its search set to true find partitions so this goes through each HCI port and looks for a good partition table which is how file systems are stored also buffer oxa a55 thank you so much for the follow I totally missed it half an hour ago might be might be anyway we Loop over each of the devices again and if it's an HCI Port this time right not an HCI controller a port of an ahci controller what we do is if we're supposed to search it we get the port controller and the driver so we create not create but we use the uh portcon data one as our driver which basically just means that we can use it to uh read write and stuff like that it's a virtual class uh searching HCI Port blah for a GPT I'm sure we'll see next searching HCI Port 0 for a GPT and then it says if GPT GPT is present so that's in gpt.cpp here's is GP is GPT present buffer x855 is not a problem dude thank you so much I'm glad you are enjoying and still here and I appreciate the follow we all do it's kind of hard to tell between all the if deaf debugs but basically all this does is say if we can actually uh read 512 bytes from from the import and it actually contains a valid header signature for GPT then we can say hey it's valid and return true and if that's true we say GPT is present which it was then we say okay here's our GPT header which we create here's our sector which we create a basically a byte array so that we can store what we're reading as we go and then we say read 512 bytes uh from 512 bytes so this skips the uh the boot sector so if there's a bootloader on the hard drive we skip it we read the GPT header and then we uh we get it into this address of the smart footer and this smart putter basically just means that on destruction it'll free its payload so that's it that just means we don't have to use delete down here but yeah we read 512 bytes and say hey iterate over each partition table entry and if we should ignore it ignore it right otherwise if it's a null good ignore it otherwise if the end lb is less than the start LBA ignore it there's not much to be said there that doesn't make any sense we don't allow for backwards file systems or partitions sorry it says smart pointers hey and you're saying you don't want a C plus plus standard lip this is very different from LC plus plus smart voters work that's basically just a Destructor that calls delete which is how unique putter works right oh and you're saying you don't want a sleepover plus standard lib C plus plus standard lab is just gigantic and monstrous and confusing it's like they solve problems that nobody has and the problems that people have they don't solve it's a killer uh if we find a valid partition we print out all the stuff about it bro right and uh we basically then say okay we found one it's a GPT partition and it's this big I think that's next actually we create a partition driver so we basically have a driver to handle all good partition tables or good partition HCI ports right and then when we read and write from this we can Etc do things and then we say GPT partition set flag search to true because we want to search all partitions possible you can see that we have a new system device which is a GPT partition which should be added to the system right here but uh we basically say don't touch partitions with any known guides for now so partitions with known guides would for example be uh like Microsoft NTFS file system so we'll just ignore those we're just going to say yeah we we're not going to do that so it says okay then here's the deal I'll implement the stuff that you're already using but I'll add lots of underscores and put it in a namespace called standard if you uh if you want to have your own Fork of lenser os you can do that there pull them out straight says I'm fine with using Pascal case too if that's what you prefer oh no again there's literally no naming convention that's the horrid part I'm pretty sure functions are meant to be snake case and like local variables are meant to be camel case and then Global variables are meant to be Pascal case with the G in front of them a lowercase G and then I don't even know I'm pretty sure class names are supposed to be Pascal case types or Pascal case from what I can tell yeah type names and then all caps for the numerators there is a naming convention it's just an interesting one oh but yeah basically if it's a known good we say hey don't don't do this thing we don't need it and if we add it that's perfect we add it as a system device our new Partition else we delete part driver because we created it and we don't need it for this partition and then we say for their actual HCI Port set flag search to false we've already searched it okay now are you ready for where everything goes wrong we should have left it at uh GPT right getting the GPT partitions and parsing them and making system devices we may have even should have left it at HCI ports the kernel shouldn't really be shouldn't have file system drivers in it however this is lenser OS it's not a good kernel it's mine so there are file system drivers in the kernel they're not going to be for user space user space file system driver is still going to be in user space but uh for now we have a file system driver in the kernel that way we can actually run programs that are included I otherwise we're kind of screwed right so we do need a file system driver in the kernel at least one the rest can be who cares right all in user space and deal with that using uh syscalls and stuff anyway we then detect file systems on all of our partitions and stuff like that or ahci ports or stuff like that so we say okay if it's a system major storage search and it's major storage look look in it if it's a partition look for a partition create a good partition driver or use the good partition driver that was created and then we can basically say add file system which is this file system if it passes the fat test else if Dev minor system minor HCI Port so basically if we have an HCI Port that is still searchable which means it did not have a good partition table on it what we go ahead and do is say look for a file system on that which we only know about fat for now but we could add any amount of file systems as you can imagine just add a new test to each one of these and uh not too hard but yeah so we add our file systems if we find them then we say virtual file system print debug and that's where this happens VFS debug info no mounts no open files how about that we then go through and say Mount all of our virtual all of our file systems our non-virtual file systems actually go ahead and mount those right and basically we say slash FS with a number after it right so this will be slash fs0 FS1 FS2 blah blah blah and then we Mount those as paths into our virtual file system just like Linux but not in the mount directory right that's it by the way I know what the problem is with your volatile read inferences you're casting away the volatile and calling mem copy yes do we need a volatile mem copy how does that work then also I'm pretty sure we're not calling mem copy you can remove it and test but I'm pretty sure we're copying things that are we're reading and writing one two four eight bytes so these are happening sorry to say yes but yeah I don't think the mem copy is being called that would definitely be an issue though you're right because then it's not volatile I don't know I've got nothing for you the pointers on the right hand side are not volatile either that's also a problem well you can make that be a problem how is that a problem you can't write to a volatile pointer from a non-volatile pointer how would you ever write to a volatile pointer how would you ever create one how would you ever initialize it this doesn't make any sense I don't think that's correct I'm pretty sure you can you can do this because this is just a u60 bore this is a volatile u64 which means that Hardware may change it at any time but when we read it oh in this case it's not a problem that's what I was thinking when we're reading it shouldn't be a problem either we read this volatile pointer and copy it into a non-volatile pointer volatile read both are volatile and you're casting it so if out wasn't volatile is that what we're saying either one of the pointers doesn't need to be volatile or something is wrong I would guess that out doesn't need to be volatile you can check in the hpep how we use it here's how it's used oh boy so we're passing it and wrecked which is definitely not a volatile pointer and it's size four I think we'd also read byte these are just reblown I don't even know pointer arithmetic is hard never Cast Away volatile that defeats the whole purpose of it again I wrote this like six months ago trying to write an H pet driver as I didn't know what I was doing if you're reading from a memory mapped address that address needs to be volatile exactly that's what this is this doesn't know if you're writing to a memory mapped address that address needs to be volatile yep volatile volatile we're good we are good which means that we can eventually take off if def V box right uh anyways where were we the VFS uh after setting up the VFS we go on to do some other stuff we initialize the pit timer with a frequency of like 20 or something or a thousand I don't even remember 20 Hertz we basically tell it to count for US 20 times a second let us know that it happens and this lets us know like okay this is 1 20th of a second has gone by 1 20th of a second has gone by blah blah blah and that's how this timer in the top right functions the pit elapsed that's where that comes from this pit timer right here counting 20 times a second then we initialize the TSS the task State segment which is used for switches between privilege levels so like from kernel to user space AKA ring 0 to ring three so it says basically the address that can change without the compiler knowing it must be volatile yeah yeah if Hardware writes to it it needs to be volatile TSS initialize and then scheduler initialize so this scheduler is a whole thing in case you didn't know scheduling oh hello I'm pretty sure that emacs just oh nope we're fine okay we're good anyway it's like emacs just crashed the scheduler is basically a group it's a namespace it's a group of things that uh handle multitasking ain't that fun right and uh what this means is that you can add processes and remove processes based on pids and this will actually uh switch between them eventually so to initialize we call timer tick equals pit tick which basically says this is a function pointer I know it's not clear really timertic is a function pointer so this could be hpet tick if we set up the hpet instead and want to use that as our main system timer whatever we want to use we set it here and uh there's multiple reasons why that's needed irq Handler in assembly switches processes using this function so to switch a process we use scheduler switch which is a function written just down below that's switch process scheduler switch no I don't know it's somewhere uh oh yeah scheduler switch is the scheduler switch process so wherever again it's not here yeah here it is okay so here's the scheduler switch process which is just a function pointer external symbol for scheduler.asm there you go yeah there it is and it's missing things too so this is our irq0 Handler so basically whenever our timer ticks right we're meant to call this Handler now does that make sense so our timer tick is set because every time it happens we would like to say hey install a Handler at irq0 we call this irq0 Handler and then we call timer tick does that make sense hopefully that makes sense uh in any case ireq arguments already on the stack we have some arguments from uh an irreg queue but basically we swap GS if we need to don't worry about that we push all of our registers we increment our timer tick count we call a c plus function argument in an RDI which is scheduler switch process we end the interrupt by sending this byte out through the bus charade says nasm POG yeah it's true I'm pretty sure everything in lenser OS is written in nasm except for lib C his writing libsy and now sometimes horrid so it says no more percentages and then we restore the CPU state from the stack this thing here and we eat RSP off the stack because we're doing a bunch of pushes and Pops how about that hmm how about that and that's a context switch and in scheduler switch process you can see that we copy the current CPU state into the CPU state right we copy the given CPU State on the stack right which is basically this we copy that into this current process specific CPU State then we say if the current process is null then go back around to the beginning otherwise current process equals next viable process which could be anything and uh you know again this comment is incorrect but don't worry about it otherwise current process equals next viable process this next viable process just looks for a process that we can run eventually it'll be more complicated and have to do with like CPU times and stuff like that it doesn't matter this is fine for now uh anyways that's what it does when it tries to switch processes it sets current process so now current process is new so we copy the current uh process CPU because we just switched it right so the new process CPU copy that into the CPU State on the stack which will again overwrite all of these which means all of these will then be changed by that when we return so copy this CPU onto the stack flush the page map for this new process so each process gets its own virtual page map and that's what this is doing here it's switching that update es and DS to SS that's a complicated way to say there are these registers that have to do with what privilege level you're in so you have to make sure that they correspond to the proper things and we just set them to zero because things and same with fs and GS technically we could use these for whatever these are technically just for the OS but we just set them to something so that it's not uh confusing how about that how about that that's the scheduler we initialized that I mean look and then we set up the standard out file this is very very rudimentary yeah you'd think so in our VFS we basically say Okay create a debug out driver which is just a driver where is that implemented I don't even know sit really in uh storage device drivers yeah debug out but you can see that the debug out driver basically just writes a buffer into the uart output debug message output in Reading you can't read we don't support that again it doesn't matter reading from standard out uh whoever needed to do that right no but uh this is just again very rudimentary and temporary we create standard out here by creating a new file metadata which is a debug out metadata thing so that this file we know how to actually access it and then we can add this file to the VFS so this file doesn't actually need to be in any uh path it's just standard out does that make any sense so we're basically creating a standard out file that just writes to the debug out by default it's really not complicated it's just specific handling so that we can actually see output from programs anyway if there's more than zero file systems then we say Okay file path equals fs0 blaze it and it says opening blow with VFS and it tries to do it got file descriptive blah right so let's see what this does also here's the TSS and scheduler initialization not really important flushed IDT after installing new irq0 Handler that's perfect VFS debug info you can now see that we have a mount with the path fs0 and it is a file allocation table file system a fat file system with a driver and a storage device driver how about that how about that opened files there is an open file with bite offset 0 at the very beginning of the file system there is a file and it is Blaze It so we tried to open blaze it right did we no we didn't yet this is standard out that's right that makes more sense so this is standard out which is a always open file in the kernel for now then we get to here open fs0 blaze it with VFS got file descriptor one that's our first file descriptor then we debug again and you can see that we have an open file one with a storage device driver that matches the file system and a bite offset which makes sense 800 000 bytes into the file system is a file about that reading the first few bytes which is what we do here right we read 11 bytes from the start I don't know why we it's 11 but it's 11. we read 11 bytes from the start of the file and if it matches uh yeah we basically just print that out which is what this is it's an elf file which you can see and then we basically say if it does not equal negative one then try and create an elf user space 64 process from it and uh this is the elf loader and it basically is just a very simple implementation to load elf programs and execute them there's a whole lot to do but basically we get the headers from the beginning of the file we copy the current page table by forking and then we make sure that the proper things uh happen so you see we clone the active page map we map the new page table into itself so that the new page table can access itself which is important as it turns out before you switch to it otherwise you can never switch out we set up the stack Flags which uh we basically just set all of them I'm pretty sure no we don't set it as executable which I think we used gnu stack for that in any case load PT load program headers mapping to Virtual address as necessary that's what that does so you can see we attempt to map virtual blur to physical blur and Page table at blur and what that allows is for this program header the program can access it at this address the physical RAM it's actually stored in is at this address and then the page table it's used in which means where this mapping takes place is here which is specifically the page table for this new process if you take a look somewhere here where is it cr3 yeah so you can see seven four nine zero zero zero seven four nine zero zero zero anyway we map and then we say okay what are our flags mapped we did it by the way our flags are present non-writable user accessible and none of these which is pretty important and then we map the second program header much like our kernel up at the beginning if you remember we had two program headers we have the same thing in these user space programs that have been compiled these user space programs are each have two headers so there's our two headers and uh then this one as you can see is writable so this is probably data and this is code and then we added the process to the scheduler that's it and then the scheduler has two processes this is the kernel process and this is the user space process you can tell because user space processes have a a stack segment which ends in three because they're in ring three uh kernel processes have a stack segment that ends in zero because they're in ring zero ain't that fun and then that we successfully created a new process from blaze it so that brings us all the way back to here and then we close the file descriptor and we uh we print debug so we close the file descriptor one and then we print this info and you can see that it closed the proper thing the file is no longer opened now we open standard out another file that we try and open and we say try and open this executable and we just do the same thing as above so we didn't really make it as complicated and uh if it works it works and then we just close it and get out of there no more debug output and just go yep it worked you can see that this one has three program headers it's a little more complicated two for data and or two for code I don't know no this is read-only data code and uh data BSS section sorry it says const expert POG although it is here I don't think I even know what it means I think I just put it in there and like does it still work if I do this because look there's one right up here and it doesn't have it I'm just like yeah I don't know who knows here we'll do it boom now they're both const expert should be static constex further so why why is this C sharp all of a sudden when did C plus plus become C sharp look at these keywords this is horrible oh Lord anyways this is when we initialize the H cut which uh if you again change config about cmape anything but vbox will have the hpac work but V of x v Box means each pet will not work just because it crashes the entire system trying to do anything with it and uh I'd rather have it work on virtualbox and not have some obscure High Precision event timer and just use the RTC with it instead totally fine less crashes more important charade says C plus plus has been keyword soup for a while now const expert doesn't guarantee that it's initialized at compile time you need static comps expert for that and on file scope you need to use inline const expert instead what does that mean so like if I was making something at the highest level in the file uh Christopher's one if I was making something like here I couldn't just use constex for I'd have to do in lung inline where does it go or are you talking about like functions I don't even know can you do complex expert functions that'd be dope nope variables okay so like that was correct why is it giving me a warning inline variables are C plus plus 17 extension so it's just warning me that this is c17 crazy yeah that's obvious ly weird anyway after we uh do this user Space Program loading and initialize the hpet initialize the PS2 Mouse we enable irq interrupts that will be used which are the system timer the keyboard the cascaded pick which is the interrupts 8 through 15. if you have any more questions about const expert I'll delegate you to like half a dozen Jason Turner videos just go to C plus plus weekly YouTube channel and search for const expert thank you bless charade says of course you can do const expert functions you can do arbitrary calculations at compile time oh God yeah so we enable all these interrupts like the real time clock the PS2 Mouse interrupts the uart comm1 so if someone's trying to talk to us we're like yep we need that and uh stuff like that then you can see that we have different ways to print out our memory but we print out our EFI memory map summed and that's what all this blue is you can see we successfully created standard out process hpet buggy on virtualbox Mouse initialized perfectly using serial port id0 here is our EFI memory map so you can see that this is summed but it gives us a bunch of regions right and each of these regions has a type so reserved memory is stuff that is stuff reserved for UEFI no matter what I should never touch these memory regions and these are 256 megabytes in total right not maybe bytes megabytes and uh so this means 256 megabytes of ram will just always be used there's nothing I can do about it and uh then you can see that we have some more stuff like runtime Services code and data which uh if you're not planning on returning to UEFI you can just gate these who cares boot Services code and data definitely don't touch these right loader data and loader code that's the bootloader so who cares do whatever you want to it conventional memory is the actually usable memory so conventional memory that's actually free that is what the uh what the hardware is giving us and saying use it however you want so it says this is the channel in question post the link if you're interested in C plus plus I recommend you check it out he does a video about random C plus plus topic every week and he's been doing that for like five years now or something and he really likes const expert lamell yeah there's some acpi memory for the tables there's some memory mapped i o Etc that's all our memory map here's our Heap at the end of initialization you can see it's not too bad we have a few gaps in there but really it's mostly non-segmented we could probably clean it up there's eight bytes here right that we don't need 16 11 291 168 it's really not that bad it is really not that bad at all already uh but yeah so you can see Heap metadata versus payload ratio in used regions lower is better 43 percent so this means that 43 of our Heap that is in use is actually just uh being taken up by the headers the actual data that the Heap requires to keep track of everything so the the smaller this gets the more efficient all of this is if that makes sense interesting very interesting pretty sure this is wrong kernel memory compacting phase when I mean it would be right here right at the end of case stage one would be here impact memory here but yeah that's definitely something we can do to make things more efficient it's not too bad though as far as Heap implementations go and uh you can see our memory manager debug info so total memory 357. used memory 305 megabytes and free memory 52 megabytes and of this 305 remember that 256 of it is reserved by EFI so that's not me boot Services data and code that's another 30 megabytes right so then we're up to 290 and then all of these so 295 so 295 of these megabytes aren't mine which tracks because there's 52 megabytes free we started with 61. so there's about 10 megabytes of usage that the OS uses so the OS runs on 10 megabytes of RAM how about that how about that there's only like uh I think 128 megabytes of ram given to QE move should we look at the bat what is it there's a hundred megabytes look at that 100 megabytes of memory given to qimo and we have no problems that's something I'm very proud of our low memory usage is pretty dope uh so yeah I mean I know it's not low low it's not kilobytes but God damn you know imagine a computer with 128 megabytes of ram it could run this OS we again print out our CPU our system devices here you can see how our number system works these are uh HCI ports this is an HCI controller and this is our GPT partition and then our file system which of course has the first eight bytes of 24 which you'll you'll recognize if you know file allocation table format if you've looked at it in HEX dump ever but yeah so basically after that we uh just print out our debug info as much as possible print out all the debug info possible and here is where it gets crazy allow interrupts to trigger oh boy this is so much this is when everything we just set up this whole function this is when it really comes into play all of these interrupts that we have enabled are now going to be running which means that our handlers in interrupts right all of our handlers will be running so all of these will be running based on every time these interrupts happen so the system timer remember the scheduler actually updated that to irq0 Handler so this will run every this will run 20 times a second as soon as we call this STI as soon as this happens boom interrupts are enabled we are switching contexts 20 times a second charade says 52 megabytes that means you can run the OS entirely from within the CPU cash flow 52 megabytes is actually the free memory that's actually how much we have free used we have 10 megabytes because we started with 61 megabytes of usable memory 63 000 kilobytes and we whittled it down to 52. which means we use 9 megabytes 9 to 10 megabytes for our OS sorry it says aha well even better but yeah you're right our entire OS is probably in the CPU cache pretty dope I think that's pretty dope but look what happens when we enable interrupts Hello friends where does that come from it's not here you see it says interrupts enabled where's interrupts enabled oh wait it's down here how could that happen how could this and this not run atomically because we got a system timer and we switch to another one of our tasks which is Hello friends what is that well if you go to user and go to standard out you go to main.c you'll notice something maybe hmm that looks like Hello friends doesn't it and this is using standard Library to write to a file the standard out file a message of length string length about that so this C program it can be C plus plus it doesn't matter the C program is actually running from lenser OS Hello friends it's printing this standard out which if you remember we made standard out a file that prints to the debug out which is here which is here isn't that just so awesome that that took me six months to do I'm not even joking charade says you can print to standard out nice I know it's like that took me so long but when I did that I was like I actually did it I was like I just I stopped programming on the OS I was like I I finished charade says that's like 95 of all of programming already implemented right it's all it's the system is there the system is there actually says hello friends from main.c in this user space program and guess what this program was compiled with the compiler we compiled foreign this program is compiled with lenser GCC and this is what I'm saying whoops also I forgot I did that I don't know if you'll be able to see this but uh I'm actually able to here just do this you ready when you type in the terminal see I'm clicking over here this is where I have selected Isn't that cool when I did that I thought it was very cool you can type from the terminal and uh there's no arrow keys but you can type I thought that was so much fun but yeah you can see Hello friends and then exiting exiting what is that you may wonder that is a proof that everything is working together lib C in oh God what is it is it eunist where's exit does anybody know where exit is here it is yeah it's here it's in Eunice retina 1337 says you made a key logger uh yeah a key logger that you can draw in oh how about that hmm I love the idea that I made an entire OS just to be able to type into it it is funny to me here we're gonna erase I think this is ugly [Music] it's always fun to like scrub back and forth with space and backspace oh no I pressed enter I didn't mean to do that I'm out erasing with backspace I don't know how else to do it to be honest do a barrel roll but yeah this is the OS it's been it's stable as you can see the uh the time it's been going for like over 10 minutes now 11 minutes it's not even longer than that I don't even know has been going an hour six thousand seconds an hour am I dumb 3 600 seconds would be oh God this has been open a while has it not am I am I just being dumb I can't do math right now it's been too long but yeah here is our exit but you'll notice that in main.c we don't call exit we call return zero from Main so returning zero 3600 seconds is an hour that's what I was thinking that's what I was thinking so this has been open for like two hours nearly in 10 minutes It'll have been open for two hours well there you go it's stable as retina says you created the reverse of an Etch A Sketch basically but it would run on your computer like you could just boot into this OS easily on any modern machine I mean any x8664 modern machine but are there modern machines that aren't x8664 I don't think anybody actually has them other than universities that are creating them that's awesome though good run time good run time I always love uh drawing over it because it updates like 20 times a second I have too much fun from nothing anyway where does how to why is exiting called we don't call exit here and the answer is that this is lib C the main function is actually within a whole a whole string of things the start function isn't that crazy so you create a linked list null entry in the stack frame for exception handling or stack walking or whatever back tracing that's what it is we store ARG C and RV On The Stack uh just so we don't lose track of them then we run the global Constructors which is in underscore init this is here it's a little complicated because in dot in it GCC will put the dot in it section of crtbegain.o here and this is supposed to be crtn.o GCC has some automatic stuff to help you with building your own libc basically is what I'm trying to say and uh that's what this is this will run your Global Constructors for the entire program which is nice very nice uh but yeah then we get back ARG C and RV into our proper things for our main call because we're using the elf system 5 Abi and then we call exit with return status from Main as argument so we move racks into RDI and call exit which you'll notice we exit exiting and then sis dollar this is a sys call so you'll notice that in Unis did it we say syscall exit status while one how about that explain that one the answer is that this exits this call is meant to remove this process from execution so if exit syscall returns that means that somehow we we didn't exit we failed to exit and if that happens we just say okay wait forever I don't know what to do right you can't have a program destroy itself that'd be like The Incredibles right you can't have that but yeah so we call syscall exit and uh this syscall which is what CIS dollar means then we haven't even talked about this calls uh in interrupts there are there are maskable interrupts like Hardware interrupts irqs interrupt requests but there's also syscalls which are user user interrupts and basically we have these uh syscalls which start with this dollar and then a number which is what CIS called they are and they basically just interact with the kernel versus uh user space so this code will actually run in ring zero so anything in assist call must have like the utmost validation which we do not at the moment this is the very beginnings of syscalls there's literally four no there's there's six and one of them is poke foreign says Serenity OS naming conventions I see for sis calls yeah I didn't know you could use dollar so I was like when I figured out you could use dollar I was like okay that does look cool CIS dollars like that's a sis call baby I like it I like how it looks it's purely aesthetic it's purely aesthetic okay but yeah as you can see we have like open so we can open a path file path and we just call open in our virtual file system not really complicated same with close read same right same turns out the VFS handles all of the file handling what do you know charade says just dollar is a legal variable name in C and C plus that's crazy dollar equals 1 million how to make C look like Pearl oh it's a good idea have a naming convention wait that's so much have a naming convention where every single variable starts with a dollar sign this is this is Pearl I don't know what you're talking about we're doing driver debug out look it even breaks syntax highlighting it's real angry oh that's such a cursed idea I love it I like using just dollar as a loop variable oh that is nice that would be nice so when we do for each if we could use a dollar so weird I've I've never seen code like that use dollar for vars and no dollar for types lamal dollar string string it's not backwards foreign yeah we'll change it to dollar u64 dollar number equals sorry it's just God damn it string string that's right that honestly isn't too bad like we're joking about it but it actually looks kind of nice that fixes the namespace issue LOL definitely I don't think we'll ever have a namespace issue in the kernel oh that would be funny though that would be funny but yeah as you can see exit we basically say systola exit removed process PID what we should do is say like what number this is which is status how do I do an INT I think it's stash I yeah charade says I have this problem all the time I'll I'll have a variable called State and an enum that I also want to call state but I can't that's actually I know exactly what you mean that happens so often or like when dealing with addresses address equals address stuff like that I definitely get that so now you could do address dollar address um so I just end up calling the enum instead that's a bad solution a bad solution uh I can't imagine seeing the state I would I would cry there we go that's yeah that's T State equals St start or something like that yes because of course it's an enum struct why wouldn't it be is that an actual thing are you curious are you are you curious are you serious enum struct I've never heard of that can you actually oh no oh no oh no sorry just says yes what is an enum struct how does this work thank you then can I just a equals one like how does this work like is that so if you have enum structboo X enum structure enumclass declares a scoped enum you have to write Foo X to access C okay so you can't have members still but you'd have to write a a b c d instead of just having ABCD like in C if you just write an enum okay that makes sense that makes sense I don't know why they would use this this terminology that's confusing they could have just called it like uh strict enum that's a hard one right I don't know it's like they're scared to introduce new keywords and they keep reusing the same ones but yeah as you can see we set up this array with all of our syscalls and then in our syscall Handler when we call this interrupt we basically just say okay if it's a valid syscall save the state do your thing call the proper assist call right also this nasm syntax oh my uh but yeah we basically add we add the syscall number to the syscall array address there's definitely a better way to do this the reason why they reuse keywords is because introducing a new keyword might break things that's also the only reason why we throw exceptions the original term is to raise an exception crazy what is throw used for before exceptions what and I'm confused but yeah so this is how we enter and exit assist call and you can see that this runs in the kernel so this is in kernel mode ring zero which means our sys calls run in ring zero which means that we have the privilege to access things like the VFS and the scheduler and then you can see we were able to run a program exit from it all in the time that it took one twentieth of a second less than 1 20th of a second right because then we switched back to the original process process zero and we ended up continuing where we were at the very bottom when we get back here so after calling STI we immediately switch boom new process running Hello friends exiting blaze it is also in here which was our first user space process it just returns with a with a very specific number very specific number uh but yeah that's that right says the image here is that of raising a physical exception line from low to high yes but when they introduced exception to the C plus they found out they couldn't make raise a keyword because lots of people were using that as an identifier and they didn't want to break everyone's code so they went I mean when they say break everyone's code is it really that hard to do a search and replace on the word raise just saying anyway so they went what's a word that no one's using for anything and that sort of means something similar to raise and they settled on throw crazy very crazy but yeah so we run blaze it and we uh we run all sorts of things hopefully and then uh that's it we we're entered we're here that's all that's all that be going on that's crazy that they settled on the throw that's weird no one's programming throw pillows but yeah after we return from case stage one we are just in K Main and this is when we say you've now booted into lenser OS and then we have to according to the GPL V3 there's a license requirement that interactive terminals must print the copyright notice this is an interactive terminal since we can type here and it shows up here ASDF so this is also technically an interactive terminal here right so we we print that here as well this is just for GPL V3 uh but yeah that's done here and you can see that it is quite easy to draw a a string to the screen you just give it a draw position in the string and a color and then that's it it's pretty easy charade says that's also y equals default and equals delete work the way they do crazy so yeah C plus plus likes reusing keywords rip makes it very confusing here's where we print do a barrel roll that there happens right here and then if you uh if you remember the startup music hand-coded startup music maybe also this is now over two hours of run time this is probably the longest test I've ever done yeet we're going to restart it just so you can hear the startup music I'm loving it and that's our startup music it's the mackie's theme in case you didn't know uh and then we basically start keyboarding at draw position.origin this means that when we type you can see that we typed here instead of typing over stuff up here stuff like that and then we basically just enter this Loop this while true Loop we never break from it and we just continually print and swap the uh the thing in the top right of the screen that's it so hey that one went faster all we do is actually refresh this constantly that's it everything else is handled by interrupts so you can do all of it at the same time isn't that beautiful there's my little multitasking OS hobby OS that I made lenser OS I like it I like it a lot it's not good by any means it's not correct by any means there should be like a weight here we should wait and only update this once a second right it doesn't matter it truthfully does not matter because it works kernels are just giant event Loops OS is run on JavaScript confirmed I can't even imagine what it would take to run JavaScript it's like it breaks my brain how Serenity OS is so far so mature like running even running a program that writes to standard out is like that took me six months of just straight work like if you look at my GitHub let's do it let's go look we're gonna go look if you literally go to my uh GitHub all of this time here this is all OS all of it everything up until May from October to may this is just OS 50 contributions on one day 39 28 24 32 46 35 38 46 101. 101 commits see and that's just lindsar OS and ratty do you understand where it says it only takes half as long to compile as llvm well now sorry it says just compile V8 for your OS full that's right I mean technically any statically linked program we should be able to handle not that we will but we should and then it just comes down to supporting the proper syscalls and stuff like that but yeah as you can tell I worked on lens arrest for a long time 38 commits 20 commits in one repository open their first pull request for lenser OS gas syntax support oh no that's for korth La Mao I remember korth then I drank my first beer there's ev2 lensor OS there we go lots of lenser os basically just lenser OS did I have something oh my Posh that got merged I just see that correctly where was that where was I just I don't know it's gone now I wrote an entire markdown to Tech thing and in Python I forgot about that me I completely forgot about that I've made a lot of things I totally forgot about you know you can see the OS I worked on it I worked on the text editor I worked on the compiler and then I worked on C note you can see it progressed perfectly sir Aid says oh God you wrote a markdown parser markdown may be the worst the worst thing to parse in the world but you can see I started with mdp and then I was like this sucks as well I like writing parsers but even so I wouldn't touch markdown with a 10 foot pole yeah you're correct have you looked at it it's horrid it's horrid the just the white space so it says oh I have yeah it's it's horrid look up common mark and uh be scared you know be scared so here's the spec here's where you should go right yeah just a simple spec right simple this is the hardest part the white space or spaces of indentation is too many three spaces are allowed like what soray says I wrote a plug-in for our Minecraft server that handles markdown I eventually settled on using 10 lines of replace all calls and regex let me see if I can find that code oh Lord but yeah the horrible part comes from this uh three not four spaces thing because indentation is also allowed so it gets very confusing for example nested lists and precedence there's there's just so much there's so much uh yeah you're also supposed to support HTML entities we don't because turns out you can just paste the HTML entity into HTML and it works oh how about that scary but yeah there's just so much there's so much backslash escapes can eat eat dirt I hate backslash escapes with a passion I can never code them correctly it's hilarious it seems so simple but it's not oh so bad lots to do lots to do but yeah that's uh that's it I think I did it I did everything I can think of at least anybody have any questions any more questions I'll answer them I'll answer them the hemantly foreign reference to volatile read okay there we go what happened what where's my shell there it is foreign oh no oh my [Laughter] this is terrifying oh that's really good it would work you're correct it would absolutely work and you just replace special to Human oh that's so good I love this replacement by the way this is my favorite charade says it does work oh I believe you it it should it's not uh it wouldn't handle code would it bold lists something something stars and underscores this is a this is very complicated but it's so simple I really like it is this what is this written in by the way is this C plus plus what is this I know this is vs code I'm pretty sure based on this no that's sea lion that's sea lion let's sweat it looks like something I'd confidently copy paste from stack Overflow because it's so weird it has to work this is in Java in case you can't tell oh it's intelligent oh no oh no it's Java why no I know it's Minecraft debug test command test Fubar this text is obfuscated strikethrough nice obfuscated text is not a thing in a common mark That's not common Mark is it I was just about to say are you working in the language you complain about daily sorry it says it's a Minecraft plugin that's why it's Java LOL but it's a thing in Minecraft well okay that makes sense very cool where'd the stars go oh it's bold from here to here oh my okay we ran this again just make sure everything still works hey and uh we could even I can show you what it's like to uh Dash D machine equals cutie mode that's what we're running oh boy hmm no matching function for call the map void pointer void pointer we need Flags so it's saying this doesn't work in hpact this one right here so we need Flags what do we want to flag this as what are we mapping so when we initialize the hpac I don't even know what is it called uh let's go to case stage one and find memory map man memory page table flag there it is okay there we go so we would like this to be accessible first of all mark it as present that's probably an important one and sure we're gonna need to order this with read write because do we ever write to this header address address we it looks like we do so I don't even know dog no uh so present read write what else is there access cache disabled dirty Global larger Pages not executable present read write user super this is fine I think You're Gonna Be Happy what memory no such no match for operator or memory page table flag and memory page table flag do I have to oh man I have to yeah cast to a u64. this is where I should be using a used size by the way well it built we'll see if the hpet works it always did on a on a kilimu so foreign ly broken it's very incorrect that's not uh these are not the same not too bad though not too bad though uh yeah there you go there's the H pet working we need to get it working on cutie on not just qimoo though on v-box is where we're at writing a Minecraft plugin enclosure is a bit complicated my break function you broke a string lamal I don't know how people use software configured in Lua and just like that I avoided 3000 lines of boilerplate lamell it includes an 800 line Javascript file that generates Minecraft command Handler code oh my that's after cling formatting it of course lamell that's terrifying but yeah we've done it where if you couldn't tell getting to the end of the Stream there's not much really to do now other than uh you know nothing there's not much to do now that's all there is to it won't change it yet won't change it yet does anybody have any questions we built an OS from scratch today on stream completely we had some people join the Discord that was good I'm very happy about that Alexi thank you and uh yeah we just had a ton of fun we had so much fun I love JavaScript Mr mugamay no no or or oh no is that true oh no what is that oh my that's scary but yeah in a in a short four and a half hours we were able to build and run our OS answer some questions about it and uh just have fun overall we had we downloaded cmake for Linux how about that how about that that was impressive and uh yeah that won't close that's not good there we go goddamn Windows sucks close this we're closing it all baby but yeah that's it that's all I got for the Stream a evaluates to B if a is null or undefined and a otherwise null ish just like falsy yeah it's falsy it's kind of false oh yeah let's let's go over that foreign last thing I want to point out that I actually created the program uh that is needed to create GPT good partition tables you can use fdisk as well on Linux but on Windows you can't use fdisk so I created this uh this program which creates disk images with valid good partition tables cross platform how about that you can add a partition using the following flag which is just part path and type which is a guid or a preset which is either one of these or Etc and effectively what this means is that siraid says you can't use fdisk on Windows honestly that's not a bad thing LMAO you're right you're right I mean I like fdisk but still disc is really nice it's pretty it's pretty nice put the values in mixed Indian canonical fashion if you don't know who would have an order and uh yeah basically you just build it with cmake with NEC compiler and uh you just used to use it it's pretty simple it's it's not complicated except partition name as argument oh that's a good idea but that's a string conversion nightmare I see why I didn't do it uh hashtag to find underscore CRT secure no warnings lamal screw you msvc this is what that says but yeah we then basically just say uh oh yeah very nice we get our image we set our sector size again these should be const expert but it's a C file so it should it doesn't matter and yeah we basically just go through each one write the file into the output file and uh there's that oh yes the shut up I'm not going to use f open S warning yep you know what's funny even though this is here it still warns me it says put this in there and it won't do it and it still warns me when it's defined it's like ah there's no winning but yeah there we are there we are this uh this is the program I used to make a bootable GPT version of the fat file system that stores the kernel executable and user space executables and fonts and stuff like that pretty cool I think it's pretty cool not too bad it's not too bad at least I felt proud of it uh but yeah that's kind of all I got null coalescing that's what it is I I remember Noel coalescing from C sharp anyway that's it that's us done I got nothing if you have any uh questions pop pop them at me in the Discord because I'm about to leave twitch uh but yeah check out the Discord be sure to join it's a ton of fun it's in the links Down Below in the about section you can get announcements every time we go live and just join this awesome awesome awesome community of people Mr mugamay said it's cursed I open the Stream is at its end it's cursed La Mao every time here just for you [Music] oh no I'm so sorry why does it have to bug the one time the one time it matters it has to bug out man there we go I'm loving it [Music] just bugs out the first time just not the music at all Mr mugamay says PC speaker you are correct PC speaker in Ros in case you can't tell that's what we have open this is lenser OS and it is better than Windows and I am God and this is his next pimple how about that any who disagree says oh God no Mal yes I wonder if I'll ever get white if I right click enough spending way too much time on this but it is fun it is fun to just draw with this weird weird ability of random colors and dotted lines sorry it says oh dear Limbaugh it's here yes it is here this is an evil one I'm so goddamn immature I'm a child I'm drawing I'm drawing and finding it enjoyable just sitting here drawing a face that looks like crap it's not even good art you're right it's not it sucks but I enjoy it gur ah I'm so stupid can you believe I'm putting this on the internet for people to see by the way for non-dotted lines maybe you can just remember the position the mouse was at and fill the pixels between that position in the current position yeah just yeah you know just fill the pixels between the position easy sounds like math yeah I don't know how to do that we'd have to like calculate the rise over run and then it would be wrong all the time I think it would look even worse personally I think the dotted lines make it look fancy that's what I'm gonna go with fancy girl such a stupid thing yeah Serene says don't ask me how to do it I suck at graphic stuff oh that makes me happy because like the code to draw a rectangle made me so confused oh we're gonna go uh giving them teeth in the lazy way rainbow teeth I'm having too much fun just doing nothing which may describe all of today honestly sorry it says I didn't even like art class in school I hated art class it was dumb everyone just sits there and does nothing like it the eyes are not even they're one on screwed up oh there we go that's better oh sorry it says I didn't I'd rather spend my time implementing over engineered vectorized algorithms than deal with rendering stuff speaking of which I'm going to look at all the mem copy code and see what I can do bless Mr mugamay says does it have a lib C it does it does indeed have a lib C uh it's in user let's see here's all the lib C for example here's Eunice data there you go we have success calls lets you make syscalls why do we return a uint pointer t what I don't get this at all I don't know why we returned that that seems insane it's probably a convention probably a convention but yeah we have we have a limp C with all this stuffs it's a mini libsy but it is a libsy as you can see time.h is uh full of things full of things no there's a lot to still implement but it's honestly not too bad there's more than you would think we could definitely set these up better charade says uint pointer T is normally just the generic return type for pointer or integer all right then that's fine syscalls can fiscal can return that but yeah uh we did it I'm pretty sure we've done all of it all of it that's possible so it says IO file time I didn't even think of that yeah I know there's so much to do there's so much to do and uh it'll never end so yeah if you'd like to help out we are accepting pull requests we merged one at the beginning of today's stream in fact so don't feel uh don't feel like you can't can't get there you definitely can I'm pretty sure it just uh made the scripts executable on Linux right yep by Sir Aid shout out sorry baby but yeah that's it that's it check out the code bird of the GitHub down below Mr Mugabe says I can fix a typo and some read me if you want honestly there's so much documentation that goes with the OS as far as build instructions would be great that doesn't I just it doesn't seem right it's just slightly too slow I feel like ah you know what it is you know what it is I bet you every time we read it we have to lock it and stop it from Counting that's definitely what it is otherwise we'd read bits from multiple numbers because we can't do an atomic four byte read ah I mean we can but we can't foreign from the i o bus uh okay so yeah basically in the H pad I'm sure what's happening yeah see so when we get the hpet number we stop the main counter and then restart it serade says torn reads rip I don't know what that means uh but yeah so when we're stopping and starting the counter we should probably like not oh I'm such a dummy God so this is hardware register like we're just reading icy but it can have a large counter support and we can't read eight bytes I mean we can we just need to make sure this is an atomic read and we don't have to worry about locking and unlocking also remember when I said talk about there's Deadlocks welcome to deadlocks uh deadlock City actually because stop main counter creates a locker that never explicitly unlocks which is interesting I'm sure just in the destructor says a torn read is when you read a value while someone's writing to it and you end up with some of the bits of the old value and some of the bits of the new value yeah that's exactly okay yeah a torn read I see I it's making sense now that does make sense now yeah that's what this handles that way we say uh keep reading the low bytes until the high bytes match uh the last time so if the low bytes are red and the high bytes are red again and they're the same as the original High then it chances are it didn't change right chances are that it did not change so then we say okay we can just break and set result but if these are different then that means it's changing still and again you could argue that if we stop the main counter we don't actually need to have this torn read situation but uh I'm just curious this is a horrible idea what if we just don't you know what if we just didn't is what I'm curious about I love this by the way I love this little drawing I did uh rebuild the kernel thanks boss all right hand reboot give it to me well I may have broken things nope we're good hey it worked ah yes the classic it works great it works fantastic it's oh well we're not here to fix the H pet today Lamar I don't even know how that works I don't know how that works doc it really doesn't make sense when we initialize it nothing is different whatever we won't change it siraid says at least it's no longer no longer off by like four well true it's off by infinite uh but yeah the the reason it's off is because over time stopping and starting it means that we lose track of real time so what we should really do is like during this time that the timer was stopped we'd have to keep track of how much time goes by how long this took with another timer and then add it back to this timer by setting the main counter to something plus itself which also has to stop and start the main content oh no it's a horrible mess it's a deadlock mess in this in this in this code don't even don't even worry about it our OS works that's all I got we're at the end of the Stream uh yes use a timer to time the timer to tell the timer how much time pass while timing the timer I'm loving it siraid gets it charade says at that point just eat it and use the timer you were going to use to time the timer it's true oh it's so true but if we didn't call hpet get it wouldn't be wrong but if we didn't call hpet get we wouldn't know what it is it's like the classic like particle like you can see where it is but it won't be there anymore it's now somewhere else me whatever it works that's all I'm happy about we have user space processes that can write to standard out it's nope we got no whis it's a hobby OS but it's an OS and uh yeah I'm happy with it oh that looks funky sorry this timer is accurate is that what it said in each pet it's probably would have said in h bed I would bet because it's supposed to be the most accurate timer sorry it says so long as you don't try to use it that is exactly HVAC can count super accurately you just can't tell what the counter is at unless you make it inaccurate so funny Mr mugamay sounds like quantum physics oh thank you all so much for watching I had a great time today I laughed I cried I pissed I no I didn't I don't know why that came to my brain but it did uh I'm not like that normally I swear but we laughed we cried we did a lot be sure to check out the Discord join us Mr mugma says what don't worry about it me uh it's just a joke gone wrong I could tell us as I was saying it it was like this is a bad idea you shouldn't do this it was just uh funny how casual it was gonna die laughing I'm just the screen's gonna end with wheeze me okay anyway let me do my little Spiel I've been streaming like five hours that's a long time so I would greatly appreciate it if you would donate that way I can afford arthritis medication for when I'm older I'ma need it if I sit down for this long in a row no but seriously I am going to need it so uh be sure to check out that donate button down below if you leave a donation I will read your message on stream and if you leave your username I'll attribute it to you and say thank you thank you thank you shout out to our most recent contributor rpwh or underscore rpwh or Rory or whatever you want to call them they're the best they donated 10 bucks and they said thanks for the stream listed they're awesome thank you so much Rory and uh thanks for being so active in the community as well rpwh you're very active and it's a ton of fun along with all of you if you don't uh if you wouldn't like to give money or if you can't give money that's fine don't worry about it just check out the Discord come say hi and just be a friend that's way more valuable than 10 bucks thank you and goodbye no thank you all so much for watching I really appreciate it check out the YouTube Down Below in the links check out everything check out check out everything that's down there code bird GitHub star follow watch do the things and make me proud I love all you thank you for coming I'll see you next time and uh this is gonna be it for now see you till next time I don't even know what we're gonna do next time maybe compiler Dev maybe maybe C note maybe light we'll work on the text editor who knows who knows Mr moogamous says I'm gonna DDOS you if you don't end it