mirror of
https://github.com/MintCN/linux-insides-zh.git
synced 2026-02-12 06:46:49 +08:00
Update Booting/linux-bootstrap-2md.md
This commit is contained in:
@@ -179,4 +179,30 @@ lgdt gdt
|
||||
将启动参数拷贝到"zeropage"
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
让我们从`main`函数开始看起,这个函数中,首先调用了[`copy_boot_params(void)`](https://github.com/torvalds/linux/blob/master/arch/x86/boot/main.c#L30)。 这个函数将内存设置信息拷贝到`boot_params`结构的相应字段。大家可以在[arch/x86/include/uapi/asm/bootparam.h](https://github.com/torvalds/linux/blob/master/arch/x86/include/uapi/asm/bootparam.h#L113)找到`boot_params`结构的定义。
|
||||
让我们从`main`函数开始看起,这个函数中,首先调用了[`copy_boot_params(void)`](https://github.com/torvalds/linux/blob/master/arch/x86/boot/main.c#L30)。
|
||||
|
||||
这个函数将内存设置信息拷贝到`boot_params`结构的相应字段。大家可以在[arch/x86/include/uapi/asm/bootparam.h](https://github.com/torvalds/linux/blob/master/arch/x86/include/uapi/asm/bootparam.h#L113)找到`boot_params`结构的定义。
|
||||
|
||||
1. 将[header.S](https://github.com/torvalds/linux/blob/master/arch/x86/boot/header.S#L281)中定义的`hdr`结构中的内容拷贝到`boot_params`结构的字段`struct setup_header hdr`中。
|
||||
|
||||
2. 如果内核是通过老的命令行协议运行起来的,那么就更新内核的命令行指针。
|
||||
|
||||
这里需要注意的是拷贝`hdr`数据结构的`memcpy`函数不是C语言中的函数,而是定义在 [copy.S](https://github.com/torvalds/linux/blob/master/arch/x86/boot/copy.S)。让我们来具体分析一下这段代码:
|
||||
|
||||
```assembly
|
||||
GLOBAL(memcpy)
|
||||
pushw %si
|
||||
pushw %di
|
||||
movw %ax, %di
|
||||
movw %dx, %si
|
||||
pushw %cx
|
||||
shrw $2, %cx
|
||||
rep; movsl
|
||||
popw %cx
|
||||
andw $3, %cx
|
||||
rep; movsb
|
||||
popw %di
|
||||
popw %si
|
||||
retl
|
||||
ENDPROC(memcpy)
|
||||
```
|
||||
Reference in New Issue
Block a user