OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 9:57 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: C# for ARM
PostPosted: Sun Apr 28, 2013 8:14 am 
Offline
Member
Member

Joined: Mon Apr 09, 2007 12:10 pm
Posts: 775
Location: London, UK
The ARM port of my CIL to native code compiler (tysila) has now reached the stage where it can compile simple C# to ARM code. The code at rpi_test/Program.cs can now be successfully run on the Raspberry Pi and prints 'Hello from C#!' on the serial port.

Obviously its a very early work-in-progress and many things will not work, but I'll be looking to expand the range of code it can work on over the coming weeks.

Regards,
John.

_________________
Tysos | rpi-boot


Top
 Profile  
 
 Post subject: Re: C# for ARM
PostPosted: Sun Apr 28, 2013 1:37 pm 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
Nicely done!

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: C# for ARM
PostPosted: Wed May 01, 2013 5:06 pm 
Offline
User avatar

Joined: Wed May 01, 2013 4:54 pm
Posts: 4
Good job :D
What features your CIL have and how much opcodes it support?


Top
 Profile  
 
 Post subject: Re: C# for ARM
PostPosted: Thu May 02, 2013 8:28 am 
Offline
Member
Member

Joined: Mon Apr 09, 2007 12:10 pm
Posts: 775
Location: London, UK
The frontend supports all CIL opcodes (with some very limited exceptions of opcodes like arglist and endfilter which are not used in mainstream .NET languages anyway) and converts this into an intermediate language. There exist various different backends for different architectures (x86_64, i386 and ARM) which support the various intermediate language opcodes to a greater or lesser extent. The ARM backend is currently the least completely implemented, particularly with regard to floating-point opcodes and some bitwise operators (purely because these have not been required to assemble the functions I have tested it on). For many opcodes, however, if there is not a concrete implementation in the assembler itself, a function call to a library function is used instead (similar to how gcc outputs calls to libgcc functions on certain architectures).

Regards,
John.

_________________
Tysos | rpi-boot


Top
 Profile  
 
 Post subject: Re: C# for ARM
PostPosted: Thu May 02, 2013 10:41 am 
Offline
User avatar

Joined: Wed May 01, 2013 4:54 pm
Posts: 4
Cool =D>
I asked exactly about CIL because i saw some extra opcodes in your sources. How did you use them?
And the final question(if, of course, this endless questions are not annoying you) is why did names for assembly functions look like this:
Code:
_ZN8libsupcs17libsupcs#2Ex86_643CpuM_0_7get_Cr2_Ry_P0:


Top
 Profile  
 
 Post subject: Re: C# for ARM
PostPosted: Thu May 02, 2013 11:43 am 
Offline
Member
Member

Joined: Mon Apr 09, 2007 12:10 pm
Posts: 775
Location: London, UK
The frontend converts CIL opcodes to intermediate representation opcodes which are listed here via the function EncodeOpcode (and the helper functions in that file). The code then undergoes a series of optimization passes before being converted to machine code by the code snippets referenced in the various backends. These are listed in the arch_init_opcodes() function (e.g. for x86_64/i586 and for ARM).

Air wrote:
why did names for assembly functions look like this:
Code:
_ZN8libsupcs17libsupcs#2Ex86_643CpuM_0_7get_Cr2_Ry_P0:
This is a mangled version of the C# function:
Code:
namespace libsupcs.x86_64 {
    class Cpu {
        public extern static ulong Cr2 { get; }
    }
}
in module libsupcs. The getter function of the Cr2 property is tagged as [MethodImpl(MethodImplOptions.InternalCall)] to identify to the compiler that it doesn't have an implementation and that the compiler will provide it instead. When a function like this is called, first enc_intcall() is called to see if the compiler actually does provide it. If it does, then the function is inlined, else a call to an external function with that mangled name is emitted. Eventually I plan on incorporating a lot of these cpu-specific functions as inlineable internal calls, I just haven't got around to it yet.

The reason the names are mangled is that, exactly like C++, multiple functions in both the same and different classes can have the same name, and therefore each needs a unique identifier to use in the linking phase. The mangling rules are here.

Regards,
John.

_________________
Tysos | rpi-boot


Top
 Profile  
 
 Post subject: Re: C# for ARM
PostPosted: Thu May 02, 2013 2:29 pm 
Offline
User avatar

Joined: Wed May 01, 2013 4:54 pm
Posts: 4
Thanks man. Now i understand how it works - So you choose implement architecture-depended functions out of compiler-generated-code and c# code instead of including them in :wink: That look easy to implement but ...when compiler will grow ,code will grow too since it need support for each extra function you have. Does it make any bad impact on performance?


Top
 Profile  
 
 Post subject: Re: C# for ARM
PostPosted: Thu May 02, 2013 4:27 pm 
Offline
Member
Member

Joined: Mon Apr 09, 2007 12:10 pm
Posts: 775
Location: London, UK
Air wrote:
when compiler will grow ,code will grow too since it need support for each extra function you have.
The number of architecture-specific functions (i.e. those which cannot be encoded through equivalent high level language instructions) is small and doesn't carry much footprint, so this isn't really an issue.

Air wrote:
Does it make any bad impact on performance?
These functions are called relatively infrequently and therefore any performance loss caused by adding one extra function call into the mix is small. As I said, inling them is something I plan to do, but given how relatively infrequently an OS will update the control registers for example, I simply cannot make it a priority at the moment.

Regards,
John.

_________________
Tysos | rpi-boot


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 120 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