LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-11-2005, 08:17 AM   #1
NCC-1701&NCC-1701-D
Member
 
Registered: May 2005
Distribution: Debian Woody,Knoppix
Posts: 88

Rep: Reputation: 16
How much assembler needed in OS authoring?


Hi all,
My first contact with linux was inspired by it's popen source implementation. I was excited by reading the C programming language (the original book) and also the Operating Systems Design and Implementation, which included Minix. There are some source files in minix which contain pure assembly. I haven't studied yet the hole linux code, but I think there are similarities. Now, my question is can an os be written completely in C or C++?

Thank you!
 
Old 06-11-2005, 09:08 AM   #2
sekelsenmat
Member
 
Registered: Apr 2005
Location: São Paulo - Brazil
Distribution: Mageia Linux 1
Posts: 353

Rep: Reputation: 30
No, this is absolutely impossible. C does not offer the direct hardware access provided in assembler.

Remember that when you compile the following happens: c code >>> assembler code >>> machine instructions

So anything done in c can be done in assembler, but the inverse is not true.

How could you ever do I/O in pure c??? c offers nothing in terms of I/O. Remember that those glibc functions you use in c to do I/O like printf were actually written in assembler or link to something written in assembler.

Linux kernel contains an estimated 15% assembler code witch is considered very low and very good since assembler code is not portable, but c is.
 
Old 06-11-2005, 09:30 AM   #3
NCC-1701&NCC-1701-D
Member
 
Registered: May 2005
Distribution: Debian Woody,Knoppix
Posts: 88

Original Poster
Rep: Reputation: 16
Thanks!!!
 
Old 06-11-2005, 12:48 PM   #4
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
Actually, most of the I/O code in Linux is written in C. The only thing that needs assembler by in large is maybe a little in the raw disk access. In general, you will need assembler for the bootloader, and bits and pieces of the memory management and interrupt handling systems. For example, code that switches the CPU from ring 0 to rings 1 or 2 or that manipulates the MMU must be done in assembler. What you also need is a good understanding of protected mode x86 programming (assuming you're developing for x86).
 
Old 06-11-2005, 03:16 PM   #5
sekelsenmat
Member
 
Registered: Apr 2005
Location: São Paulo - Brazil
Distribution: Mageia Linux 1
Posts: 353

Rep: Reputation: 30
Quote:
Originally posted by btmiller
Actually, most of the I/O code in Linux is written in C. The only thing that needs assembler by in large is maybe a little in the raw disk access.
Please, enlighten me on how anything involving raw disk access can be done in c. I've being told that even printf was written in assembler. I tryed to find printf code, but could not find it.

I never actually got involved in coding the linux kernel, but I'm a reasonably experienced Intel Assember coder.

Even the most simple c tutorials will say that c does not provide I/O access and you must use glibc for such things.
 
Old 06-11-2005, 04:07 PM   #6
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
First off, understand that the kernel does not use glibc, all of the the internal library functions are provided in the kernel. Even the glibc printf is probably not written in assembler, although to be honest I don't know 100% for sure. In any case, I'll tell you where you can find a C version of printf -- download the GRUB source code (I used 0.96 but probably any recent version will do) and looks in the docs/ directory. There is a little example kernel that shows how to write a simple OS that uses GRUB and in the kernel.c source file is a simple printf implementation written in C. Basically, it just declares a pointer into video RAM and manipulates it.

Granted, this is not the slightest bit portable to non-x86 hardware. What the C tutorials say is that ANSI/ISO standard C provides no portable I/O routines beyond the stdio library, which is correct.

[edit to add]

Of course, the Linux glibc does not use raw access to video hardware as the example I gave does. It uses the open, read, write, etc. system calls in Linux, read the man pages for these calls for more info.

Last edited by btmiller; 06-11-2005 at 04:09 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Media authoring in Linux Zeniq Linux - Software 3 10-07-2005 06:08 AM
DVD encoding and authoring doctorwebbox Linux - Software 1 08-13-2005 12:28 PM
Flash authoring tools Bonu Linux - Software 1 07-18-2005 02:46 PM
DVD Authoring DoctorVell Linux - Software 1 05-15-2005 08:13 PM
DVD Authoring on Linux ddepuemd Linux - Software 3 05-22-2002 10:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration