C Sharp Bare Bones: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
(Added wayback links for tysos. Kept the original links too, because some of them don't work.)
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(5 intermediate revisions by 4 users not shown)
Line 13:
 
This is only required if you have not downloaded the pre-compiled binaries above. Use subversion to get the latest sources 'svn co http://www.tysos.org/svn/trunk tysos' (not in Wayback Machine), or download the latest tar ball from http://www.tysos.org/files/src/tysos-latest.tar.bz2 (http://web.archive.org/web/*/http://www.tysos.org/files/src/tysos-latest.tar.bz2). Tysos is a project developing a full OS kernel and drivers in C#, however we only want the compiler from it therefore we only want to compile part of the build tree. Enter the tysos directory and run
<sourcesyntaxhighlight lang="bash">
cd tybuild && make && cd ..
cd mono/corlib && make mscorlib.dll && cd ../..
cd tysila2 && make && cd ..
</syntaxhighlight>
</source>
 
You will need to put the mono/corlib/mscorlib.dll, tysila2/bin/Release/tysila2.exe, tysila2/bin/Release/libsupcs.dll, tysila2/bin/Release/libtysila.dll, tysila2/bin/Release/tydbfile.dll, tysila2/bin/Release/tydisasm.dll and tybuild/bin/Release/tybuild.exe files somewhere in your path.
Line 31:
This is the assembly stub which will contain a Multiboot header.
 
<sourcesyntaxhighlight lang="asm">
global sthrow
 
Line 52:
hlt
jmp sthrow
</syntaxhighlight>
</source>
 
===kernel.cs===
Line 58:
This is the actual simple kernel - it just prints a message to the screen.
 
<sourcesyntaxhighlight lang="csharp">
namespace BareBones
{
Line 89:
}
}
</syntaxhighlight>
</source>
 
===linker.ld===
Line 95:
The linker script
 
<sourcesyntaxhighlight lang="c">
ENTRY (_start)
 
Line 123:
}
}
</syntaxhighlight>
</source>
 
===iso/boot/grub/grub.cfg===
This is a short file to tell grub where to find our kernel
<sourcesyntaxhighlight lang="c">
multiboot /kernel.bin
boot
</syntaxhighlight>
</source>
 
==Building it all==
The following commands should build your new C# kernel. First, assemble the multiboot stub:
<sourcesyntaxhighlight lang="bash">nasm -felf -o loader.o loader.asm</sourcesyntaxhighlight>
To compile the .cs file to a .exe you have a choice of three options (depending on your architecture):
<sourcesyntaxhighlight lang="bash">
gmcs /target:exe /out:kernel.exe /unsafe kernel.cs
csc /target:exe /out:kernel.exe /unsafe kernel.cs
tybuild.exe /unsafe kernel.cs
</syntaxhighlight>
</source>
To compile kernel.exe to machine code we use tysila:
<sourcesyntaxhighlight lang="bash">tysila2.exe --arch i586-elf-tysos -fno-rtti -o kernel.o kernel.exe</sourcesyntaxhighlight>
Here, the -fno-rtti switch disables run-time type information, support for which would greatly enlarge the size of your kernel and require you to provide a great number of run time functions to support this.
 
To link:
<sourcesyntaxhighlight lang="bash">ld -m elf_i386 -T linker.ld -o iso/kernel.bin loader.o kernel.o</sourcesyntaxhighlight>
 
Then we make a bootable iso image with:
<sourcesyntaxhighlight lang="bash">grub-mkrescue -o barebones.iso iso</sourcesyntaxhighlight>
 
And run it on qemu with:
<sourcesyntaxhighlight lang="bash">qemu-system-i386 -cdrom barebones.iso</sourcesyntaxhighlight>
 
[[Category:Bare bones tutorials]]
[[Category:CSharp]]