Thread: How do they compile code for an OS ?

  1. #31
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Hi,

    Ok now i got more understanding of it.

    But i really want to know who created the first OS? And how? How did he write the code? How did he compile it?

    And also i asked this question some time ago in this board, and just wondering if any of u guys know it:

    How were the C standard libraries written? Who wrote it? Using what language?

    Without the C libraries you can almost do nothing in c programming, thats why i wanna know.

    thnxq

  2. #32
    Registered User
    Join Date
    Jan 2002
    Posts
    363
    >>But i really want to know who created the first OS? And how? How did he write the code? How did he compile it?

    It was probbably written in native code or something similar so he didn't have to compile it.

    >>How were the C standard libraries written? Who wrote it? Using what language?

    Mixture of c and assembly.
    I'd suggest you go out and take a look at some basic assembly, it'll clear all this stuff up for you. . . . and keep you entertained till like 2005.
    http://webster.cs.ucr.edu/Page_asm/ArtOfAsm.html

  3. #33
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    >But i really want to know who created the first OS? And how? How did he write the code? How did he compile it?<

    I can't answer that, and I doubt anyone can for that matter. There's too many platforms out there, along with too many OS's to have a record of the first one. The first one was probably a very, very simple program written in binary. From there, they probably programmed a more sophisticated one. It most likely evolved into an OS.

    But, there may be a record of the first true OS. Let me know if anyone finds out.

    >How were the C standard libraries written?<

    Using a compiler or assembler just like any other program.

    >Who wrote it?<

    Which one? For example Stoned_Coder is writing his own; so am I. There's more than one LibC out there.

    >Using what language?<

    I can only speak for myself. I'm using C and inline assembly. My compiler is DJGPP (DOS port of GCC). Most others are heading this direction as well...

    This might interest you: http://www.execpc.com/~geezer/osd/libc/index.htm

  4. #34
    Unregistered
    Guest
    Okay guys,

    I read all your posts. But why everybody is ending at GCC or some port of GCC.

    Let me put something more beyond to this :

    compiling means(including linking) first checking for the syntax and then linking with its libraries, this will produce the OBJ code and the obj code is then linked with runtime libraries and is been converted into machine dependent executable. Actually a compiler is targetted towards a target system i.e. how the systems deals with I/O,memory etc.

    First thing to create an O/S actually involves in creating a compiler for that O/S. This is something called self compilation. So you write a compiler which compiles it self and produces the compiler. Using that compiler you can start coding your o/s.

    For getting started with this method, you need to code some basic logic in assembly of that particular platform. This assembly code will run your first compiler which compiles it self and produces a compiler and creates the runtime libraries which are platform specific.

    And hence you got the first chicken which lays eggs;-).

    But you dont need work that hard like K&R to produce your first compiler. You will get some environments which will run on one system but can produce the executables targetted to run on another platform. (i think they call them Emulators....i am not sure).

    If you need more info search for terms like Yacc, Lex etc.
    Oh, ya... do you know what is the full form of Yacc.

    --cheers.

  5. #35
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    >Actually a compiler is targetted towards a target system i.e. how the systems deals with I/O,memory etc.<

    You _can_ (on some compilers) compile as a freestanding module, hence targeting no OS and using no libraries.

    >First thing to create an O/S actually involves in creating a compiler for that O/S.<

    I'm sorry, unregistered, but I've got an angry posse (hehe, been wanting to use that word.) of fellow OS dev'rs that beg to differ.

  6. #36
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Im in an os class right now and the way weve been going about it is to use pure asm to achieve a level where we can have basic user interaction, i.e. typing in commands at a command prompt, right now we are learning about implementing a high-level-language compiler into it to allow us to write os code.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  7. #37
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    ARe there any books out there which talks about inline assembly in C?

  8. #38
    Registered User
    Join Date
    Jan 2002
    Posts
    363
    Yes, but they are all books on assembly. . . . .

  9. #39
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    ok so i suppose they only put a chapter or two in assembly books on stuff like inline asm in C...

  10. #40
    Registered User
    Join Date
    Jan 2002
    Posts
    363
    No, inline asm is still asm. You need to know how to programme in assembly in order to use it, or just blatantly copy code.

  11. #41
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Ok, so inline asm is the same as asm, but there are special braces or brackets or keywords around the code to indicate they are asm code, and is to be compiled in another way.

    okok

  12. #42
    Registered User
    Join Date
    Oct 2001
    Posts
    197
    @KEN:
    >I thought GCC originated on Linux? Or did he write GCC to compile his os?

    Linus Torvalds first used Minix (which was an UNIX-like OS for x86-computers developed by Andrew Tannenbaum) on his 386-PC to develop his terminal-emulation-program which became Linux then. He compiled it with the GNU GCC-compiler. The GNU-tools for UNIX existed at this time yet and stood under the GPL.
    After having crashed Minix one day, he portated the GCC to Linux and used from that day on only his own OS.

    klausi
    When I close my eyes nobody can see me...

  13. #43
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Since we're on the subject, so in theory, you could compile a program "simply" by generating a pattern of bits which in turn are the actual representation of machine binaries? And so what really does it mean to "run" the program? That is, there must be a program that the OS runs to "run" executables-how does it work, differentiating from "opening" or "reading" or "writing" a file, what then does "running it" actually mean, to the OS, that is? And what is the name of that program on a windows machine? I would love to look it up...

    Right now I am working on the parse-end of a compiler. I am dreading the next step, asm. Nonetheless, this is the most interesting program I've worked on yet! Anyone know the BEST book to read on ASM that is readable and interesting?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  14. #44
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >I read all your posts. But why everybody is ending at GCC or some port of GCC.

    It's a great compiler, free, open source and there are ports for many OS'es.

    >compiling means(including linking)

    Hope you don't mean that compiling includes linking. Linking is a different process. A compiler produces object code, this can be a compiled C-file. To fullfill the process, there is need to link the object code with libraries so externals will be solved. If an external can't be found, the linker will tell you about unresolved externals.

    >the obj code is then linked with runtime libraries

    Hmmm. Isn't a runtime library linked at runtime? Or were that the dynamic link libraries?

    >First thing to create an O/S actually involves in creating a compiler for that O/S.
    >This is something called self compilation. So you write a compiler which compiles it self

    How does a compiler compile itself?

    I've written a few simple OS'es for microcontrollers, used crosscompilers for that.

  15. #45
    Registered User
    Join Date
    Jan 2002
    Posts
    363
    Originally posted by Sebastiani
    Since we're on the subject, so in theory, you could compile a program "simply" by generating a pattern of bits which in turn are the actual representation of machine binaries? And so what really does it mean to "run" the program? That is, there must be a program that the OS runs to "run" executables-how does it work, differentiating from "opening" or "reading" or "writing" a file, what then does "running it" actually mean, to the OS, that is? And what is the name of that program on a windows machine? I would love to look it up...

    Right now I am working on the parse-end of a compiler. I am dreading the next step, asm. Nonetheless, this is the most interesting program I've worked on yet! Anyone know the BEST book to read on ASM that is readable and interesting?
    I think it involves calling the main function.
    Although thats a very simplistic view of the process, there's probbably a lot more in the form of threading and whatnot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code won't compile
    By monkles in forum C Programming
    Replies: 3
    Last Post: 05-28-2009, 01:45 PM
  2. Compile Errors in my Code. Can anyone help?
    By DGLaurynP in forum C Programming
    Replies: 1
    Last Post: 10-06-2008, 09:36 AM
  3. Cross (compiler | OS) && reuseable code
    By audinue in forum C Programming
    Replies: 6
    Last Post: 07-22-2008, 12:46 PM
  4. How Can I compile 3 source code in 1 program ?
    By lord_cedrich in forum C Programming
    Replies: 8
    Last Post: 12-10-2006, 05:10 AM
  5. ....this code doesn't compile, very odd error
    By Leeman_s in forum Windows Programming
    Replies: 2
    Last Post: 11-03-2002, 02:31 PM