Archived

This topic is now archived and is closed to further replies.

Promit

How do you compile an OS?

Recommended Posts

Ive always been wondering on this. Obviously you cant compile to any sort of stright executable, because the executable format itself is defined by the OS. The compiler needs to support compiling for that OS, so you''ll need a custom compiler and/or linker, won''t you? And then, how do you beta test an OS that doesnt actually do very much yet? I have no experience with systems programming like this, so i was just curious... ----------------------------- The sad thing about artificial intelligence is that it lacks artifice and therefore intelligence.

Share this post


Link to post
Share on other sites
You have to write a bootloader which sits at the beginning of the drive. The bios then loads this code, and starts executing it. Now you''re running your code you can do whatever you want, which generally includes loading your files off disk etc...

How do you beta test? I''m not sure i understand what you mean because you can test at any stage - even when it just prints "Hello World! JxOS Started..." this is testing that you can actually get to that particular stage in the program.

This is a really basic view of it, but i hope you get the idea of how you get control in the first place.

Jx

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You write the OS to be compiled in some already existing OS. Typically the OS is loaded by a simple loading program (This is what linux, windows, etc, do.) This bootloader is the thing that needs to understand the executable format of the OS binary. The technical term for this is bootstrapping. The process to port a compiler onto a type of hardware that''s never had a compiler before is similar.

Linux was first compiled on minix, for example, and required minix to be present to compile properly. Only later was it ''ported'' to itself.

Having an OS or compiler compile itself is considered one of the early hurdles for the project, but it sure doesn''t happen right away.

Share this post


Link to post
Share on other sites
If you get an x86 emulator (bochs for example), you can create
your operating system in windows and create the bootsector
information for your operating system, and test it in windows
in a window(obviously ), that''d save a lot of time and would
be a lot easier. Hope u understand wot i mean, i''m tired
and my english is slowly slipping away, even though i''ve spoken
it for about 15years(1 and 2 don''t count)

Share this post


Link to post
Share on other sites
It's a process of "bootstrapping".

First you need to design an exectuable format.

Then you write a loader on an existing OS (Windows, Linux).

After you're convinced that it works, you write a cross-compiler for your OS. You "simply" have to modify GCC "a little bit" so it outputs your executable format.

Cross-compile your exectuable loader and hope for the best.
The rest is just a matter of writing a complete set of I/O, process scheduling, multithreading... etc routines.

Really, it can be done in maybe 2 years by one person.

Linus Torvalds did it... kind of.


Premature optimizations can only slow down your project even more.

Edited by - tangentz on January 31, 2002 4:40:04 PM

Share this post


Link to post
Share on other sites
quote:
Original post by tangentz
First you need to design an exectuable format.

Then you write a loader on an existing OS (Windows, Linux).

After you''re convinced that it works, you write a cross-compiler for your OS. You "simply" have to modify GCC "a little bit" so it outputs your executable format.


Why?
What''s wrong with ELF or COFF or COM or A.OUT? Unless your OS requires some sort of special features, it''s much easier to stick with an existing file format.

Share this post


Link to post
Share on other sites
well I a few people have already explained most of this but
you don''t realy need a compiler/linker that is custom writen...
but you do need one that can generate a flat binary.... no headers no OS specific libs (just about everthing...)
ummm NASM (a open source assembler could be use) gcc (built as a cross compiler)... and the list gose on
as far as testing... its fairly easy to write your own screen IO functions.... so you can just use them for testing...

I''ve got a bunch off sources for boot-loaders(some that load custom binnarys others that load elfs exe com ect) miniOSs howtos on toolsets elf header stripers and such.... if you want I can e-mail them to you...

Share this post


Link to post
Share on other sites
great milenko, how abouts sending them to me too gavcoates@btinternet.com

I looked into it a while ago and started making my os (YabOS = Yet another bloody OS) but never got past the "YabOS is now loading..." stage

Share this post


Link to post
Share on other sites
try my "hello 32" page.. it will put x86 into "flat mode" and you can write your main os program in C.. the page explains the whole thing..

http://www.geocities.com/bpj1138/hello32.html

have fun!

Share this post


Link to post
Share on other sites