EFI Boot Application in C#
github.com
github.com
Other languages:
Rust: https://medium.com/@gil0mendes/an-efi-app-a-bit-rusty-82c36b...
Wasn't able to find an example for Go, but seems likely it's out there.
NERF/LinuxBoot has a lot of Go components though as I remember it the EFI application is actually the Linux kernel, with the userland (i.e. init) being written in Go.
The good part is that the unsafe bits can be easily constrained, instead of hidding away in every single line of code.
However, you can cut pretty much all of those allocations with a bit of care and still retain some F# niceties.
I recently wrote a very low allocation text file parser that could ingest log files at over 200MB/s single threaded. All in F# using structs and Span the same way I would in C#.
Except I get the safety, terse syntax and rigor of options, records and matches
They have started fixing this by introducing value tuple, value option and supporting C# performance primitives like Span. But they have a way to go still.
https://github.com/dotnet/corert
Written about here:
https://mattwarren.org/2018/06/07/CoreRT-.NET-Runtime-for-AO...
"One of the first things people asked about CoreRT is “what is the size of a ‘Hello World’ app” and the answer is ~3.93 MB (if you compile in Release mode), but there is work being done to reduce this."
..
"So Test.CoreLib really is a minimal runtime!! But the difference in size is dramatic, it shrinks down to 0.49 MB compared to 3.93 MB for the fully-featured runtime!"
You can see the code and README for it here https://github.com/dotnet/corert/tree/master/src/Test.CoreLi... and I also wrote a bit about it in this post https://mattwarren.org/2018/06/07/CoreRT-.NET-Runtime-for-AO...
https://github.com/MichalStrehovsky/zerosharp/blob/master/no...
https://github.com/MichalStrehovsky/zerosharp
"no-runtime is a rather pointless sample that demonstrates how to write code in C# that is directly runnable without a runtime. C# has value types and you can p/invoke into an unmanaged memory allocator, so you can do things with this, but you're so severily limited it's rather pointless. But Hello world ends up being about 4-5 kB native EXE, so that's rather cool.
with-runtime is something that can be actually useful. This includes the full managed and unmanaged runtime - GC, exception handling, and interface dispatch all work. Test.CoreLib used as the class library here is the same Test.CoreLib that you can find in the CoreRT repo. Don't look for things like Object.ToString() because being compatible with .NET is not the point. This sample comes down to about 400 kB, most of which is the C runtime library.
efi-no-runtime is an EFI boot application that lets you run C# on bare metal, without an OS. Similar restrictions to the no-runtime sample apply. Making a version of this sample with a runtime would require some porting work on the runtime side."
https://github.com/dotnet/corert/tree/master/src/ILCompiler
The rest was the quotes about how big the runtime has to be to be "minimally useful."
As the author wrote about "no runtime" example (see my other comment for the reference): "C# has value types and you can p/invoke into an unmanaged memory allocator, so you can do things with this, but you're so severily limited it's rather pointless." and about his efi example: "Similar restrictions to the no-runtime sample apply."
https://gist.github.com/yackx/a52010a05a430496ae11
https://github.com/MichalStrehovsky/zerosharp/blob/master/ef...
(The Asm above was for good old BIOS, here's the EFI version: http://x86asm.net/articles/uefi-programming-first-steps/hell... )
The vast majority of the code is just defining the minimal set of standard C# data types needed to compile any C# program.
Something that is very unique and interesting is the usage of the System.Runtime & System.Runtime.InteropService , I'm guessing that some of the contorting needed to get things working in the code lays with those functions. The other half would be the ilc and the linker having the EFI subsystem as an option.
[1] http://x86asm.net/articles/uefi-programming-first-steps/efi....