.Net OS

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
anon19287473
Member
Member
Posts: 97
Joined: Thu Mar 15, 2007 2:27 pm

Re: .Net OS

Post by anon19287473 »

mystran wrote:
anon19287473 wrote:
If you want to write an OS in a non-native language, at least use LISP, then you OS can rewrite itself! :P :D :P :D :P :D
Arguably, the only native language for a processor is it's own machine code. One could even claim that when you break each byte into two 4-bit parts in order to display it in a hexadecimal format, you are no longer working in the truly native format, though in this case the required conversion in trivial and bijective.

Once you introduce a macro-assembler which automatically selects best possible (usually shortest) encoding for a given logical instruction (such as using shortest possible offset encoding for a relative jump), you lose this bijection; now several "native" encodings would map to same logical encodings in the assembler language upon disassembly.

You can ofcourse regain bijection by only considering the semantics of the native encoding, instead of it's physical form or alternatively you could establish a bijection between native encoding generated by said assembler, and it's disassembly, provided your assembler is deterministic. At this point stuff is still pretty theoretical and uninteresting....

Now, what this has to do with rewriting a system on the fly? Well, when you introduce offline components like a linker, stuff gets more interesting: consider a linker, which takes care of replacing labels with real addresses, and links the result in a flat binary. Now, starting from the original source with labels, assembling and linking, we have no way to regain that information when disassembling... unless ofcourse we store debugging symbols or some such...

However, for the purposes of dynamically replacing a system, we not only want to be able to disassemble the system, but also modify it, then assembling it again. Ofcourse if we keep the original source, we can cheat somewhat by modifying said source, and replacing previous compiled version with the newly modified and compiled version. However, if the system contains information which is not accessible at runtime, then modifying such information at runtime will likewise be impossible.

The nature of the language used is not really important. Rather, in order to actually avoid rewriting native code on the fly, we want to use late-binding for everything that is a candidate for runtime modification. If stuff like procedure addresses are hardcoded into other procedures, then we need to modify those procedures in order to replacing another procedure... or implement some sort of kludges in order to reroute the calls. If on the other hand, there is an indirection with said calls, then simply modifying this indirection will be enough.

If Lisp is good for this, it is simply because (and only when) said Lisp is very late-binding. Smalltalk could easily do the same. There is even research on extending C++ like vtables to support dynamic late-binding object models, which allow methods to be replaced on the fly.

Doing a complete replacement of a system is ofcourse not quite trivial, since one will normally need at least small amount of "black box" runtime code to get any higher level language (including C) running, but if said runtime is only needed to get the actual system running, and any parts of it necessary during execution use some form of late-binding, then it becomes possible to replace those parts after startup and we can consider the system able to rewrite itself as a whole.

--------------

I am actually doing some research on this stuff right now. The current approach I'm looking into basicly considers a "byte code" form to be the "native" or canonical representation of code. With a fairly simple indirection mechanism one should be able to arrange functions to be JIT compiled to native form the first time they are called. At any point of time, one can throw the native representation away, and instead resort to evaluating the bytecode directly, or JIT compile it again.

So why bother? Well, the point is to be able to garbage collect code. Now, if the native code is nothing but a cached version of the bytecode, and the bytecode is nothing but data, then one avoids having to disassemble native code to see what data is refers to. It also means that if something is statically bound at JIT compilation time, if those assumptions (like locations) change later, all we have to do is throw the native code away, and it'll get recompiled automatically as the system attemps to execute it.

Finally, dumping the whole system state into a file becomes a lot easier if you don't need to try to dump native code. Instead just have the heap with the bytecode dumped, and have the loader contain an interpreter. JIT compiler can be bytecode in the heap just like everything else.

....

Well, then the idea is to throw a REPL on it, get it to run in priviledged mode on bare hardware, without relying on static runtime after startup, give it direct access to memory, and have fun. :)

And after that add a bytecode validator which can figure out if running some code would be dangerous, and you got language based security.

And yeah, my current plan is to use something like Lisp. Actually Scheme without first-class continuations would be closer.
WOW. :shock:

I'm gonna use a microkernel which can dynamically recompile its servers (daemon type thing that runs on a microkernel), which act as libraries, via ipc (sorta like .layers in Amiga), this way userspace applications as well as the kernel can active rebuild itself. Processes will be able to mutex part of a server, so that applications wont conflict, they will just spawn a new server to use instead. Its not terribly functional, just something fun to do =) :P :P :P :D :D :D :D :D :D :D Obviously there would be security issues, but i dont see anybody taking the time to write malicious code for an OS one or two people use.

And hey, w/ some good AI, perhaps it could write itself :P :P :P :P :P :P

Peace.
User avatar
mystran
Member
Member
Posts: 670
Joined: Thu Mar 08, 2007 11:08 am

Post by mystran »

Oh and I actually have a minimal Lisp compiler that compiles to native x86 assembly (and for most purposes works, even if it lacks most of runtime and some of it's front-end), but it turns out that building a system heap image and either loading that from a file or linking it into the loader-code is much easier way to setup an introspective environment.... :P
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: .Net OS

Post by Colonel Kernel »

anon19287473 wrote:C# is a peice of ****, only microsoft could make C suck. C# is C++, but minus everything good about it (this may be java's influence). Just do it in C or C++, writing an OS in C# will give you a slow os, whose only potential advantage would be in security, but even that would require a lot of work, and could easily be replicated w/o C#.

Theres simply no good way to compile C# into native code, if as i suspect, MS did not release their assembler and compiler.
This is a troll, and it's unfortunate because there are otherwise glimmers of intelligence in your posts.

You are of course free to criticize C# and Singularity (I do myself on occasion)... but blurting out "it's a piece of @#@#$" and making unsubstantiated claims about its performance just drags the level of discussion on this board down into the gutter. It also makes it clear that you haven't read the research, which makes you unqualified to be saying anything definitive about it.

I probably shouldn't waste my time doing this, but I at least want to salvage some semblance of reasonable discussion from your post:
C# is a peice of ****, only microsoft could make C suck. C# is C++, but minus everything good about it (this may be java's influence).
Your opinion of C# is irrelevant. It just happens to be the language that MS chose for their research project. The point is to investigate issues around "sealed process" architectures and the use of language-based verification for process isolation, among other things. Substitute any language for C# and the idea itself is still worth investigating.
writing an OS in C# will give you a slow os
Why? Have you seen Singularity's benchmarks? If so, how do you interpret that as being a "slow OS"?
Theres simply no good way to compile C# into native code, if as i suspect, MS did not release their assembler and compiler.
C# is just a high-level language, like any other high-level language. Any sufficiently talented individual could write their own C# compiler that emits native code, and put whatever optimizations they want in that compiler. Ditto for IL-to-native compilers. It's all just code, so besides some subjective idea of MS-induced "suckiness", what is it about C# and IL that makes them impossible to compile into efficient native code?

Also, what assembler are you talking about? The Singularity project uses a customized C# compiler that emits IL (they're actually using a research dialect of C# called Sing# that includes some extra features), plus Bartok, which takes in IL, optimizes and verifies it, and emits native code. The only assembler they would be using is for the small portions of the Singularity kernel actually written in assembler like the ISR stubs. My guess is that they use MASM (since MS is allergic to anything GPL like gas), but this really has nothing to do with translating C# into native code....

From now on, please debate rationally and cease your pointless mud-slinging. This board remains useful and engaging so long as the tone remains civil.
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: .Net OS

Post by Candy »

anon19287473 wrote:C# is a peice of ****, only microsoft could make C suck. C# is C++, but minus everything good about it (this may be java's influence). Just do it in C or C++, writing an OS in C# will give you a slow os, whose only potential advantage would be in security, but even that would require a lot of work, and could easily be replicated w/o C#.
C# is a wonderful language that allows you to abstract out all of the information containment issues and most of the pointer arithmetic for just the gist of the code. You can make such wonderful programs in it.

The language itself doesn't have any performance, it'll only get a given performance after compiling.
Theres simply no good way to compile C# into native code, if as i suspect, MS did not release their assembler and compiler.
That's a common mindblock I think. If Microsoft doesn't you can't. Let me be the first to tell you - you can do ANYTHING if you have the knowledge, motivation and an infinite supply of expendable labor (aka, time). If microsoft doesn't release the compiler, make one and write your os in C# if you like.

If you want to write an OS in a non-native language, at least use LISP, then you OS can rewrite itself! :P :D :P :D :P :D


Peace.
Ahum... what good does Lisp has that any other language can't have? You sound too much influenced by things like brands and not so much by the content.
Crazed123
Member
Member
Posts: 248
Joined: Thu Oct 21, 2004 11:00 pm

Post by Crazed123 »

Lisp represents code as data. That explains why people get hyped up about metaprogramming the most for Lisp.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

Crazed123 wrote:Lisp represents code as data. That explains why people get hyped up about metaprogramming the most for Lisp.
C is pretty much the same, except that common formats forbid code modifying itself and that it's a compiled as opposed to an interpreted language (so you'd be modifying the compiled code, not the bare code). All attempts at doing so were vouched to be bad, except for those you could do at compile time. Lisp only has the advantage of being interpreted (or compiled with its own interpreter in it).
anon19287473
Member
Member
Posts: 97
Joined: Thu Mar 15, 2007 2:27 pm

Post by anon19287473 »

mystran wrote:Oh and I actually have a minimal Lisp compiler that compiles to native x86 assembly (and for most purposes works, even if it lacks most of runtime and some of it's front-end), but it turns out that building a system heap image and either loading that from a file or linking it into the loader-code is much easier way to setup an introspective environment.... :P
Sounds bad@#$, could you post the code (assuming you are using copyleft or public domain.)
Last edited by anon19287473 on Mon Mar 19, 2007 4:03 pm, edited 1 time in total.
anon19287473
Member
Member
Posts: 97
Joined: Thu Mar 15, 2007 2:27 pm

Post by anon19287473 »

Candy wrote:
Crazed123 wrote:Lisp represents code as data. That explains why people get hyped up about metaprogramming the most for Lisp.
C is pretty much the same, except that common formats forbid code modifying itself and that it's a compiled as opposed to an interpreted language (so you'd be modifying the compiled code, not the bare code). All attempts at doing so were vouched to be bad, except for those you could do at compile time. Lisp only has the advantage of being interpreted (or compiled with its own interpreter in it).
Even if C were interpreted, its macro capabilities could never reach that of lisps. There is a reason why lisp has all those parens; lisp is an syntax tree in simplist terms. Programs are composed of lists, which can be manipulated by a LIStProcessor (LISP). C is not represented in such terms. C is good for somethings (fast code, low level stuff), and lisp is good for some things (convenience, power etc.). C and LISP are on opposite sides of the spectrum.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

...and people use C/C++/C#/Java/Basic/Pascal in osdeving because lisp's fundaments are totally opposite of that of the CPU (functional v.s. instructional).
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

You could implement something similar to Mono at nano-kernel level, and then write all your drivers/servers/user-programs in a language similar to C#.
My OS is Perception.
User avatar
dc0d32
Member
Member
Posts: 69
Joined: Thu Jun 09, 2005 11:00 pm
Location: Right here

Post by dc0d32 »

I am actually writing a CIL to native, optimizing compiler in C#. Right now i am using the express edition of Visual C# 2005, but i'm sure it will work with mono. Note that i'm targetting ECMA CIL, specification of which is free; not MSIL.

For writing a hello world kernel, i am also writing (or rather borrowing most of) a minimal CLR (not even ECMA VES spec compliant) in parallel.

With some parts like memory manager, GC, exception handling code etc. in C/C++, and with the same name mangling for labels generated from C# as that of C++, the kernel should run on bare metal.

[please IM me if anyone is interested and wants to join]
LogicalError
Posts: 12
Joined: Wed Sep 05, 2007 6:10 am
Location: capelle aan den ijssel, the netherlands
Contact:

sharpos

Post by LogicalError »

You might be interested to know that we're currently building our own OS based on .net technology, written in C#.

It's called SharpOS, and you can find it at sharpos.sourceforge.net.

We're currently working on formalizing a lot of things because of the interest in this project.

We recently created a "Provisional Governance Board" and currently debating which license we'll use for the project.

Currently the project compiles and runs, altough there's a bug in the kernel atm, caused by the AOT (ahead of time) compiler which compiles .NET CIL to x86 instructions.

The AOT compiler is currently being documented and rewritten to make it easier to find bugs and make it easier for people to contribute to it's development.

The project is still in a very early process, but if anyone is interested in helping out: don't be shy! :)
Avarok
Member
Member
Posts: 102
Joined: Thu Aug 30, 2007 9:09 pm

Post by Avarok »

So basically it's written in C#, converted to assembler, and then run as an OS? and the C#, is it a PE file? Does it boot from grub multiboot spec, or do you have 16-bit C#? How do you load the VM to run C# using C#?

After all that, does it really help to have the BIOS interrupts, port I/O, IDT, IRQ, PIC, GDT, vm86 code etc. in a language that has no concept of such things?

I completely agree with Crazy123; it's practically nonsensical to me.
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies.
- C. A. R. Hoare
LogicalError
Posts: 12
Joined: Wed Sep 05, 2007 6:10 am
Location: capelle aan den ijssel, the netherlands
Contact:

Post by LogicalError »

Avarok wrote:So basically it's written in C#, converted to assembler, and then run as an OS? and the C#, is it a PE file? Does it boot from grub multiboot spec, or do you have 16-bit C#? How do you load the VM to run C# using C#?

After all that, does it really help to have the BIOS interrupts, port I/O, IDT, IRQ, PIC, GDT, vm86 code etc. in a language that has no concept of such things?
The kernel is written in C# and then compiled (by the AOT compiler, also written in C#) to x86 instructions (not assembly).
At the moment we use GRUB and a disk image on which the compiled kernel resides so we can run it in a virtual machine.
We're currently using stubs for the assembly instructions which we use in the kernel.
Obviously you wouldn't be able to use that functionality in an application that would, eventually, run on SharpOs.
We're also using parts of mono for the project.
Avarok wrote:I completely agree with Crazy123; it's practically nonsensical to me.
Well you're certainly entitled to your opinion.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Avarok wrote: I completely agree with Crazy123; it's practically nonsensical to me.
Well you're certainly entitled to your opinion.
Avarok, it is in no way nonsensical. It is merely slightly different to the norm. I myself have been wondering for a while if there were not some extensions I could make to C to better suit my needs, and have thought about writing my own compiler. (not going to though, too much work). C# is just an extension to C (++), which happens, in the .NET implementation, to rely a lot on dynamic libraries.

While I would not myself use C# for OS development (nothing against anyone else, I just don't personally like it, and lack of pointers would make low-level stuff a chore) it seems a perfectly reasonable concept to me.

Definately not non-sensical.

JamesM
Post Reply