使用ngen.exe编译内核
据我所知,Cosmos 和 SharpOS 已经制作了自己的编译器来从 C# 构建二进制代码,但是您可以使用 Microsoft 的 .NET AOT 来做同样的事情吗?也就是说,将 C# 编译为 x86。我认为您必须省略 using 语句,就像操作系统开发时涉及 include 语句一样。 任何反馈表示赞赏。谢谢
编辑:我想在内核开发中使用 C# 的主要原因是托管代码带来的内存管理,特别是单一地址空间属性。是否需要启动 JIT 编译器,然后编译 C#?还是说当时的环境还太恶劣?感谢您的反馈
I understand that the Cosmos and SharpOS have made their own compilers to build binary code from C#, but could you use Microsoft's .NET AOT to do the same thing? Compiling C# to x86, that is. I assume you would have to leave out using statements, much like OS development when it comes to include statements.
Any feedback appreciated. Thanks
EDIT: The main reason I want to use C# in kernel development is for the memory management that managed code brings with it, especially the single address space property. Would it be necessary to boot a JIT compiler, then compile C#? Or is the environment still too crippled at that point? Thanks for feedback
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
简短回答:不,使用 ngen.exe / AOT 编译器不足以编译内核。
长答案:ngen.exe / AOT 编译器消除了 JIT 编译器的工作,但 CLR 不仅仅是一个 JIT 编译器 - 即使不引用任何其他程序集,它也提供内存管理、垃圾收集、类型等功能检查和异常处理(以及除此之外的一大堆其他事情)。
是的,使用 ngen 确实会让你更接近用 C# 生成内核,但它并没有让你更接近 - 你仍然有一大堆其他问题需要解决,通过编写一个编译器可以更容易地解决这些问题目标是您的预期环境(而不是 CLR)。
更新:如果您想要 C# 的“托管”部分,那么您需要为自己创建一个托管环境来运行您的代码,即垃圾收集器等...(或者尝试获取类似的现有环境) CLR 才能工作,这可能会更困难)。即使有底层操作系统的支持,这也是一项相当艰巨的任务,当您操作系统时,执行此操作更是如此(尽管绝不是不可能的 - 毕竟这是正是像 Singularity 和 Cosmos 这样的项目所做的)。
Short answer: No, using ngen.exe / an AOT compiler would not be enough to compile a kernel.
Long answer: ngen.exe / an AOT compiler cuts out the job of the JIT compiler, but the CLR is a lot more than just a JIT compiler - even without referencing any other assemblies it also provides things like memory management, garbage collection, type checking and exception handling (and a whole load of other things besides).
Yes using ngen does take you a step closer to producing a kernel in C#, but it doesn't take you that much closer - you still have a whole load of other problems to solve, ones which are more easily solved by writing a compiler that targets your intended environment (rather than the CLR).
Update: If you want the "managed" part of C# then you need to create yourself a managed environment to run your code in, i.e. garbage collector etc... (or try and get an existing on like the CLR to work, which would probably be more difficult). This is a pretty herculean task even with the support of an underlying OS, doing this when you are the OS even more so (although by no means impossible - after all this is exactly what projects like Singularity and Cosmos have done).
不,你不能用 ngen 做到这一点。 ngen 输出本身的级别不够低,无法在没有所有支持的 CLR 和 Windows 基础设施的情况下启动内核。
您提到的其他项目将 CLR 的子集编译为二进制文件,这是一个略有不同的过程。
No you could not do it with ngen. The ngen output itself is not low-level enough to bring up a kernel without all the supporting CLR and windows infrastructure being carried along as well.
The other projects you mention compile a subset of the CLR to binary which is a slightly different process.
你不能。
C# 是一种托管语言,这意味着它的代码(IL 代码)将在运行时编译...您可以编写自己的编译器,将 C# 编译为本机计算机代码,但这将使您失去 .NET 的许多功能有,例如垃圾收集器、内存管理、JIT 编译器,并且将类似于 C++,只是使用 C# 语法
作为一个抽象的想法,我认为您可以使用 JIT 编译器和垃圾收集器创建一个小型的 CLR 替代品,将嵌入到您的应用程序中,但这会增加您的应用程序大小,并且您将需要更多资源......
You can't.
C# is a mannaged language, that means it's code(IL code) will be compiled at the runtime... you could write your own compiler that will compile C# into native computer code but this will leave you without a lot of features that .NET has, such as Garbage Collectors, memory mannagment, JIT Compilers, and will be something like C++ just with C# syntax
As an abstract Idea, i think you can create a small CLR alternative with JIT Compilers, and garbage collectors,that will be ebmedded into your application, but this will increase your application size and you'll need more resources...
我发现这个 资源 用于将 IL 编译为本机代码,在 cosmOS 中使用项目
I found this resource that is using to compile IL to native code, used in cosmOS project