编写我自己的内核
我需要一些指导来开始学习编程我自己的操作系统内核。
只是为了教育目的。
我怎样才能编写自己的内核?
I need some directions to start learning about programming my own operating system kernel.
Just for educational purpouses.
How can I write my own Kernel?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我首先要问:你为什么选择“编写内核”?除了“在内存中实现我自己的任务结构以由我编写的调度程序交换并使用由我编写的代码管理并受机器级原子指令的抽象保护并被赋予的内存”之外的任何答案/O 通过位于实际硬件接口之上的抽象进行访问对我来说很有吸引力”可能是一个糟糕的答案,表明您没有进行任何研究并且正在浪费时间。
如果您的回答与上述类似,那么您就有了一个良好的起点,并且知道需要研究什么(也就是说,您能够在某种程度上查明哪些信息是您不知道但需要找出的)。
不管怎样,我认为这个问题不值得问。在一种情况下,您自己没有进行任何研究来发现自己是否真的可以做到这一点,而在另一种情况下,您提出了一个过于宽泛的问题。
I would first ask: why did you pick "writing a kernel?" Any answer other than "the idea of implementing my own task structures in memory to be swapped by a scheduler that I write and using memory that is managed by code that I wrote and is protected by abstractions of machine-level atomic instructions and is given I/O access through abstractions that sit atop actual hardware interfaces appeals to me" is probably a bad answer that indicates you haven't done any research whatsoever and are wasting your time.
If you answered similarly to the above, then you have a good starting point and you know what you need to research (that is, you are able to pinpoint to some degree what information you do not know but need to find out).
Either way, I don't think this question is worth asking. In one case, you have done no research of your own to discover if you can actually do this, and in the other case you asked an overly-broad question.
这并不难,但您需要了解正确的资源管理和低级设备 I/O。如果您的目标是商用 x86 机器,那么您需要了解 BIOS 的工作原理以及磁盘的结构。例如,BIOS会将磁盘的第一个块读入内存中某个固定地址,然后跳转到该地址。由于一个块中可能没有足够的空间来存储内核,因此您需要编写一个引导加载程序来从磁盘读取内核并加载它。
编写一个最小的内核来执行一些简单的多任务处理并仅使用 BIOS 执行 I/O 并不太困难,只是不要指望很快就会出现任何窗口和鼠标移动。您将忙于尝试实现一个简单的文件系统并让
read()
和write()
工作。It isn't that hard, but you need to learn about proper resource management and low-level device I/O. If you're targeting a commodity x86 box, then you'll need to learn about how the BIOS works and how the disk is structured. For example, the BIOS will read the first block of the disk into memory at some fixed address and then jump to that address. Since there probably won't be enough space in one block to store your kernel, you'll need to write a boot loader to read your kernel off the disk and load it.
Writing a minimal kernel that does some simple multitasking and performs I/O using just the BIOS isn't too difficult, just don't expect to be throwing up any windows and mousing around any time soon. You'll be busy trying to implement a simple file system and getting
read()
andwrite()
to work.也许你可以先研究OS/161,这是哈佛大学的简化操作用于教育目的的系统。该操作系统在模拟器上运行,因此您不需要新机器来运行它。我在操作系统课程中使用了它,它确实很有帮助。
另外,我认为如果您还没有这样做,您可能真的想考虑参加操作系统课程。
Maybe you can start by looking into OS/161, which is a Harvard's simplified operating system for educational purposes. The OS runs on a simulator, so you don't need a new machine to run it. I used it for my operating system course, and it really did help a lot.
Also I think you may really want to consider taking an operating system course if you haven't done so.