Open source code inquiry guide (ZT)

xiaoxiao2021-03-06  40

Open source code exploration guidance :: Wang Dong :: Linux As an excellent operating system, one of why should belong to an open kernel source code. Speaking of the kernel source code, we have to save the awe of psychology. It is like the status of Linux as important as the status of our body, it is the soul of the entire operating system. For most Linux enthusiasts, you may have already understood the basic operations of the system and the server's application, but have you ever thought about analyzing the source code? Some people may say: "The volume of the Linux kernel is large, and it is analyzed and very boring. It seems that it is not very good for practical applications. Why do we know it? Yes, directly analyze the source code It is a boring and heavy work, but I think you have learned Linux, then you should make a decision of the difficulties. In this article, the author wants to overcome difficulties with Linux enthusiasts, share this piece The difficult big pie, the source code we use is Linux 2.4. We should know what is guidance before learning. Speak boot, you may want to boot the program - Lilo and GRUB. But we want to analyze today. Not these two programs, but analyzing how the computer is running after we turn on. First we roughly look at the computer boot process: After power-on, the CPU completes the self-test and initialization, set the initial value in the register, and then execute The first instruction. The address of the instruction is CS * 16 IP, ie 0xfffoh, which is a BIOS's entry address. After completing self-testing of the entire machine system, record basic information about system configuration in memory BIOS data In the area, then read the first sector of the guide disk into the 0x7C00H of the memory. Go to the point, give the control power to the boot program, the final boot program reads the operating system into the memory, and give control Operating system kernel. Since the system works in the real mode when the system is in the real mode, it can only access the memory 640kb. So Linux often packs its kernel image, put it into memory by the boot program. The boot program is Bootsect and setup, so the structure sequence of several sectors in front of a guide disk is: bootsect-> setup-> Unzip-> compressed kernel image. Bootsect's role is to read the operating system core from the boot disk to memory Among them, its specific work is as follows: (Everyone can open /usr/src/arch/i386/boot/bootsect.s to follow.

SETUPSECTS = 4 / * In the default, only the SETUP program of 4 sectors * / bootseg = 0x07c0 / * is loaded into the physical memory 0x07c0 * / initseg = def_initseg / * Move to 0x90000 * / setupseg = Def_setupseg / * setup program starts from here (0x90200) * / sysseg = def_sysseg / * Nuclear reading the operating system to 0x10000 (65536) * / sysSize = Def_sysize / * core size (0x7f00) ), Its true size is SYSSIZE * 16 * / Step: Move yourself from 0x7c00 to 0x90000 to execute MOVW $ bootseg,% AX MOVW% AX,% DS / *% DS = bootseg * / MovW $ INITSEG,% AX MOVW% AX,% ES / *% AX =% es = initseg * / MOVW $ 256,% CX / * 256 word * / subw% Si,% Si Subw% di,% di CLD Rep Movsw ljmp $ INITSEG, $ Go / * Go to the GO position at 0x9000 to start executing * / Step 2: At 0x94000-12 Stack GO: MoVW $ 0x4000-12,% di / * 0x4000 is large enough to put Bootsect, setup and stack, * / / * The 12 bytes left to the disk parameters. * / MOVW% AX,% DS / * Now% AX and% ES already contains INITSEG * / MOVW% AX,% SS MOVW% DI,% SP / * bundled in Initseg: 0x4000-12 * / third step : Copy the disk parameters from 0x78 to 0x94000-12 Now the value of each segment register is as follows by% CS =% DS =% ES =% ss = initseg,% FS ​​= 0. MOVW% CX,% FS ​​/ *% FS = 0 * / MOVW $ 0x78,% bx / *% fs:% BX is the parameter table address * / pushw% DS LDSW% FS: (% bx),% Si Movb $ 6, % CL / * Copy 12 bytes * / pushw% di / *% di = 0x4000-12. * / Rep MOVSW POPW% DI POPW% DS MOVB $ 36, 0x4 (% DI) / * Set the maximum number of sector 36 * / MOVW% di,% fs: (% bx) MOVW% ES,% FS: 2 (% BX) fourth step: directly load SETUP program MOVW $ 0x0001,% AX / * in 0x90200 Speed, each time read only one track * / MOVW $ Sread,% Si MoVW% AX, (% Si) XORW% AX,% AX / * reset FDC * / XORB% DL,% DL INT $ 0x13 MoVW $ 0x0200, % bx / * address = 512, in initseg * / ┊ ┊ Step 5: Terfer which follow-up device can be used, if it is defined, what is not dry, execute is defined. Step 6: Go to the first instruction of the setup program start execution. LJMP $ setupseg, $ 0 Step 7: This boot has been completed, this part of the memory is used to store BIOS information.

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

New Post(0)