Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are cores (device abstraction level) of OSs written entirely in C? (Like: "UNIX is written in C")

Are cores of OSs (device interaction level) really written in C, or "written in C" means that only most part of OS is written in C and interaction with devices is written in asm?

Why I ask that:

  1. If core is written in asm - it can't be cross-platform.
  2. If it is written is C - I can't imagine how it could be written in C.

OK. And what about I\O exactly - I can't imagine how can interaction with controller HDD or USB controller or some other real stuffs which we should send signals to be written without (or with small amount of) asm. After all, thanks. I'll have a look at some other sources of web.

PS (Flood) It's a pity we have no OS course in university, despite of the fact that MIPT is the Russian twin of MIT, I found that nobody writes OSs like minix here.

like image 685
Ben Usman Avatar asked Oct 19 '10 13:10

Ben Usman


People also ask

Can an OS be written entirely in C?

It is possible to write an OS using "only C" if you use some non-standard compiler features like naked functions, and inline assembly for a few things like hlt . People wrote OS's in assembly before C came along (and even after).

Is UNIX OS written in C?

Unix distinguishes itself from its predecessors as the first portable operating system: almost the entire operating system is written in the C programming language, which allows Unix to operate on numerous platforms.

Is kernel written in C?

Linux kernel development started in 1991, and it is also written in C. The next year, it was released under the GNU license and was used as part of the GNU Operating System. The GNU operating system itself was started using C and Lisp programming languages, so many of its components are written in C.

Why are OS written in C?

It's closeness to the hardware, explicit memory management feature, flexible structure, compatibility, and portability makes it the ideal choice for low-level development such as operating systems and embedded software.


2 Answers

The basic idea in Unix is to write nearly everything in C. So originally, something like 99% of it was C, it was the point, and the main goal was portability.
So to answer your question, interaction with devices is also written in C, yes. Even very low-level stuff is written in C, especially in Unix. But there are still very little parts written in assembly language. On x86 for example, the boot loader of any OS will include some part in assembler. You may have little parts of device drivers written in assembly language. But it is uncommon, and even when it's done it's typically a very small part of even the lowest-level code. How much exactly depends on implementations. For example, NetBSD can run on dozens of different architectures, so they avoid assembly language at all costs; conversely, Apple doesn't care about portability so a decent part of MacOS libc is written in assembly language.

like image 168
Jean Avatar answered Nov 15 '22 06:11

Jean


It depends.

An OS for a small, embedded, device with a simple CPU can be written entirely in C (or C++ for that matter).
For more complicated OS-es, such as current Windows or Linux, it is very likely that there are small parts written in assembly. I would expect them most in the task scheduler, because it has some tricky fiddling to do with special CPU registers and it may need to use some special instructions that the compiler normally does not generate.

Device drivers can, almost always, be written entirely in C.

like image 43
Bart van Ingen Schenau Avatar answered Nov 15 '22 06:11

Bart van Ingen Schenau