如何加载内核或能够在自己的引导加载程序中使用更多空间? [英] How to load kernel or be able to use more space in own bootloader?

查看:65
本文介绍了如何加载内核或能够在自己的引导加载程序中使用更多空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注:
( http://www.codeproject.com/KB/tips/boot-loader. aspx )
但不确定下一步如何做.
如何在其中加载自写内核?还是比单个细分市场更多的地方?
以及如何处理二进制文件?我必须将引导加载程序复制到第一个扇区,好吧,但是对于内核等,只要放在软盘/光盘上就可以了?

I've been following this:
( http://www.codeproject.com/KB/tips/boot-loader.aspx )
But not sure what and how to do next.
How to load self written kernel in it? Or how to make more place than in single segment?
And what to do with binaries? I have to copy bootloader to first sector, ok, but what with kernel, etc, just put on floppy/disc?

推荐答案

如何加载内核"归结为知道内核在磁盘上的位置以及在内存中的位置,然后使用BIOS磁盘服务读取它.如果希望将内核加载到0x00100000以上,则可能需要将每个部分加载到临时缓冲区中(BIOS可以在实模式下访问BIOS),然后使用保护模式或非实模式"将其从缓冲区复制到您真正想要的地方.如果要支持压缩,则可能需要加载文件然后将其解压缩.如果您希望内核使用复杂的文件格式(例如ELF或PE,而不是简单的平面二进制文件),则可能还需要解析标头,重定位节等.

"How to load a kernel" comes down to knowing where the kernel is on disk and where you want it in memory, and then using BIOS disk services to read it. If you want the kernel to be loaded above 0x00100000 then you may need to load each part into a temporary buffer (that the BIOS can access in real mode), then use either protected mode or "unreal mode" to copy it from the buffer to where you actually want it. If you want to support compression, then you may need to load files then decompress them. If you want the kernel to use a complex file format (e.g. ELF or PE, rather than a simple flat binary) then you may need to parse headers, relocate sections, etc too.

我的引导加载程序通常大于1个扇区.第一个扇区中的代码加载第二个扇区,第一和第二个扇区中的代码加载引导加载程序的其余部分.这样,引导加载程序可以为20 KiB(例如),只要您小心且不要尝试使用尚未加载的任何代码或数据即可.您还可以有第二阶段(如果您愿意的话,可以是第三,第四等),其中引导程序加载第二阶段,第二阶段加载下一部分,等等.

My boot loaders are typically much larger than 1 sector. Code in the first sector loads the second sector, and code in the first and second sectors load the remainder of the boot loader. In this way the boot loader can be 20 KiB (for e.g.), as long as you're careful and don't try to use any code or data that hasn't been loaded yet. You could also have a second stage (and third, fourth, etc stages if you felt like it) where the boot loader loads the second stage, and the second stage loads the next piece, etc.

关于二进制文件的存储位置,这取决于您计划使用的文件系统.如果您不希望任何文件系统(或者如果要使用的文件系统在开始时具有足够的保留"空间),则可以将二进制文件连接在一起,并在引导加载程序之后立即存储它们.否则,引导加载程序(和/或其他阶段)将需要在您正在使用的任何文件系统中查找文件.

For where to store the binaries, this depends on what file system/s you're planning to use. If you don't want any file system (or if the file system you want to use has enough "reserved" space at the beginning), then you could just concatenate the binary files together and store them immediately after the boot loader. Otherwise, the boot loader (and/or additional stages) will need to find files in whichever file system you're using.

注意:不同的引导加载程序的工作方式不同.对于从网络启动之类的东西,引导加载程序可以是512 KiB,并且需要使用PXE API从网络下载数据.对于CD-ROM,您可能最终会使用ISO9660文件系统(和2个KiB扇区).对于硬盘,您将需要处理分区(并且可能有一个用于"MBR分区"的引导加载程序,另一个用于"GPT分区"的引导加载程序).您将得到的是几个完全不同的引导加载程序,它们都加载内核(如果是微内核,则可能加载某种RAM磁盘映像),并在启动内核时使计算机处于特定状态(例如,特定的CPU模式,位于特定地址的内核,位于特定位置的其他文件等),这样内核本身就不必关心哪个引导加载程序加载了它.对于额外的复杂性,可以在此预定义状态"中包含更多内容(例如,ACPI表的地址,预配置的视频模式的描述等),以便可以为其他类型的系统编写引导加载程序,而内核不会无需担心它是从"PC BIOS",UEFI或OpenFirmware或其他任何方式启动的.

Note: Different boot loaders work differently. For something like booting from network, the boot loader can be 512 KiB and needs to download data from the network using the PXE API. For CD-ROM you'll probably end up using the ISO9660 file system (and 2 KiB sectors). For hard disks you'll need to handle partitions (and maybe have one boot loader for "MBR partitions" and another boot loader for "GPT partitions"). What you'll end up with is several completely different boot loaders, that all load the kernel (or maybe some sort of RAM disk image if it's a micro-kernel) and leave the computer in a certain state when starting the kernel (e.g. a specific CPU mode, the kernel at a specific address, other file/s at specific places, etc), such that the kernel itself needn't care which boot loader loaded it. For extra complexity, it's possible to include a lot more in this "predefined state" (e.g. address of ACPI tables, description of preconfigured video mode, etc) so that it's possible to write boot loaders for other types of systems and the kernel won't need to care if it booted from "PC BIOS" or UEFI or OpenFirmware or whatever else.

这篇关于如何加载内核或能够在自己的引导加载程序中使用更多空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆