Read kernel-Linux kernel startup-BIOS

Source: Internet
Author: User

Source: http://www.top-e.org/jiaoshi/html? 196. html

 

"It's really cool to tell me that the real entry address of the C program compiled using the glibc library in Linux is _ start (). Isn't that enough ?" The rotten eggs flat.

Well, I just want to use a special way to describe the problem. I pay more attention to the ways of thinking embodied in the process of exploration and the fun of it.

Return to our topic. Why is the Linux Kernel not executed from the main function? In fact, there are many main () functions in the Linux kernel source code, but take a closer look. They all run in user mode. In fact, we can see from the previous section that the main () function is just a symbol. Start_kernel () is mentioned in many books (). It is similar to main (). But just as calling Main () is _ start (). There is still a lot of code before start_kernel. Therefore, the real kernel entry is not start_kernel ().

What really decides the program execution entry is to load the program. For the common C program helloworld, the Linux kernel (bash in strict terms) is responsible for setting the helloworld entry point and starting the helloworld process.

So the problem arises. What is the Linux kernel loader? Are you loading yourself?

Such similar problems have occurred many times in the history of computers. For example, C programs can be written using the C compiler. So what should C compiler use to write? Of course, there are many solutions, such as writing in assembly language. So what should the assembler use to write? It can be written in machine language. Although it is a painful thing, the idea of benefiting so many people (to be divergent, the C compiler can compile compilers or interpreters for various new languages such as Perl, then programmers can use Perl to compile various complex systems.) This is so great that the programmer who writes the assembler in machine language will be very energetic. The common solution to these problems is to construct a simple system to solve the problem of a complicated system, finally, a very complex problem is solved. Therefore, we naturally think of using a simple kernel (No, it is just a program, or even not called a kernel, because it has limited functions) to start the real kernel. Just like using a small equivalent atomic bomb to trigger a hydrogen bomb.

Based on the kiss (keep it simple and stupid) principle, you may first think of BIOS. The BIOS usually exists on the Rom. With the expansion of Rom capacity (up to 1 MB or more), the BIOS function on the PC is very powerful, including drivers of many devices. It not only performs hardware detection, but also implements basic input and output functions. (Basic Input/Output System ). The BIOS setting screen displayed by pressing the Del key at startup is a masterpiece of BIOS. It is not impossible to implement an OS on the BIOS. In fact, DOS is implemented based on bios.

However, one of the fatal disadvantages of BIOS is that it can only run in 16-bit real-address mode so far. After all, the ROM capacity is very limited. (Of course, it is not absolute. BIOS also provides a method to scan the PCI device in the protection mode. You can run the BIOS in the protection mode .) The CPU is in the 16-bit real-address mode when it is powered on. Its other fatal disadvantage is that it is too small. Because of the diversity of modern operating systems, it is impossible for the BIOS to take into account all possible situations.

However, when the PC is started, the x86 CPU will still start automatically from the bios, which is determined by the hardware, because the value in the register CS is 0 xFFFF during power-on, the value in the IP address is 0. Therefore, the CPU starts to take commands from the linear address 0xffff0. Where is 0xffff0?

Run CAT/proc/iomem

First 5 rows

201710000-0009fbff: System Ram

0009fc00-0009ffff: Reserved

000a0000-000bffff: Video RAM Area

000c0000-000cc7ff: Video Rom

000f0000-000fffff: system ROM

We can see that 0xffff0 is system ROM, that is, BIOS.

Note that the address here is a linear address in 16-bit real address mode.

What the BIOS can do, including checking the device at startup, and finally reading the 512 bytes of the first sector (that is, the boot sector MBR) on the hard disk, copy them to the memory at 0x7c00. So far, the BIOS boot mission has been completed. Although later Linux kernel boot will also use the BIOS function, the mission of boot is already on other programs.

Source: http://www.top-e.org/jiaoshi/html? 196. html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.