Load Kernel
806 词 5 分钟BIOS
It is a firmware that provide the necessary instruction for the computer to perform basic functions such as hardware initialization.
Functions of the BIOS
- Power-On Self-Test (POST):
When you turn on your computer, the BIOS performs a POST to check that all the necessary hardware components (like memory, keyboard, and storage devices) are functioning correctly. - Bootloader Execution:
After the POST, the BIOS looks for a bootable device (like a hard drive, SSD, USB drive, or CD/DVD) and loads the bootloader from the bootable device into memory. The bootloader then takes over to load the operating system kernel. - Hardware Initialization:
The BIOS initializes and configures hardware components, setting up basic operational parameters. This includes setting up the CPU, memory, and peripherals such as disk drives and video cards. - BIOS Setup Utility:
The BIOS includes a setup utility that users can access to configure hardware settings, such as system time and date, boot sequence, and hardware parameters. - BIOS Services:
The BIOS provides low-level routines that operating systems and programs can use to interact with hardware. These routines offer a standardized way for software to communicate with hardware devices without needing to know the details of the hardware.
BIOS interrupt
It refer to invoke routines provided by the BIOS to the x86-based computer. It allows the CPU to switch from executing the current program to the routine provided by the BIOS.
Calling BIOS Interrupts:
- To invoke a BIOS interrupt, software sets up registers with specific values, including the interrupt number (represented as an index into the IVT). Then, the software triggers the interrupt using the
INT
instruction, which causes the CPU to transfer control to the corresponding ISR in the BIOS.
Purpose and Usage: - BIOS interrupts are used to perform low-level operations that interact directly with hardware, such as disk I/O, keyboard input, video display, system timer control, and system shutdown/restart functions.
- They provide a standardized interface for software running in real mode to access these hardware functions without needing to know specific hardware details.
Example of BIOS interrupt
INT 13h: Provides disk services, such as reading and writing sectors from/to disk drives
INT 15h: Provides system services, including memory allocation, system configuration query, and power management functions.
Bootloader
Bootloader is a program to load the operator system kernel into memory.
Functions of a Bootloader
- Power-On Self-Test (POST):
When you turn on your computer, the Basic Input/Output System (BIOS) or the Unified Extensible Firmware Interface (UEFI) performs a POST to check hardware components’ functionality. - Boot Device Detection:
After the POST, the BIOS/UEFI searches for a bootable device, such as a hard drive, SSD, USB drive, or CD/DVD, based on the boot order specified in BIOS/UEFI settings. - Loading the Bootloader:
Once a bootable device is detected, the BIOS/UEFI loads the initial bootloader program stored in a specific location on that device (e.g., the Master Boot Record or EFI System Partition). - Bootloader Execution:
The bootloader program takes control, initializes hardware (if necessary), and allows the user to select which operating system or kernel to load if multiple options are available (e.g., dual-boot systems). - Loading the Kernel:
The main task of the bootloader is to load the operating system kernel into memory. It reads the kernel file from the boot device and transfers control to the kernel, passing any necessary parameters. - Transition to Operating System:
Once the kernel is loaded and initialized, the operating system takes over and continues the boot process. The OS then loads necessary drivers, initializes system services, and presents the user with a login screen or desktop environment.
Load kernel process
LBA
LBA is commonly used in BIOS (Basic Input/Output System) and operating systems to access data on hard drives, solid-state drives (SSDs), and other storage devices.
When reading or writing data to a disk using LBA, the operating system or application specifies the LBA address along with other parameters (such as the number of sectors to read/write and the buffer address).
How to read a sector
- Prepare Registers:
mov $0x42, %ah
setsAH
to0x42
to indicate the Extended Read function.mov %sp, %si
setsSI
to point to the stack pointer, which will be used as the pointer to the data packet.
- Push [[Data packet]] onto the Stack:
- Push the packet size (
16
bytes). - Push the number of sectors to read (
1
sector). - Push the buffer offset (
0
), which is the offset within the segment where data should be read into. - Push the buffer segment (
ES
), which is the segment where data should be read into. - Push the LBA address in three parts (high part, mid part, low part).
- Push the packet size (
- Call BIOS Interrupt:
int $0x13
calls the BIOS interrupt to perform the Extended Read operation using the data packet.