Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 23

Agenda for Today

 Review of previous lecture


 Interrupts, traps, and signals
 Hardware Protection (CPU, I/O, and memory

protection )
 Operating system components and services
 System calls
 Lecture Recap

1
Interrupts
 Interrupts are signals by external devices,
normally I/O devices. They tell the CPU to stop its
current activities and execute the appropriate part
of the operating system.

2
Interrupt Handing
 When the CPU is interrupted it stops what it is
doing
 The address of the interrupted instruction is
saved
 Called Interrupt Service Routine (ISR)
 After the interrupt is serviced, the saved address
is loaded to the Program Counter
 The Interrupted computation can resume as
though the interrupt had not occurred.
 Different service routines handle different type of
interrupts.

3
Trap
 An event generated by CPU.
 Divide a number by zero.
 To entertain trap, CPU executes trap service
routine.
 In case of trap CPU state (address of next
instruction and contents of registers) are not
saved.
 Trap service routine terminates the program with
error message.
 ISR and Trap service routines are part OS code.

4
Signal
 An event sent to a running program or process.
 The process can take one of three possible

actions:
i. Ignore the signal
ii. Default action defined by OS
iii. Programmer defined action

5
Hardware Protection
 Dual Mode Operation
 I/O Protection
 Memory Protection
 CPU Protection

6
Dual Mode Operation
 CPU runs in two modes:
i. User mode – execution done on behalf of a
user.
ii. Kernel mode (also kernel mode or system
mode) – execution done on behalf of
operating system.
 The instructions executed in kernel mode are
called privileged instructions.
 When an ISR is executing CPU is kernel mode.

7
Dual-Mode Operation …
 Mode bit added to computer hardware to indicate
the current mode: Kernel (0) or user (1).
 When an interrupt or fault occurs hardware

switches to monitor mode.


Interrupt/fault

Kernel user
set user mode

Privileged instructions can be executed only in kernel mode.


I/O Protection
 All I/O instructions are privileged instructions.
 Using privileged instructions, I/O devices are

protected.
 It is needed in TSS, if not implemented then one

user can edit the data files of other users or user


process can edit interrupt vector table.
Memory Protection
 An address space is the region in main memory
that a process can access legally.
 Must provide memory protection outside the

address space of a process.


 In order to have memory protection, add two

registers that determine the range of legal


addresses a program may access:
 Base register – holds the smallest legal physical

memory address.
 Limit register – contains the size of the range
Use of Base and Limit
Register
Hardware Support
CPU Protection
 Timer – interrupts computer after specified period
to ensure operating system maintains control.

 Timer is decremented every clock tick.

 When timer reaches the value 0, an interrupt


occurs.

 Load-timer is a privileged instruction.


OS Components
 Process management
 Main memory management
 Secondary storage management
 I/O system management
 File management
 Protection system
 Command-line interpreter (shells)

14
Operating System Services

Services for user and users of programs:


 Program execution
 File System Manipulation
 I/O Operations
 Communications between processes/users


Error detection and handling
Operating System Services

Services for efficient system operation:


 Resource management
 Accounting
 Protection
OS Kernel
Users
Applications
Operating System API, AUI
Operating System Kernel
Computer Hardware

Real work is done in the kernel


Entry Points into Kernel

System Call Signal

Interrupt Trap
System Calls
 User processes must not be given open access to
the kernel code
 The system call interface layer contains entry point
in the kernel code
 System call is programming interface to the
services provided by OS.
Types Of System Calls
 Process Control
 File Management
 Device Management
 Communications
 Information maintenance
System Call Execution
 The user program makes a call to a library function.
 Library routine puts appropriate parameters at a
well-known place (registers, stack, or a table in
memory).
 The trap instruction is executed to change mode
from user to kernel.
 Control goes to operating system.
 Operating system determines which system call is
to be carried out.
Semantics of System Call
Execution …
 Kernel indexes the dispatch table, which
contains pointers to service routines for system
calls.
 Service routine is executed and return parameter
or error code placed at well-known places (usually
a CPU register).
 Control given back to user program.
 Library function executes the instruction following
trap.
System Call …
Process

Library Call

System Call

trap

Dispatch Table
Service
Code
Kernel
Code

You might also like