Study Guide

Firmware, Booting and Interrupts

What has to run, in what order, before an application can: hardware, firmware with its bootloader, the operating system, then applications; and how the CPU is interrupted by a key press, a mouse movement or a program error, and what it does about it.

Lesson 3.9 Computer Systems

For: Cambridge IGCSE Computer Science learners

Stage: Think

From the power button to the game

A pupil (a made-up one) presses the power button of a laptop, and a short while later is playing a game. At the moment the button is pressed, RAM is empty. The operating system and the game are stored on the laptop’s drive, and the CPU can only run what is in primary storage.

Think it through

Something has to run first, before the operating system, and it must already be in place at the moment of switch-on. What kind of program could this be, where could it be kept, and what job must it do?

Show what happens

It must be a small program kept in memory that holds its contents without power, such as ROM, because RAM is empty. Its job is to find the operating system on the drive, copy it into RAM, and let it take over.

Firmware is software stored permanently in non-volatile memory inside a device, such as ROM, so that it is there as soon as the power is switched on. It is called firmware because it sits between hardware (the physical parts) and software: it is a program, but it is kept in the hardware and is rarely changed.

The firmware of a computer includes a bootloader. The bootloader is the first program to run: when the power is switched on, the hardware starts running it. Its job is to start the computer up (it is also called booting): it finds the operating system on secondary storage, loads it into RAM and hands control to it.

From power-on to a running application

Each step names what is running. The order is the same on a laptop, a phone or a games console, although real computers have more stages.

  1. Hardware

    Step 1 of 6: Power is switched on

    Electricity reaches the hardware. RAM is empty and nothing is running.

  2. Hardware and firmware

    Step 2 of 6: The CPU starts the bootloader

    The hardware starts running the bootloader, which is stored in the firmware (in ROM or similar non-volatile memory).

  3. Bootloader (firmware)

    Step 3 of 6: The operating system is found

    The bootloader looks on the secondary storage for the operating system.

  4. Bootloader (firmware)

    Step 4 of 6: The operating system is loaded into RAM

    The bootloader copies the operating system into RAM, then hands control to it.

  5. Operating system

    Step 5 of 6: The operating system takes over

    It starts the user interface, loads the drivers and prepares to run applications.

  6. Application

    Step 6 of 6: The user opens a game

    The application is loaded into RAM, and it runs on the operating system, which gives it what it needs.

Do not confuse: What runs on what

Runs on the hardwareBootloader (firmware)
The first program to run, stored permanently in non-volatile memory in the hardware.The start-up program in ROM.
Is run by the firmwareOperating system
Loaded into RAM by the bootloader, then in control of the computer.The system that manages files, memory and devices.
Runs on the operating systemApplication
Loaded and run by the operating system, which provides the services it needs.The game or the word processor.

Reading upwards: the hardware runs the bootloader, the bootloader starts the operating system, and the operating system runs the applications. Without any layer, the ones above it cannot run.

Stage: Explain

Putting the start-up in order

Number the events in the order they happen when a computer is switched on, from 1 to 6.
EventOrder (1 to 6)
The operating system is copied into RAM
The user opens an application, which runs on the operating system
The hardware starts running the bootloader from the firmware
The operating system takes over and starts the user interface
Power is switched on
The bootloader finds the operating system on the drive

    Show the completed table
    EventOrder (1 to 6)
    The operating system is copied into RAM4
    The user opens an application, which runs on the operating system6
    The hardware starts running the bootloader from the firmware2
    The operating system takes over and starts the user interface5
    Power is switched on1
    The bootloader finds the operating system on the drive3

    Check your understanding

    The bootloader is kept in firmware, but the operating system is kept on the drive. What is the best reason?
    Show the answer

    Answer: A. The operating system is large and often updated, so it is kept on the drive; only the bootloader is in firmware.

    Small and fixed in firmware; large and updated on the drive.

    Apply it

    Dev says: “Firmware is hardware, because it is stored in a chip inside the computer.” What is the best correction?
    Show the answer

    Answer: B. Firmware is a program, so it is software, kept in non-volatile hardware so that it is there at switch-on.

    Firmware is software stored in hardware.

    Apply it

    A pupil installs a game on a laptop. Which of these correctly states what the game relies on to run?
    Show the answer

    Answer: B. It relies on the operating system, loaded by the bootloader in the firmware, which runs on the hardware.

    Applications on the operating system, the operating system on the firmware, the bootloader on the hardware.

    Stage: Think

    The fire alarm

    A teacher is marking a pupil’s essay at her desk, halfway down page three, when the fire alarm sounds.

    Think it through

    What should the teacher do about the marking, and in what order? What does she need to remember, to carry on afterwards without starting again?

    Show what happens

    She should stop at once (the alarm cannot wait), make a note of where she had got to, for example by putting a finger on the line, deal with the alarm, and then go back to the note and carry on from page three.

    The CPU is in the teacher’s position. It is running a program, and something else needs attention. An interrupt is a signal sent to the CPU to say that something needs attention now. The CPU pauses its current program, deals with the cause, and then carries on with the program from where it stopped.

    An interrupt is generated when something happens that needs the CPU: a device sends a signal to the CPU, or a program or the operating system produces one because it has found a problem. Each kind of interrupt has its own program, called an interrupt service routine (ISR), written to deal with it, in the way a fire drill is a plan for an alarm.

    In the fetch-decode-execute cycle, the CPU carries out one instruction at a time. At the end of each cycle it checks whether an interrupt signal has arrived. (This is the simplification used in this course: real CPUs have more detailed rules.) If one has, it is handled in these steps:

    A key is pressed while a word processor is running

    The interrupt arrives during one instruction, and is handled when that cycle ends. The order of the steps is what matters.

    1. Keyboard

      Step 1 of 7: The interrupt is generated

      The pupil presses a key. The keyboard sends a signal to the CPU to say that it needs attention.

    2. CPU

      Step 2 of 7: The current cycle is finished

      The CPU completes the instruction it is working on, so that nothing is left half done.

    3. CPU

      Step 3 of 7: The interrupt is noticed

      At the end of the fetch-decode-execute cycle, the CPU checks for interrupts and finds the keyboard’s signal.

    4. CPU

      Step 4 of 7: The program’s place is saved

      The CPU saves the contents of its registers, including the program counter, so that it knows exactly where to resume.

    5. Interrupt service routine

      Step 5 of 7: The ISR runs

      The CPU runs the routine for a key press. It reads which key was pressed and stores the character where the word processor can take it.

    6. CPU

      Step 6 of 7: The place is restored

      The CPU puts the saved register contents back, including the program counter.

    7. Word processor

      Step 7 of 7: The program carries on

      The word processor resumes at the next instruction, as if nothing had happened, and now has the character to display.

    Check your understanding

    Why does the CPU save its registers, including the program counter, before it runs an interrupt service routine?
    Show the answer

    Answer: B. So that it can return to the interrupted program and carry on from where it stopped.

    Saving the registers is keeping the place.

    Stage: Predict

    Why not just keep checking?

    Another way to notice a key press would be for the CPU to check the keyboard over and over, many times a second, to see whether a key has been pressed.

    Think it through

    What would be the drawback of the CPU checking the keyboard, the mouse and every other device again and again? What does an interrupt let the CPU do instead?

    Show what happens

    Most checks would find nothing, so the CPU would spend a great deal of time asking questions instead of running programs. With interrupts, the CPU carries on with its work, and a device only interrupts when it actually has something to report.

    Interrupts come from two kinds of source.

    • A hardware interrupt is generated by a hardware device. Pressing a key on the keyboard and moving the mouse are examples: each sends a signal to the CPU. Others are a printer that has run out of paper, and a drive that has finished reading some data.
    • A software interrupt is generated by a program (or by the operating system) when something goes wrong or when it needs the operating system’s help. Two examples are division by zero, which cannot be calculated, and two processes trying to access the same memory location, which could corrupt the data both rely on.

    What happens as a result depends on the interrupt. A key press ends with the character being stored and shown. A software interrupt for division by zero or a conflict over memory usually ends with the operating system’s routine displaying an error message, and either stopping the program that caused it, or deciding which process may use the location first. The other programs carry on.

    Is each event a hardware interrupt or a software interrupt? Type hardware or software.
    EventHardware or software?
    A key is pressed on the keyboard
    A program tries to divide a number by zero
    The mouse is moved across the desk
    Two programs try to change the same memory location
    A printer reports that it has run out of paper

      Show the completed table
      EventHardware or software?
      A key is pressed on the keyboardhardware
      A program tries to divide a number by zerosoftware
      The mouse is moved across the deskhardware
      Two programs try to change the same memory locationsoftware
      A printer reports that it has run out of paperhardware

      Check your understanding

      Which event would generate a software interrupt?
      Show the answer

      Answer: B. A program tries to use a memory location that another process is already using.

      Software interrupts come from programs; hardware interrupts from devices.

      Stage: Apply

      Following an interrupt through

      A spreadsheet is recalculating a large table. The pupil moves the mouse. Describe what the CPU does, in order, and why.

      1. Notice where it comes from. The mouse is a hardware device, so this is a hardware interrupt: it sends a signal to the CPU.
      2. Say when the CPU responds. The CPU does not stop in the middle of an instruction. It finishes the current instruction, and at the end of the cycle finds the signal.
      3. Say what must be kept. The recalculation is only half done. The CPU saves its registers, including the program counter, so it can come back to the next instruction of the spreadsheet.
      4. Run the right routine. The CPU runs the interrupt service routine for the mouse, which finds out how far the mouse moved and updates the pointer’s position.
      5. Return. The CPU restores the saved registers, and the recalculation carries on from where it was. The pupil sees the pointer move and the calculation still finishes.

      At every step, the reason is the same: respond quickly to the device, and lose nothing from the program that was running.

      Apply it

      Mia says: “After the interrupt service routine finishes, the CPU has to start the interrupted program again from its first instruction.” What is wrong with this?
      Show the answer

      Answer: B. The CPU saved the registers, including the program counter, so it carries on from where it stopped.

      The CPU resumes the program; it does not restart it.

      Apply it

      A program run by the pupil divides a total by a number that has become 0. The computer shows an error message and closes that program, while the music player carries on. Which statement describes what happened?
      Show the answer

      Answer: C. A software interrupt was generated by the division by zero, and its routine stopped only that program.

      A program’s error generates a software interrupt.

      Apply it

      The CPU is in the middle of executing an instruction when an interrupt signal arrives. According to this lesson, when does it deal with the interrupt?
      Show the answer

      Answer: A. At the end of the current fetch-decode-execute cycle, after the instruction is finished.

      The check is made at the end of each cycle.

      Go deeper What if two interrupts arrive together?

      Interrupts are given priorities. A more urgent one, such as a power failure, is handled before a less urgent one, such as a key press, and an interrupt that is more urgent than the one being handled can interrupt its routine. Real computers can also hold some interrupts back (called masking them) while they do something that must not be disturbed. Priorities are not needed for the IGCSE course.

      Stage: Consolidate

      Show what you know

      Think it through

      Explain what happens, in order, from the moment a pupil presses a key while a game is running, until the game carries on. Use the words interrupt, interrupt service routine and program counter.

      Show a model answer

      A good answer follows the order. For example: “The keyboard generates a hardware interrupt, a signal to the CPU. The CPU finishes the instruction it is on, and at the end of the cycle it notices the interrupt. It saves its registers, including the program counter, so that it can find its place again. Then it runs the interrupt service routine for a key press, which stores the key. Afterwards it restores the saved registers, so the game carries on from where it stopped.”

      Check your understanding

      Which of these is the correct order, from the first thing that runs to the last, when a computer is switched on and a game is opened?
      Show the answer

      Answer: D. Hardware, bootloader (firmware), operating system, application.

      Hardware, then bootloader, then operating system, then application.

      • An application needs three layers beneath it: the operating system, the firmware and the hardware. Applications run on the operating system. The operating system is loaded by the bootloader, which is firmware. The bootloader is run by the hardware.
      • Firmware is software stored in non-volatile memory (such as ROM) in a device. The bootloader finds the operating system on secondary storage, loads it into RAM and hands control to it.
      • An interrupt is a signal to the CPU that something needs attention now. At the end of each fetch-decode-execute cycle, the CPU checks for one.
      • To handle it, the CPU saves its place (its registers, including the program counter), runs the interrupt service routine for that interrupt, restores its place, and carries on with the interrupted program.
      • A hardware interrupt comes from a device (a key press, a mouse movement). A software interrupt comes from a program (division by zero, two processes using the same memory location).

      Sources and scope

      • What this lesson is. The ninth lesson of the Computer Systems module, written for this site. It teaches Cambridge IGCSE Computer Science (0478) points 4.1.3 and 4.1.4 (2026 to 2028, version 6): hardware, firmware and the operating system, and interrupts. With Lesson 8 it covers all of point 4.1. Its curriculum links are provisional and imply no endorsement by any examination board. It has not been approved by the site owner.
      • Original material. The pupil’s laptop, the fire alarm and the teacher, the spreadsheet and the other people named are fictional and were written for this lesson.
      • Simplified on purpose. Real start-up has more stages (hardware checks, settings, a choice of operating system), and the firmware of modern computers is often kept in flash memory so that it can be updated. The CPU is shown checking for interrupts at the end of each fetch-decode-execute cycle, which is how the IGCSE course describes it; real CPUs may check after each instruction, may delay some interrupts, and give them priorities. Where the registers are saved (usually on a stack in memory) is not described.