Page 1 of 1

GCC "binary" output

Posted: Sun Dec 05, 2010 6:26 am
by mariuszp
My operating system uses a custom binary format, called "DEF", and it is pretty simple.

It assumes that everything (code, data, bss) is loaded at address 0xC0100000. Every DEF file starts with a header. It was easy to get NASM to create DEF binaries. All I did was use the '-f bin' option so that it puts everything in the same place. Then I had the following code to create a program that would trigger INT3. I manually put the header, ORG and BITS directive in:

Code: Select all

org 0xC0100000
bits 32
db 'ADEF'
dd 7
db 0, 0, 1
db 'init'
resb 16 ; padding name 'init'
db 'PROJECT DARMA'
resb 7 ; padding developer name
dd _start
db 32
resb 44

_start:
	mov eax,[_start]
	int 3
	jmp $
Simple. The problem is that now I want to make C binaries, and I could not find any way of putting everything in the same place. I tried a linker script, but it says that 'bin output format does not support external references'. So what do I do?

The question is basically: how do i get gcc to compile a program and assume that code, data and bss sections all start at 0xC0100000. And make it export my own executable format.

Re: GCC "binary" output

Posted: Sun Dec 05, 2010 7:08 am
by Combuster
You don't

Use ld instead.

Re: GCC "binary" output

Posted: Sun Dec 05, 2010 7:45 am
by mariuszp
HOW??

Wouldn't ld create an ELF? That's what I DON'T want!!!!!!!!!!!!!!!!!

How do I make it so that after linking it just assumes everything is at that address?? And I want the header to be there too.

Re: GCC "binary" output

Posted: Sun Dec 05, 2010 8:54 am
by Combuster
Third hit, please learn to use Google.

(And if someone suggests that ld can do something you never imagined, wouldn't it be a good time to check it out? :wink:)

Re: GCC "binary" output

Posted: Sun Dec 05, 2010 9:49 am
by mariuszp
Oh. Thanks. I always find it hard to put correct keywords into google.