CHAPTER 209 LINUX FIRST EDITION

The source code package sent by readx;?linus is about 12,000 lines of code, and it took him about ten days to write these codes, and if you count the time he spent preparing for this, he would add at least a month-:. Pen @ fun @ pavilion wWw. biqUgE。 info3∴35686688 but Lin Hong finished reading the code, but it only took about three hours to read it.

Lin Hong found that many places in it borrowed the writing of minix, after all, linus had been studying minix before, and borrowed a lot of features and functions from it. For example, the structure of the file system.

The file system of minix is written in imitation of UNIX, and only when the file system is implemented can it be possible to read and write to the disk, so to speak, the file system is the management program of the disk. Although the current Linux does not involve the disk read and write function, this part of Linux still implements it.

According to the usual practice of programming, usually the first program is to implement "hello, wolrd", and Linus has also printed this statement on the monitor, but the version of the function he sent to Lin Hong is not so simple.

He implemented two important features in this release, namely Protected Mode and Multi-Process.

These two characteristics are not possessed by the DOS system and are regarded as important functions of the modern CÀO system.

"Protected mode" is a term for memory.

Intel released a 16-bit CPU in 1978, the 8086, which was an important milestone in Intel's history and one of the most important products that laid Intel's chip in the PC field.

The 8086 CPU always has 20 address lines, which can address up to 2 to the 16th power, which is 1MB of address space-:.

This is the maximum memory address that an 8086CPU-based computer can support, and this mode is called "real mode". The DOS system works in this mode.

Real mode only supports up to 1MB of memory. As far as Lin Hong wants to upgrade the Compaq computer he is using, add another 1MB of memory to the memory module, the DOS system can't recognize it, it doesn't help at all, and Xing can not improve anything.

This was dictated by the hardware structure of the 16-bit CPU, which at the time was quite good with 1MB of RAM. All apps are enough to use.

However, in the field of electronics, there is a "Moore's Law", integrated circuits continue to develop rapidly, and soon the 8086CPU will not be able to meet the requirements.

So Intel launched the 80386, an upgraded version of the 8086 in 1985.

This time, the number of bits in the register has been doubled, from 16 bits to 32 bits.

The 80386 CPU adds a number of advantages, not only does it have a large addressing space, but it also introduces the concepts of multitasking and protection mode. Device: No ads, full text, more

In protected mode, memory management is no longer the segmented structure it used to be. Instead, it has become a paging mechanism, which has great advantages and can greatly improve memory management.

However, in the computer world, there is a "forward compatibility" rule, that is, the 80386 must be compatible with the 8086 CPU mechanism, the program that can run on that before. It also runs on the upgraded CPU.

So by default, this "Protected Mode" is not turned on, and the "Real Mode" is still used.

In order to turn on the "protected mode", you need to cào the address line 20 with a code to "wake up". It is the guardian who enters the protection mode, and it must be done with its consent.

It's easy to say, but the whole process is quite complicated to implement.

That's why it took so long for Linus to finally finish the version.

They want Linux to keep up with the development of the times, so that the future functions of Linux can be comparable to these latest CàO systems, and it is essential to enter the protected mode, because only by entering the protected mode can the maximum xing energy of the 80386 CPU be maximized.

When Lin Hong read "Cào System Design and Implementation" before, he was very confused in this part, and he also checked a lot of information. But I still can't figure out why this mechanism is designed like this.

However, after seeing the implementation code of Linus today, he suddenly had a sudden epiphany.

Unlike when you usually program, you don't have to worry about the underlying structure of the hardware, but the underlying code of the cào system is closely connected to the hardware. The original boot and load programs had to be assembled to be competent. It is confirmed to a certain register of the CPU, and it is also confirmed to a certain sector of the disk.

To understand this code, you must have a very clear understanding of the hardware structure of the CPU and disk. For example, how many pins does the CPU have, how many registers are in it, and what is the purpose of each register.

Good in these technical parameters. Intel has very detailed technical documentation. Such a small chip, but the technical information involved is a few thick tomes.

Lin Hong had to sigh. In this small chip, it carries the most advanced knowledge crystallization in human civilization, bringing human wisdom to the extreme, and every pin and not a single register is finally settled after thousands of continuous experiments.

Lin Hong configured the development environment according to the documentation written by Linus, and then compiled the code under the minix platform.

After fixing a few minor bugs, he finally compiled the Linux image file.

He only had one computer, so he ended up having to install this Linux on his own computer.

Of course, he used a multi-system installation, and the other two systems were not affected.

After restarting, he selects the menu and hits enter.

A series of characters flashed on the monitor, constantly swiping upwards.

At this moment, Lin Hong already has a very deep understanding of the detailed process of computer startup, and it is no longer the same as before. There is no idea what the computer is really doing.

When the power switch is pressed, the machine starts to power on, and the motherboard's control chip then sends a reset signal to the CPU to restore the CPU to its original state, and when the chipset detects that the power supply on the CPU is stable, the CPU will start working.

The first thing it does is read the instruction from the 0xffff0 address in memory to run.

And in this address. There is usually a jump command to jump to the self-test system of the BIOS, and the self-test process begins. BIOS is a system that motherboard manufacturers have long brushed into the firmware, the purpose of which is to manage the hardware.

The purpose of the self-test is to check whether the hardware of each part of the computer is normal, if there is missing or damaged hardware, the boot will be suspended immediately.

Only after all hardware checks have been passed, will it finally jump to the first sector, read the MBR, and start executing the CÀO system installed on the disk.

And linus completes the function. It is how to load the CÀO system into memory for execution after reading the MBR.

The process is very fast, the characters are constantly refreshed upwards, the hardware detection is over quickly, and then the display flashes, and suddenly the characters like "aaaaaabbbb......" appear at the top - other book friends are reading:.

Looking at the AB characters that kept appearing on the monitor, Lin Hong knew that this time the startup process was over. He's already seen what Linus has written.

If other people who don't understand technology see this, they will definitely scoff at this and say, "This is also called a cào system?" Just kidding! ”

In fact, when Linus wrote this version, he excitedly called his sister Sara to watch it. After all, this is a work that he has put a lot of effort into compiling, and after working hard for so long, he finally succeeded, and naturally wanted to share his joy with others.

But Sarah, who was holding the teddy bear, stared at the monitor for about five seconds, said "good", and went back to the room to talk on the phone with her best friend.

Linus was stunned for a long time, and it took a long time to realize that he and people who didn't understand technology had no common language at all. He even hoped that his sister would be able to understand the efforts and results he had made. This is simply naïve.

In the eyes of the other party, this is simply showing a few characters, nothing special at all, and I don't know what the point of doing such a function is.

However, Lin Hong knew that the AB characters that were constantly displayed on the display screen were printed on the screen by two processes. In other words, in this version, Linus not only implements the protection mode, but also makes the prototype of multi-task management.

"Awesome!"

"Very bāng!"

“nicejob!”

These are Lin Hong's comments on Linus.

This part of the content seems to be understandable though. But Lin Hong knew that if he let himself write it. It must take more time and effort than the other party. It's not because my own technology is not at home, but because my understanding of this aspect is not deep enough, or that there is too little information in this area, and I can't write it at all with just a book of "Cào System Design and Implementation", and it also involves the accumulation of a lot of other knowledge.

Usually, Lin Hong observes and uses computers from a macroscopic perspective, but when he sees this most primitive cào system, he suddenly has a feeling of observing under a microscope.

All the black boxes were gone, and he knew exactly what the computer was going to do next, and all the details were at a glance.

It was already past two o'clock in the morning at this moment, and Lin Hong wanted to communicate with Linus, but the other party was not online at the moment.

So, he was in a mood and began to devote himself to the development of Linux in earnest.

What he wants to do is to port the previous linus all the way up to bash in minix, that is, the shell, to linux.

The shell is very important, it can be said to be the mother of all programs, and only by porting it can other applications be able to execute smoothly.

Bash itself is an open-source program that can be downloaded for free from the internet, but Lin Hong has its source code in his hand, which was mailed to him by Linus last time.

To write this, you have to implement some system call commands for the cào system, such as the display directory "ls" command, the "cd" command to enter the directory, which are the most basic.

There are a lot of system calls, and Lin Hong plans to complete the support in minix for the time being. Rest, more on that later.

In order to avoid duplicate development by Linus, he first sent an email to the other party, and then immersed himself in development.

The porting process was a little more difficult than expected, but fortunately Linux uses the same file system as Minix, and by the time the sun rises in the east, he has already ported the bash program to the same extent. (To be continued)