No C++ compiler for IOP?
No C++ compiler for IOP?
Is there any reason why there is no C++ compiler for the IOP?
I'm currently using the precompiled compilers for windows but they dont have a C++ compiler for the IOP.
I also can't find any toolchains that do.
I'm currently using the precompiled compilers for windows but they dont have a C++ compiler for the IOP.
I also can't find any toolchains that do.
I want to port my existing C++ application to the IOP. Converting to C just for the IOP is not an option. Without going into a C vs C++ discussion, what would be the easyest way to get C++ to compile for the IOP?
I don't need the STL or any other libraries and I've already got my own new and delete functions.
I don't need the STL or any other libraries and I've already got my own new and delete functions.
You would need to build the iop-g++ first, I dont know of anyone who has attempted this before. The "easist" way to do this would be to look into how ee-g++ is configured and built, and then try to make it work for iop-g++. MIPS R3000 is supported by g++.
However you might run into issues with IRX output, as this is a homebrew patch and it might be gcc specific, but I'm not sure. Then you will probably also need to patch the PS2SDK IOP headers with the extern "C" (see http://en.wikipedia.org/wiki/Compatibil ... nd_C%2B%2B). There will probably be additions problems, so I'm afraid there is no easy way :-)
I'd personally just port it over to C, as I think you might be looking at least a few days works just to get everything running smoothly and you will probably run into more problems down the road aswell. Whereas iop-gcc has been tested over a long period of time and considered to be stable and compatible with PS2SDK out of the box.
If you succeed in building iop-g++, and making it work with PS2SDK, please share the patches :-)
However you might run into issues with IRX output, as this is a homebrew patch and it might be gcc specific, but I'm not sure. Then you will probably also need to patch the PS2SDK IOP headers with the extern "C" (see http://en.wikipedia.org/wiki/Compatibil ... nd_C%2B%2B). There will probably be additions problems, so I'm afraid there is no easy way :-)
I'd personally just port it over to C, as I think you might be looking at least a few days works just to get everything running smoothly and you will probably run into more problems down the road aswell. Whereas iop-gcc has been tested over a long period of time and considered to be stable and compatible with PS2SDK out of the box.
If you succeed in building iop-g++, and making it work with PS2SDK, please share the patches :-)
The compiler seems to work fine! I've got some C++ code to compile and run in IOP, showing a "hello world" in ps2client.
Instead of modifying every header file, I included the header files as extern "C". This seems to work fine as I was able to do a printf.
There is still one problem though, the constructors of the global classes aren't called, so I'll have to find a way to do that in the _start function.
Instead of modifying every header file, I included the header files as extern "C". This seems to work fine as I was able to do a printf.
There is still one problem though, the constructors of the global classes aren't called, so I'll have to find a way to do that in the _start function.
The crt0.s for EE in PS2SDK calls the global constructors for C++ among things, you might want to look into it and add your own simple crt0.s for IOP and then use main() as the entry function instead of _start().Maximus32 wrote: There is still one problem though, the constructors of the global classes aren't called, so I'll have to find a way to do that in the _start function.
Relevant code from EE crt0.s
Code: Select all
# Call global constructors through _init().
la $8, _init
beqz $8, 1f # does _init() exist?
nop
jalr $8
nop
1: nop
Code: Select all
# Call global deconstructors through _fini().
la $8, _fini
beqz $8, 1f # does _fini() exist?
nop
jalr $8
nop
1: nop
Code: Select all
extern void _init();
extern void _fini();
I think both _init and _fini are provided by a library I don't have.
I could use my own _init and _fini, but I'm not sure if the constructor and destructor tables are present. They should be defined as a .ctors and .dtors section in the link script, but I can't find the script used for the IOP.
The _init should look something like this (_fini looks almost the same):
update: using iop-readelf I can see the .ctors and .dtors sections. Still don't know where the link script is though.
update2: I found the scrips in $PS2DEV/iop/iop/lib/ldscripts/. But it seems as if the linker doesn't use the scripts, becouse even garbage gets linked just fine. Someone else placed a post about this a few years ago, but never got a reply: http://forums.ps2dev.org/viewtopic.php?t=3319. I need to modify the scripts so the the constructor and destructor tables get placed in a proper location, with a symbol (like __CTOR_LIST__, used above) I can use.
I could use my own _init and _fini, but I'm not sure if the constructor and destructor tables are present. They should be defined as a .ctors and .dtors section in the link script, but I can't find the script used for the IOP.
The _init should look something like this (_fini looks almost the same):
Code: Select all
extern "C" void
_init()
{
extern void (*__CTOR_LIST__)(); //the ctor list is defined in the linker script
void (**constructor)() = &__CTOR_LIST__; //hold current constructor in list
int total = *(int *)constructor; //the first int is the number of constructors
constructor++; //increment to first constructor
while(total)
{
(*constructor)();
total--;
constructor++;
}
}
update2: I found the scrips in $PS2DEV/iop/iop/lib/ldscripts/. But it seems as if the linker doesn't use the scripts, becouse even garbage gets linked just fine. Someone else placed a post about this a few years ago, but never got a reply: http://forums.ps2dev.org/viewtopic.php?t=3319. I need to modify the scripts so the the constructor and destructor tables get placed in a proper location, with a symbol (like __CTOR_LIST__, used above) I can use.