Operating System Notes-Chapter 2 Start/Interrupt, Exception and System Call

1. Start

  • DISK: Store OS
  • BIOS: Basic I/O processing system (check the peripherals before you can load the software to start execution)
  • Bootloader: Load the OS (load from the hard disk to the memory, so that the CPU can execute the operating system)
    Start the call flow
  • POST (power-on self-test): find graphics card and execute BIOS

2. Interrupts, exceptions and system calls

2.1 Why can't applications directly access peripherals, but through the operating system?

  • When the computer is running, the application is untrusted, and the kernel is a trusted third party
  • Provide a simpler and unified interface for the superstructure, shielding the complexity and difference of the bottom layer

2.2 Definition:

  • System call (from the application program): The application program actively sends a service request to the operating system (a special instruction)
  • Abnormal (from bad application): illegal instruction or other bad processing status (such as memory error)
  • Interrupts (from peripherals): timers and network interrupts from different hardware devices

2.3 Comparison of interrupts, exceptions and system calls

  • source:
    • Interrupt: Peripheral
    • Exception: unexpected behavior of the application
    • System call: The application requests the operating system to provide services
  • Processing time:
    • Interrupt: Asynchronous
    • Exception: sync
    • System call: synchronous or asynchronous
  • response:
    • Interruption: The application continues and is transparent to the user application
    • Exception: Kill the application or re-execute unexpected application instructions
    • System call: wait and continue

2.4 Interrupt handling mechanism

  • Hardware: Set interrupt flag (CPU initialization)
    • Set interrupt flags for internal and external events
    • ID of the interrupt event
  • Software (operating system)
    • Save the current processing state (for subsequent recovery)
    • Interrupt service routine processing
    • Clear interrupt flag
    • Restore the previously saved processing state
      * that is, the application program mentioned before is transparent, and the application program does not perceive the generation of the interrupt program

2.5 Exception handling mechanism

  • Save the scene
  • Exception handling
    • Kill the abnormal program
    • Re-execute the abnormal instruction (note that the repaired is re-executed)
  • Restore the scene

2.6 Principle of System Call

  • The application program needs the operating system to provide services, and the operating system needs to provide an interface, namely the system call interface
  • Program access is mainly through high-level API interfaces rather than direct system calls
    • Win32 API for Windows
    • POSIX API is used for POSIX-based systems (including all versions of Unix, Linux, and Mas OS X)
    • Java API is used for the Java Virtual Machine (JVM) (the API interface that is not part of the operating system, but ultimately uses the API of the current system)
  • The difference between program call and system call
    • The system call needs to complete the stack switch and state transition, which takes longer;
    • Program calls are processed in the stack and produce results

2.7 Implementation of system calls

  • Need to complete the transition from user mode to kernel mode

3. The cost of crossing operating system boundaries

  • Execution time exceeds program call
  • Expenses (worth and necessary, to ensure that the operating system is executed in a safe and reliable environment)
    • Initialization overhead for establishing the mapping relationship between interrupt/exception/system call numbers and corresponding service routines
    • The operating system has its own stack and builds the kernel stack (processing overhead for saving and restoring)
    • Verification parameters (parameter verification is required for not trusting the application)
    • The kernel mode is mapped to the address space of the user mode; the page mapping permissions are updated
    • Kernel independent address space (TLB)

Guess you like

Origin blog.csdn.net/MaoziYa/article/details/105285160