开发者

Using ngen.exe to compile a kernel

开发者 https://www.devze.com 2023-03-23 15:12 出处:网络
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开发者_Pytho

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开发者_Python百科 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


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).


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.


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...


I found this resource that is using to compile IL to native code, used in cosmOS project

0

精彩评论

暂无评论...
验证码 换一张
取 消