GCC "binary" output

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
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

GCC "binary" output

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: GCC "binary" output

Post by Combuster »

You don't

Use ld instead.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: GCC "binary" output

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: GCC "binary" output

Post 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:)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: GCC "binary" output

Post by mariuszp »

Oh. Thanks. I always find it hard to put correct keywords into google.
Post Reply