如何在一台旧的台式电脑上构建一个小型操作系统?

时间:2023-01-24 18:40:31

This might be in vain, as I know writing an operating system is unbearably complicated (especially by oneself).

这可能是徒劳的,因为我知道编写一个操作系统是非常复杂的(尤其是自己)。

  • I don't expect to build the next linux, or windows.

    我不期望构建下一个linux或windows。

  • I know it will be horrible, and buggy, and won't work, but that's fine.

    我知道这将是可怕的,有问题的,而且不会工作,但那很好。

I want to write everything myself, in Assembly, C, and (some) C++.

我想自己写所有东西,用汇编语言、C语言和(一些)c++语言。

This is a future project, as I'm busy with some other things at the moment and don't have the time immediately, but I figured I would ask it now, so maybe I could get lots of answers to this, and it could build up and be a useful resource for this kind of approach (everything else I have seen involved building off of minix, using an existing bootloader, building it in a virtual booting program thing, etc).

这是一个未来的项目,因为我忙于其他事情,没有时间,但是我想我现在会问,所以也许我可以得到很多的答案,它可以建立和是一个有用的资源,为这种方法(我所看到的一切涉及建筑minix的,使用现有的引导装载程序,建立在一个虚拟的引导程序,等等)。

I want to set up one of my older desktops with a monitor, keyboard and mouse, and start working on a blank hard drive.

我想在一台老式的台式机上安装一个显示器、键盘和鼠标,然后开始在一个空白硬盘上工作。

I want to learn how to write my own bootloader (I've found lots of resources about this, but for completeness, please still add some good ones), my own USB driver (if that's necessary), a CD driver (if that's necessary), etc. Everything, from the ground up.

我想学习如何编写我自己的引导加载程序(我已经找到了很多关于这个的资源,但是为了完整性,请仍然添加一些好的),我自己的USB驱动程序(如果有必要的话),CD驱动程序(如果有必要的话),等等。

  • How do I put the code onto the computer? Is it best to do it with a floppy disk? Can most computers do it from a USB stick?

    我怎么把代码放到电脑上?最好是用软盘来做吗?大多数电脑都能通过USB接口完成吗?

  • What drivers do I need, and can you suggest any references to building those?

    我需要什么驱动程序,你能给我一些建议吗?

  • After the booting sequence--then what? How do I get into protected mode etc.

    在引导序列之后——然后呢?如何进入保护模式等。

  • How do I manage memory without the help of an operating system? Do I just use whatever addresses I want? No initialization necessary?

    如何在没有操作系统的帮助下管理内存?我要用什么地址?没有初始化必要的吗?

  • What will I undoubtedly run into that will confuse me?

    毫无疑问,我会遇到什么会让我迷惑?

  • How can I make it either a command line O/S, and a graphical one?

    如何使它成为命令行O/S,以及图形化的?

  • What is a graphical O/S built on? Like, how would I do something like, a command line, with a font, and a picture at the top?

    图形O/S是基于什么构建的?比如,我要怎么做,命令行,字体,顶部的图片?

  • Where can I read about setting up a multitasking environment? (ie., having two graphical-like command lines running side-by-side).

    在哪里可以看到关于设置多任务环境的信息?(即。,有两个类似于图形的命令行并排运行)。

  • How would I set up a sort of windowing system? How do I display graphics on the screen once simple multitasking is set up?

    我如何建立一种窗口系统?一旦设置了简单的多任务处理,如何在屏幕上显示图形?

Believe me, I understand that this is a very complicated project, and I probably will never get around to completing it or writing anything on it of any use.

相信我,我理解这是一个非常复杂的项目,我可能永远都不会去完成它或者写任何有用的东西。

There are lots of other pieces to this I haven't mentioned, if you think of any, feel free to add those too.

这里还有很多我没有提到的东西,如果你想到的话,也可以把它们加进去。

Please put one "topic" per answer--for example, USB drivers, and then maybe a list of resources, things to look out for, etc.

请在每个答案上放一个“主题”——例如,USB驱动程序,然后可能是一个资源列表,需要注意的东西等等。

Also, please don't suggest building off of another O/S or pre-existing code. I know I will read a lot of pre-existing code (such as the linux kernel, or example resources, existing drivers, etc) but ultimately I want to do all the writing myself. I know I should build off of something else, and there are lots of other questions on SO about that that I can read if I change my mind and go that route. But this one is all about doing the whole thing from scratch.

另外,请不要建议建立其他的O/S或预先存在的代码。我知道我将阅读大量的预先存在的代码(比如linux内核,或者示例资源,现有的驱动程序等等),但是最终我想自己完成所有的写作。我知道我应该建立在其他东西的基础上,还有很多其他的问题,如果我改变主意,沿着这条路走,我可以读到。但是这个就是从头开始。

Any suggestions on how to get it graphical? Different video modes and how to work with them, etc?

关于如何使它图形化有什么建议吗?不同的视频模式以及如何使用它们等等?

20 个解决方案

#1


50  

First things first. Read, read, read, read, read. You need to have a firm understanding of how the OS works before you can hope to implement your own.

先做重要的事。读,读,读,读,读。在您希望实现自己的操作之前,您需要对操作系统的工作方式有一个确切的了解。

Grab one of Andrew Tanenbaum's books on operating systems. This is the one we used in my OS class in college:

拿一本Andrew Tanenbaum关于操作系统的书。这是我们在大学的OS课程中使用的:

Modern Operating Systems PDF

现代操作系统PDF

Modern Operating Systems on Amazon

亚马逊上的现代操作系统

Despite the ridiculous cover, it's a fantastic read, especially for a textbook. Tanenbaum is really an expert in this area and his explanations of how the OS works underneath the hood are clear and easy to understand. This book is mostly theory, but I believe he also has a book that discusses more of the implementation. I've never read it, though, so I can't comment on it.

尽管封面很可笑,但这本书读起来非常棒,尤其是一本教科书。Tanenbaum确实是这方面的专家,他对操作系统如何工作的解释很清楚,也很容易理解。这本书主要是理论,但我相信他也有一本关于实现的书。我从来没读过,所以我不能评论它。

That should help you bone up on process management, memory management, filesystems, and everything else your OS kernel needs to do to get it up to a bootable state. From that point on it's basically a matter of writing device drivers for the hardware you need to support, and offering implementations of the C library functions to make kernel calls for things like opening files and devices, reading and writing, passing messages between processes, etc.

这将有助于您深入研究进程管理、内存管理、文件系统以及操作系统内核需要做的所有其他工作,使其达到可引导状态。从那时起,它基本上就是为您需要支持的硬件编写设备驱动程序,并提供C库函数的实现,以进行内核调用,比如打开文件和设备、读写、在进程之间传递消息等等。

Read up on x86 assembly (assuming you are designing this for an x86 machine). That should answer a lot of your questions with regards to moving between processor operating modes.

阅读x86程序集(假设您正在为x86机器设计这个程序集)。这应该可以回答您关于在处理器操作模式之间移动的许多问题。

If you've got any electronics knowledge, it may be easier to start with writing an operating system for an embedded device that has ample documentation, because it will generally be simpler than an x86 PC. I've always wanted to write my own OS as well, and I'm starting with writing a microkernel embedded OS for This Development Board from Digilent. It can run the soft-core MicroBlaze processor from Xilinx, which has very thorough documentation. It's also got some RAM, flash data storage, LEDs, switches, buttons, VGA output, etc. Plenty of stuff to play around with writing simple drivers for.

如果您有任何电子知识,那么从编写一个具有丰富文档的嵌入式设备的操作系统开始,可能会更容易一些,因为它通常比x86 PC更简单。我也一直想写我自己的OS,我从Digilent开始为这个开发委员会编写一个嵌入式操作系统的微内核。它可以运行Xilinx的软核MicroBlaze处理器,它有非常完整的文档。它还有一些RAM,闪存,led,开关,按钮,VGA输出等等。

One of the benefits of an embedded device is also that you may be able to avoid writing a VGA driver for a long time. In my case, the Digilent development board has an onboard UART, so I can effectively use the serial output as my console to get the whole thing up and booting to a command line with minimal fuss.

嵌入式设备的好处之一是,您可以在很长一段时间内避免编写VGA驱动程序。在我的例子中,Digilent开发委员会有一个内置的UART,所以我可以有效地使用串行输出作为我的控制台,以使整个事情启动并引导到一个命令行,而不会有什么麻烦。

Just make sure that whatever you choose to target has a readily available and well-tested compiler for it. You do not want to be writing an OS and a compiler at the same time.

只要确保您选择的目标有一个可用的、经过良好测试的编译器。您不希望同时编写操作系统和编译器。

#2


26  

http://www.osdev.org/ and http://www.osdever.net/

http://www.osdev.org/和http://www.osdever.net/

welcome to the OS Development world.

欢迎来到OS开发世界。

See also other x86 documentation links in SO's tag wiki: Intel and AMD manuals, compiler / assembler docs, and various guides.

请参阅SO的x86标记wiki: Intel和AMD手册、编译器/汇编程序文档和各种指南中的其他x86文档链接。

It also suggests using BOCHS or other virtual environment for debugging, since you can single-step your bootloader and examine registers.

它还建议使用BOCHS或其他虚拟环境进行调试,因为您可以单步引导引导程序并检查寄存器。

#3


15  

I would suggest working, at least at first, on Bochs or some other virtual machine the reason being that you can take it with you wherever you want, it's easier to debug (you can see the exact state of the hardware), and if you need outside help debugging they can use the exact same 'hardware' as you.

我建议工作,至少在一开始,在Bochs或其他虚拟机的原因是,你可以把它与你任何你想要的,更容易调试(硬件)的可以看到的状态,如果你需要外界帮助调试他们可以使用相同的“硬件”。

The most useful advice I have is to get yourself into a state where you can be running C code as quickly as possible -- i.e. boot up, setup your descriptor tables, and get yourself to a point where it's safe to run compiled C. Most if not all the kernel should be in C if you want to stay sane and keep working on it. Assembly, while required in some places, is tedious and tends to be hard to debug.

最有用的建议我是让你自己,你可以尽快运行C代码,即启动,设置你的描述符表,并让自己的安全运行编译C .大多数(如果不是全部的话)内核应该在C语言中,如果你想保持冷静并继续工作。在某些地方,组装是很繁琐的,而且很难调试。

#4


14  

At its lowest level the minimum that an operating system needs to be able to do is to drive a system's hardware in some way and somehow load an execute some sort of "user code." If you're going to start with a PC then you need to write code that can be loaded by it from some device or another. Older PCs have a BIOS in firmware which determines how the hardware performs some initialization (at least video, keyboard, and some form of storage or boot loader). (Update October 2017: Newer PCs have EFI or UEFI firmware ... which is largely a pedantic difference; the serve the same purposes for this discussion).

操作系统需要做的最低限度就是以某种方式驱动系统的硬件,并以某种方式加载某种类型的“用户代码”。如果你打算从PC开始,那么你需要编写可以从某些设备或其他设备加载的代码。旧的pc机在固件中有一个BIOS,它决定硬件如何执行一些初始化(至少是视频、键盘和某种形式的存储或引导加载程序)。(2017年10月更新:更新的pc有EFI或UEFI固件……)这在很大程度上是学究式的差异;这个讨论的目的是一样的)。

So start by learning the low level details of how to use the BIOS or other firmware, on your target system. That is, learn how to write a program that the BIOS can load and execute. That will eventually morph into your boot loader. Start small. Just get a program that prints: "Hello, Linus" directly from the firmware boot process (on a floppy, or USB thumb drive, would be a good start ... or on a hard drive if you like).

因此,首先学习如何在目标系统上使用BIOS或其他固件的底层细节。也就是说,学习如何编写BIOS可以加载和执行的程序。这最终会改变到引导加载程序中。从小事做起。只要得到一个程序,打印:“你好,Linus”,直接从固件引导过程(在软盘,或USB拇指驱动器,将是一个良好的开始…或者在硬盘上,如果你喜欢)。

From there I'd recommend writing a very simple serial driver ... update your boot loader to initialize some serial port, and start a download there from. Then it can execute the code it pulls across. From there write a bit of bootstrap that can write to another set of blocks (we haven't implemented a file system yet ... not even partition table parsing; so we'd just deal with raw ranges of blocks on the disk at first).

从那里我建议写一个非常简单的串行驱动程序……更新引导加载程序以初始化一些串行端口,并从那里开始下载。然后它就可以执行它所经过的代码。从这里开始,编写一些可以写入另一组块的引导程序(我们还没有实现文件系统……)甚至没有分区表解析;所以我们首先要处理磁盘上的原始块范围)。

At that point your boot loader should be able to pull new code across the serial line, dump it into a partition (yes, implement partition table handling of some sort ... whether it conforms to standard PC conventions is up to you at this point), and execute it.

此时,您的引导加载程序应该能够在串行线上拉出新的代码,并将其转储到分区中(是的,实现某种类型的分区表处理……)在这一点上,它是否符合标准PC惯例取决于您),并执行它。

From there you should be able to work on far more sophisticated features. From this base you can write and compile a new "kernel" ... reboot your testbed, and have the new kernel deployed to it.

从那时起,您应该能够处理更复杂的特性。从这个基础上,您可以编写和编译一个新的“内核”……重新启动您的testbed,并将新的内核部署到其中。

(Your bootloader should take some signal, such as a BREAK over the serial handshaking lines as a command to skip the download and just boot the existing image; and it should handle some timeout in this way as well).

(引导加载程序应该接收一些信号,比如中断串行握手行作为命令,以跳过下载,只引导现有映像;它也应该以这种方式处理一些超时)。

From there write a very simple terminal layer and command shell? A filesystem? Implement commands to download new executable content other than the kernel (files or objects of some sort). And so on.

从那里编写一个非常简单的终端层和命令shell?一个文件系统?实现命令来下载内核之外的新可执行内容(文件或某种类型的对象)。等等。

Naturally you could have started with a console driver using the PC keyboard and video (the BIOS INT 0x16h and INT 0x10H stuff, respectively, if I recall correctly). However, I'd suggest starting with a serial driver since you can then automate your build/deploy/test cycle from any other existing (functional) system. Since your new OS will start as a cross-compiled project it's going to be essential for you to have a streamlined way of handling that.

当然,您可以使用PC键盘和视频(如果我没记错的话,分别是BIOS INT 0x16h和INT 0x10H)开始使用控制台驱动程序。但是,我建议您从一个串行驱动程序开始,因为您可以从任何其他现有(功能)系统自动生成/部署/测试周期。由于您的新操作系统将作为一个交叉编译的项目开始,因此您必须使用一种简化的方式来处理它。

I don't know how far you want to take your project. A reasonably impressive goal would be to achieve "self hosting." If you can create a simple assembler/compiler that can allow you to use your new OS to (re-)build, link, and boot into a working version of your new OS ... then you've achieved that goal. (Note that's not a requirement. Many embedded systems are never going to be self-hosting and there's nothing wrong with that).

我不知道你的项目要走多远。一个令人印象深刻的目标是实现“自我托管”。如果您可以创建一个简单的汇编器/编译器,允许您使用您的新操作系统来(重新)构建、链接和引导到新操作系统的工作版本中……然后你就实现了这个目标。(注意这不是一个要求。许多嵌入式系统永远不会成为自宿主,这也没什么错。

#5


12  

If you don't mind using hardware virtualisation, there is a course (book + lectures + software) that will take you 'From Nand to Tetris'. You create a full computer system entirely yourself from the (for these purposes atomic, and given) electrical NAND gate, right through to building the OS, a language, and finally coding a simple game on your personal machine.

如果你不介意使用硬件虚拟化,有一门课程(书本+讲座+软件)会让你“从Nand到俄罗斯方块”。您可以完全自己创建一个完整的计算机系统,从(出于这些目的,原子和给定的)电子NAND gate,一直到构建OS,一种语言,最后在您的个人计算机上编写一个简单的游戏。

I think it's a great idea and something I fully intend to get stuck into soon. The book is surprisingly cheap and I believe the course is taught at MIT. I can imagine no greater feeling than having the full, complete knowledge of an entire system you built yourself from the ground up.

我认为这是一个好主意,而且我完全打算很快就陷入其中。这本书出奇的便宜,我相信这门课是在麻省理工学院教授的。我想象不出比拥有你自己从地面上建立起来的完整的、完整的系统知识更有感觉的了。

Link: http://www1.idc.ac.il/tecs/

链接:http://www1.idc.ac.il/tecs/

#6


10  

I would start small and purchase an 8086 embedded development kit, and develop a multitasking OS on that. Once you have a kernel and are acquainted with working at the hardware level, you will be ready to do something more challenging.

我会从小做起,购买一个8086嵌入式开发工具包,然后在上面开发一个多任务操作系统。一旦您有了内核,并且熟悉了在硬件级别上的工作,您就可以做一些更具挑战性的事情了。

Building even a VGA display DOS clone is a fairly challenging thing. The details are enormous. :-)

甚至构建VGA显示DOS克隆也是一件相当具有挑战性的事情。细节是巨大的。:-)

specific topics.

How do I put the code onto the computer? Is it best to do it with a floppy disk? Can most computers do it from a USB stick?

我怎么把代码放到电脑上?最好是用软盘来做吗?大多数电脑都能通过USB接口完成吗?

The BIOS will do elementary bootstrapping.

BIOS将执行基本的引导。


What drivers do I need, and can you suggest any references to building those?

我需要什么驱动程序,你能给我一些建议吗?

anything that isn't direct cpu/memory operations. Anything that isn't directly in the CPU reference manual.

任何不是直接的cpu/内存操作。任何不在CPU参考手册中的内容。


After the booting sequence--then what? How do I get into protected mode etc.

在引导序列之后——然后呢?如何进入保护模式等。

Protected mode will be part of the boot sequence.

保护模式将是引导序列的一部分。

then you start multitasking and figuring out how to start processes.

然后你开始多任务处理,并弄清楚如何启动进程。


How do I manage memory without the help of an operating system? Do I just use whatever addresses I want? No initialization necessary?

如何在没有操作系统的帮助下管理内存?我要用什么地址?没有初始化必要的吗?

Correct. You will probably want to sort out a virtual memory system eventually.

正确的。最终,您可能希望对虚拟内存系统进行排序。


What will I undoubtedly run into that will confuse me?

毫无疑问,我会遇到什么会让我迷惑?

not having debugging tools, not having IO

没有调试工具,没有IO。


How can I make it either a command line O/S, and a graphical one?

如何使它成为命令行O/S,以及图形化的?

With grief. Look up Windows 3.1 and Linux, in particular X windows.

与悲伤。查找Windows 3.1和Linux,特别是X Windows。


What is a graphical O/S built on? Like, how would I do something like, a command line, with a font, and a picture at the top?

图形O/S是基于什么构建的?比如,我要怎么做,命令行,字体,顶部的图片?

Look up X windows.

查找X windows。


final advice: study linux/x windows. It's not perfect, but it provides an understanding of one approach. Also study embedded systems.

最后的建议:学习linux/x windows。它不是完美的,但是它提供了对一种方法的理解。还研究嵌入式系统。

#7


8  

The OS Development Series @ BrokenThorn might interest you.

你可能会感兴趣的是OS开发系列。

#8


8  

Try to read the code of a small, basic open-source OS, such as MikeOS.

尝试阅读一个小型的、基本的开源操作系统的代码,比如MikeOS。

Alternatively, I suggest the following steps (should be fun!):

或者,我建议以下步骤(应该是有趣的!)

  1. Write a virtual machine. Define all your processor instructions so that you know your system inside and out. Interface it with SDL for keyboard, mouse, screen, audio access. Keep it simple so that you can fit everything in your head at once. It doesn't need to be a state-of-the-art virtual machine, just one that can emulate the function of a 'real' computer.
  2. 写一个虚拟机。定义您的所有处理器指令,以便您了解系统的内部和外部。与SDL接口,用于键盘、鼠标、屏幕、音频访问。保持简单,这样你就能马上把所有的事情都记在脑子里。它不需要是一个最先进的虚拟机,只需模仿“真实”计算机的功能。
  3. Write an assembler for your virtual machine's processor. Remember that this assembler need not be a program written in the virtual machine's language, but anything that can convert your assembly language to machine code.
  4. 为您的虚拟机的处理器编写一个汇编程序。请记住,这个汇编程序不需要是用虚拟机语言编写的程序,而是任何可以将汇编语言转换为机器代码的程序。
  5. Define an executable format, and write a simple linker.
  6. 定义可执行格式,并编写一个简单的链接器。
  7. You've got all the parts to write your operating system now! Write it in the assembly language, assemble it ... etc .. you don't need such a complicated bootloading process, just get your machine to run your OS first.
  8. 现在您已经拥有了编写操作系统的所有部件!用汇编语言写,汇编……等。您不需要如此复杂的引导过程,只需让您的机器先运行OS即可。

The above steps may seem kinda stupid for writing a simple OS, but hey, it's damn fun.

上面的步骤对于编写一个简单的操作系统来说似乎有点愚蠢,但是嘿,这太有趣了。

#9


7  

I see plenty of good references to OS development sites, so I'll describe a different approach:

我看到很多关于OS开发站点的很好的参考,所以我将描述一种不同的方法:

If you want the experience of implementing an OS from bare metal, there are way better hardware choices than an old PC. With the PC architecture, you will spend an inordinate amount of your time coding around uninteresting artifacts of its 30 year design history. For example, just the bootloader part of the project has probably burned out many a brave programmer.

如果您想体验从裸机实现操作系统的体验,有比旧电脑更好的硬件选择。使用PC架构,您将花费大量的时间来编写其30年设计历史中无趣的工件。例如,仅仅是项目的引导加载程序部分就可能耗尽许多勇敢的程序员的精力。

For example, you'll need one set of drivers to read your kernel off of disk and/or the network. Then you'll need code to get into protected mode. At that point, you need another set of drivers! Very little of the work you do to get the chip into protected mode will be transferable after that point. You want to run it on a different PC +- 4 years and you'll need yet another set of drivers.

例如,需要一组驱动程序从磁盘和/或网络中读取内核。然后需要代码进入保护模式。此时,您需要另一组驱动程序!为了使芯片进入保护模式,你所做的工作中只有很少一部分是可以在那之后转移的。你想要在不同的PC上运行它+ 4年,你将需要另外一组驱动。

Look into bootstrapping an ARM or other 32-bit "embedded" chip. Inexpensive development boards are available, or you can solder your own! Some have built-in ethernet and usb. I think you will have more fun working on a sane, non-crusty architecture, and perhaps end up with some re-usable skills.

查看引导一个ARM或其他32位“嵌入式”芯片。有便宜的开发板,或者你可以自己焊接!有些有内置的以太网和usb接口。我认为你将会有更多的乐趣,在一个健全的,非粗糙的建筑,也许最终会有一些可重用的技能。

#10


7  

More than anything else, if you want this to run on real hardware, you absolutely need a copy of your processor's manual. The Intel manuals (http://www.intel.com/products/processor/manuals/) are invaluable. They go over everything from switching modes (real/protected) to virtual memory management (if you choose to go that far) to making syscalls (if you ever get to doing user mode). Most importantly they explain in great detail a number of things that must be set up for things to function, like the TSS and segment registers, that most OS texts don't discuss because they're more concerned with higher-level concepts than processor-specific details.

最重要的是,如果您想让它在真正的硬件上运行,您绝对需要一个处理器手册的副本。英特尔的手册(http://www.intel.com/products/processor/manuals/)是无价的。他们检查了从切换模式(真正的/受保护的)到虚拟内存管理(如果您选择这么做的话)到创建syscalls(如果您曾经使用过用户模式的话)的一切。最重要的是,它们非常详细地解释了许多必须设置的功能,比如TSS和段寄存器,大多数OS文本都不讨论这些,因为它们更关心高级概念,而不是处理器特定的细节。

#11


6  

check out MikeOS. Its a fairly simple OS written is readable (as in commented) assembly. Even though its fairly simple, it does have a GUI and supports some networking and multimedia.

查看MikeOS。这是一个相当简单的操作系统编写是可读(如注释所示)汇编。尽管它相当简单,但它确实有一个GUI,并且支持一些网络和多媒体。

edit: MenuetOS is graphical. Its also written is straight asm, but its more sophisticated than MikeOS

编辑:MenuetOS图形。它也写的是直asm,但它比MikeOS更复杂

#12


6  

You have an ambitious goal. But execution is key.

你有一个雄心勃勃的目标。但执行是关键。

Most of the structured approaches (textbook or college class) will walk you through the process, but they supply a lot of the nitty-gritty code that glosses over the arcane details of your chosen platform and lets you focus on the big-picture ideas: process scheduling, memory management, deadlock prevention, I/O, and so forth.

大部分的结构化方法(或大学教科书类)将指导您完成这一过程中,但他们提供的很多事实真相掩盖了神秘的代码的细节你选择的平台,让您专注于宏观的想法:进程调度、内存管理、死锁的预防、I / O,等等。

My advice is this: cut way back on your expectations and start with a basic question.

我的建议是:降低你的期望,从一个基本的问题开始。

What is an operating system?

什么是操作系统?

A computer scientist will (hopefully) never say that an OS is a graphical user interface, or a web browser, or a way to hook up USB devices, or anything that a user can actually see or touch. Instead, an OS at its most fundamental level are those things I mentioned above. They all fall under one big umbrella: resource management.

一位计算机科学家(希望如此)永远不会说操作系统是一个图形用户界面,或者一个web浏览器,或者一个连接USB设备的方法,或者任何用户可以看到或触摸到的东西。相反,一个最基本的操作系统是我上面提到的那些东西。它们都属于一个大保护伞:资源管理。

An operating system is nothing more than a program that manages the hardware resources of the computer: memory, CPU, and peripherals.

操作系统只不过是一个管理计算机硬件资源的程序:内存、CPU和外围设备。

Here's a simple operating system: a program lets the user type in a program (in hexadecimal or binary) using a serial connection. Once the program has been typed in, it runs the program. When the program is finished, control is returned to the user where they can either run the program again or type in a new one.

这是一个简单的操作系统:程序允许用户使用串行连接在程序中输入(十六进制或二进制)。一旦程序被输入,它就会运行程序。当程序完成时,控件返回给用户,用户可以再次运行该程序,也可以输入新的程序。

Do this on a "clean" architecture such as an embedded ARM processor with 64K of memory or so. You can code this up in assembly after a few days of learning the ins and outs of the ARM. And voila!, you've got yourself an operating system.

在“干净”的体系结构上执行此操作,例如具有64K内存的嵌入式ARM处理器。你可以在几天的学习之后在汇编中编写这个程序。瞧!你有自己的操作系统。

It does everything an OS is supposed to do:

它做了操作系统应该做的一切:

  • It manages memory by not letting the user overwrite the OS itself.
  • 它通过不让用户覆盖操作系统本身来管理内存。
  • It schedules a single process to run.
  • 它调度要运行的单个进程。
  • It handles the I/O to the single serial peripheral.
  • 它将I/O处理到单个串行外设。

This gives you a building block to start from. You have many choices now. Perhaps one of them would be to allow two programs to be loaded into memory and let the user decide which one to run next.

这为您提供了一个基础。你现在有很多选择。其中之一可能是允许将两个程序加载到内存中,让用户决定接下来运行哪个程序。

Or you could let the user suspend execution of one program, switch to the other, suspend, and switch back. This is rudimentary multitasking, even though it's entirely manual.

或者,您可以让用户挂起执行一个程序,切换到另一个程序,挂起,然后返回。这是基本的多任务处理,尽管完全是手工操作的。

Your choices are unlimited but each one is a baby step from what you had before.

你的选择是无限的,但是每一个都是你以前所拥有的。

It's fun if you don't set your sights too high!

如果你不把眼光放得太高,那就太有趣了!

#13


5  

I maintain a list of resources on *: How to get started in operating system development. Please add new resources to it as you begin you're adventure (I'm about to begin :) )

我维护了*上的一个资源列表:如何开始操作系统开发。当你开始冒险时,请添加新的资源(我即将开始:)

#14


4  

Many schools have OS classes that do much of what you describe. My school (CMU) taught OS in C, and we wrote a kernel, file system, and shell, and were provided with code for a boot loader.

许多学校都有操作系统课程,它们可以完成您所描述的大部分工作。我的学校(CMU)用C语言教授OS,我们编写了内核、文件系统和shell,并为引导加载程序提供了代码。

Unfortunately, I wasn't able to find any definitive resource for this course (15-412) on the web, and it's evolved over time. But perhaps people could post links to sources and assignments for schools that do have good resources on the web.

不幸的是,我无法在web上找到这门课程的任何确定的资源(15-412),而且它是随着时间而发展的。但是,也许人们可以在网上发布一些学校的资源和作业的链接。

#15


3  

You might enjoy this tutorial named "Roll your own toy UNIX-clone OS", its very insightful and should help you on your way.

您可能会喜欢这个名为“滚动自己的玩具UNIX-clone OS”的教程,它非常有见地,应该会在您的道路上帮助您。

Good luck.

祝你好运。

#16


3  

Study the A2 System (formerly called the Oberon system) for ideas you can steal. It is a graphical OS built by just two people, although admittedly one is Niklaus Wirth. First released around 1990 and the speed is astonishingly good. There is a book by Gutknecht.

研究A2系统(以前称为奥伯龙系统),你可以窃取。这是一个仅由两个人开发的图形操作系统,但不可否认的是,其中一人是Niklaus Wirth。第一次发布于1990年左右,速度惊人的好。有一本古特克尼希特的书。

#17


3  

You might want to consider taking a look at Operating Systems Concepts, by Abraham Silberschatz - Understanding Systems Programming concepts is a fundamental requirement, take a peek into F/OSS kernel internals of OSes linux *BSD and GNU/Linux, especially earlier versions, which are probably a bit more documented.alt text http://ecx.images-amazon.com/images/I/51zezQiqYYL._SL500_AA240_.jpgalt text http://ecx.images-amazon.com/images/I/51NEmsW4TCL._SL500_AA240_.jpg

您可能想要看看操作系统的概念,Abraham Silberschatz的《理解系统编程的概念是一个基本的需求》,看看os linux *BSD和GNU/ linux的F/OSS内核内部,特别是早期的版本,它们可能有更多的文档。您可以在http://ecx.images-amazon.com/images/I/51zezQiqYYL._SL500_AA240_.jpgalt文本http://ecx.images-amazon.com/images/I/51NEmsW4TCL._SL500_AA240_.jpg。

#18


3  

About low-level graphics programming, this will give you a lot of information: http://www.osdever.net/FreeVGA/home.htm. (It's very interesting for text mode as well.)

关于低级图形编程,这将给您提供许多信息:http://www.osdever.net/FreeVGA/home.htm。(文本模式也很有趣。)

What will I undoubtedly run into that will confuse me?

毫无疑问,我会遇到什么会让我迷惑?

You will realize that on PC there's an awful lot of stuff that is unclear: the x86 instruction set itself is complicated, and when you get direct access to hardware, it can take quite a while before you understand how to write a single character on screen.

您将意识到,在PC上有很多东西是不清楚的:x86指令集本身是复杂的,当您直接访问硬件时,您可能需要很长时间才能理解如何在屏幕上编写单个字符。

Don't worry about floppy disk and such, most of the time you will use an emulator such as Bochs or QEmu.

不要担心软盘之类的问题,大多数时候您将使用Bochs或QEmu之类的仿真器。

#19


2  

Take a look at Minix. Study the source code along with "Operating Systems Design and Implementation". Consider making contributions to the project. I think Minix is a really good and promising OS in the making. It is also well funded project. That means, you might even get paid for your contributions!

看看Minix。学习源代码以及“操作系统设计和实现”。考虑为这个项目做出贡献。我认为Minix是一个很好的、很有前途的操作系统。这也是一个资金充足的项目。这意味着,你甚至可能会因为你的贡献而得到报酬!

#20


1  

It is very easy thanks to the fact that the BIOS already have many input/output functions built into it for changing screen mode, changing pixel color, writing text to the screen and many other things. However, it does not include support for file systems, that is one of very few things you must incorporate in your OS.

由于BIOS中已经内置了许多输入/输出函数,用于改变屏幕模式、改变像素颜色、向屏幕写入文本和其他许多功能,所以它非常简单。但是,它不包括对文件系统的支持,这是您必须在操作系统中包含的少数内容之一。

The BIOS loads the first sector on the hard drive and starts executing the code from there, so your OS must be placed with the first instruction in the first sector on the hard drive.

BIOS加载硬盘上的第一个扇区并开始从那里执行代码,因此您的操作系统必须在硬盘上的第一个扇区放置第一个指令。

This Wikipedia article should get you started on BIOS interrupts for writing text to the screen, receiving keys from the keyboard and other stuff. https://en.wikipedia.org/wiki/BIOS_interrupt_call

这篇*的文章会让你开始使用BIOS中断来向屏幕写入文本,从键盘和其他东西接收键。https://en.wikipedia.org/wiki/BIOS_interrupt_call

Even if you plan to use c++ I would strongly recommend reading up on assembly programming, as it is vital to understanding how the hardware works.

即使您打算使用c++,我也强烈建议您阅读汇编编程,因为理解硬件的工作原理是非常重要的。

#1


50  

First things first. Read, read, read, read, read. You need to have a firm understanding of how the OS works before you can hope to implement your own.

先做重要的事。读,读,读,读,读。在您希望实现自己的操作之前,您需要对操作系统的工作方式有一个确切的了解。

Grab one of Andrew Tanenbaum's books on operating systems. This is the one we used in my OS class in college:

拿一本Andrew Tanenbaum关于操作系统的书。这是我们在大学的OS课程中使用的:

Modern Operating Systems PDF

现代操作系统PDF

Modern Operating Systems on Amazon

亚马逊上的现代操作系统

Despite the ridiculous cover, it's a fantastic read, especially for a textbook. Tanenbaum is really an expert in this area and his explanations of how the OS works underneath the hood are clear and easy to understand. This book is mostly theory, but I believe he also has a book that discusses more of the implementation. I've never read it, though, so I can't comment on it.

尽管封面很可笑,但这本书读起来非常棒,尤其是一本教科书。Tanenbaum确实是这方面的专家,他对操作系统如何工作的解释很清楚,也很容易理解。这本书主要是理论,但我相信他也有一本关于实现的书。我从来没读过,所以我不能评论它。

That should help you bone up on process management, memory management, filesystems, and everything else your OS kernel needs to do to get it up to a bootable state. From that point on it's basically a matter of writing device drivers for the hardware you need to support, and offering implementations of the C library functions to make kernel calls for things like opening files and devices, reading and writing, passing messages between processes, etc.

这将有助于您深入研究进程管理、内存管理、文件系统以及操作系统内核需要做的所有其他工作,使其达到可引导状态。从那时起,它基本上就是为您需要支持的硬件编写设备驱动程序,并提供C库函数的实现,以进行内核调用,比如打开文件和设备、读写、在进程之间传递消息等等。

Read up on x86 assembly (assuming you are designing this for an x86 machine). That should answer a lot of your questions with regards to moving between processor operating modes.

阅读x86程序集(假设您正在为x86机器设计这个程序集)。这应该可以回答您关于在处理器操作模式之间移动的许多问题。

If you've got any electronics knowledge, it may be easier to start with writing an operating system for an embedded device that has ample documentation, because it will generally be simpler than an x86 PC. I've always wanted to write my own OS as well, and I'm starting with writing a microkernel embedded OS for This Development Board from Digilent. It can run the soft-core MicroBlaze processor from Xilinx, which has very thorough documentation. It's also got some RAM, flash data storage, LEDs, switches, buttons, VGA output, etc. Plenty of stuff to play around with writing simple drivers for.

如果您有任何电子知识,那么从编写一个具有丰富文档的嵌入式设备的操作系统开始,可能会更容易一些,因为它通常比x86 PC更简单。我也一直想写我自己的OS,我从Digilent开始为这个开发委员会编写一个嵌入式操作系统的微内核。它可以运行Xilinx的软核MicroBlaze处理器,它有非常完整的文档。它还有一些RAM,闪存,led,开关,按钮,VGA输出等等。

One of the benefits of an embedded device is also that you may be able to avoid writing a VGA driver for a long time. In my case, the Digilent development board has an onboard UART, so I can effectively use the serial output as my console to get the whole thing up and booting to a command line with minimal fuss.

嵌入式设备的好处之一是,您可以在很长一段时间内避免编写VGA驱动程序。在我的例子中,Digilent开发委员会有一个内置的UART,所以我可以有效地使用串行输出作为我的控制台,以使整个事情启动并引导到一个命令行,而不会有什么麻烦。

Just make sure that whatever you choose to target has a readily available and well-tested compiler for it. You do not want to be writing an OS and a compiler at the same time.

只要确保您选择的目标有一个可用的、经过良好测试的编译器。您不希望同时编写操作系统和编译器。

#2


26  

http://www.osdev.org/ and http://www.osdever.net/

http://www.osdev.org/和http://www.osdever.net/

welcome to the OS Development world.

欢迎来到OS开发世界。

See also other x86 documentation links in SO's tag wiki: Intel and AMD manuals, compiler / assembler docs, and various guides.

请参阅SO的x86标记wiki: Intel和AMD手册、编译器/汇编程序文档和各种指南中的其他x86文档链接。

It also suggests using BOCHS or other virtual environment for debugging, since you can single-step your bootloader and examine registers.

它还建议使用BOCHS或其他虚拟环境进行调试,因为您可以单步引导引导程序并检查寄存器。

#3


15  

I would suggest working, at least at first, on Bochs or some other virtual machine the reason being that you can take it with you wherever you want, it's easier to debug (you can see the exact state of the hardware), and if you need outside help debugging they can use the exact same 'hardware' as you.

我建议工作,至少在一开始,在Bochs或其他虚拟机的原因是,你可以把它与你任何你想要的,更容易调试(硬件)的可以看到的状态,如果你需要外界帮助调试他们可以使用相同的“硬件”。

The most useful advice I have is to get yourself into a state where you can be running C code as quickly as possible -- i.e. boot up, setup your descriptor tables, and get yourself to a point where it's safe to run compiled C. Most if not all the kernel should be in C if you want to stay sane and keep working on it. Assembly, while required in some places, is tedious and tends to be hard to debug.

最有用的建议我是让你自己,你可以尽快运行C代码,即启动,设置你的描述符表,并让自己的安全运行编译C .大多数(如果不是全部的话)内核应该在C语言中,如果你想保持冷静并继续工作。在某些地方,组装是很繁琐的,而且很难调试。

#4


14  

At its lowest level the minimum that an operating system needs to be able to do is to drive a system's hardware in some way and somehow load an execute some sort of "user code." If you're going to start with a PC then you need to write code that can be loaded by it from some device or another. Older PCs have a BIOS in firmware which determines how the hardware performs some initialization (at least video, keyboard, and some form of storage or boot loader). (Update October 2017: Newer PCs have EFI or UEFI firmware ... which is largely a pedantic difference; the serve the same purposes for this discussion).

操作系统需要做的最低限度就是以某种方式驱动系统的硬件,并以某种方式加载某种类型的“用户代码”。如果你打算从PC开始,那么你需要编写可以从某些设备或其他设备加载的代码。旧的pc机在固件中有一个BIOS,它决定硬件如何执行一些初始化(至少是视频、键盘和某种形式的存储或引导加载程序)。(2017年10月更新:更新的pc有EFI或UEFI固件……)这在很大程度上是学究式的差异;这个讨论的目的是一样的)。

So start by learning the low level details of how to use the BIOS or other firmware, on your target system. That is, learn how to write a program that the BIOS can load and execute. That will eventually morph into your boot loader. Start small. Just get a program that prints: "Hello, Linus" directly from the firmware boot process (on a floppy, or USB thumb drive, would be a good start ... or on a hard drive if you like).

因此,首先学习如何在目标系统上使用BIOS或其他固件的底层细节。也就是说,学习如何编写BIOS可以加载和执行的程序。这最终会改变到引导加载程序中。从小事做起。只要得到一个程序,打印:“你好,Linus”,直接从固件引导过程(在软盘,或USB拇指驱动器,将是一个良好的开始…或者在硬盘上,如果你喜欢)。

From there I'd recommend writing a very simple serial driver ... update your boot loader to initialize some serial port, and start a download there from. Then it can execute the code it pulls across. From there write a bit of bootstrap that can write to another set of blocks (we haven't implemented a file system yet ... not even partition table parsing; so we'd just deal with raw ranges of blocks on the disk at first).

从那里我建议写一个非常简单的串行驱动程序……更新引导加载程序以初始化一些串行端口,并从那里开始下载。然后它就可以执行它所经过的代码。从这里开始,编写一些可以写入另一组块的引导程序(我们还没有实现文件系统……)甚至没有分区表解析;所以我们首先要处理磁盘上的原始块范围)。

At that point your boot loader should be able to pull new code across the serial line, dump it into a partition (yes, implement partition table handling of some sort ... whether it conforms to standard PC conventions is up to you at this point), and execute it.

此时,您的引导加载程序应该能够在串行线上拉出新的代码,并将其转储到分区中(是的,实现某种类型的分区表处理……)在这一点上,它是否符合标准PC惯例取决于您),并执行它。

From there you should be able to work on far more sophisticated features. From this base you can write and compile a new "kernel" ... reboot your testbed, and have the new kernel deployed to it.

从那时起,您应该能够处理更复杂的特性。从这个基础上,您可以编写和编译一个新的“内核”……重新启动您的testbed,并将新的内核部署到其中。

(Your bootloader should take some signal, such as a BREAK over the serial handshaking lines as a command to skip the download and just boot the existing image; and it should handle some timeout in this way as well).

(引导加载程序应该接收一些信号,比如中断串行握手行作为命令,以跳过下载,只引导现有映像;它也应该以这种方式处理一些超时)。

From there write a very simple terminal layer and command shell? A filesystem? Implement commands to download new executable content other than the kernel (files or objects of some sort). And so on.

从那里编写一个非常简单的终端层和命令shell?一个文件系统?实现命令来下载内核之外的新可执行内容(文件或某种类型的对象)。等等。

Naturally you could have started with a console driver using the PC keyboard and video (the BIOS INT 0x16h and INT 0x10H stuff, respectively, if I recall correctly). However, I'd suggest starting with a serial driver since you can then automate your build/deploy/test cycle from any other existing (functional) system. Since your new OS will start as a cross-compiled project it's going to be essential for you to have a streamlined way of handling that.

当然,您可以使用PC键盘和视频(如果我没记错的话,分别是BIOS INT 0x16h和INT 0x10H)开始使用控制台驱动程序。但是,我建议您从一个串行驱动程序开始,因为您可以从任何其他现有(功能)系统自动生成/部署/测试周期。由于您的新操作系统将作为一个交叉编译的项目开始,因此您必须使用一种简化的方式来处理它。

I don't know how far you want to take your project. A reasonably impressive goal would be to achieve "self hosting." If you can create a simple assembler/compiler that can allow you to use your new OS to (re-)build, link, and boot into a working version of your new OS ... then you've achieved that goal. (Note that's not a requirement. Many embedded systems are never going to be self-hosting and there's nothing wrong with that).

我不知道你的项目要走多远。一个令人印象深刻的目标是实现“自我托管”。如果您可以创建一个简单的汇编器/编译器,允许您使用您的新操作系统来(重新)构建、链接和引导到新操作系统的工作版本中……然后你就实现了这个目标。(注意这不是一个要求。许多嵌入式系统永远不会成为自宿主,这也没什么错。

#5


12  

If you don't mind using hardware virtualisation, there is a course (book + lectures + software) that will take you 'From Nand to Tetris'. You create a full computer system entirely yourself from the (for these purposes atomic, and given) electrical NAND gate, right through to building the OS, a language, and finally coding a simple game on your personal machine.

如果你不介意使用硬件虚拟化,有一门课程(书本+讲座+软件)会让你“从Nand到俄罗斯方块”。您可以完全自己创建一个完整的计算机系统,从(出于这些目的,原子和给定的)电子NAND gate,一直到构建OS,一种语言,最后在您的个人计算机上编写一个简单的游戏。

I think it's a great idea and something I fully intend to get stuck into soon. The book is surprisingly cheap and I believe the course is taught at MIT. I can imagine no greater feeling than having the full, complete knowledge of an entire system you built yourself from the ground up.

我认为这是一个好主意,而且我完全打算很快就陷入其中。这本书出奇的便宜,我相信这门课是在麻省理工学院教授的。我想象不出比拥有你自己从地面上建立起来的完整的、完整的系统知识更有感觉的了。

Link: http://www1.idc.ac.il/tecs/

链接:http://www1.idc.ac.il/tecs/

#6


10  

I would start small and purchase an 8086 embedded development kit, and develop a multitasking OS on that. Once you have a kernel and are acquainted with working at the hardware level, you will be ready to do something more challenging.

我会从小做起,购买一个8086嵌入式开发工具包,然后在上面开发一个多任务操作系统。一旦您有了内核,并且熟悉了在硬件级别上的工作,您就可以做一些更具挑战性的事情了。

Building even a VGA display DOS clone is a fairly challenging thing. The details are enormous. :-)

甚至构建VGA显示DOS克隆也是一件相当具有挑战性的事情。细节是巨大的。:-)

specific topics.

How do I put the code onto the computer? Is it best to do it with a floppy disk? Can most computers do it from a USB stick?

我怎么把代码放到电脑上?最好是用软盘来做吗?大多数电脑都能通过USB接口完成吗?

The BIOS will do elementary bootstrapping.

BIOS将执行基本的引导。


What drivers do I need, and can you suggest any references to building those?

我需要什么驱动程序,你能给我一些建议吗?

anything that isn't direct cpu/memory operations. Anything that isn't directly in the CPU reference manual.

任何不是直接的cpu/内存操作。任何不在CPU参考手册中的内容。


After the booting sequence--then what? How do I get into protected mode etc.

在引导序列之后——然后呢?如何进入保护模式等。

Protected mode will be part of the boot sequence.

保护模式将是引导序列的一部分。

then you start multitasking and figuring out how to start processes.

然后你开始多任务处理,并弄清楚如何启动进程。


How do I manage memory without the help of an operating system? Do I just use whatever addresses I want? No initialization necessary?

如何在没有操作系统的帮助下管理内存?我要用什么地址?没有初始化必要的吗?

Correct. You will probably want to sort out a virtual memory system eventually.

正确的。最终,您可能希望对虚拟内存系统进行排序。


What will I undoubtedly run into that will confuse me?

毫无疑问,我会遇到什么会让我迷惑?

not having debugging tools, not having IO

没有调试工具,没有IO。


How can I make it either a command line O/S, and a graphical one?

如何使它成为命令行O/S,以及图形化的?

With grief. Look up Windows 3.1 and Linux, in particular X windows.

与悲伤。查找Windows 3.1和Linux,特别是X Windows。


What is a graphical O/S built on? Like, how would I do something like, a command line, with a font, and a picture at the top?

图形O/S是基于什么构建的?比如,我要怎么做,命令行,字体,顶部的图片?

Look up X windows.

查找X windows。


final advice: study linux/x windows. It's not perfect, but it provides an understanding of one approach. Also study embedded systems.

最后的建议:学习linux/x windows。它不是完美的,但是它提供了对一种方法的理解。还研究嵌入式系统。

#7


8  

The OS Development Series @ BrokenThorn might interest you.

你可能会感兴趣的是OS开发系列。

#8


8  

Try to read the code of a small, basic open-source OS, such as MikeOS.

尝试阅读一个小型的、基本的开源操作系统的代码,比如MikeOS。

Alternatively, I suggest the following steps (should be fun!):

或者,我建议以下步骤(应该是有趣的!)

  1. Write a virtual machine. Define all your processor instructions so that you know your system inside and out. Interface it with SDL for keyboard, mouse, screen, audio access. Keep it simple so that you can fit everything in your head at once. It doesn't need to be a state-of-the-art virtual machine, just one that can emulate the function of a 'real' computer.
  2. 写一个虚拟机。定义您的所有处理器指令,以便您了解系统的内部和外部。与SDL接口,用于键盘、鼠标、屏幕、音频访问。保持简单,这样你就能马上把所有的事情都记在脑子里。它不需要是一个最先进的虚拟机,只需模仿“真实”计算机的功能。
  3. Write an assembler for your virtual machine's processor. Remember that this assembler need not be a program written in the virtual machine's language, but anything that can convert your assembly language to machine code.
  4. 为您的虚拟机的处理器编写一个汇编程序。请记住,这个汇编程序不需要是用虚拟机语言编写的程序,而是任何可以将汇编语言转换为机器代码的程序。
  5. Define an executable format, and write a simple linker.
  6. 定义可执行格式,并编写一个简单的链接器。
  7. You've got all the parts to write your operating system now! Write it in the assembly language, assemble it ... etc .. you don't need such a complicated bootloading process, just get your machine to run your OS first.
  8. 现在您已经拥有了编写操作系统的所有部件!用汇编语言写,汇编……等。您不需要如此复杂的引导过程,只需让您的机器先运行OS即可。

The above steps may seem kinda stupid for writing a simple OS, but hey, it's damn fun.

上面的步骤对于编写一个简单的操作系统来说似乎有点愚蠢,但是嘿,这太有趣了。

#9


7  

I see plenty of good references to OS development sites, so I'll describe a different approach:

我看到很多关于OS开发站点的很好的参考,所以我将描述一种不同的方法:

If you want the experience of implementing an OS from bare metal, there are way better hardware choices than an old PC. With the PC architecture, you will spend an inordinate amount of your time coding around uninteresting artifacts of its 30 year design history. For example, just the bootloader part of the project has probably burned out many a brave programmer.

如果您想体验从裸机实现操作系统的体验,有比旧电脑更好的硬件选择。使用PC架构,您将花费大量的时间来编写其30年设计历史中无趣的工件。例如,仅仅是项目的引导加载程序部分就可能耗尽许多勇敢的程序员的精力。

For example, you'll need one set of drivers to read your kernel off of disk and/or the network. Then you'll need code to get into protected mode. At that point, you need another set of drivers! Very little of the work you do to get the chip into protected mode will be transferable after that point. You want to run it on a different PC +- 4 years and you'll need yet another set of drivers.

例如,需要一组驱动程序从磁盘和/或网络中读取内核。然后需要代码进入保护模式。此时,您需要另一组驱动程序!为了使芯片进入保护模式,你所做的工作中只有很少一部分是可以在那之后转移的。你想要在不同的PC上运行它+ 4年,你将需要另外一组驱动。

Look into bootstrapping an ARM or other 32-bit "embedded" chip. Inexpensive development boards are available, or you can solder your own! Some have built-in ethernet and usb. I think you will have more fun working on a sane, non-crusty architecture, and perhaps end up with some re-usable skills.

查看引导一个ARM或其他32位“嵌入式”芯片。有便宜的开发板,或者你可以自己焊接!有些有内置的以太网和usb接口。我认为你将会有更多的乐趣,在一个健全的,非粗糙的建筑,也许最终会有一些可重用的技能。

#10


7  

More than anything else, if you want this to run on real hardware, you absolutely need a copy of your processor's manual. The Intel manuals (http://www.intel.com/products/processor/manuals/) are invaluable. They go over everything from switching modes (real/protected) to virtual memory management (if you choose to go that far) to making syscalls (if you ever get to doing user mode). Most importantly they explain in great detail a number of things that must be set up for things to function, like the TSS and segment registers, that most OS texts don't discuss because they're more concerned with higher-level concepts than processor-specific details.

最重要的是,如果您想让它在真正的硬件上运行,您绝对需要一个处理器手册的副本。英特尔的手册(http://www.intel.com/products/processor/manuals/)是无价的。他们检查了从切换模式(真正的/受保护的)到虚拟内存管理(如果您选择这么做的话)到创建syscalls(如果您曾经使用过用户模式的话)的一切。最重要的是,它们非常详细地解释了许多必须设置的功能,比如TSS和段寄存器,大多数OS文本都不讨论这些,因为它们更关心高级概念,而不是处理器特定的细节。

#11


6  

check out MikeOS. Its a fairly simple OS written is readable (as in commented) assembly. Even though its fairly simple, it does have a GUI and supports some networking and multimedia.

查看MikeOS。这是一个相当简单的操作系统编写是可读(如注释所示)汇编。尽管它相当简单,但它确实有一个GUI,并且支持一些网络和多媒体。

edit: MenuetOS is graphical. Its also written is straight asm, but its more sophisticated than MikeOS

编辑:MenuetOS图形。它也写的是直asm,但它比MikeOS更复杂

#12


6  

You have an ambitious goal. But execution is key.

你有一个雄心勃勃的目标。但执行是关键。

Most of the structured approaches (textbook or college class) will walk you through the process, but they supply a lot of the nitty-gritty code that glosses over the arcane details of your chosen platform and lets you focus on the big-picture ideas: process scheduling, memory management, deadlock prevention, I/O, and so forth.

大部分的结构化方法(或大学教科书类)将指导您完成这一过程中,但他们提供的很多事实真相掩盖了神秘的代码的细节你选择的平台,让您专注于宏观的想法:进程调度、内存管理、死锁的预防、I / O,等等。

My advice is this: cut way back on your expectations and start with a basic question.

我的建议是:降低你的期望,从一个基本的问题开始。

What is an operating system?

什么是操作系统?

A computer scientist will (hopefully) never say that an OS is a graphical user interface, or a web browser, or a way to hook up USB devices, or anything that a user can actually see or touch. Instead, an OS at its most fundamental level are those things I mentioned above. They all fall under one big umbrella: resource management.

一位计算机科学家(希望如此)永远不会说操作系统是一个图形用户界面,或者一个web浏览器,或者一个连接USB设备的方法,或者任何用户可以看到或触摸到的东西。相反,一个最基本的操作系统是我上面提到的那些东西。它们都属于一个大保护伞:资源管理。

An operating system is nothing more than a program that manages the hardware resources of the computer: memory, CPU, and peripherals.

操作系统只不过是一个管理计算机硬件资源的程序:内存、CPU和外围设备。

Here's a simple operating system: a program lets the user type in a program (in hexadecimal or binary) using a serial connection. Once the program has been typed in, it runs the program. When the program is finished, control is returned to the user where they can either run the program again or type in a new one.

这是一个简单的操作系统:程序允许用户使用串行连接在程序中输入(十六进制或二进制)。一旦程序被输入,它就会运行程序。当程序完成时,控件返回给用户,用户可以再次运行该程序,也可以输入新的程序。

Do this on a "clean" architecture such as an embedded ARM processor with 64K of memory or so. You can code this up in assembly after a few days of learning the ins and outs of the ARM. And voila!, you've got yourself an operating system.

在“干净”的体系结构上执行此操作,例如具有64K内存的嵌入式ARM处理器。你可以在几天的学习之后在汇编中编写这个程序。瞧!你有自己的操作系统。

It does everything an OS is supposed to do:

它做了操作系统应该做的一切:

  • It manages memory by not letting the user overwrite the OS itself.
  • 它通过不让用户覆盖操作系统本身来管理内存。
  • It schedules a single process to run.
  • 它调度要运行的单个进程。
  • It handles the I/O to the single serial peripheral.
  • 它将I/O处理到单个串行外设。

This gives you a building block to start from. You have many choices now. Perhaps one of them would be to allow two programs to be loaded into memory and let the user decide which one to run next.

这为您提供了一个基础。你现在有很多选择。其中之一可能是允许将两个程序加载到内存中,让用户决定接下来运行哪个程序。

Or you could let the user suspend execution of one program, switch to the other, suspend, and switch back. This is rudimentary multitasking, even though it's entirely manual.

或者,您可以让用户挂起执行一个程序,切换到另一个程序,挂起,然后返回。这是基本的多任务处理,尽管完全是手工操作的。

Your choices are unlimited but each one is a baby step from what you had before.

你的选择是无限的,但是每一个都是你以前所拥有的。

It's fun if you don't set your sights too high!

如果你不把眼光放得太高,那就太有趣了!

#13


5  

I maintain a list of resources on *: How to get started in operating system development. Please add new resources to it as you begin you're adventure (I'm about to begin :) )

我维护了*上的一个资源列表:如何开始操作系统开发。当你开始冒险时,请添加新的资源(我即将开始:)

#14


4  

Many schools have OS classes that do much of what you describe. My school (CMU) taught OS in C, and we wrote a kernel, file system, and shell, and were provided with code for a boot loader.

许多学校都有操作系统课程,它们可以完成您所描述的大部分工作。我的学校(CMU)用C语言教授OS,我们编写了内核、文件系统和shell,并为引导加载程序提供了代码。

Unfortunately, I wasn't able to find any definitive resource for this course (15-412) on the web, and it's evolved over time. But perhaps people could post links to sources and assignments for schools that do have good resources on the web.

不幸的是,我无法在web上找到这门课程的任何确定的资源(15-412),而且它是随着时间而发展的。但是,也许人们可以在网上发布一些学校的资源和作业的链接。

#15


3  

You might enjoy this tutorial named "Roll your own toy UNIX-clone OS", its very insightful and should help you on your way.

您可能会喜欢这个名为“滚动自己的玩具UNIX-clone OS”的教程,它非常有见地,应该会在您的道路上帮助您。

Good luck.

祝你好运。

#16


3  

Study the A2 System (formerly called the Oberon system) for ideas you can steal. It is a graphical OS built by just two people, although admittedly one is Niklaus Wirth. First released around 1990 and the speed is astonishingly good. There is a book by Gutknecht.

研究A2系统(以前称为奥伯龙系统),你可以窃取。这是一个仅由两个人开发的图形操作系统,但不可否认的是,其中一人是Niklaus Wirth。第一次发布于1990年左右,速度惊人的好。有一本古特克尼希特的书。

#17


3  

You might want to consider taking a look at Operating Systems Concepts, by Abraham Silberschatz - Understanding Systems Programming concepts is a fundamental requirement, take a peek into F/OSS kernel internals of OSes linux *BSD and GNU/Linux, especially earlier versions, which are probably a bit more documented.alt text http://ecx.images-amazon.com/images/I/51zezQiqYYL._SL500_AA240_.jpgalt text http://ecx.images-amazon.com/images/I/51NEmsW4TCL._SL500_AA240_.jpg

您可能想要看看操作系统的概念,Abraham Silberschatz的《理解系统编程的概念是一个基本的需求》,看看os linux *BSD和GNU/ linux的F/OSS内核内部,特别是早期的版本,它们可能有更多的文档。您可以在http://ecx.images-amazon.com/images/I/51zezQiqYYL._SL500_AA240_.jpgalt文本http://ecx.images-amazon.com/images/I/51NEmsW4TCL._SL500_AA240_.jpg。

#18


3  

About low-level graphics programming, this will give you a lot of information: http://www.osdever.net/FreeVGA/home.htm. (It's very interesting for text mode as well.)

关于低级图形编程,这将给您提供许多信息:http://www.osdever.net/FreeVGA/home.htm。(文本模式也很有趣。)

What will I undoubtedly run into that will confuse me?

毫无疑问,我会遇到什么会让我迷惑?

You will realize that on PC there's an awful lot of stuff that is unclear: the x86 instruction set itself is complicated, and when you get direct access to hardware, it can take quite a while before you understand how to write a single character on screen.

您将意识到,在PC上有很多东西是不清楚的:x86指令集本身是复杂的,当您直接访问硬件时,您可能需要很长时间才能理解如何在屏幕上编写单个字符。

Don't worry about floppy disk and such, most of the time you will use an emulator such as Bochs or QEmu.

不要担心软盘之类的问题,大多数时候您将使用Bochs或QEmu之类的仿真器。

#19


2  

Take a look at Minix. Study the source code along with "Operating Systems Design and Implementation". Consider making contributions to the project. I think Minix is a really good and promising OS in the making. It is also well funded project. That means, you might even get paid for your contributions!

看看Minix。学习源代码以及“操作系统设计和实现”。考虑为这个项目做出贡献。我认为Minix是一个很好的、很有前途的操作系统。这也是一个资金充足的项目。这意味着,你甚至可能会因为你的贡献而得到报酬!

#20


1  

It is very easy thanks to the fact that the BIOS already have many input/output functions built into it for changing screen mode, changing pixel color, writing text to the screen and many other things. However, it does not include support for file systems, that is one of very few things you must incorporate in your OS.

由于BIOS中已经内置了许多输入/输出函数,用于改变屏幕模式、改变像素颜色、向屏幕写入文本和其他许多功能,所以它非常简单。但是,它不包括对文件系统的支持,这是您必须在操作系统中包含的少数内容之一。

The BIOS loads the first sector on the hard drive and starts executing the code from there, so your OS must be placed with the first instruction in the first sector on the hard drive.

BIOS加载硬盘上的第一个扇区并开始从那里执行代码,因此您的操作系统必须在硬盘上的第一个扇区放置第一个指令。

This Wikipedia article should get you started on BIOS interrupts for writing text to the screen, receiving keys from the keyboard and other stuff. https://en.wikipedia.org/wiki/BIOS_interrupt_call

这篇*的文章会让你开始使用BIOS中断来向屏幕写入文本,从键盘和其他东西接收键。https://en.wikipedia.org/wiki/BIOS_interrupt_call

Even if you plan to use c++ I would strongly recommend reading up on assembly programming, as it is vital to understanding how the hardware works.

即使您打算使用c++,我也强烈建议您阅读汇编编程,因为理解硬件的工作原理是非常重要的。