为x86架构开发操作系统

时间:2021-06-21 03:17:12

I am planning to develop an operating system for the x86 architecture.

我计划为x86架构开发一个操作系统。

  • What options of programming languages do I have?
  • 我有哪些编程语言选项?

  • What types of compilers are there available, preferably on a Windows environment?
  • 有哪些类型的编译器可用,最好是在Windows环境中?

  • Are there any good sources that will help me learn more about operating system development?
  • 是否有任何好的资源可以帮助我了解有关操作系统开发的更多信息?

  • Is it better to test my operating system on a Virtual Machine or on physical hardware?
  • 在虚拟机或物理硬件上测试我的操作系统更好吗?

Any suggestions?

13 个解决方案

#1


42  

For my final year project in collage I developed a small x86 OS with a virtual memory manager, a virtual file system and fully preemptive multitasking. I made it open source and the code is heavily commented, check out its source forge page at:

对于我拼贴的最后一年项目,我开发了一个带有虚拟内存管理器,虚拟文件​​系统和完全抢占式多任务的小型x86操作系统。我把它作为开源代码并且代码被大量评论,请查看其源代码页面:

https://github.com/stephenfewer/NoNameOS

From my experience I can recommend the following:

根据我的经验,我可以推荐以下内容:

You will need x86 assembly language for various parts, this in unavoidable, but can be kept to a minimum. Fairly quickly you will get running C code, which is a proven choice for OS development. Once you have some sort of memory manager available you can go into C++ if you like (you need some kind of memory manager for things like new and delete).

您将需要x86汇编语言的各个部分,这是不可避免的,但可以保持在最低限度。相当快,您将获得运行C代码,这是OS开发的可靠选择。一旦你有了某种内存管理器,如果你愿意,可以使用C ++(你需要某种内存管理器来处理新的和删除的事情)。

No matter what language you choose you will still need assembly & C to bring a system from boot where the BIOS leaves you into any useable form.

无论您选择何种语言,您仍然需要使用assembly&C将系统从BIOS启动后带入任何可用的形式。

Ultimately, the primary language you choose will depend on the type of OS you want to develop.

最终,您选择的主要语言将取决于您要开发的操作系统类型。

My development environment was the Windows port of the GNU development tools DJGPP along with the NASM assembler. For my IDE I used IBM's Eclipse with the CDT plugin which provides a C/C++ development environment within Eclipse.

我的开发环境是GNU开发工具DJGPP的Windows端口以及NASM汇编器。对于我的IDE,我使用IBM的Eclipse和CDT插件,该插件在Eclipse中提供了一个C / C ++开发环境。

For testing I recommend BOCHS, an open source x86 PC emulator. It lets you boot up your OS quickly which is great for testing and can be integrated into eclipse so you can build and run your OS at the push of a button. I would also recommend using both VMWare and a physical PC occasionally as you can pick up on some subtle bugs that way.

为了测试,我推荐BOCHS,一个开源的x86 PC仿真器。它允许您快速启动操作系统,这非常适合测试,并且可以集成到eclipse中,因此您只需按一下按钮即可构建和运行操作系统。我还建议偶尔使用VMWare和物理PC,因为你可以通过这种方式获取一些微妙的错误。

P.S. OS development is really fun but is very intensive, mine took the best part of 12 months. My advice is to plan well and your design is key! enjoy :)

附:操作系统的开发非常有趣,但非常密集,我的开发时间为12个月。我的建议是计划好,你的设计是关键!请享用 :)

#2


5  

Language and compiler depend entirely on what you're attempting to accomplish. I would suggest, though, that you might be approaching the problem from too low a level.

语言和编译器完全取决于您尝试完成的任务。不过,我建议您可能从太低的水平接近问题。

There are materials out there on operating system fundamentals. MIT has OpenCourseware on the subject. Read through Andrew Tannenbaum's Operating Systems series, and look at things like Minix.

有关于操作系统基础知识的材料。麻省理工学院有关于这个主题的OpenCourseware。阅读Andrew Tannenbaum的操作系统系列,看看像Minix这样的东西。

Get an idea for what's out there. Start tinkering with things. Borrow ideas, and see where they go. You can reinvent the wheel if you really want, but you'll learn more by building on the works of others.

了解那里有什么。开始摆弄东西。借用想法,看看他们去哪里。如果你真的想要,你可以重新发明*,但你可以通过建立他人的作品来学习更多。

#3


5  

It doesn't really matter, what language you choose. If the language is Turing-complete, then you can write an OS in it.

这并不重要,你选择什么语言。如果语言是Turing-complete,那么您可以在其中编写OS。

However, the expressiveness of the language will make certain kinds of designs very easy or very hard to implement. For example, the "liveliness" and dynamism of the old Smalltalk OSs depends on the fact that they are implemented in Smalltalk. You could do that in C, too, but it would probably be so hard that you wouldn't even think about it. JavaScript or Ruby OTOH would probably be a great fit.

然而,语言的表现力将使某些类型的设计变得非常容易或很难实现。例如,旧的Smalltalk操作系统的“活力”和动态取决于它们是在Smalltalk中实现的。你也可以在C中做到这一点,但它可能会很难你甚至不会想到它。 JavaScript或Ruby OTOH可能非常合适。

Microsoft Research's Singularity is another example. It simply couldn't be implemented in anything other than Sing#, Spec# and C# (or similar languages), because so much of the architecture is dependent on the static type safety and static verifiability of those languages.

Microsoft Research的Singularity是另一个例子。除了Sing#,Spec#和C#(或类似语言)之外,它根本无法实现,因为很多架构依赖于这些语言的静态类型安全性和静态可验证性。

One thing to keep in mind: the design space for OSs implemented in C is pretty much fully explored. There's literally thousands of them. In other languages, however, you might actually discover something that nobody has discovered before! There's only about a dozen or so OSs written in Java, about half a dozen in C#, something on the order of two OSs in Haskell, only one in Python and none in Ruby or JavaScript.

需要记住的一件事是:用C实现的操作系统的设计空间已经得到了充分的探索。实际上有成千上万的人。但是,在其他语言中,您可能会发现以前没有人发现过的东西!只有大约十几个用Java编写的操作系统,大约有六个用C#编写,有些是Haskell中两个操作系统的顺序,只有一个用Python编写,没有一个用Ruby或JavaScript编写。

Try writing an OS in Erlang or Io, and see how that influences your thinking about Operating Systems!

尝试在Erlang或Io中编写操作系统,看看它会如何影响您对操作系统的思考!

#4


4  

There is an OS course offered at the University of Maryland that utilizes GeekOS. This is a small, extensively commented OS designed for educational purposes which can be run using the Bochs or QEMU emulators.

马里兰大学提供了一个使用GeekOS的OS课程。这是一个小型,广泛评论的操作系统,专为教育目的而设计,可以使用Bochs或QEMU仿真器运行。

For an example of how it is used in a course, check out a previous offering of the course at the class webpage. There, you will find assignments where you have to add different functionality to GeekOS.

有关如何在课程中使用它的示例,请在课程网页上查看课程的先前课程。在那里,你会发现你必须为GeekOS添加不同功能的作业。

Its a great way to get familiar with a small and simple OS that runs on the x86 architecture.

它是熟悉在x86架构上运行的小而简单的操作系统的好方法。

#5


3  

You might want to look up XINU. it's a tiny OS for x86 that isn't really used for anything other than to be dissected by students.

您可能想要查找XINU。它是x86的一个小操作系统,除了被学生解剖之外,它还没有真正用于任何其他操作系统。

#6


3  

Use ANSI C, and start off with an emulator. When you port over to a real machine, there will be some assembler code. Context switching and interrupt handling (for instance) is easier to write in assembler.

使用ANSI C,并从模拟器开始。当您移植到真正的机器时,会有一些汇编程序代码。上下文切换和中断处理(例如)在汇编程序中更容易编写。

Andy Tannenbaum has written a good book on OS. Many other good ones exist.

Andy Tannenbaum写了一本关于操作系统的好书。存在许多其他好的。

Good luck! There is nothing quite like haveing written your own OS, however small.

祝好运!没有什么比编写自己的操作系统更好了,无论多么小。

#7


3  

Also check out the OSDev.org which have all information you need to get started.

另请查看OSDev.org,其中包含您开始使用所需的所有信息。

#8


2  

I've done that once for a 386SX, which was on a PCI board. A good source on how to start a X86 cpu in protected mode is the source code of linux. It's just a few assembly statements. After that you can use gcc to compile your C code. The result is objectcode in ELF format. I wrote my own linker, to make a program out of the objectcode. And yes, it worked! Good luck.

我曾经为PCI板上的386SX做过一次。关于如何在保护模式下启动X86 cpu的一个很好的来源是linux的源代码。这只是一些汇编语句。之后,您可以使用gcc编译C代码。结果是ELF格式的目标代码。我编写了自己的链接器,用于从对象代码中创建程序。是的,它奏效了!祝好运。

#9


2  

Be sure to check out the answers to my question:

请务必查看我的问题的答案:

How to get started in operating system development

如何开始操作系统开发

#10


1  

If you are making a full OS, you will need to use a range of languages. I would expect Assembly, C and C++ at the very least.

如果您要制作完整的操作系统,则需要使用一系列语言。我至少会期待Assembly,C和C ++。

I would use a Virtual Machine for most of the testing.

我会在大多数测试中使用虚拟机。

#11


1  

Without a doubt, I'd use Ada. It's the best general-purpose systems-programming language I have come across, bar none. One example, Ada's much better for specifying bit layout of objects in a record than C. Ada also supports overlaying records on specific memory locations. C requires you to play with pointers to acheive the same effect. That works, but is more error-prone. Ada also has language support for interrupts.

毫无疑问,我会使用Ada。这是我遇到过的最好的通用系统编程语言,没有。一个例子,Ada更好地指定记录中对象的位布局而不是C.Ada还支持在特定内存位置上覆盖记录。 C要求你玩指针来实现相同的效果。这有效,但更容易出错。 Ada还为中断提供语言支持。

Another: Safety. Ada defaults to bound checking array assignments, but allows you to turn it off when you need it. C "defaults" to no bound checking on arrays,so you have to do it yourself manually whenever you want it. Time has shown that this is not the right default. You will forget one where it is needed. Buffer overflow exploits are the single most common security flaw used by crackers. They have whole websites explainng how to find and use them.

另:安全。 Ada默认绑定检查数组分配,但允许您在需要时将其关闭。 C“默认”为对数组没有绑定检查,因此您必须在需要时自己手动执行此操作。时间已经表明这不是正确的默认值。你会忘记一个需要它的地方。缓冲区溢出漏洞是破解者使用的最常见的安全漏洞。他们有整个网站解释如何查找和使用它们。

As for learning about doing this, the two books I'm aware of are XINU (Unix backwards, nothing to do with Scientology), and Project Oberon. The first was used in my Operating Systems graduate course, and the second was written by Nikalus Wirth, creator of Pascal.

至于学习这样做,我所知道的两本书是XINU(Unix向后,与Scientology无关)和Project Oberon。第一个用于我的操作系统研究生课程,第二个是由Pascal的创建者Nikalus Wirth编写的。

#12


1  

C most probably...all major OS-es have been written in C/C++ or Objective-C(Apple)

C最有可能......所有主要的操作系统都是用C / C ++或Objective-C(Apple)编写的

#13


-5  

If you want write an OS then you need a couple of people. A OS can not write a single people. I think it is better to work on existing OS projects

如果你想写一个操作系统,那么你需要几个人。操作系统不能写一个人。我认为最好在现有的OS项目上工作

  • Reactos --> C, Assembler
  • Reactos - > C,汇编程序

  • SharpOS --> C#
  • SharpOS - > C#

  • JNode --> Java
  • JNode - > Java

This is only a short list of OS projects. How you can see there is a project for every possible language.

这只是OS项目的简短列表。如何看待每个可能的语言都有一个项目。

#1


42  

For my final year project in collage I developed a small x86 OS with a virtual memory manager, a virtual file system and fully preemptive multitasking. I made it open source and the code is heavily commented, check out its source forge page at:

对于我拼贴的最后一年项目,我开发了一个带有虚拟内存管理器,虚拟文件​​系统和完全抢占式多任务的小型x86操作系统。我把它作为开源代码并且代码被大量评论,请查看其源代码页面:

https://github.com/stephenfewer/NoNameOS

From my experience I can recommend the following:

根据我的经验,我可以推荐以下内容:

You will need x86 assembly language for various parts, this in unavoidable, but can be kept to a minimum. Fairly quickly you will get running C code, which is a proven choice for OS development. Once you have some sort of memory manager available you can go into C++ if you like (you need some kind of memory manager for things like new and delete).

您将需要x86汇编语言的各个部分,这是不可避免的,但可以保持在最低限度。相当快,您将获得运行C代码,这是OS开发的可靠选择。一旦你有了某种内存管理器,如果你愿意,可以使用C ++(你需要某种内存管理器来处理新的和删除的事情)。

No matter what language you choose you will still need assembly & C to bring a system from boot where the BIOS leaves you into any useable form.

无论您选择何种语言,您仍然需要使用assembly&C将系统从BIOS启动后带入任何可用的形式。

Ultimately, the primary language you choose will depend on the type of OS you want to develop.

最终,您选择的主要语言将取决于您要开发的操作系统类型。

My development environment was the Windows port of the GNU development tools DJGPP along with the NASM assembler. For my IDE I used IBM's Eclipse with the CDT plugin which provides a C/C++ development environment within Eclipse.

我的开发环境是GNU开发工具DJGPP的Windows端口以及NASM汇编器。对于我的IDE,我使用IBM的Eclipse和CDT插件,该插件在Eclipse中提供了一个C / C ++开发环境。

For testing I recommend BOCHS, an open source x86 PC emulator. It lets you boot up your OS quickly which is great for testing and can be integrated into eclipse so you can build and run your OS at the push of a button. I would also recommend using both VMWare and a physical PC occasionally as you can pick up on some subtle bugs that way.

为了测试,我推荐BOCHS,一个开源的x86 PC仿真器。它允许您快速启动操作系统,这非常适合测试,并且可以集成到eclipse中,因此您只需按一下按钮即可构建和运行操作系统。我还建议偶尔使用VMWare和物理PC,因为你可以通过这种方式获取一些微妙的错误。

P.S. OS development is really fun but is very intensive, mine took the best part of 12 months. My advice is to plan well and your design is key! enjoy :)

附:操作系统的开发非常有趣,但非常密集,我的开发时间为12个月。我的建议是计划好,你的设计是关键!请享用 :)

#2


5  

Language and compiler depend entirely on what you're attempting to accomplish. I would suggest, though, that you might be approaching the problem from too low a level.

语言和编译器完全取决于您尝试完成的任务。不过,我建议您可能从太低的水平接近问题。

There are materials out there on operating system fundamentals. MIT has OpenCourseware on the subject. Read through Andrew Tannenbaum's Operating Systems series, and look at things like Minix.

有关于操作系统基础知识的材料。麻省理工学院有关于这个主题的OpenCourseware。阅读Andrew Tannenbaum的操作系统系列,看看像Minix这样的东西。

Get an idea for what's out there. Start tinkering with things. Borrow ideas, and see where they go. You can reinvent the wheel if you really want, but you'll learn more by building on the works of others.

了解那里有什么。开始摆弄东西。借用想法,看看他们去哪里。如果你真的想要,你可以重新发明*,但你可以通过建立他人的作品来学习更多。

#3


5  

It doesn't really matter, what language you choose. If the language is Turing-complete, then you can write an OS in it.

这并不重要,你选择什么语言。如果语言是Turing-complete,那么您可以在其中编写OS。

However, the expressiveness of the language will make certain kinds of designs very easy or very hard to implement. For example, the "liveliness" and dynamism of the old Smalltalk OSs depends on the fact that they are implemented in Smalltalk. You could do that in C, too, but it would probably be so hard that you wouldn't even think about it. JavaScript or Ruby OTOH would probably be a great fit.

然而,语言的表现力将使某些类型的设计变得非常容易或很难实现。例如,旧的Smalltalk操作系统的“活力”和动态取决于它们是在Smalltalk中实现的。你也可以在C中做到这一点,但它可能会很难你甚至不会想到它。 JavaScript或Ruby OTOH可能非常合适。

Microsoft Research's Singularity is another example. It simply couldn't be implemented in anything other than Sing#, Spec# and C# (or similar languages), because so much of the architecture is dependent on the static type safety and static verifiability of those languages.

Microsoft Research的Singularity是另一个例子。除了Sing#,Spec#和C#(或类似语言)之外,它根本无法实现,因为很多架构依赖于这些语言的静态类型安全性和静态可验证性。

One thing to keep in mind: the design space for OSs implemented in C is pretty much fully explored. There's literally thousands of them. In other languages, however, you might actually discover something that nobody has discovered before! There's only about a dozen or so OSs written in Java, about half a dozen in C#, something on the order of two OSs in Haskell, only one in Python and none in Ruby or JavaScript.

需要记住的一件事是:用C实现的操作系统的设计空间已经得到了充分的探索。实际上有成千上万的人。但是,在其他语言中,您可能会发现以前没有人发现过的东西!只有大约十几个用Java编写的操作系统,大约有六个用C#编写,有些是Haskell中两个操作系统的顺序,只有一个用Python编写,没有一个用Ruby或JavaScript编写。

Try writing an OS in Erlang or Io, and see how that influences your thinking about Operating Systems!

尝试在Erlang或Io中编写操作系统,看看它会如何影响您对操作系统的思考!

#4


4  

There is an OS course offered at the University of Maryland that utilizes GeekOS. This is a small, extensively commented OS designed for educational purposes which can be run using the Bochs or QEMU emulators.

马里兰大学提供了一个使用GeekOS的OS课程。这是一个小型,广泛评论的操作系统,专为教育目的而设计,可以使用Bochs或QEMU仿真器运行。

For an example of how it is used in a course, check out a previous offering of the course at the class webpage. There, you will find assignments where you have to add different functionality to GeekOS.

有关如何在课程中使用它的示例,请在课程网页上查看课程的先前课程。在那里,你会发现你必须为GeekOS添加不同功能的作业。

Its a great way to get familiar with a small and simple OS that runs on the x86 architecture.

它是熟悉在x86架构上运行的小而简单的操作系统的好方法。

#5


3  

You might want to look up XINU. it's a tiny OS for x86 that isn't really used for anything other than to be dissected by students.

您可能想要查找XINU。它是x86的一个小操作系统,除了被学生解剖之外,它还没有真正用于任何其他操作系统。

#6


3  

Use ANSI C, and start off with an emulator. When you port over to a real machine, there will be some assembler code. Context switching and interrupt handling (for instance) is easier to write in assembler.

使用ANSI C,并从模拟器开始。当您移植到真正的机器时,会有一些汇编程序代码。上下文切换和中断处理(例如)在汇编程序中更容易编写。

Andy Tannenbaum has written a good book on OS. Many other good ones exist.

Andy Tannenbaum写了一本关于操作系统的好书。存在许多其他好的。

Good luck! There is nothing quite like haveing written your own OS, however small.

祝好运!没有什么比编写自己的操作系统更好了,无论多么小。

#7


3  

Also check out the OSDev.org which have all information you need to get started.

另请查看OSDev.org,其中包含您开始使用所需的所有信息。

#8


2  

I've done that once for a 386SX, which was on a PCI board. A good source on how to start a X86 cpu in protected mode is the source code of linux. It's just a few assembly statements. After that you can use gcc to compile your C code. The result is objectcode in ELF format. I wrote my own linker, to make a program out of the objectcode. And yes, it worked! Good luck.

我曾经为PCI板上的386SX做过一次。关于如何在保护模式下启动X86 cpu的一个很好的来源是linux的源代码。这只是一些汇编语句。之后,您可以使用gcc编译C代码。结果是ELF格式的目标代码。我编写了自己的链接器,用于从对象代码中创建程序。是的,它奏效了!祝好运。

#9


2  

Be sure to check out the answers to my question:

请务必查看我的问题的答案:

How to get started in operating system development

如何开始操作系统开发

#10


1  

If you are making a full OS, you will need to use a range of languages. I would expect Assembly, C and C++ at the very least.

如果您要制作完整的操作系统,则需要使用一系列语言。我至少会期待Assembly,C和C ++。

I would use a Virtual Machine for most of the testing.

我会在大多数测试中使用虚拟机。

#11


1  

Without a doubt, I'd use Ada. It's the best general-purpose systems-programming language I have come across, bar none. One example, Ada's much better for specifying bit layout of objects in a record than C. Ada also supports overlaying records on specific memory locations. C requires you to play with pointers to acheive the same effect. That works, but is more error-prone. Ada also has language support for interrupts.

毫无疑问,我会使用Ada。这是我遇到过的最好的通用系统编程语言,没有。一个例子,Ada更好地指定记录中对象的位布局而不是C.Ada还支持在特定内存位置上覆盖记录。 C要求你玩指针来实现相同的效果。这有效,但更容易出错。 Ada还为中断提供语言支持。

Another: Safety. Ada defaults to bound checking array assignments, but allows you to turn it off when you need it. C "defaults" to no bound checking on arrays,so you have to do it yourself manually whenever you want it. Time has shown that this is not the right default. You will forget one where it is needed. Buffer overflow exploits are the single most common security flaw used by crackers. They have whole websites explainng how to find and use them.

另:安全。 Ada默认绑定检查数组分配,但允许您在需要时将其关闭。 C“默认”为对数组没有绑定检查,因此您必须在需要时自己手动执行此操作。时间已经表明这不是正确的默认值。你会忘记一个需要它的地方。缓冲区溢出漏洞是破解者使用的最常见的安全漏洞。他们有整个网站解释如何查找和使用它们。

As for learning about doing this, the two books I'm aware of are XINU (Unix backwards, nothing to do with Scientology), and Project Oberon. The first was used in my Operating Systems graduate course, and the second was written by Nikalus Wirth, creator of Pascal.

至于学习这样做,我所知道的两本书是XINU(Unix向后,与Scientology无关)和Project Oberon。第一个用于我的操作系统研究生课程,第二个是由Pascal的创建者Nikalus Wirth编写的。

#12


1  

C most probably...all major OS-es have been written in C/C++ or Objective-C(Apple)

C最有可能......所有主要的操作系统都是用C / C ++或Objective-C(Apple)编写的

#13


-5  

If you want write an OS then you need a couple of people. A OS can not write a single people. I think it is better to work on existing OS projects

如果你想写一个操作系统,那么你需要几个人。操作系统不能写一个人。我认为最好在现有的OS项目上工作

  • Reactos --> C, Assembler
  • Reactos - > C,汇编程序

  • SharpOS --> C#
  • SharpOS - > C#

  • JNode --> Java
  • JNode - > Java

This is only a short list of OS projects. How you can see there is a project for every possible language.

这只是OS项目的简短列表。如何看待每个可能的语言都有一个项目。