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 

[Ann] PSP Development Tutorial, modules

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



Joined: 26 Jan 2007
Posts: 16

PostPosted: Wed Feb 28, 2007 7:15 pm    Post subject: [Ann] PSP Development Tutorial, modules Reply with quote

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_Modules,_Exports,_Imports_and_Patches.download

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

Thanks :o)

Ani.
Back to top
View user's profile Send private message
jockyw2001



Joined: 29 Sep 2005
Posts: 339

PostPosted: Wed Feb 28, 2007 10:55 pm    Post subject: Reply with quote

Wonderful !

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

Cheers
JockyW
Back to top
View user's profile Send private message
adrahil



Joined: 16 Mar 2006
Posts: 277

PostPosted: Wed Feb 28, 2007 11:48 pm    Post subject: Reply with quote

nice :)
Back to top
View user's profile Send private message
Holmz



Joined: 14 Feb 2007
Posts: 5
Location: Las Vegas, NV

PostPosted: Thu Mar 01, 2007 3:41 am    Post subject: Wow... Reply with quote

A very good read, thanks for taking the time to write it.
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Thu Mar 01, 2007 4:43 am    Post subject: Re: [Ann] PSP Development Tutorial, modules Reply with quote

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_Modules,_Exports,_Imports_and_Patches.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.
Back to top
View user's profile Send private message
Anissian



Joined: 26 Jan 2007
Posts: 16

PostPosted: Thu Mar 01, 2007 4:57 am    Post subject: Re: [Ann] PSP Development Tutorial, modules Reply with quote

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



Joined: 10 Sep 2006
Posts: 750

PostPosted: Thu Mar 01, 2007 5:17 am    Post subject: Reply with quote

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



Joined: 18 Jan 2004
Posts: 918

PostPosted: Thu Mar 01, 2007 5:39 am    Post subject: Reply with quote

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



Joined: 05 Oct 2005
Posts: 123

PostPosted: Thu Mar 01, 2007 5:45 am    Post subject: Reply with quote

Nice read. :)
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Thu Mar 01, 2007 6:04 am    Post subject: Reply with quote

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



Joined: 19 Jan 2007
Posts: 25

PostPosted: Thu Mar 01, 2007 10:44 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
monsti



Joined: 04 Mar 2007
Posts: 13
Location: Germany

PostPosted: Wed Mar 07, 2007 5:18 am    Post subject: Re: [Ann] PSP Development Tutorial, modules Reply with quote

Anissian wrote:

http://ps2dev.org/psp/Tutorials/PSP_Modules,_Exports,_Imports_and_Patches.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
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Wed Mar 07, 2007 5:52 am    Post subject: Re: [Ann] PSP Development Tutorial, modules Reply with quote

monsti wrote:
Anissian wrote:

http://ps2dev.org/psp/Tutorials/PSP_Modules,_Exports,_Imports_and_Patches.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...
Back to top
View user's profile Send private message AIM Address
Zenurb



Joined: 30 Sep 2005
Posts: 106
Location: United Kingdom

PostPosted: Wed Mar 07, 2007 6:28 am    Post subject: Reply with quote

Good work man :D[/list]
_________________
Proud Dvorak User
US 1.5 PSP (Original)
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Grizzly_cf



Joined: 24 Jul 2006
Posts: 6

PostPosted: Sat Mar 10, 2007 11:31 am    Post subject: Reply with quote

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
Quote:
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
Quote:
# 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
Quote:
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
Quote:
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 :/
_________________
Back to top
View user's profile Send private message
Holmz



Joined: 14 Feb 2007
Posts: 5
Location: Las Vegas, NV

PostPosted: Sat Mar 10, 2007 1:35 pm    Post subject: Reply with quote

SP_O_CREAT should be PSP_O_CREAT, simple typo in the tutorial that you duplicated.
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
Anissian



Joined: 26 Jan 2007
Posts: 16

PostPosted: Sat Mar 10, 2007 6:23 pm    Post subject: Reply with quote

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



Joined: 05 Feb 2006
Posts: 13

PostPosted: Wed Mar 14, 2007 12:33 pm    Post subject: Reply with quote

Great!,That's a great document I'm looking for
Back to top
View user's profile Send private message
Grizzly_cf



Joined: 24 Jul 2006
Posts: 6

PostPosted: Thu Mar 15, 2007 7:27 am    Post subject: Reply with quote

Ok, thanks. Its works!!! :D
_________________
Back to top
View user's profile Send private message
dot_blank



Joined: 28 Sep 2005
Posts: 498
Location: Brasil

PostPosted: Tue Mar 27, 2007 1:10 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Diddl



Joined: 27 Mar 2007
Posts: 9

PostPosted: Thu Mar 29, 2007 4:53 am    Post subject: Reply with quote

Thank a lot, this tutorial is exactly what I need now!!!!
Back to top
View user's profile Send private message
genshiken



Joined: 31 Mar 2007
Posts: 1

PostPosted: Sat Mar 31, 2007 2:24 am    Post subject: Reply with quote

well, that's what i want
thx
_________________
FLCL
Back to top
View user's profile Send private message
fishdrop



Joined: 31 Oct 2006
Posts: 16

PostPosted: Wed Nov 21, 2007 6:47 pm    Post subject: Is working patching import stub? Reply with quote

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?
Back to top
View user's profile Send private message
fishdrop



Joined: 31 Oct 2006
Posts: 16

PostPosted: Thu Nov 22, 2007 3:31 pm    Post subject: Re: Is working patching import stub? Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP 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