views:

304

answers:

6

What is the language used to write operating systems (Windows) or a boot CD?

+5  A: 

Boot loaders are usually written in Assembly, as well as low-level kernel parts, like hardware drivers.
The kernel itself can be written in different languages, like Assembly, C or C++.

Macmade
Is it native C?
Snoob
What do you call «native C»?
Macmade
Is there such a thing as non-native C?
Tim Robinson
Sorry, how to build GUI depend on C ?
Snoob
Even low-level kernel parts and hardware drivers are likely to be almost entirely C, with tiny bits of inline asm.
Gian
GUI has nothing to do with the programming language. And operating systems may not have a GUI.
Macmade
Building a GUI depends on first writing all the supporting drivers and mechanisms for interfacing with the video hardware and exposing some region of memory that represents a video surface you can draw on. Then you can go about writing a GUI interface in terms of drawing operations. All of this stuff gets hidden away in the OS internals, so it's transparent to application programmers.
Gian
OS are written in C-> but how about compiler?
Snoob
Voting to close. Your question is really too vague.
Macmade
@Snoob - compiler is typically written in C or C++ too, though certainly other languages are common enough. When it reaches a certain degree of functionality, it is often used to build itself - "self hosting". There's a bootstrap issue, but developers have been pulling themselves up by their bootstraps since the earliest days of computing. The key is to start simple, then use the simple thing as a tool to build the next level of complexity, and so on.
Steve314
+5  A: 

Maybe you want to look into the Singularity Project.

Its from Microsoft Reseach, on how today a OS could be built.

there you find a lot of papers, on the concepts of building an OS.

Singularity

cRichter
-> English link
Snoob
Singularity is great, but it's very different from Windows.
Tim Robinson
A: 

I just know Unix and Linux are written in C for sure, but Windows. Can anybody tell me this also?

Truong Ha
don't ask a question in an answer, please.
Warren P
+1  A: 

Well, the question is also "What is the operating system?" (does bundled Internet Explorer count in?), but otherwise I believe Windows is mostly C and C++.

mcepl
bundling something with the operating system doesn't make it part of the operating system, if the operating system will still install and run applications without it.
Warren P
+2  A: 

I'm pretty sure the earliest versions of Windows were written primarily in Pascal. That's why you can still find references to pascal calling conventions in old documents and header files, though AFAIK those conventions only ever applied to 16 bit Windows.

These days, Windows is probably written in a mixture of languages, though with the emphasis strongly on C and C++. For example, some parts of .NET are probably written in C#, and these days that easily counts as an O/S component.

Similarly, I'll bet there are at least a few Objective C components in modern versions of the Mac O/S.

There are a lot of languages that are somewhat suited to writing operating systems. In niche areas, I'm certain you'll find Ada, Modula 2 and more.

Imperative languages without garbage collection are probably most common because of the relative ease of interfacing to hardware and assembler code. However, most functional languages are impure. There are low-level versions of Lisp around, if you look hard enough. And ML-family languages and Haskell have probably been used in operating systems, at least for research/academic purposes.

In fact, I wouldn't be surprised to find even a bit of Prolog in some operating systems components - and certainly some code written using custom-made domain specific languages.

A real-world operating system is usually a very large software system. Even embedded operating systems have a fair bit of complexity, e.g. for options you don't need for your hardware but someone else does. I've never worked on one, but I'll bet that to get that working, the developers are primarily pragmatists - using whatever they have that works to get the job done.

Steve314
Isn't an OS just an application itself? That being the case, who's to say you can't write some asm to build a foundation that you can use to have a python OS installed and run if you wanted to?
Logan Young
In the Windows 3.1 era (the pascal calling convention origin), Windows really was truly an application running over a minimal operating system, however because it provided its own non-pre-emptive multitasking services, and even some hardware assisted 16-bit real-mode virtualization (for the dos box), it also contained things that were clearly "operating system" features.
Warren P
*An* application is a bit wrong - many O/S components are complete applications in themselves. But in principle, you're right - just remember that standard Python is bootstrapped in C, so even once you have your basic kernel and I/O subsystems, you'll have to write a complete Python runtime in pure assembler - *definitely* not something I'd want to do. Computers don't have dynamic typing, garbage collection etc built into the hardware - you'd have to write all that and more in pure assembler.
Steve314
@Warren - and in any case, Microsoft wrote the underlying DOS too, and that was probably written substantially in Pascal as well. Microsoft were rather keen on their Pascal development tools at one stage - and seriously irked when Borland undercut them with Turbo Pascal.
Steve314
@Logon - just to be clear, the theme of my answer is that virtually any language can play some role in O/S development. Python is, of course, in the set of "virtually any language". But you do want to be sure you choose the right tasks for it. You can't write your memory management in Python, for instance, because a complete memory management system complete with garbage collection needs to already be there before you can run your first line of Python code.
Steve314
@Steve314: In the Klein VM (an implementation of Self), the garbage collector is written 100% in high-level idiomatic Self. The trick is simply to have a good JIT compiler which can eliminate unnecessary memory allocations. If the compiler is intelligent enough to eliminate all memory allocations at least inside the memory allocator itself (and also inline all method calls inside the method dispatcher), then you're pretty much home free. (Those two places are basically the gnarliest, at least for a garbage colected OO language.) There's no reason why that wouldn't work for Python.
Jörg W Mittag
@Jörg - of course that still means you have to rewrite the whole Python runtime - and now you need to write a whole bunch of sophisticated optimisation in your bytecode interpreter/jit, still without any other language available to implement that than assembler or an extremely truncated subset of Python. If you were dead set on this, I'd at least recommend a statically compiled Python-like language such as Boo.
Steve314
@Jörg: I found some old release notes (v0.1, 2006) on the Klein VM. That's as recent as I can find. "There is a half-written Self interpreter written in C++, called Yoda" which is an unfinished experimental offshoot - but it also appears to be the only reference to any garbage collector having been developed (and then, "rudimentary" and "seems to work"). The first entry in "Work Left to be Done" is "Garbage Collector". Perhaps there's a more recent release? - or perhaps they never wrote a working GC in self after all?
Steve314
+2  A: 

Operating Systems can be written in pretty much any language, and there are plenty of Operating Systems written in an whole bunch of languages. Just a couple of examples:

  • Singularity is written in Sing# which is a superset of Spec#, which in turn is a superset of C#
  • House is written in Haskell
  • all of the Lisp OS's are written in Lisp
  • there are several Smalltalk OSs written in Smalltalk
  • many embeddded OSs are written in Forth
  • SharpOS and Cosmos are written in C#
  • NewOS and JNode are written in Java
  • Ununumium used to be written largely in Python, but now they have shifted their focus, it is written largely in assembly
  • You can argue whether JS/UX is an OS or not, but it is written in JavaScript
  • Modula-2 was explicitly invented for the purpose of writing an OS
  • Oberon also was explicitly invented for OS development
  • the original MacOS was written in Pascal
  • the original OS/400 was written in Modula-2 and PL/MI
  • Eleanor McHugh has some preliminary ideas for writing an OS in Ruby
  • the Windows NT kernel is written largely in C, however the farther away you get from the kernel, there might be some C++ or even C# in there
Jörg W Mittag