OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Apr 27, 2024 8:21 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: C# compiler for Kernel dev?
PostPosted: Wed Dec 16, 2009 6:31 am 
Offline
Member
Member

Joined: Sat Sep 22, 2007 7:26 am
Posts: 115
Okay, I'm looking to make my kernel using C# as you probably gathered from the subject. I have been recently reading some of the benefits and some of the issues still needing to be sovled and I think it will be fun! What I have been having trouble figuring out is what compiler to use. I downloaded the latest Singularity release and tried to find the "Bartok" compiler but only found a visual studio solution that I couldn't open for some reason in VS2008. I have also downloaded Cosmos and SharpOS but haven't had a chance to really dive into the stuff I downloaded. My main question is:

Is there an out of the box C# compiler I could use for kernel development?

I would really prefer to use Visual Studio but from the Singularity project it seems like this won't work. I think SharpOS is using the mono project to compile stuff for their OS but I am not sure if it is an unmodified version. I basically understand what JIT is and AOT. but I don't understand the implementation as I have not delved into the inner workings of the C# language and IL. If I do need to write my own compiler for C# so that I can make a kernel that would be a cool project to undertake but I don't know where to start. I have been looking for compiler source and instruction but havn't found much. Any help would be greatly appreciated.

_________________
Getting back in the game.


Top
 Profile  
 
 Post subject: Re: C# compiler for Kernel dev?
PostPosted: Wed Dec 16, 2009 7:11 am 
Offline
Member
Member

Joined: Thu Feb 26, 2009 12:58 am
Posts: 109
Location: Gurgaon/New Delhi, India
LordMage wrote:
Is there an out of the box C# compiler I could use for kernel development?


uh..."out of the box"?? what, in your dictionary, refers to an out of the box solution? is it a compiler which compiles C# code to native assembly code? then you should check out Cosmos and their IL2CPU system.

LordMage wrote:
I basically understand what JIT is and AOT. but I don't understand the implementation as I have not delved into the inner workings of the C# language and IL.


why do you wish to use C#?
is it because the language is good?
well, trust me, mate.
using C# is *only* effective when it has a runtime associated with it.
and with no base operating system, where *your* kernel is operating, how do you implement a runtime?
you should first have a good command of the C# language, as well as IL.
take a couple of months, pick up a good book.
and here's a tip: when you write some C# code, and run it, disassemble the managed executable using ildasm. that will help you understand how the 'behind-the-scenes' IL works.
also, obtain a copy of the ECMA specifications for the CLR and C#. they are downloadable and also can be ordered.
and..they're invaluable.

check out my blueprint for my project.
http://sites.google.com/site/thehackerlabsfoundation/home/the-mk1-research-os/Blueprint.doc?attredirects=0&d=1
hopefully, it will answer some of your questions, and maybe even have you jump onboard!

good luck, kid. you're gonna need it.

_________________
"Do you program in Assembly?" she asked. "NOP," he said.

"Intel Inside" is a Government Warning required by Law.


Top
 Profile  
 
 Post subject: Re: C# compiler for Kernel dev?
PostPosted: Wed Dec 16, 2009 7:16 am 
Offline
Member
Member

Joined: Thu Feb 26, 2009 12:58 am
Posts: 109
Location: Gurgaon/New Delhi, India
when you read the blueprint, you'll see how my solution could actually *work*.
AOT isn't worth a thing, since it still doesn't bring out the true power of the CLR.
only a JIT implementation can do that.
and that's the reason where i feel that Singularity, Cosmos and SharpOS/MOSA lack.
*all* of them use AOT to compile C# to native assembly, usually x86 assembly.
and that really isn't what i'd intend using C# for...i mean, it wasn't intended for AOT!

and to the people working on MOSA and Cosmos:
NO OFFENSE INTENDED.
i applaud the fact that you guys have working kernels ready, against all odds.

_________________
"Do you program in Assembly?" she asked. "NOP," he said.

"Intel Inside" is a Government Warning required by Law.


Top
 Profile  
 
 Post subject: Re: C# compiler for Kernel dev?
PostPosted: Wed Dec 16, 2009 12:15 pm 
Offline
Member
Member

Joined: Sat Sep 22, 2007 7:26 am
Posts: 115
Okay, I will go read your blueprint. I have downloaded Cosmos and read about the IL2CPU, but I wasn't sure if that is what I wanted. One question though.

I agree that JIT is probably better for security than AOT. but how do you have a JITed kernel. wouldn't that be impossible. If this is explained in your blueprint don't yell at me. I just wanted to get some questions out during lunch break. Also I was asking the question I asked to aquire links to the resources you are talking about with the C# CLR and IL explained. If I built the parts of the kernel I wanted using say the standard C# .NET compiler and then used IL2CPU would that even work for kernel dev? is there part of the runtime in windows that gets builtin that I would have to strip out first? that is why I was asking for an "out of the box" and yes to me that means that C# gets compiled to single file ASM code. anyway, I'm going to read your blueprint and see what I think, I will also search for the keywords you gave and hope I come up with the documentation I want.

_________________
Getting back in the game.


Top
 Profile  
 
 Post subject: Re: C# compiler for Kernel dev?
PostPosted: Wed Dec 16, 2009 8:14 pm 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2293
Location: USA (and Australia)
I'm working on a .Net JIT'er embedded into a kernel, and I have to say writing a C#->native or AOT compiler would be much harder than a JIT'er.

It is entirely possible to write a C# or IL front end for GCC. You'd need to link against a rather complex runtime (that is different to the library) that'll handle garbage collection, metadata (attributes, ToString(), boxing/unboxing, reflection), and events.

_________________
My OS is Perception.


Top
 Profile  
 
 Post subject: Re: C# compiler for Kernel dev?
PostPosted: Wed Dec 16, 2009 8:46 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 29, 2008 11:21 am
Posts: 42
Location: Aachen, Germany
@LordMage: At Mosa (http://mosa-project.org and http://github.com/Kintaro/Mosa) we're working on a compiler that can work as a JIT and AOT compiler for .NET. We have a pretty basic booting example. And small demonstration can be found here http://www.youtube.com/watch?v=ob8Zg5qcpu4
If you need more information, just visit us on #mosa on freenode

_________________
Project: MOSA Framework


Top
 Profile  
 
 Post subject: Re: C# compiler for Kernel dev?
PostPosted: Thu Dec 17, 2009 7:11 am 
Offline
Member
Member

Joined: Sat Sep 22, 2007 7:26 am
Posts: 115
@Redoktober: okay, I will read that blueprint today after work. I had to download OpenOffice because I don't have MS Office on my pc because its a relatively new install.

@MessiahAndrw: I would really like to see some of your stuff for putting the JITer in the kernel, your site doesn't seem to have been updated in a bit and only has info from an old version of your OS.

@MOSA: I couldn't read the text on that you tube video, but you compiled twice was that linking and then compiling or was that first compile to IL and then compile to AOT executable? forgive me if I don't use the proper terminology, I hope you get the jest of my question.

Thank everyone for the replies

_________________
Getting back in the game.


Top
 Profile  
 
 Post subject: Re: C# compiler for Kernel dev?
PostPosted: Thu Dec 17, 2009 7:51 am 
Offline
Member
Member
User avatar

Joined: Fri Feb 29, 2008 11:21 am
Posts: 42
Location: Aachen, Germany
@LordMage: There are 3 steps in the video. First: Compiling everything from C# -> IL, 2nd step is to compile the "kernel" from IL -> x86 and 3rd step is creating the disk images.

_________________
Project: MOSA Framework


Top
 Profile  
 
 Post subject: Re: C# compiler for Kernel dev?
PostPosted: Thu Dec 17, 2009 4:51 pm 
Offline
Member
Member

Joined: Sat Sep 22, 2007 7:26 am
Posts: 115
@redoktober: Okay, finally skimmed over your blueprint. I am sure I missed something but I get the basic idea. I really like the idea of the micro .NET runtime but I am really wanting to dev a hobby OS I can run on x86_64. So I don't think your project would help me much until The micro .NET is compatible with common PC hardware or visa versa.

@rootnode: Okay, thats what I was kinda hopeing it was. given that is is possible to "strip" a C# project in visual studio of all namespace references and maybe change some of the project settings, then compile to IL, then compile to x86 and viola have a kernel? Or do I need to use a specific compiler to convert the C# Kernel code into IL?

Okay, I have my own bootloader that I have been working on for a while following Neons tutorials. They are great for creating a traditional Unmanaged OS using hardware protection and so on. So I would like to keep what I have learned from that but I want to use the C# managed Kernel so I will be creating my own disk image. I use Windows primarily although I dabble in linux from time to time. What I really want is a Bartok similar development enviroment where I code using visual Studio as my IDE. since the IDE and compiler are separate I should be able to do this. My main question is - Is the compiler being used for the mosa project, that is the compiler that takes C# and makes it IL, homegrown, of the shelf, or proprietary?

If it is homegrown can I get the source to study? If it is of the shelf where do I get it? If it is proprietary I guess I am sol.

Secondly, are you using IL2CPU like Cosmos? or do you have something different to convert the IL to x86 code?

Forgive me for asking questions that I am sure are probably on the MOSA site. I looked at it a few days ago and didn't have much luck finding things. I am looking again tonight and will postback if I find the answers before you post them. Thanks for being patient and the help.

_________________
Getting back in the game.


Top
 Profile  
 
 Post subject: Re: C# compiler for Kernel dev?
PostPosted: Thu Dec 17, 2009 6:22 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 29, 2008 11:21 am
Posts: 42
Location: Aachen, Germany
@LordMage: You can use the standard MS compiler or mono to get from C# to IL. The rest is done by our compiler.
To get from C# to IL I use mostly mono, or MS compiler if it happens that I work on windows.
But if you combine one of these two with our compiler, then it is similar to bartok. With the only difference that
our compiler is not only for AOT but for JIT also.

_________________
Project: MOSA Framework


Top
 Profile  
 
 Post subject: Re: C# compiler for Kernel dev?
PostPosted: Thu Dec 17, 2009 7:12 pm 
Offline
Member
Member

Joined: Sat Sep 22, 2007 7:26 am
Posts: 115
Okay, you just made my day! WOOT! So if I have this right I can use VS2008 and make a C# program just with out the windows system namespaces, I'd have to make my own OS specific ones I'm assuming and compile that as a ?Class Library?Console App?, not sure what project type to use, then use your compiler with a certain command to AOT the kernel then add it to a disk image and poof I'm ready? I know it's not that easy but is that basically what you are saying?

_________________
Getting back in the game.


Top
 Profile  
 
 Post subject: Re: C# compiler for Kernel dev?
PostPosted: Thu Dec 17, 2009 7:17 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 29, 2008 11:21 am
Posts: 42
Location: Aachen, Germany
Yes, basically that's the idea and plan. The working sample (let's call it) "kernel" is written in pure C# in VS as an application.
We still lack some CIL operations, but we're near to finish them.

_________________
Project: MOSA Framework


Top
 Profile  
 
 Post subject: Re: C# compiler for Kernel dev?
PostPosted: Fri Dec 18, 2009 9:38 am 
Offline
Member
Member

Joined: Thu Feb 26, 2009 12:58 am
Posts: 109
Location: Gurgaon/New Delhi, India
hmm.
i daresay, then it's MOSA and Cosmos you should be concentrating at.
i like the .NET micro framework for two reasons:
1) bootable runtime;
2) it supports ARM.

apart from the reasons i want a bootable runtime, i like the ARM architecture because it's pretty simple to write assembly code for, it's pretty inexpensive, has a low power requirement. perfect for robotics.

good luck!

_________________
"Do you program in Assembly?" she asked. "NOP," he said.

"Intel Inside" is a Government Warning required by Law.


Top
 Profile  
 
 Post subject: Re: C# compiler for Kernel dev?
PostPosted: Sat Dec 19, 2009 12:03 am 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2293
Location: USA (and Australia)
LordMage wrote:
@MessiahAndrw: I would really like to see some of your stuff for putting the JITer in the kernel, your site doesn't seem to have been updated in a bit and only has info from an old version of your OS.


Sorry about that, I don't see a point in updating my site just yet when I could be working on the kernel. My first version will only have a very minimal runtime library, yet I'm aiming for a complete compliant CLI runtime. You'll be able to run any .Net <= 2.5 assembly (even those depending on libraries if you also load them), however you won't be able to link to unmanaged code (which includes the Microsoft .Net and Mono libraries), but I'll allow unsafe code (so you can write to 0xb800 for text).

So basically, my kernel will be able to load a C# assembly and run it on raw hardware the same as GRUB can load an C++ ELF executable and run it on raw hardware. You can be sure I'll make an announcement when it's ready. Of course, interrupts and IO won't be in just yet.

My road-map for my proof-of-concept kernel is basically as follows:
Release 1: JIT'ing unsafe code and executing it on bare metal x86.
Release 2: Restrict to safe code, multithreading, and IO via the kernel.
Release 3: Multiple application domains (multitasking) and IPC.

Release 3 will mark the end of the proof-of-concept stage, and I'll design a much more useful kernel architecture and start using it in a practical way.

_________________
My OS is Perception.


Top
 Profile  
 
 Post subject: Re: C# compiler for Kernel dev?
PostPosted: Sat Dec 19, 2009 1:23 am 
Offline
Member
Member
User avatar

Joined: Fri Feb 29, 2008 11:21 am
Posts: 42
Location: Aachen, Germany
MessiahAndrw wrote:
Sorry about that, I don't see a point in updating my site just yet when I could be working on the kernel. My first version will only have a very minimal runtime library, yet I'm aiming for a complete compliant CLI runtime. You'll be able to run any .Net <= 2.5 assembly (even those depending on libraries if you also load them), however you won't be able to link to unmanaged code (which includes the Microsoft .Net and Mono libraries), but I'll allow unsafe code (so you can write to 0xb800 for text).


We'll have a solution for that later. At the moment we're patching the mono libraries to make them fully managed and remove all P/Invokes from their mscorlib.
We already spoke to Miguel about that. If the patches are as fast as the unmanaged version they'll include them, otherwise there will be a configure flag to choose between unmanaged code and our managed patches. Maybe you could use them.

_________________
Project: MOSA Framework


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 24 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group