Operating Systems 2026F Lecture 16

From Soma-notes
Revision as of 15:15, 18 November 2026 by Soma (talk | contribs) (Created page with "==Video== Video from the lectures given on November 17th and 18th, 2026 are now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2026f/lectures/comp3000-2026f-lec16a-20261117.mp4 Lecture 16A] * [https://homeostasis.scs.carleton.ca/~soma/os-2026f/lectures/comp3000-2026f-lec16b-20261118.mp4 Lecture 16B] ==Notes== ===Lecture 16A=== <pre> Lecture 16A ----------- How does the kernel start running? - we want to run it early - but, how can we get it loaded when...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Video

Video from the lectures given on November 17th and 18th, 2026 are now available:

Notes

Lecture 16A

Lecture 16A
-----------

How does the kernel start running?
 - we want to run it early
 - but, how can we get it loaded when the kernel
   is the part of the system that understands how to load
   data into memory (along with lots of other things?)

You need a boot loader
 - code that is initially loaded by your computer in order to load an operating system
 - could be the operating system itself, but generally isn't for multiple reasons

So how can that initial code be loaded?

The original IBM PC design would just load the first sector of
the boot disk, treat that code as 16-bit 8086 code. And that was it
 - that code could make use of other code that was built into the
   system, the BIOS (basic input output system)
This wasn't much code, like less than 512 bytes

Note that 16 bit code stuck around until systems were 32 and even 64 bit systems!

The old PC BIOS was replaced with EFI
 - have a full OS built into the computer that could be used
   to load an operating system
 - "extensible firmware interface" - so the code could be extended

After EFI loads, it has to load a boot loader
 - for most Linux systems, that is GRUB

GRUB then loads the linux kernel + the inital ram disk (initrd)
 - initrd has modules needed to mount the real root filesystem

Then the linux kernel runs, loads the modules it needs, mounts the root filesystem, and runs init.
 - init then loads the rest of userspace

task is a concept that more comes from Mach
 - represents kernel-level procesess & threads
 - it has all the data associated with a running process or thread
   - pid, parent pid
   - address space
   - and LOTS of other things

One task struct is always special: current
 - the task that made the system call that is being processed
 - (so if the kernel isn't processing a system call,
    current isn't defined)

Scheduling
 - what task should a CPU core run next?

Basic flow of control

 user space runs -> kernel runs -> user space runs

we switch from userspace to the kernel because
 - a hardware event happened (timer, network packet, etc)
 - user space made a system call

When a system call happens
 - system call dispatcher runs
 - system call-specific code runs
 - scheduler runs
   - chooses user space task to run next

How to choose?
 - first come first serve?
   - but are all tasks equally important?

Lecture 16B

Lecture 16B
-----------

How does a computer start up? And where does the kernel fit in?

The kernel contains the software needed to run applications. But what software does the kernel need?
 - has to be loaded from storage (HD, ssd, network, etc)

Key insight: there's software built into your computer
 - older PCs: BIOS
 - current PCs: EFI
 - other platforms: varies

So the infrastructure provided for booting an operating system varies. Today we'll talk about PCs


BIOS ruled PCs for decades
 - first PCs were in the early 1980's
 - EFI was only started in 2006

BIOS - basic input output system
 - code built in to a PC
 - enough code to load a bit of code from disk

how little? less than 512 bytes!
 - size of a sector (block)

In that block there should be an 8086 program that loads the rest of the system
 - can rely on the BIOS
 - but still not much there

The boot sequence on a classic PC has multiple stages
 - each one implementing more functionality so more code
   can be loaded

So what you put in those 512 bytes is the first part of the boot loader
 - software designed to load operating systems

EFI is the replacement for the PC BIOS
 - extensible firmware interface
 - an entire OS that loads before your OS


What is trusted computing?
 - set of mechanisms designed to ensure running code is "trusted"
 - here, trusted means the code has been signed by an entity that is trusted
   - code can still have bugs, vulnerabilities, or could even be malware if the trusted party makes a mistake or is compromised

So, the code should all have been digitally signed by the right keys

To have a system be trusted, all code has to be properly signed, from the bootloader on up!