Hey, how to compile CSharp to machine code?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
SiliconOS
Posts: 17
Joined: Sun Feb 14, 2021 12:41 am

Hey, how to compile CSharp to machine code?

Post by SiliconOS »

I want to build a 64bit Graphical CSharp OS, named Silicon OS(such as my name).
I want to know:
How can I compile C Sharp code to machine code?
How can CSharp to operate filesystem(FAT32, NTFS)?

I'm a Chinese.Your advice are most welcome!
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: Hey, how to compile CSharp to machine code?

Post by Octocontrabass »

SiliconOS wrote:I want to build a 64bit Graphical CSharp OS, named Silicon OS(such as my name).
Welcome! That's an ambitious project. I suggest reading this post for information that will help you.
SiliconOS wrote:How can I compile C Sharp code to machine code?
Take a look at the C# OS projects listed on the wiki. Those should give you some ideas for how to do it.
SiliconOS wrote:How can CSharp to operate filesystem(FAT32, NTFS)?
It works the same way with any language. (But there's no official NTFS documentation, so NTFS will be difficult.)
SiliconOS
Posts: 17
Joined: Sun Feb 14, 2021 12:41 am

Re: Hey, how to compile CSharp to machine code?

Post by SiliconOS »

First, I need a tool to compile CS to native machine code.
Next, the OS need a bootloader, so I'm studying C and C++.
The C# library will be more difficult.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Hey, how to compile CSharp to machine code?

Post by bzt »

SiliconOS wrote:First, I need a tool to compile CS to native machine code.
Which doesn't exists. There used to be one, but disappeared with tysos. Good luck with webarchive and latest C# versions...
SiliconOS wrote:Next, the OS need a bootloader, so I'm studying C and C++.
Try BOOTBOOT, it will load your x86_64 kernel no matter what language it was compiled from (if you can compile native machine code from C#, that is).
SiliconOS wrote:The C# library will be more difficult.
But a must. Languages need run-time support libraries, that's how they work. Some languages require less, others more. In general you can say that the most "advanced" a language is, the bigger run-time it requires and harder to use it for bare-metal development (like RTTI in C++ for example). C is the preferred choice because you can use it without any run-time whatsoever (so called freestanding mode), and it compiles to native machine code directly (not an interpreted language like C# and Java).

Cheers,
bzt
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Hey, how to compile CSharp to machine code?

Post by nexos »

Have you looked at FlingOS? They have a C# AOT compiler that turns C# IL to machine language.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: Hey, how to compile CSharp to machine code?

Post by Octocontrabass »

bzt wrote:
SiliconOS wrote:First, I need a tool to compile CS to native machine code.
Which doesn't exists. There used to be one, but disappeared with tysos.
Tysos moved to GitHub. The CIL compiler is also on GitHub.
SiliconOS
Posts: 17
Joined: Sun Feb 14, 2021 12:41 am

Re: Hey, how to compile CSharp to machine code?

Post by SiliconOS »

I'm in China and my OS is Windows
:(
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Hey, how to compile CSharp to machine code?

Post by bzt »

Octocontrabass wrote:
bzt wrote:
SiliconOS wrote:First, I need a tool to compile CS to native machine code.
Which doesn't exists. There used to be one, but disappeared with tysos.
Tysos moved to GitHub. The CIL compiler is also on GitHub.
Would you care to update our wiki with this info? Thanks a lot!

Cheers,
bzt
Post Reply