Problem building IRX modules for IOP

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

Moderators: cheriff, Herben

Post Reply
redcoat
Posts: 21
Joined: Wed Aug 11, 2004 9:30 am

Problem building IRX modules for IOP

Post by redcoat »

I'm attempting to build an IRX module for the IOP. I've been studying the "Hello IOP" tutorial that I downloaded from http://ps2dev.org/files/helloiop.zip.

I've detailed the problem below, what I need to know is:
Am I using the right version of the toolchain?
Is this a known problem?
How can I build IRX modules for the IOP that contain both ".s" and ".c" source code?


I'm using a fresh install of the toolchain (from http://www.oopo.net/consoledev), and the PS2DEV source code was checked-out of CVS on Aug. 16th.

Tool versions are:
iop-gcc 3.2.2
iop-as 2.14 20030612
iop-ld 2.14 20030612

I was told by a couple of people on IRC (EFnet#ps2dev), including Oobles, that this tutorial was out-of-date, but the problem appears to occur with two such simple files I have difficultly believings its age is the explanation.

I have tweaked and added some options to the Makefile, to use the latest libkernel.a and to spit-out diagnostic information. However, varying these options has no affect on the error message

Make output (additional options added to give additional information):

iop-as -EL -G0 -march=r3000 -o export/exp.o export/exp.s
iop-gcc -I. -I/usr/local/ps2dev/ps2lib/common/include -I/usr/local/ps2dev/ps2lib/iop/include -g -march=r3000 -o export/export.o -c export/export.c
iop-ld -dc -mmipsirx -r export/exp.o export/export.o -L/usr/local/ps2dev/ps2lib/iop/lib -t -lkernel -o export/export.elf
iop-ld: mode mipsirx
export/exp.o
export/export.o
(/usr/local/ps2dev/ps2lib/iop/lib/libkernel.a)iop_loadcore.o
(/usr/local/ps2dev/ps2lib/iop/lib/libkernel.a)iop_stdio.o
built in linker script:51: undefined symbol `_start' referenced in expression
make: *** [export/export.elf] Error 1


I have gone to the extreme of defining a label "_start:" in the "exp.s" file, but all this did was change the error to be:

built in linker script:51: undefined symbol `_gp' referenced in expression.


After researching the problem I infer that iop-ld is using the linker script:
$PS2DEV/iop/iop/lib/ldscripts/mipsirx.xr

I have no knowledge of how to read/write/fix/tweak linker scripts so I have not attempted to change it.

For convenience I have appended the two files, exp.s and export.c, that I'm attempting to build.

# --o export/exp.s o--

/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, David Ryan ( oobles@hotmail.com )
------------------------------------------------------------------------
exp.s Example Export Function List.
*/



.text
.set noreorder
.global func_dec
.global iop_module
.extern blah
.extern start

.local iop_module

iop_module:
.word 0x41c00000
.word 0
.word 0x00000101
.ascii "export\0\0"

.align 2

func_dec:
.word start
.word do_nothing
.word do_nothing
.word do_nothing
.word blah

.word 0

do_nothing:
.word 0x03e00008
.word 0

# --o--


# --o export/export.c o--

/*
_____ ___ ____
____| | ____| PSX2 OpenSource Project
| ___| |____ (C)2002, David Ryan ( oobles@hotmail.com )
------------------------------------------------------------------------
export.c EXAMPLE LIBRARY OF FUNCTIONS MODULE
*/

#include <tamtypes.h>
//#include <stdio.h>
#include <kernel.h>

/* This is defined in exp.s */
extern int * iop_module;


/* The function that makes up this library */
/* Yes.. It doesn't do much! */

int blah()
{
printf( "EXPORT: blah function called\n" );
return 22;
}


/* a loadcore library function to export */
/* our function list. */

int start(int argc, char *argv[])
{
int ret;

printf( "EXPORT: Module Loaded.\n" );

ret = ExportFunctions( &iop_module );
printf( "EXPORT: ExportFunctions returned = %i\n" , ret );
return ret;
}

# --o--
apache37
Posts: 76
Joined: Fri Jun 04, 2004 3:13 pm

Post by apache37 »

isnt it supposed to be: int _start(int argc, char *argv[]) ??
redcoat
Posts: 21
Joined: Wed Aug 11, 2004 9:30 am

Post by redcoat »

I believe that "start" is correct. My recall is that C and Asm identifiers are prefixed with "_" (underscore) by gcc/gas/ld when they build their internal symbol lists. Though, I confess I haven't found any online reference that supports my recollection.

However, look at the 'man' page for 'iop-ld' and you'll see:

-y symbol
--trace-symbol=symbol
Print the name of each linked file in which symbol appears. This
option may be given any number of times. On many systems it is
necessary to prepend an *underscore*.

This option is useful when you have an undefined symbol in your
link but don't know where the reference is coming from.


I accept I could be completely wrong on this point (about underscores) as I don't know what the PS2 patches do to the toolchain.

BTW: The function names & labels in the C and Asm code are as they were in the original tutorial.
redcoat
Posts: 21
Joined: Wed Aug 11, 2004 9:30 am

Post by redcoat »

I tried your (apache37) suggestion, and changed all occurrences of "start" to "_start". This just gives the same error about "_gp" being undefined(?).
apache37
Posts: 76
Joined: Fri Jun 04, 2004 3:13 pm

Post by apache37 »

try going here: \ps2dev\ps2lib\iop\sample\hello in your ps2lib setup

compile that. simple enough and easy.
redcoat
Posts: 21
Joined: Wed Aug 11, 2004 9:30 am

Post by redcoat »

Excellent! Thanks apache37.

Now, you see I didn't know about this "-miop" option for "iop-gcc".

I think mharris is right, you definitely need a FAQ around here so newbie won't keep bugging you with silly questions :wink:
apache37
Posts: 76
Joined: Fri Jun 04, 2004 3:13 pm

Post by apache37 »

np. fyi next time dont post that in this section ;)

This is toolchain development. Maybe better off in Q&A or IOP Dev.

Good luck.
Post Reply