GP32 Wtf


nihil-00

Member
Joined
Feb 9, 2003
Messages
110
Age
40
so, as i'm trying over and over again, seems like you CAN'T istantiate any variable or constant class at global scope (or better, you can, but it's useless)

this is ridiculous.
does anybody know the reason of this stupid beahaviour of gcc(under windows)?


edit:
more infos:
i tried either with a namespace, and with a class with static const members initialized at global scope.
it does work no way.
 
Have you tried using a different devkit such as devkitARM? I noticed some really odd behavior like that when trying to use the Windows toolchain off Mirko's site with C++.
 
nihil-00 posted on Jul 30 2004 at 03:39 AM said:
so, as i'm trying over and over again, seems like you CAN'T istantiate any variable or constant class at global scope (or better, you can, but it's useless)

this is ridiculous.
does anybody know the reason of this stupid beahaviour of gcc(under windows)?


edit:
more infos:
i tried either with a namespace, and with a class with static const members initialized at global scope.
it does work no way.
i've already told you, but you didn't listened.

i've just tried with variables. global variables make your programm crash or behave odd in all cases.
i've tried with gcc 3.4.1, devkitarm and mrmirko's devkit so far and all had the same result. maybe it works with ads.
someone told me that it maybe has something to do with the crt0., but i'm aint sure.

btw: in the crt0 that comes with http://www.abc21.dial.pipex.com/hand_build...32_gcc_tool.htm is a small info on how to get the crt0 to call constructors of global classes i think.
 
Last edited by a moderator:
no_skill: uhm...
it doesn't crash, and it isn't odd, either.
as you said, i think it's just it doesn't call costructors for classes, at global scope.
it did crash, in your case, because you called functions that assumed non null vars on null vars :\

however, i din't listen at you because i didn't believe your words.. i just tought it was just a different matter.

ok, so now that i'm interested in this stuff, we are two now try to solve this problem.
however, thank you about the devkit advice.. i was going to loose some more time...

thank you..

edit:yes, it's a crt0.s matter (no .ctors section)
 
i encountered odd behaviour like missing text on the screen buffer depending on whetever the buffer variables were global. (all initialized in main).

i have not tested global classes on the gp32 so far.
 
generalnmx: no way..
it's about constructors...
there's something missing in the crt0.s..
someone with asm knowledge willing to help?
 
nihil-00 posted on Jul 30 2004 at 06:45 PM said:
generalnmx: no way..
it's about constructors...
there's something missing in the crt0.s..
someone with asm knowledge willing to help?
I told you some days ago, to use the provided crt0.s in the help dir, it is complete, and from spivvy, it will solve youre c++ problems. But iam repeating myself...
 
Last edited by a moderator:
ok, so to have a working c++ solution, you need mmulib. to add mmulib, you need to patch libc. i tried at that, but failed... anyone with a working (patched) libc.a? in the meantime, i will try again.
edit: ok;i correctly patched the libc. if anyone needs, let me know (just a stupid error about instructing gcc to compile in soft float mode)

edit2:
global constructors don't work this way, either.
other than that, mmulib crashes geepee.

uhm.
this is becoming frustrating.
 
nihil-00 posted on Jul 31 2004 at 01:13 AM said:
ok, so to have a working c++ solution, you need mmulib. to add mmulib, you need to patch libc. i tried at that, but failed... anyone with a working (patched) libc.a? in the meantime, i will try again.
edit: ok;i correctly patched the libc. if anyone needs, let me know (just a stupid error about instructing gcc to compile in soft float mode)

edit2:
global constructors don't work this way, either.
other than that, mmulib crashes geepee.

uhm.
this is becoming frustrating.
are you using glibc or newlib ?
 
Last edited by a moderator:
nihil-00 posted on Jul 31 2004 at 11:38 AM said:
newlib...
c++ is working here out of the box, with global classes.

cpp.cpp:
#include "gp32.h"
#include "cpp_prototypes.h"
//#include "cpp.h"

using namespace std;

class basis {
private:
int wert;
public:
basis() {}
basis(int wert) {this->wert=wert;}
int get_private() { return wert;}
};


int calling_cpp() {

basis *donald = new basis(100);
int i = donald->get_private();
delete donald;
return i;

//works also:
//basis pluto(200);
//return pluto.get_private();
}


main.cpp:
#include "gp32.h"
#include "cpp_prototypes.h"
//#include "cpp.h"

u16 *framebuffer;

int calling_cpp();

int main() {

int x;
framebuffer = (u16*) FRAMEBUFFER1;
gp_setCpuspeed(33);
gp_initFramebuffer((u32)framebuffer,16,85);

gp_clearFramebuffer16(framebuffer,0xffff);

gp_drawString(30,30,22,"Starting c++ Programm ",0xf800,framebuffer);
x=calling_cpp();
if (x==100)
gp_drawString(30,50,22,"Ending c++ Programm ",0xf800,framebuffer);


while (1) { if ( gp_getButton()&BUTTON_A) gp_Reset(); }

}


COMPILING:
arm-elf-c++ -I../lib.src/include -O2 -s -w -mtune=arm9tdmi -c -o main.o main.cpp
arm-elf-c++ -I../lib.src/include -O2 -s -w -mtune=arm9tdmi -c -o cpp.o cpp.cpp
arm-elf-gcc -c -o crt0.o crt0.S
arm-elf-g++ -nostartfiles -s -Wall -Wl,-Map,Test.map -T lnkscript crt0.o -o cpp.elf main.o cpp.o -L../lib -lmirkoSDK
arm-elf-objcopy -O binary cpp.elf cpp.bin
b2fxec -a Mirko_Roller -t SDK_EXAMPLE_cpp cpp.bin cpp.fxe


iam using spiivvys crt0,S in the help dir, the other one works also too ...
 
Last edited by a moderator:
try this,please:

Code:
#include "gp32.h"
#include "cpp_prototypes.h"

class col{
  public:
  u16 colour;
  col():colour(0){};
  col(const u16 &value):colour(value){};
};

col giangi(0xF800);

int main(){

framebuffer = (u16*) FRAMEBUFFER1;
gp_setCpuspeed(33);
gp_initFramebuffer((u32)framebuffer,16,85);

gp_clearFramebuffer16(framebuffer,giangi.colour);

while(1);
return 1;
}

this could produce a red screen.
insted, you get a black one.
this is because giangi's constructor doesn't get called, and you have value 0, insteaf of 0xF800 for giangi.colour.

let me know if i predicted well.
 
If nothing else works, you can try using a singleton pointer design. That way you have all the benefits of a single-instance global class without problems with default constructors (since it doesn't use them). I've used that in the past with compilers that don't initialize constructors properly with C++.

Code:
//CSingleton.h

class CSingleton {
private:
	static CSingleton* pinstance; //static pointer

	int blah; //private variable

protected:
	CSingleton() {};
	~CSingleton() {};

public:
	//singleton pattern functions
	static CSingleton* Instance();	//use this to obtain the one and 
    	//only instance of this class
	void Intialize(); //intialize global variables
	void Release(); //release global variables and deconstruct class

	void changeBlah (int newBlah){blah=newBlah;}
	int getBlah(){return (blah);}
};

Code:
//CSingleton.cpp

//set static pointer instance to NULL
CSingleton* CSingleton::pinstance = NULL;

//return only ONE instance
CSingleton* CSingleton::Instance()
{
	if (pinstance == NULL)
  pinstance = new CSingleton;

	return(pinstance);
}

//intialize all variables!
void CSingleton::Intialize()
{
	//only initialize once
	if (pinstance)
	{
  blah = 0;
	}
}

//release all pointers and stuff!
void CSingleton::Release()
{
	if (pinstance)
	{
  //clean up memory and other stuff
  delete pinstance; //remove singleton pointer
  pinstance = NULL;
	}
}
 
thank you :)
it's the first time i hear about them :)
i need to google i bit, i fear :\

ps: i heard that loki666 managed to get c++ working on ads (with mr mirko's??)...
loki, could you please tell us if ads solves this problem?
 
Does anyone know how to get these working in C++? I got interested in this thread so have been giving it a go. Note that I'm using my own g++ toolchain, so the ads_crt0.s in the help dir of Mirko's sdk is of course no use...

So far I have bits of the following:
_main must be called somehow, this sets up constructors.
_main should b called automatically if I change crto.s to call main rather than Main
I need to call gpstart to setup the sdk before my c++ construtors (Since my sbrk just grabs a large chunk of memory from gp_malloc).
Something about a .ctor section in crt0.s was mentioned?

What I have tried:
i) First I tried manually calling _main from the end of gpstart.c (after the sdk is set up). This did not work, since the _main symbol can not be found. I looked for it in the standard libs (with nm and grep) -> there is no such symbol.
ii) I figured that I may to use the real main and in a c++ file. So I wrote a file Kludge.cpp as follows, just to test if the constructor was called -> forwards to the usual main.:
extern "C"
{
void Main(int arg_len, char * arg_v);
}

class Kludge
{
public:
Kludge()
{
Main(0, 0);
}
};

static Kludge kludge;

int main(void)
{
}

Still no luck. I even tried calling _main directly again from this cpp file...

Has anyone actually got this working properly in g++?

Thanks,

Mark
 
Doh! Found at least one useful thing, while trying to find info on this c++ stuff. I hadn't been setting the -mtune=arm920 setting in my makefile, this gives about another 10% boost to the framerate in my port of atari800.

Mark
 
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.
 
Last edited by a moderator:
OK,

This is quite strange.

Under devkitARM I was able to run your example nihil-00 successfully. The constructor is called, the output is red.

However, it only worked if I called gp_initRTC(); at the beginning. Odd....

Here is the code I used, works perfectly in the latest devkitARM:
Code:
#include "gp32.h"
#include "cpp_prototypes.h"

class col{
 public:
 u16 colour;
 col():colour(0){};
 col(const u16 &value):colour(value){};
};

col giangi(0xF800);

u16 *framebuffer;

int main(){

framebuffer = (u16*) FRAMEBUFFER1;
gp_setCpuspeed(33);
gp_initRTC();
gp_initFramebuffer(framebuffer,16,85);
gp_clearFramebuffer16(framebuffer,giangi.colour);

while(1);
return 1;
}
 
Back
Top