Linux Start Part II

Operation System

As the Linux booting process is very long, the article has talked some prepared work in the Protected Mode and this article will briefly talk about the follow-up work of the booting process.

Main

After the Head has build the Paging system, the kernel will jump to Main, after the part most of the code are writen by C language. In Main, many initiation works are done.

  1. Read the computer information in 0x90000~0x901FD stored by Setup.
  2. Set ramdisk, if RAMDISK is defined in Makefile, alloc RAMDISK KB in 0x3FFFFF for ramdisk.
  3. As Linux 0.11 only support 16MB, here define an array mem_map to denote whether the pages denoting 1MB~16MB are used.
  4. Register all the ISR in the IDT.
  5. Initiate the Block Device request array.
  6. Set the serial port, the IRQ3 and IRQ4 of interrupt controller (8259A) is for RS232 serial communication. Initiate the console, setting the information about the monitor. Then, add keyboard ISR. More details please refer to TTY.
  7. Read the current time from a CMOS in the mainboard and transfer it into the system start-up time.
  8. Set the current task as process 0, and initiate the zero item in task[64]. Load the current TSS and LDT into GDT.
  9. Register timer interrupt and set interval as 10ms. For more details please refer to Scheduler and Timer.
  10. Register the system call interrupt, the user process can not access the kernel, but the user need to read file or print information in many cases. So the kernel offers a set of system calls. When user use this functions, it will trigger an interrupt.
  11. Initiate the Buffer.
  12. Initiate the floppy and hard disk. Here, the kernel just simply register the ISR for the device.
  13. Enable the interrupt and jump to the user mode by using the stack.

Process 1

After entering the user mode, the process 0 will fork process 1. After this, the process 0 will “sleep”(even though process 0 will take part in the scheduling, it will do nothing).

The first work of process 1 is calling the system call sys_setup(this can only be called once) to load the root file system. sys_setup will spend a lot of time to verify the information of the devices. Based on the root device number, read the data from the corresponding data, read the 257,256,258 data blocks. The super block is 257. After verifying the super block, read the whole root file system into 0x3FFFFF, and set it as root device. Initiate the file manage table, file_table[64], so Linux 0.11 can open at most 64 files at the same time. Because after loading the root file system, all the operations to the devices is by File Operation. Initiate the super block management table.

Read the super block inode and the file system inode, and add the super block to the super block management table. Because the root file system is in the memory now, these operations will not trigger any interrupts. Set the root directory’s inode as the inode of the root file system. Here the root file system is loaded.

Open the file dev/tty0, which means the console, as this is first opening file operation, the file descriptor must be 0. For more details please refer to File Operation. Then copy the file descriptor twice, for stdout and stderr.

Process 2

Process 1 use system call fork and create process 2. Process 2 inherits all the information from process 1 and close the file descriptor 0 (stdin) and open /etc/rc as input, then execute a shell program and the rc file is the input to the shell program, which start the process update. While the shell is running, the process 1 is always waiting.
When this shell program is end, process 1 will start a new shell program, at this time it will use the /dev/tty0 as stdin. In this case, we can input the command by the keyboard and start new processes with this commands.

Post Directory

Directory

  1. Main
  2. Process 1
  3. Process 2