Cosmos icon indicating copy to clipboard operation
Cosmos copied to clipboard

Cosmos x NativeAOT

Open valentinbreiz opened this issue 4 years ago • 10 comments

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:

  • Multi-plateform compilation (using Cosmos on Linux for example)
  • Multi-plateform architecture support (x86, x64, ARM...)
  • Real optimisations enhancement
  • EFI Support

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:

  • [ ] Precise control over output (X# integration...)
  • [ ] Implement .NET runtime

Four possible option for a .NET runtime use with NativeAOT: ~~1. Write the runtime from scratch~~ -> Useless work. 2. 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. 3. 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

valentinbreiz avatar Jun 25 '21 08:06 valentinbreiz

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

0xF6 avatar Jun 25 '21 08:06 0xF6

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

valentinbreiz avatar Jun 25 '21 09:06 valentinbreiz

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

0xF6 avatar Jun 25 '21 09:06 0xF6

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

MishaTy avatar Jun 26 '21 20:06 MishaTy

modified version

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

0xF6 avatar Jun 26 '21 22:06 0xF6

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

0xF6 avatar Jun 26 '21 22:06 0xF6

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

valentinbreiz avatar Jun 29 '21 09:06 valentinbreiz

I mean .NET framework classes like Console class.

MishaTy avatar Jun 29 '21 14:06 MishaTy

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

ilobilo avatar Jul 20 '21 09:07 ilobilo

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

kant2002 avatar Aug 11 '22 05:08 kant2002

'UEFI Cosmos Project'

ADev531 avatar Dec 06 '23 07:12 ADev531

Closing this for now

valentinbreiz avatar Jan 05 '24 20:01 valentinbreiz