[Ann] PSP Development Tutorial, modules

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Anissian
Posts: 16
Joined: Fri Jan 26, 2007 8:40 pm

[Ann] PSP Development Tutorial, modules

Post by Anissian »

All,

Please find (link below, PSP dev totorials section) a new PSP development tutorial concerning modules and PRXs, written by yours truly. There are a few rough edges and some parts are being fixed / completed / clarified. Many thanks to the reviewers for their insighful comments.

http://ps2dev.org/psp/Tutorials/PSP_Mod ... s.download

Comments, suggestions or fixes are welcome. I hope this can be helpful.

Thanks :o)

Ani.
jockyw2001
Posts: 339
Joined: Thu Sep 29, 2005 4:19 pm

Post by jockyw2001 »

Wonderful !

Very well written.
You should consider writing a book :)

Cheers
JockyW
adrahil
Posts: 274
Joined: Thu Mar 16, 2006 1:55 am

Post by adrahil »

nice :)
Holmz
Posts: 5
Joined: Wed Feb 14, 2007 6:06 am
Location: Las Vegas, NV

Wow...

Post by Holmz »

A very good read, thanks for taking the time to write it.
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Re: [Ann] PSP Development Tutorial, modules

Post by hlide »

Anissian wrote:All,

Please find (link below, PSP dev totorials section) a new PSP development tutorial concerning modules and PRXs, written by yours truly. There are a few rough edges and some parts are being fixed / completed / clarified. Many thanks to the reviewers for their insighful comments.

http://ps2dev.org/psp/Tutorials/PSP_Mod ... s.download

Comments, suggestions or fixes are welcome. I hope this can be helpful.

Thanks :o)

Ani.
it sounds very good but there is a common error about GPR usage :

SONY uses t0-t3 as arguments registers, that is, a4-a7 or r4-r11. Even our gcc uses those registers as arguments registers (up to 8 max, not 4 !). I think this common error comes from when you try to disassemble with psp-objdump or prxtool which uses the old register naming by default.
Anissian
Posts: 16
Joined: Fri Jan 26, 2007 8:40 pm

Re: [Ann] PSP Development Tutorial, modules

Post by Anissian »

hlide wrote: I think this common error comes from when you try to disassemble with psp-objdump or prxtool which uses the old register naming by default.
Indeed. Thank you hlide, I will incorporate these remarks in the reviewed version. I used prxtool extensively, and a few docs about R4000. I will dobule check the text, and whether prxtool has a switch or option to show register usage as you state.
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

i don't think prxtool uses the new register naming but it can display registers as r0-r31 at last. Don't forget that prxtools was coded with no assumption about the right name on registers.

In fact, using $4-$11 or a0-a3,t0-t3 or a0-a7 or r4-r11 doesn't make any change. What is important is to know that there is trully up to 8 argument registers for a function.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

prxtool disasm was written to the register model I use which uses t0 to t3 mnemonics instead of a4 to a7 and realistically that is how the toolchain maps them and I dont think the PSP uses the _new_ ABI anyway ;)

Admittedly you can switch prxtool to disasm the registers in the format 'rN' if you cant stand arbitrary mnemonics :) ('--disopts r' if I recall).
User avatar
harleyg
Posts: 123
Joined: Wed Oct 05, 2005 6:15 am

Post by harleyg »

Nice read. :)
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

TyRaNiD wrote:prxtool disasm was written to the register model I use which uses t0 to t3 mnemonics instead of a4 to a7 and realistically that is how the toolchain maps them and I dont think the PSP uses the _new_ ABI anyway ;)

Admittedly you can switch prxtool to disasm the registers in the format 'rN' if you cant stand arbitrary mnemonics :) ('--disopts r' if I recall).
yes i checked it : gcc maps them from $0 to $31 except for $sp, and can eventually accept them as additional register names with "$t0"-"$t3" instead of "$a3"-"$a7" even if you can have up to 8 registers.

And sure, psp-gcc uses ABI_EABI which is not ABI_O32 or ABI_N32.
fergie4000
Posts: 25
Joined: Fri Jan 19, 2007 3:03 pm

Post by fergie4000 »

i am having trouble compiling the prx code on page 7 i think it is. has anyone got it to work? if so can you say how/give me a makefile? thanks

EDIT
just needed to change build.mak to build_prx.mak. thanks to medium gauge the immortal
monsti
Posts: 13
Joined: Sun Mar 04, 2007 3:21 am
Location: Germany

Re: [Ann] PSP Development Tutorial, modules

Post by monsti »

Anissian wrote: http://ps2dev.org/psp/Tutorials/PSP_Mod ... s.download

Comments, suggestions or fixes are welcome. I hope this can be helpful.
nice work!

Can you also create a Bookr "friendly" version? e.g. a DIN-A-5 format.
Bye,
Monsti
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Re: [Ann] PSP Development Tutorial, modules

Post by J.F. »

monsti wrote:
Anissian wrote: http://ps2dev.org/psp/Tutorials/PSP_Mod ... s.download

Comments, suggestions or fixes are welcome. I hope this can be helpful.
nice work!

Can you also create a Bookr "friendly" version? e.g. a DIN-A-5 format.
With the latest updates, too...
Zenurb
Posts: 106
Joined: Fri Sep 30, 2005 8:33 am
Location: United Kingdom
Contact:

Post by Zenurb »

Good work man :D[/list]
Proud Dvorak User
US 1.5 PSP (Original)
Grizzly_cf
Posts: 6
Joined: Mon Jul 24, 2006 8:03 pm

Post by Grizzly_cf »

Hi.

I have a one question.
In page 6 you give a small example. I try to compile it, but there is some error. btw. You don't give source code to makefile and exports.exp. So I add from makefile and exports from PSPSDK - \psp\sdk\samples\prx\testprx:
makefile
TARGET = test
OBJS = main.o

# Define to build this as a prx (instead of a static elf)
BUILD_PRX=1
# Define the name of our custom exports (minus the .exp extension)
PRX_EXPORTS=exports.exp

USE_PSPSDK_LIBC = 1

INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBDIR =

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
and:
exports.exp
# Define the exports for the prx
PSP_BEGIN_EXPORTS

# These four lines are mandatory (although you can add other functions like module_stop)
# syslib is a psynonym for the single mandatory export.
PSP_EXPORT_START(syslib, 0, 0x8000)
PSP_EXPORT_FUNC_HASH(module_start)
PSP_EXPORT_VAR_HASH(module_info)
PSP_EXPORT_END

# Export our function
PSP_EXPORT_START(MyLib, 0, 0x0001)
PSP_EXPORT_FUNC_HASH(getModuleInfo)
PSP_EXPORT_END

PSP_END_EXPORTS
But I get some errors:
Log
make.exe -f "Makefile" all
psp-gcc -IC:/pspdev/psp/sdk/include/libc -I. -IC:/pspdev/psp/sdk/include -O2 -G0 -Wall -c -o main.o main.c
main.c: In function 'plugin_dump_file':
main.c(15) : error: 'SP_O_CREAT' undeclared (first use in this function)
main.c(15) : error: (Each undeclared identifier is reported only once
main.c(15) : error: for each function it appears in.)
main.c: In function 'plugin_thread':
main.c(42) : warning: unused variable 'res'
make: *** [main.o] Error 1
When I delete SP_O_CREAT I get:
Log2
make.exe -f "Makefile" all
psp-gcc -IC:/pspdev/psp/sdk/include/libc -I. -IC:/pspdev/psp/sdk/include -O2 -G0 -Wall -c -o main.o main.c
main.c: In function 'plugin_thread':
main.c(42) : warning: unused variable 'res'
psp-build-exports -b exports.exp > exports.c
psp-gcc -IC:/pspdev/psp/sdk/include/libc -I. -IC:/pspdev/psp/sdk/include -O2 -G0 -Wall -c -o exports.o exports.c
psp-gcc -IC:/pspdev/psp/sdk/include/libc -I. -IC:/pspdev/psp/sdk/include -O2 -G0 -Wall -L. -LC:/pspdev/psp/sdk/lib -specs=C:/pspdev/psp/sdk/lib/prxspecs -Wl,-q,-TC:/pspdev/psp/sdk/lib/linkfile.prx main.o exports.o -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lpsplibc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o test.elf
main.o: In function `module_start':
main.c:(.text+0x104): multiple definition of `module_start'
/cygdrive/c/pspdev/bin/../lib/gcc/psp/4.0.2/../../../../psp/lib/crt0_prx.o:/tmp/pspdev/pspsdk/src/startup/crt0_prx.c:109: first defined here
/cygdrive/c/pspdev/bin/../lib/gcc/psp/4.0.2/../../../../psp/lib/crt0_prx.o: In function `_main':
/tmp/pspdev/pspsdk/src/startup/crt0_prx.c:91: undefined reference to `main'
exports.o:(.rodata.sceResident+0x4): undefined reference to `getModuleInfo'
collect2: ld returned 1 exit status
make: *** [test.elf] Error 1
rm exports.c
Could You help(or/and give me some advices to compile exapmle) me with compile your exapmle, please?

Regards
Grizzly_cf

p.s. Sorry for my english. I know is terrible :/
Image
Holmz
Posts: 5
Joined: Wed Feb 14, 2007 6:06 am
Location: Las Vegas, NV

Post by Holmz »

SP_O_CREAT should be PSP_O_CREAT, simple typo in the tutorial that you duplicated.
Anissian
Posts: 16
Joined: Fri Jan 26, 2007 8:40 pm

Post by Anissian »

Grizzly_cf wrote: You don't give source code to makefile and exports.exp.
thanks for your comments. I will provide the source for the examples in the fixed version. Unfortunately, several typos are present in the document, such as the SP_CREATE.

Regarding the error yo get, that's because the example is supposed to be a pure export module with no main thread iirc, the missing Makefile should have the -mnostartfiles -mnocrt-thingie as described in the document.

Sorry for the inconveniences, but they'll be fixed.


Regards,
Ani.
rzxiao
Posts: 13
Joined: Sun Feb 05, 2006 7:55 pm

Post by rzxiao »

Great!,That's a great document I'm looking for
Grizzly_cf
Posts: 6
Joined: Mon Jul 24, 2006 8:03 pm

Post by Grizzly_cf »

Ok, thanks. Its works!!! :D
Image
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

some typos

page 13
... Assembler dump of the server.prx module
should be ...Assembler dump of the supervisor.prx module

page 08
... The following table shows the most common instruction mnemonics. It MIPS assembly, the result of
should be ...The following table shows the most common instruction mnemonics. In MIPS assembly, the result of

page 08 (Instruction table)
... lw rd offset(base) load the word at address into rd
... w rd load word at addr offset+base into rd
should be ...
... lw rd address load the word at address into rd
... w rd offset(base) load word at addr offset+base into rd

page 20
... you can use the sceKernelGetModuleIdList fuction,
should be ... you can use the sceKernelGetModuleIdList function,

page 27
... // offset to the "jla supervisor_0xB2C390CB", compute the
should be ... // offset to the "jal supervisor_0xB2C390CB", compute the

in all was decent read ...you must improve your grammatical skills
and use the comma (' , ') more properly :P as this is most common error

ex. Jack who loves to deny others of goods is one big asshole
is incorrect in grammar for the reason of improper comma usage
correct form is:
Jack, who loves to deny others of goods, is one big asshole

simple i know but you do this error many times ...i do not aspire to be a
grammatical cop, but if you, a aspiring writer, would def need to know
just exactly what can improve your writing
10011011 00101010 11010111 10001001 10111010
Diddl
Posts: 9
Joined: Tue Mar 27, 2007 7:50 pm

Post by Diddl »

Thank a lot, this tutorial is exactly what I need now!!!!
genshiken
Posts: 1
Joined: Sat Mar 31, 2007 1:59 am

Post by genshiken »

well, that's what i want
thx
FLCL
fishdrop
Posts: 16
Joined: Tue Oct 31, 2006 8:46 pm

Is working patching import stub?

Post by fishdrop »

I executed examples in your tutorial.
But patching import table method is not work in CF3.03 above.
Is it ture at CF 3.xx?
fishdrop
Posts: 16
Joined: Tue Oct 31, 2006 8:46 pm

Re: Is working patching import stub?

Post by fishdrop »

fishdrop wrote:I executed examples in your tutorial.
But patching import table method is not work in CF3.03 above.
Is it ture at CF 3.xx?
Sorry, I solved it.
Post Reply