When talking about the computer startup process, we need to first understand that the memory is a volatile memory, so before the computer is powered on, nothing exists in the memory, so from the memory program and data from scratch, this requires a process, that is, the computer startup process we will talk about.
Knowledge push: (the following data comes from Baidu encyclopedia)
1. bios and CMOS
(1) BIOS is a software program written into the hardware. BIOS functions are divided into three parts: self-check and initialization, program service processing, and hardware interrupt processing.
A) self-check and initialization
This function is divided into three parts:
I. Post power on self test (post power on Self Test): After power-on, the computer's hardware is detected. The hardware to be tested usually includes: CPU, KB of basic memory, and 1 Mbit/s of extended memory, rom, motherboard, CMOS memory, serial port, display card, hard disk subsystem and keyboard for testing.
Ii. initialization, including creating interrupt vectors, setting registers, and initializing and detecting some external devices
Iii. BOOT program is used to boot DoS or other operating systems. the BIOS first reads the Boot Record from the starting sector of the hard board. After the Boot Record is read successfully, the BIOS will hand over the control to the Boot Record, mount the operating system into the computer with boot records
B) program service processing. The service targets your applications and operating systems and provides services related to I/O devices, such as reading disks and outputting files to printers.
C) hardware interrupt handling: handles hardware requirements of applications and operating systems, such as disk and serial port services, video services, and screen printing.
(2) CMOS is mainly used to store some parameters and data set by the BIOS setup program.
2. MBR
Byte offset (HEX) |
Bytes |
Description |
00 ~ 1bd |
446 |
Guiding code |
1be ~ 1cd |
16 |
Partition Table Item 1 |
1ce ~ 1dd |
16 |
Partition Table Item 2 |
1de ~ 1ED |
16 |
Partition Table Item 3 |
1ee ~ 1fd |
16 |
Partition Table Item 4 |
1fe ~ 1ff |
2 |
55aa |
Note: The Conversion Program can be found in the "toolbox" of my blog category.
1bd = 1*16*16 + 11 (B) * 16 + 13 = 445
1be ~ 1fd = 446 ~ 509, 64 bytes in total
(1) MBR (Master Boot Record) is located in the hard disk's No. 0 cylinder, No. 0 head, no. 1 Sector (PS. hard Disk 0 \ 0 \ 0 is used to store the model, size, and other content of the disk), mainly consists of four parts.
I. Main Bootstrap program: 0000h ~ 0088 H, which is responsible for loading boot programs running the system from the active partition. This section mainly contains a command to notify the computer how to read the partition table and locate the operating system. The code in this section varies with the operating system, and the guiding code can be used to implement multiple guidance.
Ii. error information data area. The offset address 0x89 -- 0xe1 is the error information, and 0xe2 -- 0x1bd is all 0 bytes.
Iii. Partition Table, 0x1be ~ 0x1fd. Each partition table occupies 16 bytes, A maximum of four partitions can be described. (This is why the MBR partition system can only be divided into four partitions. [the partitions we usually see can be selected from 26 letters as partition IDS (more 4 ), this is because the partitions are logical partitions. The four partitions here refer to the number of Primary partitions and extended partitions, while the logical partitions are divided in the extended partitions, it is also called level 2 and level 3 extended partitions. ]). Contains four partition items, with the offset 01beh--01fdh. Each partition table item is 16 bytes long,
Partition Table items do not have order requirements, that is, the first Partition Table item is not required to be before the second partition table item. The partition table does not need to start iv and end mark from the first Partition Table item. The two byte values of the Offset address 01fe--01ff are the end mark 55aa. If this sign is not available, the operating system will think that the disk is not initialized and the partitions of the disk cannot be correctly loaded.
PS. In the embedded world, we use the famous bootloader to replace MBR on PC. The boot process of bootloader can be divided into two types: single-stage and multi-stage. In actual applications, multi-stage functions are powerful and portability is good. Currently, most bootloaders adopt two phases: stage1 and stage2: stage1 (implemented by assembly and run on flash, because the implementation of C language requires database support, obviously, the database is not ready at the time of startup): (1) hardware initialization (mainly the internal registers of the CPU) (2) Prepare the memory (RAM) for the stage2 stage of the bootloader) space (3) copy the code in the stage2 stage of bootloader to the memory space (4) set the stack (the reason for setting the stack is that C code is used in the stage2 stage, stack is used to run C code.) (5) Jump to stage2's c Entry Point stage2 (implemented in C language and run in memory): (1) initialize some onboard hardware (2) copy the kernel and root file system from flash to memory (3) Call the kernel and start the Operating System
MBR:
========================================================== ========================================================== ============================================
After the above knowledge is pushed, it is easy to start the system,
First, after the computer is powered on,
(1) the BIOS on the motherboard is started first. The BIOS completes hardware detection, resource allocation, and initialization of some registers and vectors, (assume that the first device that the BIOS detects can be started is the hard disk.) At last, the BIOS will read the slice at CHS = 0 \ 0 \ 1 on the hard disk, that is, the MBR will read the memory 0x7c00 position, and hand over control to the master Bootstrap in MBR
(2) The Master Boot Program in MBR reads the kernel image of the operating system from the hard disk to the memory according to the partition table, and gives the control to the operating system.
(3) Start the Operating System