.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Programming
General Programming Help others and get yourself helped here!

Reply
 
Thread Tools
gcc function order
Old
  (#1)
Lazy
Member
 
Lazy's Avatar
 
Status: Offline
Posts: 236
Join Date: Jan 2004
Location: Toronto, Ontario, Canada
Default gcc function order - 27-11-2005

Is there a way to make sure a function is the first one to be compiled and first one written to the executable/object?
Since I'm not using any libraries passing -nostdlib to gcc will require _start instead of main.
This works fine except if _start is not the first function the whole thing messes up.
What happens is...
Compile->Link->copy code to raw binary

I did try a hack where I put a function at the beginning of the source file which called _start but after adding a few more functions that broke too.
My goal is the smallest possible binary size, which is why I'm working directly with hardware instead of using a high level library...
Code:
#include <gba_base.h>
#include <gba_video.h>

#define FRAMEBUFFER ( ( volatile u16* ) 0x06000000 )
#define RGB15( r, g, b ) ( ( r << 10 ) + ( g << 5 ) + ( b ) )
#define ru32 register u32
#define ru16 register u16

// HACKHACKHACK
// MAKE SURE THIS IS THE FIRST FUNCTION IN THE ONLY SOURCE FILE
void _start( void );
static void GCCStartHack( void ) {
	_start( );
}

// Draws a 1 pixel wide line at the given coordinates with the given height
static void line( ru32 iX, ru32 iY, ru32 iHeight, ru16 iColor ) {
	ru32 iTarget = iY + iHeight;

	for ( ; iY < iTarget; iY++ )
		FRAMEBUFFER[ iX + ( iY * 240 ) ] = iColor;
}

static void game_drawborder( void ) {
	line( 70, 10, 150, RGB15( 15, 15, 15 ) );
	line( 170, 10, 150, RGB15( 15, 15, 15 ) );
}

// DO NOT ADD ANY CODE BEFORE THIS FUNCTION
void _start( void ) {
	REG_DISPCNT = MODE_3 | BG2_ENABLE;	// Set framebuffer mode

	game_drawborder( );

// Enter infinite loop 
main_loop:
	goto main_loop;
}
I haven't gotten far but that compiles to around 60 bytes, it'd be smaller but for some reason thumb code isn't working.
Here is my cheap makefile...
Code:
CC=arm-elf-gcc
OBJCOPY=arm-elf-objcopy
CFLAGS=-Os -fomit-frame-pointer -mcpu=arm7tdmi -I/home/lazy/dev/tools/devkitARM/libgba/include -c
LFLAGS=-mno-fpu -nostdlib

minitris.o:
	$(CC) $(CFLAGS) -o minitris.o minitris.c

minitris.elf: minitris.o
	$(CC) $(LFLAGS) -o minitris.elf minitris.o

minitris.gba: minitris.elf
	$(OBJCOPY) -O binary minitris.elf minitris.gba

all: clean minitris.gba

clean:
	rm -fv *.o
	rm -fv *.elf
	rm -fv *.gba
Any help is appreciated since I'm new to gcc and this won't work unless _start is at the beginning of the binary.
  
Reply With Quote
Re: gcc function order
Old
  (#2)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default Re: gcc function order - 27-11-2005

not sure if a custom link script (like that one in Metamod-p) will work, but I have never done this so I don't know further.

Last edited by Whistler; 27-11-2005 at 05:48..
  
Reply With Quote
Re: gcc function order
Old
  (#3)
Onno Kreuzinger
aka: memed / Server Admin
 
Onno Kreuzinger's Avatar
 
Status: Offline
Posts: 705
Join Date: Jan 2004
Location: germany
Default Re: gcc function order - 28-11-2005

ouch, w/o any libc you will be very much on you own, no one does this for long

Prehaps give dietclib a try, it's commonly used in embedded and mirco linux systems (4 mb ram+).

--OK


sunny morning view from my balcony:

see our WIKI!
see our filebase!
  
Reply With Quote
Re: gcc function order
Old
  (#4)
Lazy
Member
 
Lazy's Avatar
 
Status: Offline
Posts: 236
Join Date: Jan 2004
Location: Toronto, Ontario, Canada
Default Re: gcc function order - 28-11-2005

Actually, the only ram I have to work with is 256kb - and even that is cut down since in my case it is shared with the program itself.
http://en.wikipedia.org/wiki/Gba

I just want to see if I can code a simple game in less than 256 bytes. I know it has been done for x86 but I wanted to see if it's possible with C since all of the ones I looked at were done in assembly.

But it's not going anywhere since gcc seems to put _start wherever it wants which results in some other function getting called and the system not being initialized.

I'm going to try a few more things later tonight and see what happens.
  
Reply With Quote
Re: gcc function order
Old
  (#5)
Onno Kreuzinger
aka: memed / Server Admin
 
Onno Kreuzinger's Avatar
 
Status: Offline
Posts: 705
Join Date: Jan 2004
Location: germany
Default Re: gcc function order - 29-11-2005

well, then good luck


sunny morning view from my balcony:

see our WIKI!
see our filebase!
  
Reply With Quote
Re: gcc function order
Old
  (#6)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: gcc function order - 30-11-2005

You should ask the guys at the demo scene (start at www.pouet.net if they have a forum there). They know how to do heaps of things in 256 bytes.



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: gcc function order
Old
  (#7)
Lazy
Member
 
Lazy's Avatar
 
Status: Offline
Posts: 236
Join Date: Jan 2004
Location: Toronto, Ontario, Canada
Default Re: gcc function order - 02-12-2005

Bah.
Got too frustrated with it so I decided to port sdl sopwith to the nintendo ds.
Its working very well on real hardware so once I get the input and sound finished I can release it into the wild.
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com