编程知识 cdmana.com

linux 0.0.1

Linux The kernel starts with 0.0.1, The distribution of lines of code is as follows :

wc -l `find -type f` | sort -n | nl  ( Serial number File line number file name )

                     1 ./lib/errno.c
                     3 ./fs/file_table.c
                     4 ./lib/close.c
                     4 ./lib/dup.c
                     4 ./lib/execve.c
                     4 ./lib/setsid.c
                     4 ./lib/write.c
                     7 ./lib/_exit.c
                     8 ./include/linux/kernel.h
      10              8 ./lib/string.c
      11            10 ./include/linux/mm.h
      12            10 ./lib/wait.c
      13            11 ./kernel/panic.c
      14            13 ./include/utime.h
      15            14 ./include/asm/memory.h
      16            15 ./include/const.h
      17            15 ./include/sys/times.h
      18            16 ./include/sys/utsname.h
      19            19 ./include/stddef.h
      20            19 ./lib/open.c
      21            20 ./include/linux/head.h
      22            23 ./include/sys/wait.h
      23            24 ./include/asm/io.h
      24            28 ./include/stdarg.h
      25            29 ./lib/ctype.c
      26            33 ./kernel/printk.c
      27            34 ./include/ctype.h
      28            34 ./mm/page.s
      29            37 ./mm/Makefile
      30            38 ./include/asm/segment.h
      31            40 ./fs/ioctl.c
      32            42 ./include/time.h
      33            44 ./lib/Makefile
      34            46 ./include/sys/types.h
      35            50 ./fs/char_dev.c
      36            51 ./fs/stat.c
      37            52 ./kernel/mktime.c
      38            53 ./include/linux/config.h
      39            53 ./kernel/serial.c
      40            55 ./include/fcntl.h
      41            58 ./include/sys/stat.h
      42            59 ./fs/truncate.c
      43            60 ./include/errno.h
      44            65 ./include/signal.h
      45            66 ./include/asm/system.h
      46            68 ./tools/build.c
      47            69 ./fs/fcntl.c
      48            74 ./include/linux/tty.h
      49            80 ./include/linux/sys.h
      50            84 ./fs/file_dev.c
      51            86 ./fs/block_dev.c
      52            90 ./kernel/Makefile
      53            92 ./fs/pipe.c
      54            95 ./fs/Makefile
      55            96 ./Makefile
      56            97 ./fs/read_write.c
      57            99 ./include/linux/hdreg.h
      58          102 ./fs/super.c
      59          135 ./kernel/exit.c
      60          136 ./kernel/fork.c
      61          141 ./kernel/rs_io.s
      62          147 ./init/main.c
      63          157 ./kernel/asm.s
      64          158 ./fs/bitmap.c
      65          166 ./fs/tty_ioctl.c
      66          175 ./boot/head.s
      67          185 ./include/linux/fs.h
      68          188 ./fs/open.c
      69          199 ./kernel/traps.c
      70          216 ./kernel/sys.c
      71          219 ./kernel/system_call.s
      72          220 ./include/a.out.h
      73          222 ./include/termios.h
      74          227 ./kernel/vsprintf.c
      75          230 ./include/linux/sched.h
      76          247 ./include/unistd.h
      77          254 ./fs/buffer.c
      78          254 ./kernel/sched.c
      79          264 ./mm/memory.c
      80          288 ./fs/inode.c
      81          306 ./fs/exec.c
      82          306 ./kernel/tty_io.c
      83          329 ./boot/boot.s
      84          405 ./include/string.h
      85          409 ./kernel/keyboard.s
      86          413 ./kernel/hd.c
      87          550 ./kernel/console.c
      88          678 ./fs/namei.c

10239 Total usage

common 88 File , 10239 Line code . The biggest file namei.c There is only a 678 Line code , But these can make up a functioning system , The so-called sparrow is small , Five zang organs .

The system is constructed by 96 Yes Makefile decision , You can see that the system is made up of boot, system, and build tool Three parts .

boot Partially in boot/boot.s, from Makefile See it by as86 compile , ld86 link . Whereas as86 The use of the compiler
The universality of using is poor , Consider modifying the code a little to make it work nasm compile .
The main changes are as follows :
1. Constant definition : a=b Replace with a equ b.
2. notes : from "|" Replace with ";"
3. Paragraph name : from .text Change it to SECTION .text, Comment out .data, .bss Wait for the unused section .
4. jmpi Instructions : Replace with jmp SEG:OFFSET Format .
5. .word Replace with dw, .byte Replace with db, .string Replace with .db
6. inc xxx Replace with inc word [xxx]
7. lidt xxx, lgdt xxx Replace with lidt [xxx], lgdt [xxx]
8. mov mem,reg Replace with mov [mem],reg

And then use nasm -f bin boot/boot.s Compile the generated bin File can .

boot Partial exercise boot loader The function of , Loading from a floppy disk system Part to memory 0x10000, Then copy it to 0x00000000, Initialize to protect
Pattern , Jump to system Partial execution .

System Partly from boot/head.s And all the other parts . head.s By loader Move to physical address 0, Then initialize the page table , 1:1 Before the innuendo 8MB Memory , Set interrupt vector table , Start the paging mechanism , And then jump to main().

版权声明
本文为[shzwork]所创,转载请带上原文链接,感谢

Tags linux 0.0.1
Scroll to Top