#44842 - jormundgard - Sun Jun 05, 2005 11:08 pm
Hi, I'm new to the forum.
I'm trying to do some simple GBA work on the Mac and, I guess for the heck of it, tried to build my own gcc compiler. I did manage to set something up that works (on the Boycott emulator at least). I used Jeff Frohwein's crt0.S bootstrap(?) and just tried a simple program that draws a pixel in the center of the screen.
Anyway, the program works fine if I compile and assemble everything without the -mthumb tag (and with -mthumb-interwork, if it's relevant). But when I also use the -mthumb tag, which I figured was a good idea, the emulator accepts the rom but the pixel isn't drawn. Does anyone have an idea what I could be doing wrong? Did I build a bad gcc, or is there maybe another mistake somewhere?
#44843 - strager - Sun Jun 05, 2005 11:13 pm
Are you compiling the crt0 script with the -mthumb command? That may be the problem, but I'm not too sure.
#44844 - jormundgard - Sun Jun 05, 2005 11:21 pm
That was my first guess too. But it seems to happen even if I only use -mthumb on the C code. I'm just using -mthumb-interwork with the assember and crt0.
Oh, BTW, in case it's relevant, the C code is just a simple main() function, with some helper functions listed in Jeff F's crt0.S text readme. I admit that I don't really know exactly what's going on, and am mostly feeling my way through right now :).
#44846 - strager - Sun Jun 05, 2005 11:38 pm
Try to do a -save-temps and see if the output is ligit. Usually the instructions leek, and that's why I prefer ARM code.
#44847 - SmileyDude - Sun Jun 05, 2005 11:44 pm
strager wrote: |
Are you compiling the crt0 script with the -mthumb command? That may be the problem, but I'm not too sure. |
The crt0.s file is written in assembly -- compiling it in thumb mode or not doesn't make any difference, since the code in the file specifies what mode it is.
Can you post the code that you're trying to compile along with the commands you use to compile, link, and build the .gba file?
_________________
dennis
#44848 - strager - Sun Jun 05, 2005 11:50 pm
SmileyDude wrote: |
strager wrote: | Are you compiling the crt0 script with the -mthumb command? That may be the problem, but I'm not too sure. |
The crt0.s file is written in assembly -- compiling it in thumb mode or not doesn't make any difference, since the code in the file specifies what mode it is. |
I know that, but just to make sure... :-)
And yes, the source and Makefile would help.
#44850 - jormundgard - Mon Jun 06, 2005 12:09 am
Here's the Makefile (hopefully it's OK to just post it directly):
Code: |
ARMCC = arm-thumb-elf-gcc
ARMAS = arm-thumb-elf-as
ARMLD = arm-thumb-elf-ld
CFLAGS = -c -mthumb-interwork
ASFLAGS = -mthumb-interwork
LDFLAGS = --script lnkscript
all: HelloWorld.gba
HelloWorld.gba: HelloWorld.elf
arm-thumb-elf-objcopy -O binary HelloWorld.elf HelloWorld.gba
HelloWorld.elf: HelloWorld.o crt0.o
$(ARMLD) $(LDFLAGS) -o HelloWorld.elf HelloWorld.o crt0.o
HelloWorld.o: HelloWorld.c
$(ARMCC) $(CFLAGS) -o HelloWorld.o HelloWorld.c
crt0.o: crt0.S
$(ARMAS) $(ASFLAGS) -o crt0.o crt0.S
|
And here's the main.c
Code: |
typedef unsigned int u32;
#define IN_IWRAM __attribute__ ((section (".iwram")))
extern u32 __FarFunction (u32 (*ptr)(), ...); // Reference to routine in crt0.S
extern void __FarProcedure (void (*ptr)(), ...); // Reference to routine in crt
0.S
// u32 IWRAMCode (u32 *FuncAddr, int param1, int param2) IN_IWRAM;
int main(void)
{
// Create pointer to VRAM
unsigned short* videoBuffer = (unsigned short*) 0x6000000;
// Setup Video Mode 3
*(unsigned long*) 0x4000000 = (0x3 | 0x800);
// Draw a white pixel centered on the screen
videoBuffer[240 * 80 + 120] = 0xFFFF;
// Loop until power-down
while(1);
return 0;
}
u32 IWRAMCode (u32 *FuncAddr, u32 param1, u32 param2)
{
u32 SomeValue;
// Note: The first parameter for this function MUST be
// the *FuncAddr. Do NOT remove this parameter even
// though you probably may not need it.
return (SomeValue);
}
void AgbMain (void)
{
u32 ReturnValue = __FarFunction (IWRAMCode, 1, 2);
}
|
(Basically cribbed from Jonathan Harbor's tutorial)
#44853 - jormundgard - Mon Jun 06, 2005 12:19 am
strager wrote: |
Try to do a -save-temps and see if the output is ligit. Usually the instructions leek, and that's why I prefer ARM code. |
I'm nowhere near literate in ARM assembly, so I can't say much, but at the least I can see that my builds are definitely producing 32 bit ARM code without the -mthumb flag (or at least, there are no .code 16 statements), and 16 bit Thumb code with the flag. I figure that the emulator is fine, so I will try to take a closer look at the assembly output.
#44893 - jormundgard - Mon Jun 06, 2005 4:52 pm
I noticed that some of my C libraries don't seem to support -mthumb-interwork and, for all I know, may have been compiled as ARM code (meaning that I may have bungled the build). Would this simple program use any of the C libraries? Does every C program use the libraries in some way? Or does my confusion run even deeper than all this?
#45049 - Cearn - Tue Jun 07, 2005 9:32 am
jormundgard wrote: |
Code: | // Setup Video Mode 3
*(unsigned long*) 0x4000000 = (0x3 | 0x800); |
|
Background 2 is 0x0400, not 0x0800, so you might want to try that. Or even better, create a list of defines as raw numbers can be confusing. For interworking libraries, I think it's necessary to include -mthumb-interwork to the linker flags as well.
#45074 - jormundgard - Tue Jun 07, 2005 2:30 pm
Cearn wrote: |
Background 2 is 0x0400, not 0x0800, so you might want to try that. Or even better, create a list of defines as raw numbers can be confusing. For interworking libraries, I think it's necessary to include -mthumb-interwork to the linker flags as well. |
My linker doesn't even seem to accept the -mthumb-interwork tag. Maybe that's just because it isn't producing any new assembly code, so doesn't need it. But could there also be a problem with my linker?
(PS thanks for mentioning the DISPCNT error)