forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

No C++ compiler for IOP?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development
View previous topic :: View next topic  
Author Message
Maximus32



Joined: 27 Aug 2007
Posts: 41

PostPosted: Thu Jul 10, 2008 7:39 pm    Post subject: No C++ compiler for IOP? Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Thu Jul 10, 2008 10:47 pm    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message Visit poster's website
Lukasz



Joined: 19 Jan 2004
Posts: 248
Location: Denmark

PostPosted: Fri Jul 11, 2008 2:10 am    Post subject: Reply with quote

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.
_________________
Lukasz.dk
Back to top
View user's profile Send private message Visit poster's website
Maximus32



Joined: 27 Aug 2007
Posts: 41

PostPosted: Fri Jul 11, 2008 9:09 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
Lukasz



Joined: 19 Jan 2004
Posts: 248
Location: Denmark

PostPosted: Sat Jul 12, 2008 12:21 am    Post subject: Reply with quote

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/Compatibility_of_C_and_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 :-)
_________________
Lukasz.dk
Back to top
View user's profile Send private message Visit poster's website
Maximus32



Joined: 27 Aug 2007
Posts: 41

PostPosted: Sat Jul 12, 2008 12:51 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message Visit poster's website
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sat Jul 12, 2008 3:47 am    Post subject: Reply with quote

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. ;)
Back to top
View user's profile Send private message AIM Address
Maximus32



Joined: 27 Aug 2007
Posts: 41

PostPosted: Tue Jul 15, 2008 5:32 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
Lukasz



Joined: 19 Jan 2004
Posts: 248
Location: Denmark

PostPosted: Tue Jul 15, 2008 4:09 pm    Post subject: Reply with quote

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:
   # 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:
   # 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:
extern void _init();
extern void _fini();

_________________
Lukasz.dk
Back to top
View user's profile Send private message Visit poster's website
Maximus32



Joined: 27 Aug 2007
Posts: 41

PostPosted: Tue Jul 15, 2008 9:18 pm    Post subject: Reply with quote

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:
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.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group