No C++ compiler for IOP?

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
Maximus32
Posts: 40
Joined: Mon Aug 27, 2007 12:28 am
Contact:

No C++ compiler for IOP?

Post by Maximus32 »

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.
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

Feel free to port newlib to the IOP, and a C++ build of gcc can probably be easily done. It wouldn't be very useful, though...
User avatar
Lukasz
Posts: 248
Joined: Mon Jan 19, 2004 8:37 pm
Location: Denmark
Contact:

Post by Lukasz »

There is really no need for C++ on the IOP in my opinion. The complexity and size of user IOP modules (most of which are I/O driver related) is minimal and therefor there is no need to use C++ abstraction features.
Maximus32
Posts: 40
Joined: Mon Aug 27, 2007 12:28 am
Contact:

Post by Maximus32 »

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.
User avatar
Lukasz
Posts: 248
Joined: Mon Jan 19, 2004 8:37 pm
Location: Denmark
Contact:

Post by Lukasz »

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 :-)
Maximus32
Posts: 40
Joined: Mon Aug 27, 2007 12:28 am
Contact:

Post by Maximus32 »

Just modified stage 4 of the buildscrips to build the C++ compiler for the IOP as well. And it compiled without any problems. So now I have iop-g++.

Still need to find out if it actually works...
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Maximus32 wrote:Just modified stage 4 of the buildscrips to build the C++ compiler for the IOP as well. And it compiled without any problems. So now I have iop-g++.

Still need to find out if it actually works...
The issue isn't the compiler, it's the standard library. ;)
Maximus32
Posts: 40
Joined: Mon Aug 27, 2007 12:28 am
Contact:

Post by Maximus32 »

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.
User avatar
Lukasz
Posts: 248
Joined: Mon Jan 19, 2004 8:37 pm
Location: Denmark
Contact:

Post by Lukasz »

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.
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().

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 
And after main() exits, the deconstructors are called.

Code: Select all

	# Call global deconstructors through _fini().
	la	$8, _fini
	beqz	$8, 1f		# does _fini() exist?
	nop
	jalr	$8
	nop
1: nop
You could of course also just call _init() and _fini() in the beginning and end of _start() respectively, I think you just need to declare them as extern void to so.

Code: Select all

extern void _init();
extern void _fini();
Maximus32
Posts: 40
Joined: Mon Aug 27, 2007 12:28 am
Contact:

Post by Maximus32 »

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):

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++;
  }
}
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.
Post Reply