Winter Semester 2026–27 · VIT-AP · BACSE106 · Operating Systems · Dr. Krithika L.B

Session 1.4: Interrupts, OS design issues, building and booting

How control reaches the kernel through interrupts, traps and exceptions; the principles that guide OS design; and how a kernel is built and brought to life at power-on.

Module 1 1.5 hours Theory CO1
← Before
1.3 Services & system calls
How programs ask the kernel
You are here
1.4 Interrupts, OS design issues, building and booting
Module 1 · Operating Systems and Structure
Next →
2.1 Processes
Module 2 begins

Learning objectives

By the end of this session you should be able to:

  • Distinguish hardware interrupts, traps (system calls) and exceptions.
  • Trace the interrupt-handling cycle using the interrupt vector and an ISR; explain the role of the timer interrupt.
  • State the user and system goals of OS design and apply the mechanism–policy separation to examples.
  • Explain why modern OSes are written in high-level languages and list the steps to build a kernel.
  • Describe the boot sequence from firmware (BIOS/UEFI) through the boot loader and kernel to the first process.

Lecture notes

1. Interrupts — how the kernel gets control

Imagine the CPU has asked the disk controller to read a block. It can either poll — repeatedly check the controller's status register until it says “done”, wasting millions of cycles — or carry on with other work and let the controller interrupt it when the data is ready. Modern operating systems are interrupt driven: after boot, the kernel runs only in response to events.

Three ways control enters the kernel
  • Hardware interrupt — asynchronous signal from a device (disk done, key pressed, timer tick, packet arrived).
  • Trap / software interrupt — deliberate and synchronous: a system call (Session 1.3).
  • Exception (fault) — synchronous error caused by the running instruction: divide by zero, invalid memory access, page fault (Module 4).

The interrupt-handling cycle

  1. A device controller raises a signal on the CPU's interrupt-request line.
  2. The CPU finishes the current instruction, then checks the line (it does this after every instruction).
  3. The CPU saves the state of the interrupted program — at least the program counter and the status/flags register — and switches to kernel mode.
  4. It uses the interrupt number as an index into the interrupt vector, a table holding the addresses of the interrupt service routines (ISRs).
  5. The ISR runs: it services the device (e.g. copies data from the controller's buffer and wakes the waiting process).
  6. The ISR executes a return-from-interrupt instruction; the saved state is restored and the interrupted program continues as if nothing had happened.
Maskable vs non-maskable

Maskable interrupts can be temporarily disabled by the CPU during critical kernel code. Non-maskable interrupts (NMI) signal serious errors such as memory failure and cannot be ignored.

Priority levels

Interrupts have priorities, so a high-priority interrupt (e.g. timer) can pre-empt the ISR of a low-priority one (e.g. printer).

Interrupt chaining

When there are more devices than vector entries, each entry points to a list of handlers that are tried in turn.

The timer interrupt

The OS sets a hardware timer before giving the CPU to a user program. When it fires, the kernel regains control — so a program in an infinite loop cannot monopolise the CPU. This is what makes time-sharing and preemptive scheduling (Module 2) possible.

Terminal — interrupt counters on a running Linux machine (output shortened)
$ head -6 /proc/interrupts
            CPU0       CPU1       CPU2       CPU3
   0:         36          0          0          0   IO-APIC    2-edge      timer
   1:          0          0       9123          0   IO-APIC    1-edge      i8042
   8:          0          0          0          0   IO-APIC    8-edge      rtc0
 120:          0     184533          0          0   PCI-MSI 327680-edge      xhci_hcd
 122:      45821          0          0     398114   PCI-MSI 520192-edge      nvme0q0

Line 1 (i8042) is the keyboard, xhci_hcd the USB controller, nvme0q0 the SSD. For bulk transfers an interrupt per byte would overwhelm the CPU, so controllers use Direct Memory Access (DMA): the controller copies a whole block straight into memory and raises a single interrupt when the block is complete. DMA and device management return in Module 5.

2. OS design issues

There is no complete recipe for designing an OS, but some principles have proved themselves.

Design goals

User goals

Convenient to use, easy to learn, reliable, safe and fast.

System goals

Easy to design, implement and maintain; flexible, reliable, error-free and efficient.

These requirements are vague and sometimes conflicting, and they depend heavily on the type of system: a real-time controller, a phone, a laptop and a cloud server want different things. The first design step is always to fix the goals.

Mechanism vs policy

Separate mechanism from policy

Mechanism = how to do something. Policy = what will be done, or which choice is made.

  • The timer is a mechanism for CPU protection; how long the time slice is for each user is a policy.
  • A priority queue in the scheduler is a mechanism; whether I/O-bound programs get higher priority than CPU-bound ones is a policy.
  • File permission bits are a mechanism; who is allowed to read the exam-marks file is a policy.

Policies change over time and from place to place. If the mechanism is general enough, changing a policy means changing a parameter, not rewriting the kernel. Microkernels push this to the extreme (only basic mechanisms in the kernel); Linux lets you choose a scheduling policy per process (SCHED_OTHER, SCHED_FIFO, SCHED_RR) on top of one scheduler mechanism.

Implementation

Early OSes were written in assembly. Today most are written in higher-level languages — Linux and Windows are mostly C (with some C++ in Windows and growing amounts of Rust in Linux), with small parts in assembly (boot code, context switch, interrupt entry). A high-level language makes the code faster to write, easier to understand and debug, and portable to new hardware. Compilers are good enough that the speed penalty is small; the real performance wins come from better data structures and algorithms, and critical routines can still be hand-optimised later.

Other recurring design issues

IssueThe question the designer must answerWhere it appears in this course
Efficiency / performanceHow to keep CPU, memory and disks busy with low overhead?Scheduling (M2), paging (M4), disk scheduling (M5)
ConcurrencyHow do many activities share data safely?Synchronization (M3), deadlocks (M2)
Protection & securityWho may access what, and how to stop attacks?Access matrix, capabilities, cryptography (M5)
Reliability & fault toleranceWhat happens when hardware or software fails?Microkernels (1.2), RAID (M5)
ExtensibilityHow to add new devices and features?Modules (1.2), device drivers (M5)
Portability & compatibilityCan it run on new hardware and still run old programs?APIs (1.3), virtualization (M5)
ScalabilityDoes it work on 1 core and on 128 cores?Multiprocessor scheduling (M2)

3. Building an operating system

An OS can be built for one specific machine, but more often it is generic and must be configured for each site — a step called system generation (SYSGEN). Building a Linux kernel from source shows the steps clearly:

Terminal — building a Linux kernel from source (illustration; takes 30–90 minutes)
$ wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.6.tar.xz   # 1. obtain the source
$ tar xf linux-6.6.tar.xz && cd linux-6.6
$ make menuconfig            # 2. configure: choose drivers, file systems -> .config
$ make -j$(nproc)            # 3. compile the kernel image and the modules
$ sudo make modules_install  # 4. copy modules to /lib/modules/6.6.0/
$ sudo make install          # 5. install kernel + initramfs in /boot, update GRUB
$ sudo reboot                # 6. boot the new kernel, then check with: uname -r

Configuration choices trade size against generality: a kernel completely tailored to one machine is small and fast; one that is table-driven or uses loadable modules can adapt at run time. Distributions such as Ubuntu ship a generic kernel with most drivers as modules — the modular structure from Session 1.2 in practice.

4. Booting — getting the kernel into memory

When the power is switched on, RAM is empty. How does the kernel get loaded if loading programs is the kernel's own job? The answer is a short chain of progressively smarter loaders — booting, from “pulling yourself up by your bootstraps”.

Power on→ Firmware: BIOS / UEFI (POST)→ Boot loader (MBR → GRUB)→ Kernel + initramfs→ init / systemd (PID 1)→ Login / desktop
  1. Firmware. The CPU starts executing at a fixed address in non-volatile memory (ROM/flash) that holds the BIOS (legacy) or UEFI (modern) firmware. It runs the power-on self-test (POST), initialises essential hardware and selects a boot device.
  2. Bootstrap (first-stage) loader. A legacy BIOS reads the first sector of the disk — the 512-byte Master Boot Record (MBR) — into memory at address 0x7C00, checks that its last two bytes are the boot signature 0x55 0xAA, and jumps to it. UEFI instead loads a boot program (an EFI application) from a FAT-formatted EFI System Partition.
  3. Boot loader (e.g. GRUB). Shows a menu, then loads the compressed kernel image and an initial RAM file system (initramfs) holding the drivers needed to reach the real root file system. It passes boot parameters and jumps into the kernel.
  4. Kernel initialisation. The kernel decompresses itself, sets up memory management and the interrupt vector, detects devices, loads drivers and mounts the root file system.
  5. First user process. The kernel starts init — on most Linux systems systemd, with process id 1 — which starts services and finally the login screen. From here on, the kernel waits for interrupts and system calls.
Terminal — looking at the boot of your own machine
$ ls /boot                  # kernel images, initramfs and GRUB live here
config-6.5.0-35-generic  grub  initrd.img-6.5.0-35-generic  vmlinuz-6.5.0-35-generic
$ sudo dmesg | head -2      # first kernel messages after the boot loader handed over
[    0.000000] Linux version 6.5.0-35-generic ...
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-6.5.0-35-generic root=UUID=... ro quiet splash
$ ps -p 1 -o pid,comm       # the first user-space process
    PID COMMAND
      1 systemd
$ systemd-analyze           # how long each boot stage took
Startup finished in 6.1s (firmware) + 2.9s (loader) + 3.2s (kernel) + 9.8s (userspace) = 22.0s
You will build stage 2 yourself

In Lab 2 you write a real 512-byte boot sector that the BIOS loads at 0x7C00, ending with the 0x55 0xAA signature, and boot it in the QEMU emulator. A small C program then checks the image exactly as the firmware would.

VideoBytes

Interrupts and the interrupt cycle

Video coming soon

Interrupts and the interrupt cycle

Recorded by Dr. Krithika L.B. Slot m1-interrupts

OS design goals, mechanism and policy

Video coming soon

OS design goals, mechanism and policy

Recorded by Dr. Krithika L.B. Slot m1-design-issues

Building and booting an operating system

Video coming soon

Building and booting an operating system

Recorded by Dr. Krithika L.B. Slot m1-booting

Interactive lessons

Work through these in order after the lecture — each one expands a part of the notes with diagrams, hover notes and a quick check.

Lab connection

Check your understanding

Answer each question in your own words first, then reveal the model answer.

Revealed 0
What is the difference between an interrupt and a trap?

An interrupt is asynchronous and comes from hardware (a device or the timer), unrelated to the current instruction. A trap is synchronous and caused by software — deliberately (a system call) or by an error (an exception such as divide by zero).

Why must the CPU save the program counter before running an ISR?

So that after the ISR finishes, the interrupted program can resume at exactly the next instruction with its registers unchanged — interrupts must be invisible to the program.

What would go wrong in a time-sharing OS without a timer interrupt?

A user program that never makes a system call (e.g. an infinite loop) would never give control back to the kernel, so the OS could not schedule anything else. The timer guarantees the kernel regains control periodically.

Classify as mechanism or policy: (a) the round-robin time slice is 10 ms, (b) the context-switch routine, (c) students may not write to /exams.

(a) policy · (b) mechanism · (c) policy (enforced with the permission-bit mechanism).

Why does a legacy BIOS check bytes 510–511 of the boot sector?

They must contain the boot signature 0x55 0xAA, which marks the sector as bootable so the BIOS does not jump into random data. If it is missing, the BIOS tries the next boot device.

Key takeaways

  • The kernel is entered by hardware interrupts (asynchronous), traps/system calls and exceptions (synchronous).
  • Interrupt cycle: request line → save state → interrupt vector → ISR → restore and resume; the timer interrupt enables preemption.
  • Design starts from goals; separating mechanism from policy keeps the kernel flexible; high-level languages make it portable.
  • Boot chain: firmware (POST) → boot sector at 0x7C00 or UEFI app → GRUB → kernel + initramfs → systemd (PID 1).

Where this leads

When systemd starts as PID 1, the machine is finally running processes — and from then on almost everything the kernel does is about them: creating them with fork(), choosing which one runs next, running them as threads, and keeping them out of deadlock. That is Module 2.

Go to Module 2 — Session 2.1: Process concept and process scheduling →