Page 1 of 1

Compilation tools advice

Posted: Sat Aug 04, 2007 12:48 pm
by pushad
I've been kicking around the idea of writing an operating system for a long time now, but only recently have I found real reason to pursue it. I've been coding for ten years, mostly in Cpp with liberal inline assembly, but it has all been in Visual Studio, so I am completely lost in the world of GNU.

I've been trying Brandon F's tutorials on Bona, using the (ancient?) DJGPP version available on the site, and after configuring everything seemingly correctly, even going so far as to hard coding C_INCLUDE_PATH in djgpp.env, and continue to get the following error when trying to compile the C source files [the full ones from the Zip, via the build batch script]:

c:/djgpp/lib/gcc-lib/djgpp/3.1/djgpp.ver:1:25: sys/version.h: No such file or di
rectory (ENOENT)

Well, it clearly does exist, at least when I've hard coded the path. I've searched around, finding only unanswered Google group messages.

But on top of this, isn't gcc 3.1 almost 6 years old? And it's not gpp, and I would much prefer to write in Cpp, but I'll take whatever I can get at this point. I've got Gygwin installed, and get another wave of compiler errors and linker errors (particularly invalid file format) when I try to compile virtually any example I find on them.

Really, I'm just terribly depressed at GNU development after having a single, always working 'compile and run' button for a decade. Can anybody point me to a working out of the box bare bones / tutorial / hobby kernel / tutorial that I can compile on Windows using tools that aren't from 2002? Do I honestly have to do all my OS dev inside a linux vm? And I remember trying gpp a while back and it telling me it couldn't do nostdinc anymore.

I'm just lost I guess. I'm so eager to get coding. Please, somebody help :(

Posted: Sat Aug 04, 2007 2:41 pm
by sancho1980
hi

im new to all this too and stgill have to figure many many things out for myself but i can assure you one thing: you wont find a "one-button-compile-all" tool for developing an os! its pretty easy to code in a gui-based ide with drag&drop and everything, but it hides away from you not only the complexity of the machine but also that of the compile and linking process...

if youve done ONLY cpp in a graphical ide before and have never touched an assembler probably the first thing you should do is get familiar with assembly programming; yes i know you dont need to write your os in assembly but you probably wont be able to write an os without knowing any assembly at all

ps: and for learning assembly, the best place to my mind is http://webster.cs.ucr.edu/

and for the eagerness to start coding: i started learning assembly around 3 years ago, about one year ago i got myself "the minix book" by andrew tanenbaum (and i had to read it not only once!), and about 3 weeks ago i started coding my own os in earnest (and its only a lousy piece of code that writes strings to screen, clears the screen, scrolls the screen and *is now attempting* to output numbers) :-)
so i guess you'll have to be patient, really...

Posted: Sat Aug 04, 2007 2:58 pm
by pushad
While yes, very I'm used to my beloved graphical IDE and quite removed from the compiling and linking process, I'm far from unfamiliar with the machine my code runs on. I'm very comfortable with assembly, I was not raised on MFC / ATL / COM, I've used created projects of respectable size in masm, I used to use SoftICE for all kinds of fun projects back in 9x (before IceDump went soft), and I've perused the IA-32 architecture reference books for some time now. Design wise, I'm trying to figure out a clever way to mate the OS level garbage collector with the paging mechanism, if I go paged at all. I'm quite ready to get coding, all I need is the tools to do so.

I am however terrified of gcc's revolting at&t inline assembly syntax. Good lord.

Posted: Sat Aug 04, 2007 4:02 pm
by jnc100
pushad wrote:c:/djgpp/lib/gcc-lib/djgpp/3.1/djgpp.ver:1:25: sys/version.h: No such file or directory (ENOENT)
...
I've got Gygwin installed, and get another wave of compiler errors and linker errors (particularly invalid file format)
Several issues here - first, gcc by default tries to include some standard system include files. As you're writing an OS, you need to either a) provide them yourself or b) tell gcc not to try and use them. Look up options to gcc like --no-builtin and to ld like -nostdlib.
The ld (linker) that comes with Cygwin is designed to target a windows environment, and therefore can only produce output in the PE (Win32) format, which is probably not what your tutorial is asking it to do. You need a GCC Cross-Compiler.
sancho1980 wrote:i can assure you one thing: you wont find a "one-button-compile-all" tool for developing an os!
I've got one 8)

Regards,
John

Posted: Sat Aug 04, 2007 4:10 pm
by sancho1980
jnc100 wrote:
sancho1980 wrote:i can assure you one thing: you wont find a "one-button-compile-all" tool for developing an os!
I've got one 8)
C'mon you know what I mean

Re: Compilation tools advice

Posted: Sat Aug 04, 2007 4:41 pm
by octavio
pushad wrote: Really, I'm just terribly depressed at GNU development
Me too, thats why i just use Octasm.

Posted: Sat Aug 04, 2007 4:59 pm
by urxae
pushad wrote:I'm trying to figure out a clever way to mate the OS level garbage collector with the paging mechanism, if I go paged at all.
You may want to check out a paper called "Garbage Collection without Paging" (readily available on the 'net, just google it). They implemented a garbage collection algorithm that communicates with the paging mechanism of a modified Linux kernel to avoid touching paged-out memory. A similar technique could be useful for in-kernel GC (once paging stuff to disk is implemented).

Posted: Sun Aug 05, 2007 12:49 pm
by Candy
sancho1980 wrote:i can assure you one thing: you wont find a "one-button-compile-all" tool for developing an os!
Have one too, mine's called Make. You tell it "make cross disk.img" and it takes about 45 minutes to build. It compiles two crosscompiler environments, a copy of YASM, six copies of my libc, three of libsupc++, three kernels, three setup blocks, one bootloader, a compressor, a decompressor, a archiver, a mkfs tool and then crossinvokes these to build a disk image. If you skip the make cross it's down to 1.2 minutes.

Posted: Tue Aug 07, 2007 3:41 am
by JamesM
Hi,
I am however terrified of gcc's revolting at&t inline assembly syntax. Good lord.
Yes, I hate it too. I avoid inline assembly at all costs in G++, and try and outsource it to external .S files which I run through the preprocessor (/bin/cpp) and then through nasm (the nationwide assembler), which uses a proper intel syntax. You can also give GAS (the GNU assembler) a ".syntax intel" (or something similar, IIRC) directive to make it switch to intel syntax.

OK, heres a quick heads-up on linux-environment development.

LD is your linker. For normal projects G++ calls it for you, but with a kernel because the link structure has to be very exact, you tend to run it yourself.

GCC/G++ are your compiler tools. Unless you need to outsource assembler files (which you compile with "as").

They take all their input files as command line arguments, also taking ridiculous numbers of parameters. Most people do not specify these themselves. They use GNU Make. This is a program that attempts to somewhat relieve the pain of the build process. Essentially you tell make what files you want compiling and what other files those depend on, and it'll sort everything out for you.

On an even higher level of abstraction you have GNU autoconf/automake. I use these to configure and make my OS, although a lot of people dislike them because of their complexity. GNU autoconf was designed for 'normal' programs, I.e. programs that rely on having certain files present/kernel modules etc etc etc. It will check for these at configure time, ensuring that everything is present. You can also use it to change compile flags. For example my configure command looks like:

Code: Select all

./configure --target=x86
So I can change the target architecture. (This can also be done with Make).

GNU automake is part of the same package, and works hand-in-hand with autoconf. It is particularly optimised for running 'make' over directory heirarchies, a task which with normal make is like getting blood from a stone (make is optimised for situations where all the source files are in one directory).

There are also IDEs for linux. I use KDevelop (when I'm not using emacs), which has full autoconf/automake integration (it adds everything for you) and has a magic compile button.

It can be very well automated, for example to build my kernel from scratch (you only have to run configure once) you just type

Code: Select all

make clean
make bochs
which will remove all object files, remake them, link the kernel, put the kernel in a 1.44MB floppy image (via a shell script), and boot bochs.

JamesM