That's I got you, I got I got enough request. Okay, so now let's go ahead and start recording and we can get started here.
Okay. Good morning.
Welcome to the fourth lecture for operating systems. I just started recording so those of you who have been on the zoom call may have seen some other things going on.
That's just me trying to.
I was begging if you think setup you'll see what I'm doing, so don't worry about the pole if you missed one, we're going to be getting them, I'm gonna be doing other polls in a second.
So actually, that's what I want to talk about administrative stuff so um
okay let's start this.
This is annoying.
There we go.
Okay, so.
So first off, if you don't want the tutorial one.
That's, that's good but if you're not you're a little behind but work on it.
Let's check to see when was assignment.
One.
So I said assignment. One is,
is due September 29. That's a. I'm going to put give you a few more days on assignment one because I since I haven't posted it yet, but I like to give you at least a week for assignment one, let me see what it is September.
Yeah, I'll give you a few more days for assignment one.
But that will be posted very shortly.
But going back to let's see, so.
So that's so focused on the tutorials, they'll for the assignment so today.
Okay, so first off I want to so now I want to start off with the first real poll Let me see if I can do this here.
Okay, let's so edit pole okay there we go.
So you should be reading this point poll is.
Can I change the.
Okay.
So now, let's try that.
I'm launching a poll right now.
Okay, so.
Can you all see the updates on the pole as it's being updated. Can you see this little screen or is it just a blank area. Yeah, I thought so this is a zoom Mary but you can see me editing the pole right.
okay yes yeah because I was in a web browser. I thought, okay, answers are.
But you know there are now.
There are 107 818, have you on the call I have 100 and 567 responses.
I'm going to close the poll shortly so.
If not, not done but not too difficult, asked what the isn't too bad, it's just it's just isn't too bad, until you're done, I mean, but how difficult is or not.
It's like, after.
Ok.
Okay, I'm closing the poll now. Okay, so I see well, five of you have not answered. Going once, going twice.
Going three times. Done.
So, here's the results.
So I see a good chunk of you
about.
I'm glad to see most of you have finished it that's very good to see about 24 of you are still working on it so it's hard, it's like okay that's fine.
You have you seen a little confused.
So, anyway.
Okay, so now.
So I'm going forward. I'm going to be doing polls in zoom.
Because I'm,
Because I like picture. Okay,
fair enough.
I wasn't but, yeah.
So I'm not going to do.
So there will be more polls in teams.
So, if you want.
Okay so, so that's so basically yes you don't have to worry about teams during this unless you want to have a side conversation with other people in class and if you want to do that, that's perfectly fine.
But otherwise, I'm just, you know, we're just going to do things this way.
But now let's start talking about.
So, today.
So today we're going to talk about hello world.
And this comes from tutorial to, but the.
The question I want to ask you is this. So right now, here the three I've downloaded this onto my
can another module.
I actually have this actually have a laptop setup which is beside me but I actually don't, I don't like multiple screens I never have I have for years been using virtual desktops, and I find it much easier just to switch a complete virtual desktop, than
it to actually physically move my screen.
But, um, but that's that's just me. So anyway, so just to refresh How did I get here.
So what I'll actually show you the I'm logging in, but I'll do to access.
And so now I'm on the VM, I'm not, I'm not gonna lie. So this is how you get into it. The dash j is something we talked about on teams. As you can see, it's a heck of a lot simpler way to do it.
But note what it's actually doing here is it's logging in first to access and then logging in to your VM.
So that's the Jeff j you could say it's like jump, but it's, it's very nice.
So that's the GFJ you could say it's like jump, but it's, it's very nice, um, the dash is the dash l sorry is still very useful but even for web connections and other TCP, it's a very powerful command but this is more user friendly.
But I'm going to do this because I'm going to jump through homeostasis because that way if you guys are going to access it won't interfere with what I'm doing.
Let's keep that clean.
I'm going to show you later how to get rid of this password, and still be secure. but not today.
Now. Now I can install Cisco, so the only time or.
Yeah, So now the uninstalled Cisco.
You still need Cisco.
So, yeah, just, just do that.
If you try to SSH in Windows and it fails, you're probably doing the SSH wrong.
And there's a, you have to make. So So, how will.
So, first make sure you can SSH to access. If you can't.
If you can't SSH to access, then you do, by the way the dash j make sure it's uppercase j it.
So little quirk case sensitive files are files a case sensitive as a command line or everything are case sensitive. On Linux Unix like systems, and a Mac OS and Windows, their case preserving but case insensitive.
Okay fine with the commands okay so.
No, you don't need to be so
I'm on Windows 11.
No.
We still need on the call to network. You do not need to be.
association to access is a way to get onto the call to network, the VPN is, you know.
nobody else is using the VPN except for CS may be engineering it you know will call anyone who is willing to play with command line stuff CS type folks, but, you know, there are another departments, but no one else has me doing it.
Yes, it is a bunch of 2104, which is the same VM.
Yeah.
Yeah, I have a default.
So let's talk here about.
I like the default wallpaper, although I did have another more colorful one but it's actually good for these sort of things.
Let's talk about let's look at the code here so let's go to my.
So this is code I all download.
So I did this w get from homeostasis I just gotten copy pasted the link here and W get here. So that's how I got all these files onto my VM.
Let's look at what. Hello.
Hello. See, is a valid is simple.
Yeah, I don't know why, here's the funny thing I normally am in dark mode, but when I started sharing my screen like this.
Zoom change things. So I'm not quite sure why it all with light, I'm not going to mess with it right now but I will mess with it later. Even did some weird things with my icons.
Like, I think I'm in high contrast mode, like, look at that, that's just weird.
That I come there.
Okay.
So maybe I can try it. I'm not going to mess with zoom right now but I would like to change some dark mode because, yeah, document is the way to go. I don't know why I'm.
Yeah. But anyway, so we've got here. Hello, we got me see let's compile it
will optimize it.
It runs it compiles fine, we're good.
Okay, so unrelated question Will there be an answer for tutorial one posted.
Most of the things in this course when you do it. You should know, whether it's correct or not and if you for some reason you are uncertain about it.
That basically means you should talk to someone about it asked me in a lecture ask in. Ask your TA or something talk much.
But you should be able to convince yourself that you understand what's there if you are uncertain.
That means something's fuzzy in your head.
Yeah, but you shouldn't you shouldn't need to check the answers. If you're finding yourself you need to check the answer's no. There's multiple answers for many of these questions and.
you're supposed to be building of a mental model of what is happening and operating system.
So, yeah.
Yeah, you can.
Are you allowed to use Google yes you're allowed to use Google with the tutorials.
Really what you should be doing is more experiments, then searches, not to say you shouldn't be doing searches or looking apropos or the things but what is happening.
I specifically didn't mention Google because yes I used to go.
Okay so
Okay, so we've got here, we got the hello world so now my question is is what's actually happening with hello world, what is going on.
So I gave you a couple of tools in the tutorial. And so one thing to look at is what, so how much code it so even defined main here, we include standard IO, and we have one command here print off.
Where's the code for printer, did I create printer know that's a standard library call. How am I making things appear on the screen.
So, turn the machine which get current to what was it what it does, but.
So this, I want to get the when you say get the machine code we want to get a little deeper mental model of what's actually happening.
So here's a couple of things that you can go through here to see what's happening so. So we have first do is and.
So first of all, this is the machine code that is actually in the program.
So, this is and so you'll see that there's.
Yeah, this is, this is what's in here now I'll tell you, so there's, there's a good bit more code, then you think, and I'm not going to go through, I'm not going to teach you all about assembly language.
language. It's definitely saying but the thing to understand about this view is this is a disassembly so what this is saying these not so this is saying if an offset in the binary.
This is saying.
These are the actual bytes. And this is the instruction. So what this means is, this is a human readable translation of these bytes.
So, we don't code in machine code directly because my God, look at that, but it's certainly possible to code directly in assembly language and use an assembler to transform this into this.
So this is the executable itself so I have literally just taken this, I am dumping the executable to look at what is there so if I want to see, this is what exactly is happening.
So, the basic concept of machine language is you have registers the registers are like the variables, you can operate on.
So we're getting some kind of object files was x cables, so.
So
ratios, always physical components.
So, on modern CPUs.
Register registers used to be, this is the register. This is the storage on the chip that is being directly manipulated modern CPUs they do register renaming they have many.
It's complicated, but from a basic programmers perspective we don't care about that.
So, but the register still.
You really only tell that there's weird things going on under the registers if you start looking at performance but, again, outside this.
Okay so, so I will, I will take a minute there's some questions about what is participation mean.
So,
Okay, good.
Please, no meaningful questions or ones that help others in the class well I guess if you're helping other words by pondering the meaning of life.
Anyway, try to distract others from what we're trying to talk about try to stay on topic.
So I'm.
Scroll up a bit.
Where I performance now Oh.
So basically if you look at benchmarks, you can actually see weird things happening the registers like if you use do certain kinds of operation will be faster than otherwise where it wouldn't be the case if it was actually just one bit of hardware but.
Whoo, I mean, all microprocessors.
So how come see it has to be get converted into assembly and then machine code.
Why is so cool to see the machine code compiler up, you can do that later.
It's just easier.
He's like the machine code is just the values corresponding to assembly operation so this is this. So now let's see the see the compiler, actually.
How do I see all those files that I talked about. Well first of all, I can do this.
I told it to compile dash verbose Lee so is compiling This is running assembly.
Mostly we avoid writing in assembly, but people who do low level development.
Read assembly, especially to understand why their code is or isn't working because compilers are not perfect at all, they, they can sometimes have bugs, they can do weird things so if you're doing real low level stuff.
They will you know you'll have a C program or some rust or whatever and you'll look at the assembly and look at the machine can go like, is this what I want, or is this stupid or whatever.
Sometimes it's like well maybe I should change my code to make it compiled better or maybe I'm confused the compiler something so
assembly is still very much a thing.
So, if you look here, there's a whole bunch of things here there's all these variables, these are basically environment variables that are set remember environment variables from the first tutorial.
These are all specified things can here telling you the configuration the compiler had, you know, thread model house and it's like, there's all these details.
Here's some options and things. So this is all kind of just, You know, verbose you know stuff here but then, let's but if you look inside here, you'll start seeing like options, you see all this all the buttons, where is the
okay where's looking for the actual. Oh, here we go.
So, Here is the actual. So like for here.
This is calling the assembler.
So the assembler was. So there was a dot s file. I thought was kind of check that was capitalists will see that in a second. Oh, I remember what is you'll see a second but so here's the assembly file backup generators intermediate file, and then here's
So, here's the assembly file that got generators intermediate file, and then here's the up the object file that got created up here, where is the I here is the assembly file so here this is calling the actual C compiler.
So here it's got a cc one getting all these crazy options, but here's Hello, give the dash Oh optimization. And then here it's out putting the assembly file.
So SOC s is the assembly source file. Yes.
And then the assembly source file there and then here. There we got the object file, and then here is where we generate.
This is the thing I think that generates the. Yeah, so you see dash Oh, hello. This creates the actual binary. And what we're doing is calling collect collect two is the linker.
This is the command to generate the actual Hello binary.
So tip. Yes, exactly. They are putting slash Tim, they are deleted, as you go.
So, so now, but that doesn't mean that we
that we have to have these deleted we can stop these things and see them as they're generated. So instead of this I can say dash capital S and get rid of this dash oh here.
And now I have a Hello, God, S.
Here is the assembly file.
Yeah, so the code you have that last code I highlighted was the linker yes so here is Hello dot, you know, here is the assembly code directly corresponding to the C code we created.
Then
GC dash Oh hello, see if I just do this. I now have an object fun. Oh, yeah.
Oh, gosh. Oh,
no.
Oh, thank you, thank you, like, which one is it now. Okay, yeah. Now see,
that's just your default target there but now we have Hello Don Oh, it's a nice yes it's a binary file, look at this, you know, but you see some strings in there.
But then we can do and
the object is, it gives you all these options for viewing it D is for disassemble. Sorry. The sound is Roshi on the ground making noises.
And so, this outputs the main thing that's happening and and what it does is it gives this assembles the thing of text, text is the main portion main, and here is what is there for the actual main loop.
That's all there is
no it's not a hairball that's just him scratching his back
up. So we're now.
So you see, assembly language objects, say notice the course my this is the machine code. This is the actual code here so you know the the disassembly of an object file is very simple, the sort.
This one's a bit more complicated.
But you'll notice most of the things in here.
So, the things that start with a doc, our assembly director so you'll notice much of these things dot file tech stocks section that string it like these all art.
This is not code. This is code. This is code right here, here we go this is code here that's code right there. The rest of this is just stuff to talk about alignments stuff so it's just things to go.
The things to tell the assembler how to create the machine code. But that isn't specifying the machine code specifically.
So for example, and some of this is like, I want to embed strings in the object file to say what file was compiled.
You know here is we're declaring here a literal string here, the hello world because that's going to be referred to later, that's not code that's data that gets put in a different section of the object file.
So, why say is put drugs are generally like one of the exceptions. I mean, this is not metadata, this is data, because this is an actual string. What are the things in the far left, good question.
testing actually no le aq I forget the instructions. I think that's transfer.
So, some dollar sign means absolute values of this is the stock pointer This is the instruction pointer.
With that story. So, I'm, I forget something instructions. I am not fluent in assembly language when I remember when I look things up I can kind of read it, I can translate it but, again, that's not load effective address.
I thank you Lord effective address quad Yes.
Thank you load effective address quad Yes. So it's loading the address here as whatever this addresses, but it's relative to the instruction point i'm not sure whether using instruction pointer.
I think that's the destination.
Anyway, the things to look notice though in assembly language is call instructions. Call instructions are essentially.
the big things. Comments removed at a pre processing status.
So common so comments are ignored by the compiler Yes.
So, there aren't actually comments in this, there's things that mostly are instructions for doing things, these are, you can have comments in assembly and I think it starts with a pound sign I'm not sure exactly ways but, Yeah, my son.
have comments in here but this does not have comments or explain it all understand all the words that assembly language our function calls.
I don't expect you to come.
Thank you.
So I expect you to know kind of what it is and recognize it and the idea is that.
the big thing is I want you to understand the role of assembly and know why you know where it is and the fact that it's there and when you might need to go look at it.
So when something is wrong with the compiler, we need to enter here and change the assembler and make a modification well you could. Yeah, you could hot patch the your assembly code if the C compiler some reason did something wrong, or you could try to
fix the compiler, or you could file a bug report or more likely, you just change your code in some other trivial way to do the same thing in a different way so that you don't trigger the compiler bug
Deep a quick summary there I'm summarizing as I go different things, but let me.
Let's talk what are we talking about here and this is part of what I want you to do with the tutorial. If you find this confusing. This is the material of the tutorial up.
But now we're going to talk about something a little different here.
When we know when we did this notice there was this huge. this is the linker.
And if you look at this line to the linker, you'll see a lot of option, there's a lot of things going on here but there's something that you should know that there are various bits of object files getting stuck in here, This CRTN zero.
There are these various stubs, that little bits of code that are stuck in there and this is, this is how you get.
If you look at the size of hello.oh, it's only 1500 bytes.
But if you look at the size of the Hello binary. It's 16,000 bytes.
How did you get from 1500 bytes to 16,000, is because additional object files were included in the binary. And you can see exactly which object files were included by looking here you see all your car to have been zero.
Here's this thing here I mean there's all this stuff happening, it's happening under the hood. This is the old, this is only what was actually in, you know, in the C file that we wrote everything else got thrown in there to make a working program.
Go on.
Sorry. He left.
I think the linker is just when you link all the object files into an executable file. Yes, that's exactly the linker.
So when I say resolves references between them.
So notice when we.
If you look here.
Let's look at this, let's look at the here. So if you look at this here, you'll see this call to put ass. we are calling the put s function.
So how does the linker know which object files to link in order to make the executable. Well the linker just takes whatever objects, it was given. So the question is how do you know which object files to give the linker.
Well, that's the responsibility of build systems, I mean, the basic compiler can do things simply for a basic one but if you have a more complicated binary and that's what your make file has to tell things.
How do you let but so we're calling this put s function so what is put us.
It's a function to output characters and strings. Now notice the, the print F is not there, put SS there.
That's because we didn't use any features.
yc not do anything special remember what Hello, look like.
We just printed a symbol string, we had no no substitutions no percent as no percent D or anything. So why bringing all complicated print off.
We just need to output the string, so it replace it with put us, and in fact if you just put this, we could just replace a print out with put us is that part of the opposite.
replace a printout with put us is that part of the opposite. Oh yes it optimizes the compiler definitely opera especially we say dash show but even if you don't say actually did a little bit of optimization, but that's why it's usually dash capital Oh,
Oh, yes. So does this mean that there are quite a few object files that always get LinkedIn, irrespective of what your program might be doing.
Yes.
Precisely.
But now the natural question is, why so much code.
But actually, this isn't that much code, as you will see, sorry.
Are the unknown object files relates the OS yet.
A lot of these paths have docked as part of the path, doesn't it does moving back up the structure Yes, dot dot means going up so what it means they're giving relative path yes the doc.
Doc so there.
I'm sorry if I missed your question you might have to repeat it in the things I'm trying to catch up here so it's all standard IO de de so standard Ioh tells the C compiler, how to access it, but it's not the actual code.
Yeah show optimizing so I'll let me show you something.
Let's just.
Oh,
wait.
I think what you are just commenting Yeah, yeah.
There we go. Yes, sir.
So you notice that
this is the an optimized version.
So it's got.
Okay, good. That was hello and optimized and Harris Hello optimized. So you'll notice, I just got rid of everything that had a period in it.
I had to quote it because periods actually mean wild cards and stuff in there but so so this is the an optimized one, this is the instructions that has this is the optimized one.
So you see that even just for basic things like you get down to much simpler code,
optimize this this is exactly offers more efficient yes so how can I view the unseen object files, they aren't unseen you see dash v you can go look at them and go look at them directly.
diff diff shows the difference between two
diff shows the difference between to just those different came to text files differs a way of comparing things that's all I'll show you but it was not producing intelligible out answer so this is this is clear.
Because there's all kinds of commands diff is very powerful.
One my looking for here. So this is just saying it but the important thing to know is that we don't actually have put s. So, the call to put s has to be resolved the C compiler doesn't do that, the linker does because it has to combine it with the object
file for the put s program.
Now I'm going to show you something a little different.
So,
makes you make sure you give the full path that you run. So I said, ll trace.
Oh,
wait, didn't give any.
Hmm.
I was expecting a library called their new that got optimize the way
it used to give a used to say put us, but.
Okay.
It doesn't.
That's interesting. I think it's gotten rid of that but but let's try, so l traces not showing anything he used to show.
I will track that down, I will just put a note there so.
if there is a command to optimize is there one to make it as an optimized as possible. I'm just calling the compiler by default doesn't maximum optimization
may try making your principles more complicated yeah may try making a Princeton was more complicated Let me try. Let's try that.
01.
So we'll just make, we'll just do this.
Might tap stop for all messed up.
Good.
Okay, all traces just just messed up. I don't know why it's not doing that, but let's just show you.
If you did s trace
illustration work with das z
with Tasha on compile. Okay.
Ok.
Okay, I'm not sure.
Okay, I will, I will find out why it's not doing that because why I was expecting your tell you that but so.
So,
again, used to work, these sort of things I'm supposed to break but it has so I'll find out what's going on here.
Okay.
Okay, thanks. I'll check check that Stack Overflow later to see what's going on. I want to understand what's going on so I'll do that after lecture, but.
system calls or request to the colonel.
So, what we're seeing here is these are all requests to the colonel to do things.
And we're a lot a large part of this class will be understanding what the heck is going on here. The big thing I want you to understand is and hopefully by the end of this class you will understand at least a good portion of these, if not all of them.
But the thing to notice is, there's a lot of them. Lots of system calls now.
Notice that I changed my compilation.
I compiled it with this dash static option.
And when I asked trace the Hello static.
I only got this many instructions.
But when I did before, there was a lot more me a lot more system calls going on.
So the question is, is, What did I do with this static thing well
look at those files.
Hello. Is 16 K.
Hello static is 846. k.
So, a lot bigger.
A lot bigger.
Because what's really happening here is the normal.
So binaries are compiled normally with dynamic linking so the library code is loaded at runtime, but otherwise it's loaded at
required all code Sackler, even the standard library. And so we can do something like LDD tells you what what libraries a file depends on so LED is telling me.
Hello, is loading, all these things at runtime. If you look at some of these files.
x86 64 canoe led seed or episode six
lives.
660 460 sorry.
So, c dash.
So you see that is no two megabytes.
So, This is being dynamically loaded into your program.
This is basically the, the C library. This is the code for the C library. This is like two megabytes or this part of the C library that's being loaded in every time you run hello world.
But if I do
not a dynamic executable. There's nothing that code is loading and it's static it's all included in that binary.
Sorry so so what are they displayed, are they displayed in the order astray switch so this
is a combined all the libraries in the executable. So, compared to the size of this.
This is only 846 k, this is, you know, this is two megabytes.
So, no, not all of those see libraries being loaded in, but a chunk of it is.
So, you know, you don't get the whole see live but you do get a chunk of it.
So the character looks just need to have all the other elements are the baby so understanding the relationship between all these things, this is part of the purpose of this tutorial, you want to think about what's going on what's being loaded what's there.
But there's one other thing I want to show you here.
So what is a system called when we say we're doing a system called, what is that.
Nope, it's not.
So look at all this stuff here
for.
No, no do this.
So you'll see that periodically through the binary. There are system calls.
This This call is its own instruction, you can see the zero f 05, that is the instruction of a system call it is different from.
If you look at calls.
This is a call, it is different machine code from Cisco. So this is just showing you that, at an assembly language level, a system call is a different thing from a function call.
And this matter is because.
Yeah so library call is the function call to code and the library.
We have.
You will.
So you all have had
your remember fork.
You all know exactly, he.
Okay, but I have a, I want to see.
Let's create.
Okay, let's see.
work.
Okay, let's now.
Okay, so now polls.
Okay, I just launched a poll.
See how folks are doing here.
A, if it's a barely you can just say no.
Okay, I've got 120 of you.
Okay, I will say, you can't see the pole.
You should see a pop up on your screen.
If you don't, if you don't get the poll.
Make sure you update your version of zoom.
Okay, so let's end the poll.
Okay boss Roger.
So I I just was curious to know how much you suppose I know I'm going to go over for an executive, he, but I'm just curious to.
I may go a little faster since it looks like 80% of you know me, know about four and, like,
a few of you, you know and like a quarter of, you know, both them. But,
yes, but that's not today we're not going to talk about that today but, um, but that will be next time.
Oh.
Okay.
Let's say water. So, the important part. So the question now I'll ask you is.
So, why do I need to have special things for assembly language.
I Why do I have to revert to this. The trick is is.
Yes, you can have a dress I mean, we're going to dress as a memory address
is is a memory address.
That's all it is.
So, so is it for security reasons, it isn't part of the story reasons but it's a little more complicated than that.
But you can't so.
kernel code machine code.
everything yourself.
Okay Roshi wants to come in. I'll let him back in
my work I'm in.
Okay if most he decides to come in, I will show them to you but he's right now sitting up the door not, I'm not saying I.
So all see can compile some machine code.
So, when we talked last thing I'll show you about system calls is.
So system calls have numbers.
So I went and found this file.
I had to go a bit digging because where they put this varies but it turns out it's actually on these systems user include x86 64 Linux new SM units did dot underscore 64.
So this is where 64 bit as opposed to 32 bit x86.
These are the system called numbers.
There's also a, by the way, there's also a cat named tab, but he doesn't seem to come by much. I'm not sure why, but he does combine all have to introduce some.
So, These are the numbers of system calls.
This is the main interface to the Linux kernel.
These are the calls.
So, you can. And when you make when you want to make one of these calls, you have to put into some in machine code, the system call instruction, and the appropriate number.
Now, in practice, you almost never do this.
Because, you know, because we have library functions do all these things at least all the system calls we care about.
But this is the this is the number.
where I get access to this file again this file.
I'll put this in the notes here.
cap names escape, you
I do not have a third cat only two cats, but yes there was definitely a naming scheme involved.
Okay.
Team over like it
was useful to see a trailing history your commands.
Well, you got the video for doing things could try giving you my history.
do system call numbers vary from machine to machine.
This isn't called a numbering is actually very stable but there's specific to an architecture. So if you're running, you know Linux on ARM versus let's say so I can show you this right now.
If you look at.
So there is also a 32 bit.
Notice here, this is exit for so first of all let's look at where right is. So right is right is for in this system called numbering.
And if we go to hear.
Right, is one.
What your application API stands for application binary interface so.
So why they change it.
I don't know.
So, so if you're on ARM running legs and arms. These could potentially be different as well.
Anyway, I'm out of time.