Page 1 of 1
"C" Compiler Preferences
Posted: Wed Mar 17, 2004 12:00 am
by Freakyprogrammer
ok, I'm using a prewritten Bootloader that enables a20, sets up a minimal GDT and so on... an I am going to start writing a kernel for it and it will be written in "C" and I am trying to find the best compiler for my perposes, I have to be able to export to a flat binary format cuz I dont have any kind of filesystem at the moment... so please post any relevant info or preferences to a certain compiler/language... thx
peace out...
- Freakyprogrammer
RE:
Posted: Thu Mar 18, 2004 12:00 am
by common
Well, not quite certain what exactly a binary format would have to do with a lack of a file system, after all, they're not really dependent upon each other. I use a flat binary myself, but that is for simplicities sake. I can easily relocate the binary file whereever I like, with just relinking it, a binary format tends to want to be loaded a certain address, which means you either load it at that address, or enable paging and virtualize it.
As for compiler, compilers do not really do that, that is the job of the linker, not your compiler in the first place. Compilers just translate from one language to another. Some compilers may have internal linkers, but that's not technically part of the 'compiling.' I use gcc myself, the actual one, not DJGPP or the like. I found that DJGPP did not support as many arguments, which is not its fault, but is the fault of Windows itself. In that case, you may want to go with a platform like Linux, or *BSD, which tend to support hundreds of thousands of arguments, otherwise, when your kernel grows, there may not be enough arguments available to actually link your application together in one piece.
Another thing, if you select something else, more power to you. However, if you're going to write C, inline assembly is going to be very important, so make sure your compiler can do this, and the stronger, the better. Gcc also supports this. For a lot of applications, you could just make sure nasm supports your eventual object file type, but, in the long run, you'll find that making a call is not always an option, as a 'call' uses the stack. There may not be one available, during some periods of setups. At least, not one that you could trust.
C Compiler ???
Posted: Thu Mar 18, 2004 12:00 am
by Gandalf
hi friend,
I second what common says - you cann't get anything as good as GCC. I simply love gcc & g++ - especially for their support for inline assembly.
If u have Linux or *NIX why not GCC ?
rgds
Gandalf
RE:C Compiler ???
Posted: Thu Mar 18, 2004 12:00 am
by Freakyprogrammer
yah... I've been using GCC here and there a little... and I think now i'll just stick with it... thx guys
peace out...
- Freakyprogrammer
RE:
Posted: Thu Mar 18, 2004 12:00 am
by Neptune
I use (djgpp) gcc with nasm, and ld to link.
nasm kernel.asm -f coff -o kernel_asm.o
gcc kernel.c kernel_asm.o -fwritable-strings -ffreestanding -o kernel.o
ld kernel.o -Ttext ???? --oformat binary -o kernel.bin
Where ???? is the offset you want everything aligned to (in hex).
To use an assembly function in C:
asm:
global _foo
_foo:
C:
extern int foo();
On some systems, you don't need the underscore (unix, linux, I think).
Hope that helps.
RE:
Posted: Fri Mar 19, 2004 12:00 am
by Gandalf
Hi sebastian,
Actually I would like to add something to what u said. Actually the _ (underscores) are not because of the OSes but rather because of your intermediate object file format.
Eg:
You don't need an _ for elf format.
But u need _ for COFF format.
rgds
Gandalf
RE:
Posted: Fri Mar 19, 2004 12:00 am
by Neptune
*slaps forhead*
OK, thanks - don't know what I was thinking there.