Which C++ compiler for kernel?

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
Xenos

Which C++ compiler for kernel?

Post by Xenos »

Where can I find a C++ compiler with these features:

32Bit protected mode code
far pointers + functions
flat binary output
no dependence of built-in libraries
possibly interrupt handlers (no dpmi!)
runs under Win2000 (well, Linux would also be ok)
should be free...

DJGPP doesn't know about far pointers, Watcom doesn't output flat binary (and calls a strange "__CHK"-function), Borland doesn't output flat binary either.
Or should I use compiler A to create obj and link with linker B to binary?

Thanks in advance.
Jamethiel

RE:Which C++ compiler for kernel?

Post by Jamethiel »

Why would you need far pointers if you're in 32-bit PMode?
Xenos

RE:Which C++ compiler for kernel?

Post by Xenos »

I'm trying to use a segmented memory model for my os. Each task will have its own code and data segments - as many as it needs, to separate constant and nonconstant data for example. Why not use those lots of PMode features?
Another thing is calling system functions in different segments. I try to use call gates - and they work only if I make far calls. So I would like to write far system functions to get a far return...
I have already written a simple system call dispatcher in asm, which will be part of my C-library. It is called near from an application program, finds out which function to call by using a global lookup-table, manipulates the stack and jumps through a call gate into the kernel.
CarbonBased

RE:Which C++ compiler for kernel?

Post by CarbonBased »

Using segments for call gates seems like a valid reason to use far calls, but I don't know that using segments to assign code and data segments for each task is overly important.

Why not use those lots of PMode features? you asked... well, simply put, because you don't need them all (at least not at once).  If you wish to utilize the processor's paging system (and you will want to, no doubt) then you _possibly_ don't want to use segmentation at the same time (it can prove to be _extrememly_ complicated).

You can accomplish the isolation of each task's code and data segments through the paging system just as well as you would with segmentation.

In any event, you can write a simple function in C to call a call-gate if you wish to support such a thing.

Cheers,
Jeff
Xenos

RE:Which C++ compiler for kernel?

Post by Xenos »

I _really_ try to implement segmentation ang paging at the same time... Paging is a nice protection, but I prefer segmentation. I use paging only for memory allocation, i.e. extending linear address spaces by 4kB blocks, even if they are closely packed in physical memory. (I don't store pages on a disk, because it would be to slow for my real time OS)
Stefan

RE:Which C++ compiler for kernel?

Post by Stefan »

AFAIK, only Watcom supports 48-bit far pointers... Your best bet would probably be to find a format that both BFD and OpenWatcom support, compile to it, and link with LD.

If there is no such common format, find the _simplest_ format in Watcom and write a format module for BFD.

PS: BFD = Binary File Descriptors (?), not, well, you know...
Jamethiel

RE:Which C++ compiler for kernel?

Post by Jamethiel »

Actually, "Binary File Descriptor" or whatever it is is a retcon. According to the official histories, it -was- "Big F*ing Deal" when it was first applied to the BFD library.
Xenos

RE:Which C++ compiler for kernel?

Post by Xenos »

Watcom produces OMF - DJGPP's objdump told me that it can't handle this. So what is BFD and (where) can I get something to use OMF with it?
Second point: If I disassemble Watcoms OMF, I find a call to a function named "__CHK" (probably somewhere in Watcom's libraries...) - I try not to use any libraries so far. Can I keep Watcom from calling "__CHK"?
Stefan

RE:Which C++ compiler for kernel?

Post by Stefan »

BFD: The module LD and GCC/GAS use to read and write object files.
I'm no Watcom user myself, but it shouldn't be too hard to figure out what __CHK does (from the disasm) and write a noop replacement...
You might have to write a BFD backend for OMF (and recompile DJGPP ld), i dont know...

Some links i've Googled:
http://sources.redhat.com/ml/gas2/1994/msg00084.html
http://216.239.57.104/search?q=cache:qX ... n&ie=UTF-8
http://www.ifi.unizh.ch/groups/richter/people/pilz/oct/
http://www.google.com/search?hl=en&ie=U ... &q=OMF+BFD
http://x86.ddj.com/ftp/manuals/tools/omf.pdf
Xenos

Thanks! I got it!

Post by Xenos »

Thanks a lot! It seems to work now.

__CHK checks for stack overflow and can be switched off by #pragma off (check_stack) or the -s compiler option.

I have found some ways to convert OMF to COFF. The most interesting one: Microsoft's lib packs OMF into a COFF library and extracts COFF (this is from the DJGPP FAQ).
Perhaps I'll write a simple converter - seems to be easy.
The third way: Watcom allows customizing the startup code (the source can be downloaded) and supports lots of output format. If I put my initialization into the startup code and the main loop to 'main', link to some odd format and extract the binary data, it should also work.
Xenos

Thanks! I got it! #2

Post by Xenos »

JLoc links OMF, COFF... to flat binary (exclusively) and allows configuring almost everything (base addresses, segment selectors, image addresses...) - and it's free.
I found it in Dark Fiber's OS FAQ. It can be downloaded from http://my.execpc.com/CE/AC/geezer/johnfine
The best kernel linker I ever tried...
ekp

RE:Thanks! I got it! #2

Post by ekp »

Sure - but instead of using tools that haven't being maintained for quite some time (I remember John Fine's webpae going offline 3 years ago), why don't you use a standard tool chain?

There is nothing wrong with G++/AS/LD. I don't see why you would want your kernel to be in OMF - which is a long dead format that is only used by old-style EXE files (the new ones use a bastardized COFF). There is nothing wrong with ELF.

LD has powerful scriptiong which will allow you to control every aspect of kernel. Use GRUB to boot and you're done.

I frankly don't understand the obsession with dead exec-formats and tools. Might as well put an ST506 MFM Full height 4MB Harddrive in your computer while you're at it.

JLoc isn't portable - Gnu toolchain is. I can compile my kernel under dos, linux or windows. I can cross-compile it on a Sparc, Alpha or PPC.
Post Reply