OS

  • There are three components in computer hardware systems
    • Processor, main memory and I/O devices
      OS:
  • is a program that manages the computer hardware
  • also provides a basis for application programs
  • and acts as an intermediary between a user of a computer and the computer hardware
  • 2 primary purposes:
    • Protect hardware from misuse by applications
    • Provide applications with simple and uniform mechanisms for manipulating hardware devices
      ![[Pasted image 20240710111247.png]]
      ![[Pasted image 20240813151024.png]]

process

•The program appears to have exclusive use of all the processor, main memory, and I/O devices
•The program appears to execute the instructions in the program, one after the other, without interruption
•The code and data of the program appear to the only objects in the system’s memory
![[Pasted image 20240813141024.png]]

user and kernel mode

•Process running in kernel mode can
- execute any instructions in the instruction set
– can access any memory locations in the system
•Process running in user mode can
–neither execute privileged instructions
–nor directly reference code or data in the kernel area of the address space
–only do above indirectly via system call interface

vitural memory

•An abstraction
–Each process appears to have exclusive use of the main memory
–Virtual address space
•Program code and data (global variables)
•Heap
•Shared libraries (standard and math libraries)
•Stack (function calls)
•Kernel (operating system)
–Hardware supports to translate the virtual address

file

•A sequence of bytes
•Each I/O device is modeled as a file
•Unix I/O
–using a small set of system calls reading and writing files
–All input and output in the system is performed by Unix I/O

exception

•A process running application code
–initially in user mode
•How can we change the control flow from user mode to kernel mode?
–We’ve discussed two mechanisms for changing the control flow:
•jumps
•call and return using the stack discipline
–However, both can only alter control flow in the same mode
–New instructions are introduced
•syscall / sysret

system call

  • The pair of instructions syscall/sysret are a hardware mechanism transfer of control between user and kernel mode
  • System Calls
    • A procedure-like interface between user programs and operating systems
    • Controlled access to kernel services

Parameter Passing for System Calls

•Up to 6 parameters are passed between two modes
%rdi,%rsi,%rdx,%r10,%r8,%r9
•Caller saved registers must be saved in user mode if necessary
–%rcx and %r11 are destroyed
Returns integer in %rax whether it is succeeded
![[Pasted image 20240816145807.png]]

exception

•Processor‘s state
–encoded in various bits and signals inside the processor, such as kernel bit inside the processor   
•Events
–Significant changes in the processor ‘s state
•Results of execution of syscall/sysret instructions
•data arrives from a disk or a network adapter.
•instruction doing divides by zero
•Exception
–A hardware mechanism transfers control to the kernel in response to some event

exception table

  1. Each type of event has a unique exception number k
  2. Exception table entry k points to a function (exception handler).
  3. Handler k is called each time exception k occurs.
    The exception number is an index into the ex ception table, whose starting address is contained in a special CPU register called the exception table base register.

exception handler

  • run on kernel mode
    • means they have complete access to all system resources
  • Processor pushes onto the kernel’s stack
    • Necessary information will be necessary to restart the interrupted program when the handler returns

classes of exceptions

![[Pasted image 20240829215539.png]]
Interrupts occur asynchronously as a result of signals from I/O devices that are external to the processor. Hardware interrupts are asynchronous in the sense that they are not caused by the execution of any particular instruction. Exception handlers for hardware interrupts are often called interrupt handlers.

  • Traps
    • Intentional
    • returns control to “next” instruction
    • Examples: syscall, breakpoint traps