1.Real mode code running, which does some house keeping like detecting memory layout, setting a video mode, etc

1.1 arch/x86/boot/header.S _start -> start_of_setup
1.2 arch/x86/boot/main.c main
1.3 arch/x86/boot/pm.c go_to_protected_mode -> setup_idt -> setup_gdt
1.4 arch/x86/boot/pmjump.S protected_mode_jump

2. Jump to protect mode and decompress kernel,prints “Decompressing Linux…”
2.1 arch/x86/boot/compressed/head_32.S startup_32 -> decompress_kernel

3. Jump to uncompressed kernel code
3.1 arch/x86/kernel/head_32.S startup_32 -> (*initial_code)(i386_start_kernel)
3.2 arch/x86/kernel/head32.c i386_start_kernel
3.3 init/main.c start_kernel

4.Start architecture independent start

Note:
1.the real mode code was loaded by the bootloader under 0xA0000
111 | Protected-mode kernel |
112 100000 +————————+
113 | I/O memory hole |
114 0A0000 +————————+
115 | Reserved for BIOS | Leave as much as possible unused
116 ~ ~
117 | Command line | (Can also be below the X+10000 mark)
118 X+10000 +————————+
119 | Stack/heap | For use by the kernel real-mode code.
120 X+08000 +————————+
121 | Kernel setup | The kernel real-mode code.
122 | Kernel boot sector | The kernel legacy boot sector.
123 X +————————+
124 | Boot loader | 125 001000 +————————+
126 | Reserved for MBR/BIOS |
127 000800 +————————+
128 | Typically used by MBR |
129 000600 +————————+
130 | BIOS use only |
131 000000 +————————+

2. The Code running in protect mode lies above 0x100000(1M)

3. The Real mode code (setup code) and compressed kernel is “cat” into a single file(vmlinuz) by arch/x86/boot/tools/build.c

4. The code encapsulating compressed kernel is generated by arch/x86/boot/compressed/mkpiggy.c

5. Real mode code length in vmlinuz can be calculated through “setup_sects” which is part of the boot protocol.And grub use this information to load the two part of kernel (setup and compressed kernel) (See grub code load_image() in stage2/boot.c)

 

 

 

Link:

1. Documentation/x86/boot.txt

2. http://duartes.org/gustavo/blog/post/kernel-boot-process

3. http://blog.csdn.net/wukaiyu/article/details/1766788

Advertisements