Analysis of Linux boot process

zhaozj2021-02-11  209

Analysis of Linux boot process

Skill administrator (2000-12-25 10:10) 〖Back〗 〖Forward〗

The purpose of this article is a introduction to the Boot part of Linuxkernel, because the author feels that there is a very few articles to introduce a homework system to the most beginning - load KERNEL itself into memory, and perform some machines The initialization of the relevant (Machinedependent), because Linux just uses everyone's most familiar 386,486 series PC, so when the procedure flow is explained, it is also possible to explore the relevant PC hardware architecture, which can be said to be two However, I have to assume that the reader has a general understanding of the multi-found architecture of the combination language and PC, such as registers, segments, paging, interrupt services, etc. The reader can find a few in the LinuxSourceCode / boot subdirectory. Sailen as a deployment language file, this article is to indicate, two files, two files, and as much as possible Related hardware part involved. Bootsect.s This program is the first program of Linuxkernel, including Linux's own bootstrap program, but before explaining this program, you must first explain the actions of general IBMPC boot (the boot here refers to "Open PC" : General PC When the power is opened, it is executed by the address fff: 0000 in the memory (this address must be in the ROMBIOS, and the Rombios is typically in Feoooh to FFFFH), and the content here is a JUMP instruction, Jump To another location in Rombios, start executing a series of actions, including checking RAM, Keyboard, monitors, hardcighters, etc., these actions are executed by systemtestcode, with production BIOS vendors Differences will have some differences, but they are all different, and readers can observe their own machines to check the message on the screen. Immediately after the system test code, the control will shift to the ROMBootstrapRoutine, this program reads the zero zero sector on the disk into memory (this is the general so-called bootsector, if you have been touched Computer viruses, it will hear its name), as for where to be read? - Absolute position 07c0: 0000 (ie 07c00h), this is the characteristics of IBM series PC. And the bootsector on the Linux boot disk is Linux's bootsect program, that is, bootsect is the first program that is first read into memory. Now, we can start to see what the Bootsect has done. First step, bootsect moves it "yourself" from the absolute address 0x7c00 loaded by the RombiOS, then uses a JUMPI (JUMPIIRECTLY) instruction, jump to the next line of JMPI, the next line of JMPI, the key Assemblycode is as follows: (Move the Bootsect itself) .. Jmpigo, INITSECGO: ... Indicates that the cs will jump to the CS 0x9000, IP is the location "Go" position (CS: IP = 0x9000: offsetgo), where INITSEC = 0x9000 is defined The part of the program starts, while the Label is just the position where the next line of instructions is located. Step 2 Next, other SegmentRegisters include DS, ES, and SS, point to 0x9000, and CS.

In addition, SP and DX points to an offset address (OFFSET), this address, etc., will be used to store disk parameter tables (Diskpara-metertable) to mention the disk parameter table, you must mention the BIOS interrupt 1EH. Briefly introduce the BIOS interrupt service: 80x86 Reserve the lowest 256 * 4Byte of memory to 256 interrupt vectors (each InterruptVector size is 4Byte, so there is a total of 256 * 4 = 1024byte), and the first vector point "Disk Parameter Table", this table tells the computer how to read the disk machine, and what we have to do is to move the disk parameter table to any address set. Next, change the parameters of the moved parameter table to meet our needs. Then, the interrupt vector 1Eh points to the disk parameter table we have modified, then call the BiosInterrupt's INT13H (Function0, AH = 0) reset the disk control card and disk drive, and then the disk machine will follow our meaning. If you have traced over DOS's kernel, you will find that the above action has similar corresponding processes in DOS. Let us now take a look at the key program code: ... push # 0popfsmovbx, # 0x78. (Make GS: Si = fs: bx, point to disk parameter table, then move the contents of the address "referred to in the address of the GS: Si) 6 Word To ES: DI, the address refers to this program is to adjust the FS: BX to 0078, then set the contents of GS: Si to FS: BX, here 0x78h is the start of INT1EH Location (7 * 16 8 = 120, (1 * 16 14) * 4 = 120). Adjusting ES: DI For any address set, 6 Word (ie, 12Byte) to ES: DI is moved from GS: Si, obviously the length of the disk parameter table is 6 words, (but in fact, The index length of the disk parameter table is 11 BYTE). With regard to disk parameter table, interested readers can refer to the technical manual to tell BiosInterruptServices, will have a detailed description. The reader can use Debug to observe the starting position of the disk parameter table of the DOS on their own machine (inT1eh content). The following is the case of the author (the operating system used by the author is MSDOS6.2): ​​C:> Debug-d0000: 00000000: 00008A101601F4067000-1600CB04F4067000 ... P ....... p.0000: 0010F40670000301790E- 43EB00F0EBEA00F0..P ... YC ... 0000: 002004108E340C118E34-5700CB046F00CB04 ... 4 ... 4w ... o ... 0000: 00308700CB0408079433-B700CB04F4067000 ....... 3 ... ... p.0000: 00400C01790E4DF800F0-41F800F0BA165F06..YM.. ..... 0000: 0050E-70118E341201790E9 ..... YP.4..y.0000: 006000E000F085175F06-6EFE00F0EE067000 ..... ._. n ..... p.0000: 007053FF00F0A4F000F0-220500003E4600C0S ....... "...> f .. ^^^^^^^^ Dos, disk parameters in DOS The starting position of the table (the content of INT1EH) is 0000: 0522.

Then, the 11 BYTE started in DOS 0000: 0522, that is, the content of the disk parameter table C:> Debug-d0000: 0520L100000: 05204D53DF022502121B-FF54F60F08000000MS ..% .... t ... ^^^ ^^^^^^^^^^^^^^^^^^ ^^^^^ ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ), Changed to 18h (12h in the above picture), this BYTE function is to define a data pen on one magnetic area on the track. The key program code is as follows: .MOVB4 (DI), * 18. The first step will then use the BIOS interrupt service INT13H, reset the disk controller, so that the settings are functioning. ..xorah, AHXORDL, DLINT0X13 .. Final After the disk controller is completed, BootSect reads the SETUP program next to Bootsect from the disk, which is the setup.s that will be introduced later. This read action is Use the BIOS interrupt service INT13H to function. Setup's image will read into the memory absolute address 0x90200 specified by the program, that is, in memory, close to the location of BootSect. After reading in the memory, the parameters of the current disk machine are read using the BIOS interrupt service INT13H. In the fifth step, you will read the real Linux kernel, that is, you can see "VMLinuz" in the root of Linux. Before reading, the BIOS interrupt service INT10H will be called first, read the cursor position, then call the 13h of the BIOS interrupt service INT10H, output strings "Loading" on the screen, this string When bootlinux is first seen, I believe that everyone should feel familiar. Linux's kernel will be read to the memory absolute address 0x10000, the program code of the key is as follows: .. Movax, # syssegmoves, axcallread_itcallkill_motor .. where sysseg is defined as 0x1000 when the program starts, first set the ES content to 0x1000, The subroutine in the Read_IT will be in the destination of ES, and the kernel read into memory. As for the detailed content of the READ_IT subroutine, I don't want to introduce one by one, but smart readers should have guessed, read_it must have The I / O interrupt service associated with the disk is used to use the Biosint13h. As for the Kill_Motor subroutine, its function is to stop the motor of the floppy machine (the smart readers will not think that the name of this subroutine is very expressive?), The program code is as follows: .. Kill_Motor: PushdxmovDX, # 0x3f2xoral, AloutBPopdxret .. First use DX to specify the port to be output, and 03f2 this port represents the floppydiskcontroller, and then uses Outb to send the information, and the information we sent, of course, is the Allah Already . In this way, the motor of the floppy disk stops. The next step is to check RootDevice, follow the beginning of the way, use IndirectJump to skip some setup part, the program code is as follows: .. jmpi0, setypseg where setupseg is previously defined as 0x9020 Therefore, CS: IP will be set to 9020: 0000, that is, jump to the absolute address of 0x90200, which is the starting point of Setup. Bootsect also told.

转载请注明原文地址:https://www.9cbs.com/read-3536.html

New Post(0)