Page 1 of 1

Creating a 16 bits (real mode) OS

Posted: Fri Oct 19, 2007 6:41 pm
by Fergo
Hello everyone, its my first post in here.

For the past two weeks I've been reading a lot of guides/topics/tutorials about kernel programming. Almost 100% of the papers were about protected mode and 32 bit programming, and there was a lot of information and concepts that at the time I don't understand. Due to this fact, I decided that I need to really get into the real mode before getting in something bigger.

I have some experience on creating a basic kernel in real mode using assembly, and now I want to use C to program the mini-os. The problem is that GCC/DJGPP do not compile 16 bit code (as far as I know) and I have no idea on how to link my code with the kernel_start.asm (which calls the "main" function) using TurboC 2.01 (which seems to generate a lot of junk code with only a "void main() {}"). The bootloader I've already programmed (in asm).

Can you guys give some tips on how to correctly compile and link a 16bit C code with TurboC or point another compiler that is able to generate 16bit binaries?

Sorry for my english.

Thanks in advance,
Fergo

Posted: Fri Oct 19, 2007 7:20 pm
by Brynet-Inc
I think this question has been asked before.. but I'll reply anyway..

Bruce Evans's C compiler seems decent, generates 16bit code..

This site includes it as well has a few other related utilities..

http://homepage.ntlworld.com/robert.debath/

Posted: Sat Oct 20, 2007 2:39 am
by CopperMan
Open Watcom C, I think is the best choise for 16 bit modes.

Posted: Sat Oct 20, 2007 3:17 am
by earlz
I use to use Turbo C..

Posted: Sat Oct 20, 2007 10:43 am
by Fergo
Thanks everyone.
CopperMan, can you give me some hints about compiling the code with watcom? (I've got a bit confused with the bunch of executables and command line arguments of Watcom).

Regards,
Fergo

Posted: Sat Oct 20, 2007 11:15 am
by Combuster
Most of the older DOS compilers generate 16-bits code. The question is which of those can be manipulated to the extent that it can compile kernels.

BCC has been used to compile the bios of bochs/qemu, which makes it look like a viable choice. JLoc is a linker that can generate flat binaries, and IIRC can read Turbo C generated object files, which is also a viable combination. I have seen the name openwatcom a few times before, but since I have no experience with it, I cannot vouch that it is suitable for os development, but to be honest, I can't say that for either of the other compilers until I've seen it work.

The big thing is that few of us actually write 16-bit oses - I know one, but he used to be doing it in Pascal. In essence that means that you'll have to figure mostly everything out yourself. Once you do get something working, be sure to let us know since this question does get asked relatively often while we don't have an answer ready. Of course this invitation is not limited to yourself - any 16-bit barebones is welcome :wink:

Posted: Sat Oct 20, 2007 8:05 pm
by Dex
You should go for Turbo C 2.01, here is a simple example of using it to code a real mode C kernel. Its called "OS for Dummies Loader"
http://alexfru.chat.ru/epm.html#los4d