which compiler ? and how i can compile my OS ??

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
SmartBoy

which compiler ? and how i can compile my OS ??

Post by SmartBoy »

Hello :)

ok now i try build my simple OS , i written some codes with C and assembly .

but i have big problem , i don't know which compiler should i use .

now i am using Dev-C++ (it's use GCC) and it's for windows .

my question what is the best compiler for build OS ?

and how i can compile and test my OS with this comiler ?

thanks :)
Cjmovie

Re:which compiler ? and how i can compile my OS ??

Post by Cjmovie »

DEV-C++ is real nasty, it's really meant for Windows program, it's not REALLY gcc, it's mingw. Mingw, though, is a Windows port of the linux GCC.

Goto:
http://delorie.com/djgpp

And go to zip picker, choose just the minimum. Then follow the install instructions.
As for ASM, either NASM or FASM. NASM is on sourceforge.net, not sure on FASM (don't use it myself).

But really, you should read this:
http://www.osdev.org/osfaq2/index.php/GCC
and this:
http://www.osdev.org/osfaq2/index.php/DJGPP
and this:
http://www.osdev.org/osfaq2/index.php/NASM

The OS faq is your friend :). Try it next time, you'll get your answer even faster!
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:which compiler ? and how i can compile my OS ??

Post by Solar »

Traditionally, we recommend the use of Cygwin and a GCC cross-compiler instead of DJGPP, for various reasons:
  • more complete environment;
  • more up-to-date versions of GCC and binutils;
  • less Windows dependency (with the cross-compiler, you're on equal footing with someone using a cross-compiler under Linux, which helps error tracking);
  • it's what several pages of the FAQ assume you're using.
Every good solution is obvious once you've found it.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:which compiler ? and how i can compile my OS ??

Post by Candy »

- No tendency to include a DPMI link into your programs (DPMI does not work with OSes, since it relies on DOS and 16-bit mode).
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:which compiler ? and how i can compile my OS ??

Post by Solar »

Cjmovie wrote: As for ASM, either NASM or FASM. NASM is on sourceforge.net, not sure on FASM (don't use it myself).
Ah, didn't get that one this morning: Of course you can also use GNU as, which is part of the binutils package. But they'll look at you in funny ways if you do. (Can't really understand why, it's a fine assembler and I can use the same syntax in inline assembly and make supports it very well with implicit rules... ;) )
Every good solution is obvious once you've found it.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:which compiler ? and how i can compile my OS ??

Post by Candy »

Solar wrote: Ah, didn't get that one this morning: Of course you can also use GNU as, which is part of the binutils package. But they'll look at you in funny ways if you do. (Can't really understand why, it's a fine assembler and I can use the same syntax in inline assembly and make supports it very well with implicit rules... ;) )
You can of course use GNU AS. It supports AT&T syntax x86 assembly very well and delivers exactly what you expect (if you use AT&T syntax, that is). It's also handy if you have a code file you want to speed up (note from Knuth: premature optimization is the root of all evil) since you can compile the code with gcc with the -S flag and it outputs the exact code GNU AS can use for the same output file.

On the other hand, for Intel syntax, you should also be able to use it (have seen mention of a -masm=intel or something flag) but based on my own experience (of a long time ago) it was a bastardized intel syntax with all the aspects I don't like about at&t except for parameter order.

If you prefer either and some programs gives you the wrong output type, try intel2gas (which gives the idea it can only go one way, but it has an invert switch). It can convert nearly all code flawless and the lines that usually don't work aren't needed. You do need to understand the original code for the tool to work, so it's smart to learn both of these.

For completing the assembler list, there's also TASM and MASM. TASM isn't being developed anymore (as far as I can tell) but was developed by Borland. MASM is being developed (however unlikely and slowly) by Microsoft and can be ordered using a very complicated ordering mechanism which involves Visual Studio and hand-writing a request for it. It can also be downloaded from www.masmforum.com for free, iirc.

HTH, Candy
SmartBoy

Re:which compiler ? and how i can compile my OS ??

Post by SmartBoy »

Hello ..

thank you very much all .

ok i have FASM and now i download Cygwin .

but i don't know how to use it ?? any good links explain for me ?

i am confuion now :) what should i download GCC or DJGPP or Cygwin
AR

Re:which compiler ? and how i can compile my OS ??

Post by AR »

Cygwin is a UNIX-like (Linux) environment for Windows, it basically creates the basis for GNU stuff to run on Windows with the full POSIX API.

DJGPP is a DOS port of GCC. GCC is the compiler used in both cases, however, on Cygwin you will need to build your own cross compiler from the GCC sources, a guide for that is in the Wiki. DJGPP is generally only useful if you're happy with flat binary output from an outdated GCC version.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:which compiler ? and how i can compile my OS ??

Post by Solar »

Candy wrote: On the other hand, for Intel syntax, you should also be able to use it (have seen mention of a -masm=intel or something flag) but based on my own experience (of a long time ago) it was a bastardized intel syntax with all the aspects I don't like about at&t except for parameter order.
Just add

.intel_syntax noprefix

to your source head. No register prefixing (%eax -> eax) and Intel-style parameter order.

I found one case where the Intel backend generated a different opcode from the AT&T backend - a three-byte mov instead of a possible two-byte one - but otherwise it seems to work well in both directions.
Every good solution is obvious once you've found it.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:which compiler ? and how i can compile my OS ??

Post by Solar »

SmartBoy wrote: thank you very much all .

ok i have FASM and now i download Cygwin .

but i don't know how to use it ?? any good links explain for me ?
What is "it", FASM or Cygwin?

The Cygwin installer offers to add an icon to your start menu and / or desktop. By clicking on that, you get a DOS-Box which actually is a bash shell. /cygdrive/<letter>/ under Cygwin is equivalent to <letter>:\ under Windows.

By default the Cygwin installer does not install GCC. Just restart the installer and select GCC (and, if you want to do C++, G++) from the "devel" group. (And whatever other tools you want; I'd recommend make, rcs, cvs, and openssh at minimum.

After the installer finished, you just pick up the GCC manual from gcc.gnu.org (or do 'info gcc' in the Cygwin shell) and be a happy camper.
Every good solution is obvious once you've found it.
raywill

Re:which compiler ? and how i can compile my OS ??

Post by raywill »

Personally I suggest using DJGPP under windows.
use nasm -f aout to generate .o,gcc output .o and use ld to link them together.
Cjmovie

Re:which compiler ? and how i can compile my OS ??

Post by Cjmovie »

Don't forget:
-ffreestanding
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:which compiler ? and how i can compile my OS ??

Post by Solar »

raywill wrote: Personally I suggest using DJGPP under windows.
use nasm -f aout to generate .o,gcc output .o and use ld to link them together.
Did you read the thread?
Every good solution is obvious once you've found it.
Post Reply