用 Java 或 C 编程的操作系统(内核)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4937970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OS (kernel) programmed in Java or in C
提问by Martynas
I'm going to start building operating system and I don't know which programming language to choose for kernel. My favorite language is Java
but I know that all major operating systems (Windows, Linux, Mac OS) is programmed in C
, moreover Java requires virtual machine. Does it would be much harder to program than Java-based
OS than C-based
OS? What are the advantages and disadvantages of each of these languages?
我要开始构建操作系统,我不知道为内核选择哪种编程语言。我最喜欢的语言是Java
但我知道所有主要的操作系统(Windows、Linux、Mac OS)都是用C
.NET编程的,而且 Java 需要虚拟机。与Java-based
操作系统相比,编程会比操作系统难得多C-based
吗?每种语言的优缺点是什么?
回答by friedkiwi
http://wiki.osdev.orgis an extremely useful site on that matter. It tells you how to build your toolchains, which language options that are available, and has some great example code.
http://wiki.osdev.org是一个非常有用的网站。它告诉您如何构建工具链、可用的语言选项以及一些很棒的示例代码。
Yvan
伊万
回答by Johan Sj?berg
I would humbly suggest that you truly learn a programming language before trying to build an operating system, after which you would realize in which languages you can or cannot write kernels in yourself.
我谦虚地建议你在尝试构建操作系统之前真正学习一门编程语言,之后你会意识到你可以或不能自己编写内核的语言。
Programming languages such as Java simply does not offer the low-level routines necessary to create an os. You can implement your OS in c or c++. Unless you master bootstrapping code (read assembler) anda programming language such as c, it would be a good idea to reconsider a perhaps easier task.
Java 等编程语言根本不提供创建操作系统所需的低级例程。您可以在 c 或 c++ 中实现您的操作系统。除非您掌握引导代码(阅读汇编程序)和诸如 c 之类的编程语言,否则最好重新考虑一项可能更简单的任务。
You could however emulatean OS by running it as a program in another OS, in which case you may experiment with any language of your choise.
但是,您可以通过在另一个操作系统中将其作为程序运行来模拟操作系统,在这种情况下,您可以尝试使用您选择的任何语言。
回答by S.Lott
Does it would be much harder to program than Java-based OS than C-based OS?
是否比基于 Java 的操作系统比基于 C 的操作系统更难编程?
How would you write the hardware-level programming to handle interrupts in Java?
您将如何编写硬件级编程来处理 Java 中的中断?
回答by evilcandybag
There seem to be several Java-based OSs already out there. I don't know a lot about OS-programming, but there seems to be quite an extensive literature (altough a lot of it in German) about a Java-based OS called JX, from the University of Erlangen: http://www4.informatik.uni-erlangen.de/Projects/JX/publications.html
Maybe there is something there to help.
似乎已经有几个基于 Java 的操作系统了。我对操作系统编程了解不多,但似乎有相当多的文献(尽管很多是德语)关于来自埃尔兰根大学的名为 JX 的基于 Java 的操作系统:http://www4 .informatik.uni-erlangen.de/Projects/JX/publications.html
也许有什么可以帮助的。
Writing a C-based OS should be the easiest, though, simply due to there being so much more information about it.
不过,编写基于 C 的操作系统应该是最简单的,因为关于它的信息太多了。
回答by Chris Thompson
You won't be able to program an OS kernel in Java unless you have access to a compiler that will compile Java into machine language. Java requires a virtual machine which interprets the byte code and executes native instructions (that rely on the kernel). You must be able to interact directly with the hardware in order to program an OS which is something you simply can't do with Java. Your only option, really, is C mixed with assembly.
除非您可以访问将 Java 编译为机器语言的编译器,否则您将无法使用 Java 编写操作系统内核。Java 需要一个虚拟机来解释字节码并执行本机指令(依赖于内核)。您必须能够直接与硬件交互才能对操作系统进行编程,而这是 Java 无法做到的。实际上,您唯一的选择是将 C 与汇编混合。
回答by Jerry Coffin
The JVM provides an awful lot of OS-like capabilities, and it can't be written in Java -- so either way, you're going to end up writing an awful lot of the code in C (or something that can produce code that doesn't require a virtual machine).
JVM 提供了大量类似 OS 的功能,它不能用 Java 编写——所以无论哪种方式,你最终都会用 C 编写大量代码(或可以生成代码的东西)不需要虚拟机)。