OS Structures, System Organization & Boot Process
827 words
4 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# OS Structures, System Organization & Boot Process ## 🎯 Learning Objectives - Describe the layered structure of an operating system - Differentiate between monolithic, microkernel, and hybrid kernels - Explain the boot process from power-on to OS loading - Understand system call flow: user → kernel → return - Trac...

OS Structures, System Organization & Boot Process
🎯 Learning Objectives
- Describe the layered structure of an operating system
- Differentiate between monolithic, microkernel, and hybrid kernels
- Explain the boot process from power-on to OS loading
- Understand system call flow: user → kernel → return
- Trace the xv6 boot sequence on QEMU
1. Operating System Structures
1.1 Intuition
An OS kernel is the core of the OS — the first code loaded at boot and the last code running at shutdown. Different OS designs organize kernel code differently, trading off performance vs. modularity vs. security.
1.2 OS Architectures
(Diagram)
| Architecture | Description | Pros | Cons | Examples |
|---|---|---|---|---|
| Monolithic | Entire OS runs in kernel space | Fast (direct calls), simple | Crash-prone, huge | Linux, xv6, BSD |
| Microkernel | Minimal kernel (IPC, scheduling); services in user space | Stable, secure, modular | Slow (IPC overhead) | Minix, QNX, seL4 |
| Hybrid | Monolithic core + modular loadable drivers | Balance of speed and modularity | Complex | Windows NT, macOS |
| Exokernel | Minimal kernel, gives apps direct hardware access | Flexible, fast | Complex app development | ExOS, XOK |
1.3 System Calls
System calls are the interface between user programs and the OS kernel.
(Diagram)
System call categories:
| Category | Examples |
|---|---|
| Process Control | fork(), exec(), exit(), wait() |
| File Management | open(), read(), write(), close() |
| Device Management | ioctl(), read(), write() |
| Information | getpid(), gettimeofday(), alarm() |
| Communication | pipe(), shmget(), mmap(), socket() |
2. xv6 Operating System
2.1 xv6 Overview
xv6 is a teaching operating system developed at MIT, inspired by Unix v6. It runs on RISC-V (or x86) and is the reference OS for this course.
Key characteristics:
- Monolithic kernel written in C
- RISC-V architecture (or x86 in older versions)
- ~10,000 lines of code
- Supports multiprocessing (SMP)
- Implements core Unix concepts: processes, virtual memory, file systems, pipes
2.2 xv6 Boot Process
(Diagram)
Boot sequence steps:
| Step | File | Action |
|---|---|---|
| 1 | QEMU (simulated hardware) | Loads kernel image at address 0x80000000 |
| 2 | entry.s | Sets up initial page table, enables paging |
| 3 | entry.s | Allocates stack for each CPU hart |
| 4 | entry.s | Jumps to start() in C |
| 5 | main.c | Initializes subsystems |
| 6 | proc.c | Creates first user process (init) |
| 7 | initcode.S | init process executes /init program |
| 8 | init.c | Opens console, starts shell |
2.3 xv6 Source Layout
| Directory | Contents |
|---|---|
kernel/ | Kernel source code |
kernel/proc.c | Process management |
kernel/syscall.c | System call dispatch |
kernel/trap.c | Interrupt and exception handling |
kernel/vm.c | Virtual memory management |
kernel/fs.c | File system operations |
kernel/kalloc.c | Physical page allocator |
user/ | User-level programs (sh, cat, ls, etc.) |
3. System Organization
3.1 Hardware Protection Mechanisms
| Mechanism | Purpose | How It Works |
|---|---|---|
| Dual Mode | Separate user from kernel | Mode bit (0 = kernel, 1 = user) |
| Timer | Prevent infinite loops | Generate interrupt after time quantum |
| Memory Protection | Prevent unauthorized access | Base and limit registers |
| I/O Protection | Prevent direct hardware access | Privileged I/O instructions |
3.2 CPU Modes
(Diagram)
| Mode | Privilege Level | Can Execute |
|---|---|---|
| User Mode (U-mode) | Lowest | Non-privileged instructions only |
| Supervisor Mode (S-mode) | Medium | Supervisor-level operations (xv6 kernel) |
| Machine Mode (M-mode) | Highest | All operations (bootloader, firmware) |
4. Common Pitfalls
Pitfall 1: Confusing monolithic and microkernel
Mistake: Thinking "monolithic" means the kernel is huge.
Correction: Monolithic refers to the architecture (all services in kernel space), not size. Linux is monolithic but can be small (embedded systems).
Pitfall 2: System calls vs library functions
Mistake:
printf() is a system call.
Correction: printf() is a library function that internally calls write() system call.Pitfall 3: Boot sequence order
Mistake: Thinking the OS loads before hardware initialization.
Correction: Hardware initializes itself (firmware → bootloader → OS). The OS is the last thing to load.
5. 📐 Key Formulas / Concepts
| Concept | Description | Key Insight |
|---|---|---|
| System Call | User → Kernel transition | TRAP instruction switches modes |
| Dual Mode | User/Kernel separation | Mode bit prevents unauthorized access |
| xv6 boot | ROM → QEMU → entry.s → main() → init | ~10,000 lines of C |
| Monolithic | All kernel services in kernel space | Fast but less secure |
| Microkernel | Minimal kernel, services in user space | Secure but slower |
6. 📝 Practice Questions
Q1: What is the first C function called in xv6?Answer:main()inkernel/main.c. Before that, assembly code inentry.ssets up page tables and stacks. Q2: Name three advantages of a microkernel architecture.Answer:
- Better security (services run in user space)
- Easier to extend (add new services without modifying kernel)
- More reliable (service crash doesn't crash kernel) Q3: How does a system call switch from user mode to kernel mode?
Answer: The user program loads arguments into registers and executes a TRAP (orecallon RISC-V) instruction. This causes the CPU to switch to supervisor mode and jump to a predefined handler in the kernel (the trap vector). Q4: What is the role ofproc_init()in xv6?Answer: It initializes the process table, allocating astruct procfor each possible process. It also sets up the first process (init) that eventually runs the shell. Q5: Why does a monolithic kernel have better performance than a microkernel?Answer: In a monolithic kernel, all services run in the same address space — function calls are just regular calls. In a microkernel, services run as separate processes and communicate via IPC (message passing), which involves context switches and data copying.
7. 🔗 Cross-References
- Week 1 - Process Management: System calls for process creation
- Week 12 - xv6 Internals: Deep dive into xv6 system call implementation
- BSCS3031 (CSD): Hardware organization, interrupts, memory hierarchy Join Discord PreviousProcess ManagementNextThreads