C#可以编写像c/C ++这样的操作系统 [英] can C# write operating system like c/C++

查看:79
本文介绍了C#可以编写像c/C ++这样的操作系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

有人告诉我我们可以用c#编写OS,这可能吗?你有什么意见?如果可以,怎么办?

Hello,

Someone tells me that we can write OS with c#, is it possible? what is your opinion? if it can , how?

推荐答案

是的,可以用C#构建操作系统.但是,用托管语言编写高性能内核是一个开放且尚未解决"的研究领域,面临许多挑战.此外,标准的Microsoft C#.NET编译器工具不足以完成此任务.

Microsoft使用C#的变体构建了Singularity内核. MOSA Cosmos 是建立运营的爱好项目C#中的系统内核.

就像C/C ++一样,C#可以提前"编译成机器代码.但是,将需要编写一个自定义的编译器来控制此代码的输出格式和运行时依赖项.为此,MOSA和Cosmos都为本机代码编译器提供了自定义的MSIL.开源Mono编译器还具有AOT功能,可以为此目的进行修改.

C#运行时比C/C ++运行时更广泛,但是两者都需要运行时支持. C#运行时中最大的差异和复杂性之一就是垃圾收集器.绝大多数内核不使用垃圾收集器.对于OS内核而言,垃圾收集的停止世界"暂停是一项重大挑战. Azul C4无暂停收集器可能是一种可能的解决方案,但仍然非常实用新技术.

所以,是的,您可以用C#编写一个操作系统(内核),是的,它以前已经完成过.但是,这些是具有权衡,折衷和实验的研究系统.尚不清楚是否可以用C#编写例如Linux或Windows内核等传统宏内核的版本并获得类似的性能结果-以前从未做到过.
Yes, it is possible to build an operating system in C#. However, authoring performant kernels in managed languages is an open and ''unsolved'' research area, with many challenges. In addition, the standard microsoft C# .NET compiler tools are not sufficient for such a task.

Microsoft built the Singularity kernel using a variant of C#. MOSA and Cosmos are hobby projects building operating system kernels in C#.

C# can be "ahead of time" compiled to machine code, just like C/C++. However, one would need to author a custom compiler to control the output format and runtime dependencies of this code. MOSA and Cosmos both have custom MSIL to native code compilers for this purpose. The open source Mono compiler also has AOT capabilities and could be modified for such a purpose.

The C# runtime is more extensive than the C/C++ runtime, but both require runtime support. One of the biggest differences and complexities in a C# runtime is the garbage collector. The vast majority of kernels do not use garbage collectors. Garbage collection "stop the world" pauses are a significant challenge to overcome for an OS kernel. The Azul C4 Pauseless Collector may be a possible solution, but is still very new technology.

So yes, you can write an operating system (kernel) in C#, and yes, it''s already been done before. However, these are research systems, with tradeoffs, compromises, and experimentation. It is not clear whether or not you could write, for example, a version of a traditional macrokernel like Linux or Windows-kernel in C# and get similar performance results -- it has never been done before.


不严格,不.您可以编写一个操作系统,但是C#依赖于.NET框架,而C和C ++则没有. .NET框架要依靠Windows(或在Mono的情况下为Linux/Android)才能正常工作.

因此,真正的答案是不",您不能直接在C#中编写真正的"操作系统.您可以编写位于现有操作系统之上的内容,而不是"Full Monty"操作系统本身.
Not strictly, no. You can write an operating system, but C# depends on the .NET framework in a way that C and C++ do not. And the .NET framework relies on Windows (or Linux/Android in the case of Mono) in order to work.

So the real answer is no, you can''t write a "true" operating system directly in C#. You can write something that sits on top of an existing operating system, but not the "Full Monty" OS itself.


当前分层:
1.平台(硬件,BIOS等)
2.操作系统(使用C/C ++编写的Windows或Linux,并且只需很少的汇编程序)
3. .Net(可能是用C/C ++编写)
4.您的.Net代码是Windows程序

我可以想像像这样的东西:
1.平台(硬件,BIOS等)
2. .Net(假设您使用C/C ++加上一些平台相关的程序集编写)
3.用.Net编写的操作系统
4.以任何语言编写的任何格式的操作系统程序

.Net平台当前基于操作系统实现.完全有可能在硬件/BIOS功能的基础上建立一个.Net环境,作为您OS代码的基础,但这并不是一件容易的事.我认为不这样做的原因是与性能相关的,C和C ++为您提供了更多管理资源的自由,这些语言是高级汇编"语言. :D尽管如此,也可以在当前.Net实现的顶部编写和启动第二个OS(在Windows内部)(与在基于硬件的.Net上执行该操作的方式相同),如果您坚持这样做的话,它可以加载您自己的可执行格式,等等...如果您有很多时间消磨:D
,那可能会很有趣.
您可以在硬件之上放置任意分层,您不能更改的仅仅是硬件及其汇编语言.您可以找到自己的语言,自己的操作系统,自己的编译器和自己的可执行格式...
Current layering:
1. Platform (hardware, bios, ...)
2. OS (windows or linux written in C/C++ and in minimal amount of assembly)
3. .Net (probably written in C/C++)
4. Your .Net code that is a windows program

I can imagine something like:
1. Platform (hardware, bios, ...)
2. .Net (lets say you write it in C/C++ plus some platform dependent assembly)
3. OS written in .Net
4. Programs for your OS in whatever format written in whatever language

The .Net platform is currently implemented based on the OS. It would be totally possible to build up a .Net environment on top of the hardware/bios functionality as a base for your OS code but it is not a small piece of work. I think the reason for not doing this is performance related, C and C++ give you much more freedom to manage your resources, these languages are "high level assembly" languages. :D Still, could write and start a second OS (inside windows) on top of the current .Net implementation (the same way you would do it on .Net that is built on top of the hardware) as well If you insist on this, it could load your own executable format etc... It can be fun if you have a lot of time to kill :D

You can put arbitrary layering on top of the hardware, what you can not change is just the hardware and its assembly language. You can find out your own languages, your own OS, your own compilers and your own executable formats...


这篇关于C#可以编写像c/C ++这样的操作系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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