Intro to OS

What happens when you turn the computer ON?

  • Computer loads the BIOS from some special flash memory located on motherboard
  • BIOS runs self-test and looks for bootable disks
  • The computer executes the firmware code that is on the ROM
  • ROM performs POST (Power-On Self-Test) which detects RAM
  • After that, oROM initializes CPU and hardware
  • Looks for a bootable disk, boots OS Kernel

There are 2 firmware standards in Computers:

  • BIOS ( Basic Input Output System )
  • UEFI ( Unified Extensible Firmware Interface )

BIOS is simple, supported from the pcs from 1980s.

UEFI is modern, complex to set-up. It emulates BIOS in the backend.

That is sad, because all the computers boots up in 16-bit real mode (opens in a new tab) to make the 1980 bootloaders still work.

When you turn on a computer, it loads the BIOS from some special flash memory located on the motherboard.

The BIOS runs self-test and initialization routines of the hardware, then it looks for bootable disks.

If it finds one, control is transferred to its bootloader, which is a 512-byte portion of executable code stored at the disk’s beginning.

Most bootloaders are larger than 512 bytes, so bootloaders are commonly split into a small first stage, which fits into 512 bytes, and a second stage, which is subsequently loaded by the first stage.

The bootloader has to determine the location of the kernel image on the disk and load it into memory

It also needs to switch the CPU from the 16-bit real mode (opens in a new tab) first to the 32-bit protected mode (opens in a new tab), and then to the 64-bit long mode (opens in a new tab), where 64-bit registers and the complete main memory are available

Its third job is to query certain information (such as a memory map) from the BIOS and pass it to the OS kernel.

Multi-Boot?

To avoid that every operating system implements its own bootloader, which is only compatible with a single OS, the Free Software Foundation (opens in a new tab) created an open bootloader standard called Multiboot (opens in a new tab) in 1995

Interface between the bootloader and the operating system. GNU GRUB is used in many linux systems

To make a kernel Multiboot compliant, one just needs to insert a so-called Multiboot header (opens in a new tab) at the beginning of the kernel file.

demo.json
"features": "-mmx,-sse,+soft-float",
  • '-' means disable here
  • '+' means enable here

#MMX : (MultiMedia eXtension) Set of instructions in computer processors primarily designed to enhance multimedia performance.

#SSE: (Streaming SIMD Extensions) Another set of instructions in processors aimed at improving multimedia and gaming performance by processing multiple data elements simultaneously.

#MMX and #SSE are features which support Single Instruction Multiple Data (SIMD) (opens in a new tab) instructions. That means they do a single operation to multiple datas faster. But they end up taking a lot of time, hence not giving time for the other processes to run. So, we disable it, especially in OS development.

When the kernel pauses the program, it needs to remember exactly what the program was doing so that it can resume from that point once the interruption is dealt with. To do this, it saves the current state of the program, including all the data stored in the processor's registers. However, when the MMX and SSE features are used in the program, these registers contain a lot of data related to those features. So, before the kernel can save the state of the interrupted program, it needs to make sure it saves all the data related to MMX and SSE, which can be a lot of information.

Enabling #soft-float, which means that floating-point arithmetic operations will be handled by software routines instead of relying on dedicated hardware support.