Assembly and C#
Assembly and C#
I only very recently found you can develop an OS using C#, and with that being my 'Native' language, I was rather pleased. However, while following the Barebones C# tutorial to get a start, I realised that some tasks need assembly, and that I can't use it directly in C#. So, as I was saying, how do you use assembly with C#?
Not sane
Just remember, FIND Is Not DOS
Just remember, FIND Is Not DOS
Re: Assembly and C#
I am not aware of any language that natively supports inline assembly. Even C implements it through compiler-specific mechanism. I think the Cosmos compiler contains methods for directly injecting arbritrary assembler instructions into the output, but tysila (which is used in the Barebones tutorial) does not. However there are actually very few assembly routines required once you are already in protected mode with a working kernel. For those which are required there are methods to call in the libsupcs library (see the libsupcs.OtherOperations class and its static methods e.g. Read/WriteCR3()). These still require a concrete implementation to be provided in assembly though (e.g. see tysos/cpu.asm within the repository), but I am working on removing this limitation, and indeed the class/method names may change in future (as they are currently x86 centric).
edit: you can obviously link assembler/c/any other language modules with the output of compiling c# modules with tysila to provide additional functionality.
Regards,
John.
edit: you can obviously link assembler/c/any other language modules with the output of compiling c# modules with tysila to provide additional functionality.
Regards,
John.
Re: Assembly and C#
As jnc100 said, it is compiler dependent. Letting us know which compiler you are using would help. The 3 main (mostly functional) native C# compilers that I know of are:
1. COSMOS
2. MOSA
3. TYSILA
MOSA and tysila both use a similar model. There is a "x86 native dll" reference that you add that contains some pre-established assembly routines. The methods in the reference are just stubs that are recognized by the assembler, which already knows about the routines and inserts the appropriate assembly. COSMOS uses a method that they term "plugging" methods. First you can write a method stub yourself and use it in your kernel. Then you can "plug" the methods by writing a class and/or methods that use the plug attribute. The attributed methods are not actually compiled as c#, but are parsed using their syntax and used to plug the original method.
In all of them you can write a x86/x87 kernel without having to write assembly yourself if you chose to use the tools they have provided. COSMOS is targeted at speeding up early development by providing a platform where you don't need to know a ton about low level x86 processor. You can initialize your kernel off their builtin x86 kernel and start using standard .NET functions (they plugged Console.Writeline to write out to text VGA for example).
A quick search of the code repositories for MOSA and tysila has very obvious intrinsic x86 dlls where you can see what is included in the compiler and if you want more information on assembly in COSMOS you can find a tutorial here: http://www.codeproject.com/Articles/220 ... stem-Intro. It mostly shows their old syntax as opposed to their X# assembly syntax, but the concept remains the same.
1. COSMOS
2. MOSA
3. TYSILA
MOSA and tysila both use a similar model. There is a "x86 native dll" reference that you add that contains some pre-established assembly routines. The methods in the reference are just stubs that are recognized by the assembler, which already knows about the routines and inserts the appropriate assembly. COSMOS uses a method that they term "plugging" methods. First you can write a method stub yourself and use it in your kernel. Then you can "plug" the methods by writing a class and/or methods that use the plug attribute. The attributed methods are not actually compiled as c#, but are parsed using their syntax and used to plug the original method.
In all of them you can write a x86/x87 kernel without having to write assembly yourself if you chose to use the tools they have provided. COSMOS is targeted at speeding up early development by providing a platform where you don't need to know a ton about low level x86 processor. You can initialize your kernel off their builtin x86 kernel and start using standard .NET functions (they plugged Console.Writeline to write out to text VGA for example).
A quick search of the code repositories for MOSA and tysila has very obvious intrinsic x86 dlls where you can see what is included in the compiler and if you want more information on assembly in COSMOS you can find a tutorial here: http://www.codeproject.com/Articles/220 ... stem-Intro. It mostly shows their old syntax as opposed to their X# assembly syntax, but the concept remains the same.