Linux 2.6 版内核引导过程浅谈(3)

Misc.c中这段用于解压缩内核的代码,需要具备专业知识才能写出来:

asmlinkage void decompress_kernel(void *rmode, memptr heap,

unsigned char *input_data,

unsigned long input_len,

unsigned char *output)

{

real_mode = rmode;

if (real_mode->hdr.loadflags & QUIET_FLAG)

quiet = 1;

if (real_mode->screen_info.orig_video_mode == 7) {

vidmem = (char *) 0xb0000;

vidport = 0x3b4;

} else {

vidmem = (char *) 0xb8000;

vidport = 0x3d4;

}

lines = real_mode->screen_info.orig_video_lines;

cols = real_mode->screen_info.orig_video_cols;

free_mem_ptr     = heap; /* Heap */

free_mem_end_ptr = heap + BOOT_HEAP_SIZE;

if ((unsigned long)output & (MIN_KERNEL_ALIGN - 1))

error("Destination address inappropriately aligned");

#ifdef CONFIG_X86_64

if (heap > 0x3fffffffffffUL)

error("Destination address too large");

#else

if (heap > ((-__PAGE_OFFSET-(512<<20)-1) & 0x7fffffff))

error("Destination address too large");

#endif

#ifndef CONFIG_RELOCATABLE

if ((unsigned long)output != LOAD_PHYSICAL_ADDR)

error("Wrong destination address");

#endif

if (!quiet)

putstr("\nDecompressing Linux... ");

decompress(input_data, input_len, NULL, NULL, output, NULL, error);

parse_elf(output);

if (!quiet)

putstr("done.\nBooting the kernel.\n");

return;

}

而后,进入main.c函数

D:\linux-2.6.35.4\arch\x86\boot\main.c

内核便开始初始化各进程运行的环境,创建进程,加载文件系统。后面的内容在这篇文章中,暂不讨论了。

7. 后记

内核的引导和加载过程,普遍采用AT&T汇编代码完成。用于引导内核的bootloader代码,涉及到具体的硬件知识。加载内核的代码涉及到linux各个部分的相关数据结构的初始化设置。由于学习尚未深入,各文件之间的具体调用关系以及具体代码的详细分析有待于今后补充.

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/25019.html