GP32 Wtf


dalto: with "the crt0.s in the help directory" mr.mirko intended the crt0 that meant to be used with mmulib.
it's basically the same crt0.s that you use with the standard gp lib for gcc, but you can use with mr.mirko's sdk, if you patch libc.a
the standard crt0.s that comes with mr mirko's sdk is less complex, but however both of them (the one in the help dir and the standard) give the same problem with global constructors.

i'm happy about your findings, however.
quite strange though that it works only if you call gp_RTC()

uh... the mistery thickens <_<


edit: dalto, can you show us the makefile you use with devkitarm?
 
Dalto posted on Aug 1 2004 at 02:52 PM said:
mr.mirko posted on Jul 30 2004 at 08:50 PM said:
use the provided crt0.s in the help dir, it is complete, and from spivvy, it will solve youre c++ problems.
There is not crt0.S in the help directory just one for use with ADS.
/help/gp32mem_upgrade/crt0/crt0.S

U need a modfied newlib to use it...


For me the complete c++ problems are memory problems, It has nothing to do with the compiler. The compiler genereates always correct code, but if we later start the compiled code, some memory segments could point to null, ( there are memory segments for variables, the code, the stack ... ) it is all initiallized at crt0.S, at programm start on gp32.

The only way to solve this, is to check crt0.S, and find the bug ...

I could be wrong, but to 99% i think its this problem...
 
Last edited by a moderator:
The non-gpsdk crt0.s from devkitadvance has a call to _init. I tried adding this to the sdk crt0.s, but the symbol is not defined anywhere.

I found this article which has some info about the calling of construtors/destructors. Specifically it mentions the nostartfiles link option and having to jump through hoops if it is used (but no mention of the hoops!).

http://www.dwheeler.com/program-library/Pr...cellaneous.html

Mark
 
foft posted on Aug 1 2004 at 06:53 PM said:
The non-gpsdk crt0.s from devkitadvance has a call to _init. I tried adding this to the sdk crt0.s, but the symbol is not defined anywhere.

I found this article which has some info about the calling of construtors/destructors. Specifically it mentions the nostartfiles link option and having to jump through hoops if it is used (but no mention of the hoops!).

http://www.dwheeler.com/program-library/Pr...cellaneous.html

Mark
the _init symbole is defined in the linkscript
 
Last edited by a moderator:
What about crtbegin.o, crtend.o, crti.o and crtn.o? From the gcc makefile it says:
# Compile two additional files that are linked with every program
# linked using GCC on systems using COFF or ELF, for the sake of C++
# constructors.

They look related to me and are what -nostartfiles excludes.

Mark
 
Yep - that fixed it:)

Because of the custom crt0.o and linkscript I had to have -nostartfiles. This also excluded crtn.o, crti.o, crtbegin.o and crtend.o. These can be linked manually, but linking order is important.

What I had to do:
_init needs calling to setup the constructors. In my test I added to crt0.s as. Presumably it can also be done in main... Preferably after sdk init!:
Code:
--- crt0.s      2004-08-01 18:44:28.000000000 +0100
+++ ../../../test/src/build/crt0.s      2004-05-01 12:16:54.000000000 +0100
@@ -23,7 +23,7 @@
 @ setup before executing 'main ()'. Using 'main ()' also increases
 @ your program size by ~5500 bytes.
 
-@ .equ __OfficialEntry, 1
+ .equ __OfficialEntry, 1
 
 @ The official sdt dev kit initializes various things in init.o
 @ Crt0.S performs similar tasks for compatibility. If you don't
@@ -132,10 +132,7 @@
 .ifdef __OfficialEntry
         ldr     r3,=Main
 .else
-        ldr     r3,=_call_main
-       mov     lr,r3
-       ldr     r3,=_init
-       bx      r3
+        ldr     r3,=main
 .endif
         bx  r3           @ Init.o uses 'mov pc,r3' but
                          @ 'bx r3' is used here instead. This way
@@ -241,11 +238,6 @@
 
 .endif
 
-_call_main:
-       mov     lr, #0
-       ldr     r3,=main
-       bx      r3
-
     .ALIGN
     .POOL

The in the linker you need to add these crtbegin.o etc. So in my makefile my LD line becomes:
Code:
$(PROG).elf: $(OBJS)
	$(LD) $(LFLAGS) -o $(PROG).elf crti.o crtbegin.o $(OBJS) $(LIBS) crtend.o crtn.o

Now my constructors seem to work. At least I called Main(0,0) from one as shown in an earlier post & my app runs.

Thanks,

Mark
 
As a somewhat easier fix (if using the official sdk), forget the crt0.s changes...

Just link in crti.o crtbegin.o before your objects and crtend.o crtn.o after your objects then use the following gpmain.c. Your main code should then go in main as usual c/c++...:

Code:
void GpMain(void * arg) 
{
	_init();
	main(0,0);
}

Good luck,

Mark
 
foft, could you please release a package with the patched crt0.s, the right linkscript and a makefile?


ps: THANK YOU! :D
 
OK, just put a basic archive. Hope it is useful. Follow the link from www.scrameta.net

Thanks,

Mark

P.S. (edit): This package does not have the patched crt0.s. I decided it was better to call _init in gpmain. Then it is after all the sdk setup. Since the constructors may assume the sdk is already set up.

P.S. (edit 2!): The crtbegin.o etc are under the gcc install. on mine they are in /usr/local/lib/gcc/arm-elf/3.4.0/, but it will of course vary depending on where you installed it!
 
have you tried your findigns with mr mirko's sdk?


to me compiles, but crashes both geepee and gp32

edit: did anyone notice that the make.exe that comes with devkitarm 8 is bugged?


ps:
thanks to foft, i finally got constructors working under mr mirko's sdk lib, with devkitarm.

VERY GOOD.
thank god.
 
Makefile:
Code:
CROSS := arm-elf-
CC    := $(CROSS)gcc
CXX   := $(CROSS)g++
LD    := $(CROSS)g++
AS    := $(CROSS)as
AR    := $(CROSS)ar
OBJCOPY := $(CROSS)objcopy
#CRT   := ./ld/crt0
#LNK   := ./ld/lnkscript
#CRT   := ./ld/c++crt0
#LNK   := ./ld/c++lnkscript
CRT   := ./ld/gp32_crt0
LNK   := ./ld/gp32.ld
#CRT   := ./ld/gp32_gpsdk_crt0
#LNK   := ./ld/gp32_gpsdk.ld

#INIT  := ./init/
#INIT  := ./init2/
#INIT  := ./init3/
INIT  := ./init4/

PRG := pappa
LIBS := -Lc:/gp32dev/lib -lmirkoSDK
INCLUDES := -Ic:/gp32dev/lib.src/include

CFLAGS := $(INCLUDES) -O2 -s -w -mtune=arm9tdmi
CXXFLAGS := $(CFLAGS)

OBJS := pappa.o

all:	$(OBJS)
	$(CC) -c -o $(CRT).o $(CRT).s
	#$(LD) -nostartfiles -s -Wall -Wl,-Map,Test.map -T $(LNK) $(CRT).o -o $(PRG).elf $(OBJS) $(LIBS)
	$(LD) -nostartfiles -s -Wall -Wl,-Map,Test.map  -T $(LNK) $(CRT).o -o $(PRG).elf $(INIT)crti.o $(INIT)crtbegin.o $(OBJS) $(LIBS) $(INIT)crtend.o $(INIT)crtn.o
	$(OBJCOPY) -O binary $(PRG).elf $(PRG).bin
	b2fxec -a nihil -t pappa $(PRG).bin $(PRG).fxe

install:
	gplink put $(PRG).fxe gpmm

clean:
	rm -f *.o *~ Test.map *.bin *.elf

with make.exe found in mr.mirko's distrubution:
Code:
arm-elf-g++ -Ic:/gp32dev/lib.src/include -O2 -s -w -mtune=arm9tdmi   -c -o pappa.o pappa.cpp
arm-elf-gcc -c -o ./ld/gp32_crt0.o ./ld/gp32_crt0.s
#arm-elf-g++ -nostartfiles -s -Wall -Wl,-Map,Test.map -T ./ld/gp32.ld ./ld/gp32_crt0.o -o pappa.elf pappa.o -Lc:/gp32dev/lib -lmirkoSDK
arm-elf-g++ -nostartfiles -s -Wall -Wl,-Map,Test.map  -T ./ld/gp32.ld ./ld/gp32_crt0.o -o pappa.elf ./init4/crti.o ./init4/crtbegin.o pappa.o -Lc:/gp32dev/lib -lmirkoSDK ./init4/crtend.o ./init4/crtn.o
arm-elf-objcopy -O binary pappa.elf pappa.bin
b2fxec -a nihil -t pappa pappa.bin pappa.fxe

b2fxeC v0.5d BETA - (c) 2002-4 Jouni 'Mr.Spiv' Korhonen

Crunching (0/52788)
Crunched 50.9% - total 25944 bytes


with minsys make.exe:
Code:
arm-elf-g++ -Ic:/gp32dev/lib.src/include -O2 -s -w -mtune=arm9tdmi   -c -o pappa
.o pappa.cpp
arm-elf-g++.exe: no input files
make: *** [pappa.o] Error 1

make clean works good.
tried different makefiles, all with no results (tried also with the atari800 makefile).
funny isn't it? :)
 
Have you tried removing the :'s? MSYS make is much more *NIX-like than the one with Mirko's

EDIT: Just to be clear, I mean the colons that are used after the drive letters
c/gp32dev/lib.src/include
instead of:
c:/gp32dev/lib.src/include
 
nihil-00 posted on Aug 1 2004 at 10:12 PM said:
have you tried your findigns with mr mirko's sdk?


to me compiles, but crashes both geepee and gp32

edit: did anyone notice that the make.exe that comes with devkitarm 8 is bugged?


ps:
thanks to foft, i finally got constructors working under mr mirko's sdk lib, with devkitarm.

VERY GOOD.
thank god.
There is a different linkscript/crt0.s with mirko's sdk. The gp sdk one I used will not work. I presume this is how you got it working in the end?

Note that the crt0.s supplied for mirko's sdk already calls _init before main. So the constructors are called before main (as expected), as long as you link those extra crt files. But be aware the constructors are called before the sdk init probably. Note that I don't know if Mirko's sdk needs initialising before malloc etc, since I've not used it. It may not be an issue at all.

Thanks,

Mark
 
Last edited by a moderator:
nihil-00 posted on Aug 2 2004 at 02:09 AM said:
Code:
CFLAGS := $(INCLUDES) -O2 -s -w -mtune=arm9tdmi
Wjat do lowercase -s and -w do? I can't find them in the gcc manpage (there are too many options!). Also am I better off using -mtune=arm9tdmi or -mtune=arm920?

Mark
 
Last edited by a moderator:
quick SUM UP:
to get global classes' constructors in c++ working, there are two ways, depending on which library you do use.
for the ones using gpsdk, just follow foft instructions, as seen in previous posts.
for the ones using mr. mirko's sdk, use devkitarm with gp32_crt0.s and gp32.ld found on arm-elf/lib directory on devkit arm package. when compiling, link as described in foft post, paying attention to linking order (crti.o crtbegin.o $(OBJS) $(LIBS) crtend.o crtn.o)
the crt*.o files you have to use are the ones (usually) found in
(devkit path)/lib\gcc\arm-elf\3.4.1

on foft's site and below, are some example makefiles.
some advices: put the crt*.o objects in a directory different from the one from wich you use make, otherwise make clean will erase them. just use a subdirectory or specify the original location...

..and now... the THANKS
to everyone who got involved in this discussion, and helped to solve the problem.
thanks to foft for giving us the final result, dalto for bein so much empathic and helpful, no_skill for noticing the problem to mr mirko, mr mirko for being interested in problems users have with his lib, and to the few other I'm sure i forgot.
I'm sure this little achievement will be usefull for lots of people.



ps:
From the gcc manual:
-s
Remove all symbol table and relocation information from the executable.
-w
Suppress all warnings, including those which GNU CPP issues by default.

don't know about the arm9tdmi option, i was using default compiling settings from mr mirko's makefiles...
good time to give it a twist :)

about the minsys make.exe...
i tried without semicolons, and it doesn't help. doesn't matter, however, since i'm using make.exe from the toolchain package on mr mirko's site, while using devkitarm for the rest.
 
nihil-00 posted on Aug 2 2004 at 08:35 AM said:
quick SUM UP:
to get global classes' constructors in c++ working, there are two ways, depending on which library you do use.
for the ones using gpsdk, just follow foft instructions, as seen in previous posts.....

Or you could just sod C++ off entirely and use C ;-)

Heh
 
Last edited by a moderator:
Back
Top