加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 准备加载内核

发布时间:2020-12-14 02:14:25 所属栏目:Linux 来源:网络整理
导读:即使有完美的引导装载机可供使用,我也在业余时间一次打开和关闭作为教育练习.我遇到了一个问题. 我能够执行初始启动和链接加载其他扇区没有问题.如果我正在编写自己的操作系统,我会很高兴. :)相反,我正在尝试引导Linux.我所面临的挑战是双重的. 我理解I need
即使有完美的引导装载机可供使用,我也在业余时间一次打开和关闭作为教育练习.我遇到了一个问题.

我能够执行初始启动和链接加载其他扇区没有问题.如果我正在编写自己的操作系统,我会很高兴. :)相反,我正在尝试引导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位指令.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读