1.seven. Basics of How Operating Systems Piece of work¶

one.7.1. Office of Interrupts¶

Interrupts are signals sent to the CPU by external devices, normally I/O devices. They tell the CPU to finish its electric current activities and execute the appropriate office of the operating arrangement.

There are three types of interrupts:

  1. Hardware Interupts are generated by hardware devices to signal that they need some attention from the Os. They may have just received some data (e.one thousand., keystrokes on the keyboard or an information on the ethernet card); or they accept just completed a task which the operating organization previous requested, such every bit transfering data between the hard bulldoze and memory.
  2. Software Interupts are generated by programs when they want to request a system call to exist performed by the operating arrangement.
  3. Traps are generated by the CPU itself to bespeak that some error or status occured for which assistance from the operating organisation is needed.

Interrupts are of import because they give the user amend control over the computer. Without interrupts, a user may take to look for a given awarding to have a higher priority over the CPU to be ran. This ensures that the CPU will deal with the procedure immediately.

1.7.2. CPU Execution Mode¶

At that place are two modes of execution, known equally user mode and kernel or supervisor way. User style is restricted in that certain instructions cannot be executed, certain registers cannot exist accessed, and I/O devices tin can non be accessed. Kernel mode has none of these restrictions. A system call will set the CPU to kernel mode, as will traps and interrupts. Application programs cannot do this.

Mode bit: Supervisor or User fashion

  • Supervisor fashion
    • Can execute all machine instructions
    • Tin can reference all retentiveness locations
  • User way
    • Can only execute a subset of instructions
    • Tin can merely reference a subset of memory locations

i.7.3. CPU Response to Interrupts¶

A central point towards understanding how operating systems work is to understand what the CPU does when an interrupt occurs. The hardware of the CPU does the exact aforementioned thing for each interrupt, which is what allows operating systems to take command away from the electric current running user process. The switching of running processes to execute code from the Bone kernel is called a context switch.

CPUs rely on the data independent in a couple registers to correctly handle interrupts. One annals holds a pointer to the procedure control block of the electric current running process. This register is ready each time a process is loaded into memory. The other register holds a arrow to a table containing pointers to the instructions in the Bone kernel for interrupt handlers and arrangement calls. The value in this register and contents of the table are set when the operating organisation is initialized at boot time.

The CPU performs the following actions in response to an interrupt:

  1. Using the pointer to the current procedure command block, the state and all register values for the procedure are saved for use when the process is later restarted.
  2. The CPU way bit is switched to supervisory fashion.
  3. Using the pointer to the interrupt handler table and the interrupt vector, the location of the kernel code to execute is determined. The interrupt vector is the IRQ for hardware interrupts (read from an interrupt controller register) and an argument to the interrupt assembly language instruction for software interrupts.
  4. Processing is switched to the appropriate portion of the kernel.

../_images/sys_call.jpg

The CPU uses a tabular array and the interrupt vector to find OS the code to execute in response to interrupts. A software interrupt is shown here.


../_images/process_switching.png

As the reckoner runs, processing switches betwixt user processes and the operating organisation as hardware and software interrupts are received.