How do you compile an OS?

Started by
14 comments, last by Promit 22 years, 2 months ago
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.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Advertisement
Write it in asm/machine code, I suppose
[ PGD - The Home of Pascal Game Development! ] [ Help GameDev.net fight cancer ]
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
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.
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)
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
神はサイコロを振らない!
quote:Original post by tangentz
Linus Travold did it... kind of.

Torvalds. People''s names are important (which is why I cut people who misspell mine). Linus Torvalds.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
right on, Olesuyi! (just kidding, sorry i''m bored at work)...
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
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.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Hey, are you kidding Olsueyi??!!! He''s cool (->a bit low-temperatured). Maybe he has a too huge fan.

-Kneelz.

This topic is closed to new replies.

Advertisement