15

I get that C and its super sets allow you to have low level access, but could you use a different language. For example Visual Basic, C# or even Java? I was just curious because it seems like something better should have come along since C's inception.

user538442
  • 631
  • 1
  • 7
  • 13
  • The problem with Java is that Java creates byte code, which requires a virtual machine to run it. If there isn't an operating system, then what's going to run the virtual machine? – Sam Dufel Jan 11 '11 at 17:47
  • 15
    *better* than C? Heretic. – Stephen Canon Jan 11 '11 at 17:48
  • I totally agree with that. I knew Java would prob be the worst choice on that list. – user538442 Jan 11 '11 at 17:48
  • 3
    @Sam: "which requires a virtual machine to run it". Ah, Jazelle, are you forgotten so quickly? – Steve Jessop Jan 11 '11 at 17:49
  • @Sam there seemed to be developments of CPUs that process Java bytecode directly. I don't know details though. – Eugene Mayevski 'Callback Jan 11 '11 at 17:49
  • @Sam Dufel Oh there self-hosting JVMs. IBM Jalapeno (renamed Jikes JVM) and Sun/Oracle's Maxine. There are also old-fashioned Java->binary compilers. – Tom Hawtin - tackline Jan 11 '11 at 17:49
  • @ Sam Dufel the hardawre itself can support bytecode, java can also be compiled to native code to bootstrap the loading. Reed Copsey answer is correct. – bestsss Jan 11 '11 at 17:50
  • 3
    Lisp machines had an OS (such as it was) written in Lisp. If that's worth anything to you. But Lisp can't be said to have "come along since C's inception" :-) – Steve Jessop Jan 11 '11 at 17:52
  • Jazelle is all well and good, if you're only planning on having your OS run on cell phones. – Sam Dufel Jan 11 '11 at 17:52
  • @Sam: is the question only about desktop OSes? – Steve Jessop Jan 11 '11 at 17:54
  • @Steve Jessop I didnt directly specify, that was my original thought when I asked the question, but I guess it could branch. – user538442 Jan 11 '11 at 17:55
  • 1
    Belong on super user??? Nawh. S&A, maybe. Duplicate, well, it's been answered (in the negative) in many other questions. Related: [What's the advantage of writing an OS entirely in assembly?](http://stackoverflow.com/q/1302692/2509) [Why don't people use c++ to make operating systems](http://stackoverflow.com/q/3775319/2509) (which explains that they *do* use c++) [Which language would you use in your OS?](http://stackoverflow.com/q/984302/2509) and many, many others. – dmckee --- ex-moderator kitten Jan 13 '11 at 05:04
  • Here we go. I think that [For kernel/OS is C still it?](http://stackoverflow.com/q/861257/2509) is a passable duplicate despite the different title. In particular look at [Chris Jester-Young's answer](http://stackoverflow.com/questions/861257/for-kernel-os-is-c-still-it/861286#861286) which addresses the question of managed languages. – dmckee --- ex-moderator kitten Jan 13 '11 at 05:10

11 Answers11

8

You can write an operating system in any language you choose - provided you have the bootstrapping required to compile it onto that platform.

For example, JNode is a Java based OS (with a small amount of assembler).

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
7

You could use any of those to write the operating system. However, you would need a bootstrap (probably written in C) to load and run the runtime for your language.

Google Scholar shows some good starting points for research: http://scholar.google.com/scholar?q=java+operating+system&hl=en&btnG=Search&as_sdt=1,5&as_sdtp=on

Babak Naffas
  • 12,395
  • 3
  • 34
  • 49
  • 3
    Not necessarily. You could extend the C# compiler (there are open-source implementations) to enable it to generate the bootstrap code from C#. If I'm not mistaken, Microsoft has an operating system that is written in 100% C# (although I could well be mistaken). – Brennan Vincent Jan 11 '11 at 17:48
  • I remember reading it used assembly, C (and maybe some C++) for some "glue code" between hardware and kernel but it was mostly C#. – 0xHenry Jan 11 '11 at 17:54
  • Correct. It's called Singularity. – Jeff Hubbard Jan 11 '11 at 18:02
  • 1
    And [a link](http://research.microsoft.com/en-us/groups/os/singularity/) to it. :) – 0xHenry Jan 11 '11 at 18:03
  • Actually, I believe even most OSes written in C use some assembly code, mainly for HW interaction. So even C needs some "glue code"... – sleske Jan 14 '11 at 11:43
4

http://de.wikipedia.org/wiki/JavaOS

Daniel
  • 27,718
  • 20
  • 89
  • 133
3

You can use pretty much any programming language. You'll probably need some assembly and/or C glue code to use any managed programming languages though.

You can get alot of information at OSDev wiki and forum.

There's one project where they even created C# compiler that compiles directly to machine code so there's probably not much if any C or other code in the kernel. Some assembly is pretty much a requirement for any kernel.

0xHenry
  • 512
  • 3
  • 12
2

I'm pretty sure you can, but as you say C is used since it allows you to have low level access, however, Visual Basic, Java and C# they're where maded to work under a Framework

Carlos Valenzuela
  • 816
  • 1
  • 7
  • 19
2

There may be tools out there to take bytecode (or IL in the case of C#) and compile it down to machine level code that the current processor architecture can understand. I don't know of any myself, though.

Steve Danner
  • 21,818
  • 7
  • 41
  • 51
1

ASSEMBLER ist the answer! C alone cannot produce a nice bootsector, because you don't have the right output formats available. But most OSs consider C a nice language for most of its parts.

Daniel
  • 27,718
  • 20
  • 89
  • 133
1

There are several languages you can use "out of the box" to write an OS such as C++, D, assembly.

If you want to use a language like C#, Java, or VB you will need to have a runtime environment (including JIT compiler in some of those cases). That means, you will have to WRITE those runtimes and you won't be able to do that in a language like Java. You would have to write your runtime code in a language like C/C++/Assembly then, your runtime could load your Java/VB code.

An alternative is to write a new compiler for C#/Java/VB that will compile to machine code or assembly. This will work but, you'd have a lot of trouble using languages like VB or Java at the OS/Executive level since they don't allow you to do memory access like C/C++ would. Neither lets you run CPU instructions directly.

Steve
  • 181
  • 2
  • 7
0

It seems like from all the answers that yes you can, but It wont be as simple or easy as creating one written in C. Most likely it would require either hardware support or at a minimum some c or c++ "glue code"

user489041
  • 27,916
  • 55
  • 135
  • 204
0

Cosmos - C# Open Source Managed Operating System

http://www.codeproject.com/KB/system/CosmosIntro.aspx

Tony
  • 16,527
  • 15
  • 80
  • 134