Linux Kernel在启动时执行的第一个操作是什么?

时间:2021-08-06 13:49:42

After the boot loader hands execution over to the kernel, what happens? I know assembler, so what are the first few instructions that a kernel must make? Or is there a C function that does this? What is the startup sequence before the kernel can execute an arbitrary binary?

在引导加载程序将执行交给内核后,会发生什么?我知道汇编程序,那么内核必须要做的前几条指令是什么?或者有一个C函数来做到这一点?在内核执行任意二进制文件之前的启动顺序是什么?

2 个解决方案

#1


41  

I'll assume that you're talking about x86 here...

我假设你在这里谈论x86 ......

It depends where you consider the boundary between "boot loader" and "kernel" to be: the start of the kernel proper is 32-bit protected mode code, but the kernel itself provides some boot code to get there from real mode.

这取决于您认为“引导加载程序”和“内核”之间的边界是什么:内核本身的开始是32位保护模式代码,但内核本身提供了一些引导代码以从实模式到达。

The real mode code is in arch/x86/boot/: start_of_setup does some basic setup of the environment for C, and calls main(), which does some fairly dull stuff, ending with the actual jump to protected mode (see pmjump.S).

实模式代码在arch / x86 / boot /中:start_of_setup为C做了一些基本的环境设置,并调用main(),它做了一些相当沉闷的东西,以实际跳转到保护模式结束(参见pmjump.S) )。

Where you end up now depends on whether or not the kernel is compressed. If it is, the entry point is actually a self-decompression routine. This is fairly dull stuff as well, and essentially transparent: the decompression code and compressed kernel are moved higher up in memory out of the way, then the kernel is uncompressed to the original location, and then jumped into as if it had been uncompressed all along. This code is in arch/x86/boot/compressed/ (the entry point is startup_32 in head_32.S).

你现在最终取决于内核是否被压缩。如果是,则入口点实际上是自解压程序。这也是相当沉闷的东西,并且基本上是透明的:解压缩代码和压缩内核在内存中向上移动,然后内核被解压缩到原始位置,然后跳转到好像它已经被解压缩所有沿。此代码位于arch / x86 / boot / compressed /(入口点为head_32.S中的startup_32)。

The kernel really gets going properly at startup_32 in arch/x86/kernel/head_32.S. The code there ends up by calling i386_start_kernel() in arch/x86/kernel/head32.c, which finally calls the generic kernel startup code in start_kernel().

内核确实在arch / x86 / kernel / head_32.S中的startup_32上正常运行。最后通过在arch / x86 / kernel / head32.c中调用i386_start_kernel()来获得代码,最终在start_kernel()中调用通用内核启动代码。

#2


9  

It's asmlinkage void __init start_kernel(void) C function in init/main.c.

它是asmlinkage void __init start_kernel(void)init / main.c中的C函数。

#1


41  

I'll assume that you're talking about x86 here...

我假设你在这里谈论x86 ......

It depends where you consider the boundary between "boot loader" and "kernel" to be: the start of the kernel proper is 32-bit protected mode code, but the kernel itself provides some boot code to get there from real mode.

这取决于您认为“引导加载程序”和“内核”之间的边界是什么:内核本身的开始是32位保护模式代码,但内核本身提供了一些引导代码以从实模式到达。

The real mode code is in arch/x86/boot/: start_of_setup does some basic setup of the environment for C, and calls main(), which does some fairly dull stuff, ending with the actual jump to protected mode (see pmjump.S).

实模式代码在arch / x86 / boot /中:start_of_setup为C做了一些基本的环境设置,并调用main(),它做了一些相当沉闷的东西,以实际跳转到保护模式结束(参见pmjump.S) )。

Where you end up now depends on whether or not the kernel is compressed. If it is, the entry point is actually a self-decompression routine. This is fairly dull stuff as well, and essentially transparent: the decompression code and compressed kernel are moved higher up in memory out of the way, then the kernel is uncompressed to the original location, and then jumped into as if it had been uncompressed all along. This code is in arch/x86/boot/compressed/ (the entry point is startup_32 in head_32.S).

你现在最终取决于内核是否被压缩。如果是,则入口点实际上是自解压程序。这也是相当沉闷的东西,并且基本上是透明的:解压缩代码和压缩内核在内存中向上移动,然后内核被解压缩到原始位置,然后跳转到好像它已经被解压缩所有沿。此代码位于arch / x86 / boot / compressed /(入口点为head_32.S中的startup_32)。

The kernel really gets going properly at startup_32 in arch/x86/kernel/head_32.S. The code there ends up by calling i386_start_kernel() in arch/x86/kernel/head32.c, which finally calls the generic kernel startup code in start_kernel().

内核确实在arch / x86 / kernel / head_32.S中的startup_32上正常运行。最后通过在arch / x86 / kernel / head32.c中调用i386_start_kernel()来获得代码,最终在start_kernel()中调用通用内核启动代码。

#2


9  

It's asmlinkage void __init start_kernel(void) C function in init/main.c.

它是asmlinkage void __init start_kernel(void)init / main.c中的C函数。