Liquid Snake
03-19-2004, 05:23 PM
I put together a cross compiler for the gameboy advance and it works, but it falls apart when I add my own functions. If I declare functions in either the main .c file or a header file, execution begins with that function instead of with main() like it should, how can I fix this?
Liquid Snake
03-19-2004, 06:49 PM
This is the C code:
#include"ykgba.h"
void dummy(void)
{
//main();
}
main()
{
*(short*)0x4000000=MODE3|BG0|BG1|BG2;
short* VRAM=(short*)0x6000000;
*(short*)0x4000000=MODE3|BG0|BG1|BG2;
int x=0;
while(1)
{
for(x=0; x<5000; x++)
{
VRAM[x]=x;
}
}
return 0;
}
/////////////////////////////
This is GCC's output in assembly:
.file "prog.c"
.text
.align 2
.global dummy
.type dummy, %function
dummy:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 1, uses_anonymous_args = 0
mov ip, sp
stmfd sp!, {fp, ip, lr, pc}
sub fp, ip, #4
ldmea fp, {fp, sp, pc}
.size dummy, .-dummy
.align 2
.global main
.type main, %function
main:
@ args = 0, pretend = 0, frame = 8
@ frame_needed = 1, uses_anonymous_args = 0
mov ip, sp
stmfd sp!, {fp, ip, lr, pc}
sub fp, ip, #4
sub sp, sp, #8
mov r2, #67108864
mov r3, #1792
add r3, r3, #3
strh r3, [r2, #0] @ movhi
mov r3, #100663296
str r3, [fp, #-16]
mov r2, #67108864
mov r3, #1792
add r3, r3, #3
strh r3, [r2, #0] @ movhi
mov r3, #0
str r3, [fp, #-20]
.L3:
mov r3, #0
str r3, [fp, #-20]
.L6:
ldr r2, [fp, #-20]
mov r3, #4992
add r3, r3, #7
cmp r2, r3
ble .L9
b .L3
.L9:
ldr r3, [fp, #-20]
mov r2, r3, asl #1
ldr r3, [fp, #-16]
add r2, r2, r3
ldrh r3, [fp, #-20] @ movhi
strh r3, [r2, #0] @ movhi
ldr r3, [fp, #-20]
add r3, r3, #1
str r3, [fp, #-20]
b .L6
.size main, .-main
.ident "GCC: (GNU) 3.3.2"
////////////////////////////////////////////////
Notice that the function "dummy" comes before the main function.
mdwatts
03-20-2004, 11:13 AM
Moved to the Programming/Scripts forum where you will hopefully receive assistance.
bwkaz
03-20-2004, 01:49 PM
Sounds to me like the cross compiler isn't actually working properly... does it help if you put a prototype for your function up above main, but put the actual function definition after it instead?
Liquid Snake
03-20-2004, 11:05 PM
No, it doesn't help. The compiler doesn't seem to give priority to the main function. Actually, I can rename main to whatever I want and gcc doesn't complain.
bwkaz
03-21-2004, 03:15 PM
Then I have no idea. I don't know enough about the internals of gcc to even start to figure out where to look for the bug (and yeah, I'm fairly sure it's a bug in your gcc).
Does it matter what the function is named? Maybe gcc is outputting functions in alphabetical order or something...
Any chance of there being a newer version of the cross compiler? Or, is there a maintainer for it that might know? Actually, if there is, you might want to look for a FAQ on the issue -- I doubt that one will exist, but it can't hurt.
Liquid Snake
03-21-2004, 07:32 PM
GCC turns the functions into assembler based on their position in the C file, name doesn't seem to make a difference.
binaryDigit
03-22-2004, 02:38 PM
it sounds like the entry point isn't being defined so it is defaulting to whatever it finds first.
are you linking to a crt.o file?
try using _start() as your main and see if it makes a difference.
you can also use -e with ld to change the entry point.
bwkaz
03-22-2004, 08:19 PM
Originally posted by Liquid Snake
GCC turns the functions into assembler based on their position in the C file, name doesn't seem to make a difference. Wait -- so when you put the function definition after main, but the function prototype before main, it worked?