gpt4 book ai didi

linux - 准备加载内核

转载 作者:IT王子 更新时间:2023-10-29 00:37:45 25 4
gpt4 key购买 nike

尽管有非常完整的引导装载程序可用,但我一直在业余时间断断续续地写一个,作为一种教育练习。我遇到了问题。

我能够毫无问题地执行初始引导和链加载其他扇区。如果我正在编写自己的操作系统,我会很高兴。 :) 相反,我正在尝试引导 Linux。我面临的挑战是双重的。

  1. 我明白 I need to load the kernel (Linux) into memory at 0x100000 .我知道我应该在内核的偏移量 0x202 处找到“HdrS”签名。我也知道起始地址应该在0x214。但是,当我跳转到该位置的地址时,它会停止。显然,围绕这个包装调试器非常困难。 :) 我是否遗漏了确定内核正确起始地址所必需的这一系列事实?
  2. 我怀疑 (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 - 准备加载内核,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34324968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com