linux – 准备加载内核

linux – 准备加载内核,第1张

概述即使有完美的引导装载机可供使用,我也在业余时间一次打开和关闭作为教育练习.我遇到了一个问题. 我能够执行初始启动和链接加载其他扇区没有问题.如果我正在编写自己的 *** 作系统,我会很高兴. :)相反,我正在尝试引导Linux.我所面临的挑战是双重的. >我理解I need to load the kernel (Linux) into memory at 0x100000.我知道我应该在内核的偏移量0x 即使有完美的引导装载机可供使用,我也在业余时间一次打开和关闭作为教育练习.我遇到了一个问题.

我能够执行初始启动和链接加载其他扇区没有问题.如果我正在编写自己的 *** 作系统,我会很高兴. :)相反,我正在尝试引导Linux.我所面临的挑战是双重的.

>我理解I need to load the kernel (Linux) into memory at 0x100000.我知道我应该在内核的偏移量0x202处找到“HdrS”签名.我也知道起始地址应该是0x214.但是,当我跳到该位置的地址时,它会停止.显然,围绕这个包装调试器非常困难. :)我是否遗漏了确定内核正确起始地址所必需的这一系列事实?
>我怀疑(1)的答案可能与需要用硬件发现信息填充某些内存区域有关.我在OSDev Wiki上看到了几个对此的引用,但我似乎错过了这里,确切地说需要哪些数据.引导加载程序是否负责硬件发现?如果是这样,需要将哪些数据放在哪里?

需要注意的另一点是我已经处于32位保护模式,因为我正在处理创建EFI启动系统,因此16位实模式在这里不是一个真正的选项,从而消除了实际模式的起始位置.核心.

解决方法 @Jester找到了我的问题并回答了这两个问题.解决方案实际上是在 file that I had linked,虽然我错过了相关部分.我在这里列出了相关内容供后人使用:

In 32-bit boot protocol,the first step in loading a linux kernel
should be to setup the boot parameters (struct boot_params,
Traditionally kNown as “zero page”). The memory for struct boot_params
should be allocated and initialized to all zero. Then the setup header
from offset 0x01f1 of kernel image on should be loaded into struct
boot_params and examined. The end of setup header can be calculated as
follow:

0x0202 + byte value at offset 0x0201

In addition to read/modify/write the setup header of the struct
boot_params as that of 16-bit boot protocol,the boot loader should
also fill the additional fIElds of the struct boot_params as that
described in zero-page.txt.

After setting up the struct boot_params,the boot loader can load the
32/64-bit kernel in the same way as that of 16-bit boot protocol.

In 32-bit boot protocol,the kernel is started by jumPing to the
32-bit kernel entry point,which is the start address of loaded
32/64-bit kernel.

At entry,the cpu must be in 32-bit protected mode with paging
Disabled; a GDT must be loaded with the descriptors for selectors
__BOOT_CS(0x10) and __BOOT_DS(0x18); both descriptors must be 4G flat segment; __BOOT_CS must have execute/read permission,and __BOOT_DS
must have read/write permission; CS must be __BOOT_CS and DS,ES,SS
must be __BOOT_DS; interrupt must be Disabled; %esi must hold the base
address of the struct boot_params; %ebp,%edi and %ebx must be zero.

在同一文档中也可以找到64位指令.

总结

以上是内存溢出为你收集整理的linux – 准备加载内核全部内容,希望文章能够帮你解决linux – 准备加载内核所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1032551.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存