Chapter 209 LINUX First Edition
The source code package sent by LINUS has a total of about 12,000 lines of code. It took him about ten days to write the code. If the time prepared for this before is included, at least one month will be added. Lin Hong finished reading these codes, but it only took about three hours to finish reading them.
Lin Hong found that many places in it have learned from the writing of MINIX. After all, LINU has been studying MINIX before, and has learned 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. Only when the file system is implemented can the disk be read and written. It can be said that the file system is a management program for the disk. ALTHOUGH THE CURRENT LINUX DOES NOT INVOLVE THE READ AND WRITE FUNCTION OF DISKS, THIS PART OF LINU HAS IMPLEMENTed IT.
According to programming practice, the first program usually implements "HELLO,WOLRD". LINUS has also printed this statement on the monitor, but the function of this version he sent to Lin Hong is not that simple.
He implemented two important functions in this version, namely, protection mode and multi-process.
These two characteristics are not available in the DOS system and are regarded as important functions of modern operating systems.
"Protection mode" is a statement about memory.
INTEL released a 16-bit CPU, 8086, in 1978, which is an important milestone in INTEL's history and one of the most important products that laid the foundation for INTEL's chips in the PC field.
8086CPU has a total of 20 address lines, which can address up to the 16th power of 2, that is, 1MB of address space.
This is the maximum memory address that a computer based on 8086 CPU can support. This mode is called "real mode". The DOS system works in this mode.
The 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 chip, and the DOS system can't recognize it. It doesn't help at all, and the performance has not been improved.
This is determined by the hardware structure of the 16-bit CPU, and 1MB of memory was quite good at that time. All applications are enough to use.
However, in the field of electronics, there is "Moore's Law", and integrated circuits continue to develop rapidly, and soon 8086 CPUs will not be able to meet the requirements.
So INTEL launched the upgraded version 8086 of 8086 in 1985.
This time, the number of bits in the register has doubled, from 16 bits to 32 bits.
80386CPU has added a lot of advantages. It not only has a large addressing space, but also introduces the concept of multitasking and protection mode.
Inprotected mode, the management of memory is no longer the previous segmented structure. Instead, it has become a paging mechanism, which has great advantages and can greatly improve the performance of memory management.
However, in the computer field, there is a "forward compatibility" rule, that is to say, 80386 must be compatible with the 8086 CPU mechanism, the program that could run on it before. It can also run on the upgraded CPU.
So by default, this "protected mode" is not turned on, and the "real mode" is still used.
And if you want to turn on the "protection mode", you need to use code to operate the address line No. 20 and "wake it up". It is the gatekeeper who enters the protection mode and must pass its consent.
It is simple to say, but the whole process is quite complicated to implement.
That's why it took LINUS so long to finally finish writing the V0.00 version.
They want LINUX to keep up with the development of the times, so that the future functions of LINUX can be comparable to the current latest operating systems. It is essential to enter the protection mode, because only by entering the protection mode can the maximum performance of 80386 CPU be maximized.
When Lin Hong read Operating System Design and Implementation before, he was very confused in this part and specifically checked a lot of information. But I still can't figure out why this mechanism is designed like this.
However, after he saw the implementation code of LINU today, he suddenly had a sudden epiphany.
Unlike usual programming, you don't have to care about the underlying structure of the hardware, but the underlying code of the operating system is closely connected to the hardware. The original BOOT and LOADER programs must be compiled to be competent. Accurate to a certain register of the CPU, and also to a certain sector of the disk.
To understand these codes, you must have a very clear understanding of the hardware structure of the CPU and disk. For example, how many pins the CPU has, how many registers there are in it, and what is the function of each register.
Good for these technical parameters. INTEL HAS VERY DETAILED TECHNICAL DOCUMENTS. Such a small chip involves a few thick large books.
Lin Hong had to sigh. In this small chip, it carries the most advanced crystallization of knowledge in human civilization, which gives full play to human wisdom. Every pin, no register, is finally determined after thousands of continuous experiments.
Lin Hong configured the development environment according to the instruction document written by LINUS, and then compiled the code under the MINIX platform.
After fixing a few small bugs, he finally compiled the LINUX image file.
He only has one computer, so he finally had to install this LINUX on this machine.
Of course, he uses a multi-system installation method, and the other two systems are not affected.
After restarting, he selected the "LINUX_V0.00" menu and then returned.
A series of characters suddenly flashed on the display, constantly brushing up.
At this moment, Lin Hong has a very deep understanding of the detailed process of computer startup, and it is no longer the same as before. I don't know what the computer is doing.
When the power switch is pressed, the machine begins to power on, and the control chip of the motherboard then sends a reset signal to the CPU to restore the CPU to its original state. When the chipset detects that the power supply on the CPU is stable, the CPU will start working.
The first thing it needs to do is to read the instruction from the 0XFFFF0 address in memory to run.
And in this address. There is usually a jump instruction that jumps to the BIOS self-test system, and then the self-test process begins. BIOS is a system that has long been brushed in the firmware by the motherboard manufacturer, the purpose of which is to manage the hardware.
The purpose of self-test is to detect whether the hardware of each part of the computer is normal. If the hardware is missing or damaged, the startup will be suspended immediately.
Only after all hardware detection is passed will it finally jump to the first sector, read the MBR, and start executing the operating system installed on the disk.
And the functions completed by LINUS. After reading MBR, how to load the operating system into memory for execution.
The process is very fast, the characters are constantly refreshing up, the hardware detection ends quickly, and then the display screen flashes, and the character "AAAAAABBBB..." appears at the top.
Looking at the continuous AB characters appearing on the monitor, Lin Hong knew that the start-up process had been completed. HE HAS SEEVed THE FUNCTIONS WRITTEN BY LINU.
If other people who don't know technology see this situation, they will definitely sneer at it and say, "Is this also called an operating system? Just kidding!"
In fact, after LINUS wrote this version, he excitedly called his sister Sarah to watch it. After all, this is a work he spent a lot of effort to write. After working so hard for so long, he finally succeeded. Naturally, he wanted to share his joy with others.
But Sarah, who was holding the teddy bear, stared at the display screen for about five seconds, said "very good" and went back to the room with a blank face to talk to her best friend.
LINUS was stunned for a long time, and it took a long time to realize that he and those who don't know technology have no common language at all. He even hoped that his sister could understand the efforts and achievements he had made. This is so naive.
In the other party's eyes, this is simply showing a few characters. There is nothing special at all, and I don't know what the point of doing such a function is.
However, Lin Hong knows that the AB characters that are constantly displayed alternately on the display screen are printed on the screen by two processes. That is to say, in this V0.00 version, LINUS not only implements the protection mode, but also makes a prototype of multitask management.
"Awesome!"
"Great!"
"NICEJOB!"
These are Lin Hong's comments on LINU.
Although this part of the content seems to be understandable. But Lin Hong knows that if he lets himself write it. It must take more time and energy than the other party. It's not because my technology is not home, but that my understanding in this aspect is not deep enough, or that there is too little information in this regard. It can't be written at all with a copy of Operating System Design and Implementation, and it also involves the accumulation of many other knowledge.
Lin Hong usually looks at computers from a macro perspective, but when he sees this most primitive operating system, he suddenly has a feeling of observing under a microscope.
All the black box is gone. He clearly knows what the computer will do next, and all the details can be seen at a glance.
It's past two o'clock in the morning. Lin Hong wanted to communicate with LINUS, but the other party is not online at the moment.
So, excited, he began to officially invest in the development of LINUX.
What he wants to do is to port the previous LINU to BASH in MINIX, that is, the shell program, to LINUX.
The shell program is very important. It can be said to be the mother of all programs. Only by porting it can other applications be executed smoothly.
BASH itself is an open source program that can be downloaded for free from the Internet, but Lin Hong has its source code, which was mailed to him by LINUS last time.
To write this, you must implement the system call commands of some operating systems, such as the display directory "LS" command and enter the directory "CD" command, which are the most basic.
There are many system calls. Lin Hong temporarily intends to complete what is supported in MINIX. Let's talk about the rest later.
In order to avoid repeated development by LINU, he first sent an EMAIL to the other party, and then immersed himself in the development.
The process ofporting is a little more difficult than expected, but the good thing is that the file system used by LINUX is the same as MINIX. When the sun rises in the east, he has almost ported the BASH program. ( To be continued)