CosmosOS / Cosmos

Cosmos is an operating system "construction kit". Build your own OS using managed languages such as C#, VB.NET, and more!
https://www.goCosmos.org
BSD 3-Clause "New" or "Revised" License
2.91k stars 549 forks source link

Cosmos x NativeAOT #1857

Closed valentinbreiz closed 8 months ago

valentinbreiz commented 3 years ago

NativeAOT is the ahead-of-time (AOT) toolchain that can compile .NET application into a native (architecture specific) single-file executable. We currently use IL2CPU as our CIL to assembly "compiler". This new way to compile CIL code to binary executable could bring a lot of a features to the Cosmos project:

A proof of concept from our IL2CPU compiler to NativeAOT should be done. If this works, IL2CPU will be discontinued.

Must-have for a Cosmos port:

Four possible option for a .NET runtime use with NativeAOT: 1. Write the runtime from scratch -> Useless work.

  1. Use IL2CPU infrastructure to determine what methods are needed and emit a dll with them all. That we means we dont really need a runtime since all the dependencies are already included.
  2. Write a new program to take the runtime classes and regenerate them without external methods + with our plugs. This seems to be possible with https://github.com/Lokad/ILPack but will be a bit of work 4. Some how use ILStubs https://github.com/dotnet/runtimelab/blob/feature/NativeAOT/docs/design/coreclr/botr/ilc-architecture.md#compiler-generated-method-bodies to generate all the code we need -> Is this possible?

Resources: Dev branch: https://github.com/CosmosOS/Cosmos/tree/feature/NativeAOT Variant efi no runtime runtime lab - aot branch

0xF6 commented 3 years ago

first problem i see is "no-runtime" mode not support classes 🤔

valentinbreiz commented 3 years ago

It can be done, did you take a look at https://github.com/Michael-Kelley/RoseOS ?

0xF6 commented 3 years ago

It can be done, did you take a look at https://github.com/Michael-Kelley/RoseOS ?

So, I don't see any non-static\non-abstract custom classes (except CoreLib) 🤔

MishaTy commented 3 years ago

Yeah it doesn't seem like it supports .NET runtime classes. But, maybe we could make a modified version of it to support classes?

0xF6 commented 3 years ago

modified version

Seem like a bad idea, reimplementation runtime without os-bindings maybe very hard. But it possibly still additional functional for future 🤔

0xF6 commented 3 years ago

But still, using C# as a C-like structure-based language to develop an operating system using full (almost) C# syntax sounds very cool

valentinbreiz commented 3 years ago

But still, using C# as a C-like structure-based language to develop an operating system using full (almost) C# syntax sounds very cool

It can be cool yes but it will change everything in Cosmos, we need to keep classes, for the project architecture and Cosmos users

Edit: @MishaTY, @0xF6 I tried the zerosharp repo and classes are working without runtime.

image

Source code: https://github.com/CosmosOS/Cosmos/blob/feature/NativeAOT/source/Kernel-NativeAOT/zerosharp.cs#L179

MishaTy commented 3 years ago

I mean .NET framework classes like Console class.

ilobilo commented 3 years ago

Why not use stivale2 instead of multiboot2? It has SMP support

kant2002 commented 2 years ago

I think you need to hack dotnet/runtime a bit, and provide alternative to Runtime.WorkstationGC or maybe for Boostrap. I think if you provide custom C runtime, which can allocate things using EFI api. That unlocks a lot of things IMO

ADev531 commented 9 months ago

'UEFI Cosmos Project'

valentinbreiz commented 8 months ago

Closing this for now