Notes of Operation System Course

Notes of Operation System course (2021 Autumn, Tsinghua University)

OS Overview

General Definition

OS has no standard definitions, but OS is

  • A kind of system software to manage application execution, providing easy use of computer to users
  • A kind of resource management software, serving as the middle layer of software and hardware.

Therefore, OS lays in the middle of computer hardware and other system programs or applications. Also the consistence of OS is

  • Shell: response to keyboards
  • GUI: easy for users to use
  • Kernel: manage different resources

OS’s feature includes

  • Concurrency: manage to let several applications run “at the same time”
  • Sharing: can serve several applications
  • Virtual: make users not know each other
  • Asynchronous: applications’ execution is intermittent

Common used OS

  • BSD: FreeBSD, OSX, iOS
  • Linux: Ubuntu, Debian, Android
  • Windows: XP, Vista, 7, 8, 10

Some history

  • Unix
    • Unix is a multitasking, multi-user computer operation system developed from Bell Labs together with C programming language
    • Unix is a closed source, commercial OS
  • BSD (Berkeley Software Design)
    • BSD is a Unix-like OS developed by UC Berkeley
  • macOS / iOS
    • macOS is derived from BSD, and developed by Apple Inc
    • iOS is the derived from macOS
  • Linux
    • Linux is a Unix-like OS kernel developed by Linus. Open source.
    • GNU/Linux is the full OS, which uses Linux kernel and other open source tools (e.g. gcc, gdb) from GNU organization.
    • Debian, Ubuntu, CentOS are the GNU/Linux OS Distribution, which adds more tools like desktop server
    • Android/Linux is the full OS, which uses Linux kernel and other open source tools from Android Open Source Project (AOSP)

from: https://bruhtus.github.io/posts/mac-os-linux/

Computers Load OS

Computer consists of CPU, memory (ROM and RAM) and I/O devices, including disks and keyboards.

  1. Initially, the commands of OS are stored in disks and memory RAM has nothing. Memory ROM has BIOS (Basic Input Output System) firmware, which has functions like basic input and output, system configurations, self health checking services.
  2. Once computer is turned on, CPU reads the commands from BIOS, which load the bootloader of OS from the disks
  3. Then CPU reads the commands from bootloader to load the whole OS from disks to memory RAM.
  4. CPU reads the commands of OS, OS starts to handle different actions.

Notes. Different platforms have different types of BIOS like BIOS-MBR, BIOS-GPT, PXE, but all of them supports the UEFI standards.

Note. the existence of bootloader is because different computers have different types of disks, and BIOS cannot implement to recognize all types of file systems. Therefore, bootloader is required to provide the access to the file system and then could load the whole OS.

OS Kernel

3 ways to enter OS kernel

Enter type Source Synchronize Scenario
Hardware interrupt Hardware requires to process Async Keyboard input
Exception Invalid command causes current processing failed Sync Divide 0
System call Application calls OS to request services Async or sync Application write files in disk

System Call

Applications usually use the system libraries (like Win32 API in Windows) to do the system call to OS.

Different from normal function call, system call will create new heap in memory to process, and convert the permission level.

From the command perspective, system call uses INT and IRET commands to represent the start and end, while function call uses CALL and RET commands.


jmp to BIOS [CS:EIP]
master boot record, 512 MB

  1. enable protection mode
    • enable segment-level protection. Initialize the value for CS, DS registers to point to GBT
  2. read kernel (in ELF format) to memory
    • struct elfhdr (ELF header)
    • struct proghdr
  3. jmp to ucore OS

inline assembly (use assembly in C)
use commands unsupported by C

Interrupt Service Routine (ISP) to handle Interruption (hardware, or software (system call) ) and Exceptions
ISP need to save the value of registers into stack and restore them after the interrupt is handled

relationship from interrupt number to the address of respective ISP is stored in Interrupt Descriptor Table (IDT)

the address of IDT should be stored in IDTR register by OS, the content of IDT is also need to be established by OS

Reference

  1. https://bruhtus.github.io/posts/mac-os-linux/
  2. https://en.wikipedia.org/wiki/Unix
  3. https://en.wikipedia.org/wiki/BSD/OS