Where has the time been?
"Why is the flowers so red" in the old PA caused six cheers in three minutes, but lost to Zhang Bichen. Imagine, if Chen Bing is more popular, even if he sings exactly the same way as Zhang Bichen, he may still be defeated. Why can he win? There was such a joke: no one was playing the piano, but an old woman was crying. It turns out that her husband is in cotton! This is a joke, but it breaks the mystery. In addition to singing, there are also emotional factors. If the old PA's "Why is the flowers so red" is 1 point, then Zhang Bichen's father and daughter sentiment is 1 point, "where has the time been?" is 1 point. 2: 1. Zhang Bichen's victory is a matter of course.
Shell implementation
Running your own program echo in your OS is easier to implement than you think. This benefits from the support of the file system. For more information, seeX01. OS. 7. Source Code, which can be downloaded from x01.Lab. DownloadX01. OS .13.tar.gz. After decompression, enter the terminal. After make, the bochs interface is displayed as follows:
It seems that the echo program is running well. First, let's look at the echo program. The code is as follows:
1 # include "kstd. h "2 3 int main (int argc, char * argv []) {4 int I; 5 for (I = 1; I <argc; I ++) {6 printf ("% s", I = 1? "": "", Argv [I]); 7} 8 printf ("\ n"); 9 return 0; 10}
This is very simple, but the main function is not what we usually see. It needs to run in our own OS and help from start. s. The code is as follows:
1 extern main 2 extern exit 3 4 bits 32 5 6 [section. text] 7 global _ start 8 9 _ start: 10 push eax11 push ecx12 call main13 push eax14 call exit15 hlt
This _ start is the key, which is consistent with that in kernnel. s. So, how can we run it in our own OS? In the mm. c => MM_Exec () function, there is a sentence:
G_ProcTable [src]. Regs. eip = elf_hdr-> e_entry;
Echo entry point, which completes the handover. Simply put, it is to fork a Init sub-process, and then replace it with our own program in shell, such as echo.
Learn the operating system. If you have a memory layout in your mind, you will get twice the result with half the effort. A hex program was written to calculate the conversion from the 10th to the 16th. But to run it in your own OS, there is a lot of work to do.
A perfect OS is not a human power, not a temporary power. In addition to everyone's joint efforts, is there any other way?
X01. OS. 14: Where is the time?