PSP assembler begining

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

Moderators: cheriff, TyRaNiD

Post Reply
koziadupa
Posts: 7
Joined: Sun Jan 22, 2006 2:21 am

PSP assembler begining

Post by koziadupa »

Hi there!

Recently I started my journey with PSP programing :) Like you can read from my previous post, I still can't run any homebrew compiled by me.

But, I'd like to play some with assembler. So, there's my noob quiestion:

What is minimal program, that can run on PSP and doen't crash it?

I though that it would be something like run-and-just-end program. However I can't figure out how propertly end a program. I tried this:

.global _start

_start:
syscall 0x20eb ; sceKernelExitGame

which in my opinion should just do the trick, but of course it doesn't work - just hangs the PSP. So, continue with my question above, what is an instruction to end program? (apparently not sceKernelExitGame) but propably I'm just missing something :)

So that why I've asked. I'll be gratefull for your help.

Cheers
Marcin
TheCopacabanaMan
Posts: 2
Joined: Wed Feb 01, 2006 6:26 pm

Post by TheCopacabanaMan »

Hi, koziadupa.
I tried to look at MIPS R4000 assembler, too, but with no luck! :(
Only help i can give you, is processor's assembler manual.
You can find here:
http://rapidshare.de/files/10954433/MD0 ... -02.02.rar

I disassembled some eboot.bin (for studying purposes) using psp-objdump.exe from SDK.
Maybe you too can find some info?

Ciao!
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

koziadupa, the reason that doesn't work is sceKernelExitGame only works in a thread.
_mcinek
Posts: 5
Joined: Thu Jan 26, 2006 9:21 pm

Post by _mcinek »

tyranid, can you tell me so, is it neccessary to create a thread? if so then why? and if not, how to exit program? :)

Hope this basic questions help me to undestand PSP architecture more
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

It isn't strictly necessary to create a thread for your application, you can run in the initial worker thread. This worker thread is however provided by the system itself. If you do not exit from it it will lock that up for use by anything else in the system so you cannot load more modules, you cannot exit the game using sceKernelExitGame etc. PSPSDK handles it for you, if you want to write an ASM program then just take the crt0 as is and start your asm code in main instead of _start. If you must have 100% asm (as near as damn it) then you really should create a new thread for your actual code.
Fanjita
Posts: 217
Joined: Wed Sep 28, 2005 9:31 am

Post by Fanjita »

What PSP firmware version are you using?

If you're using v2.0+, and either the TIFF or GTA loader, then you can run sceKernelExitGame from the main thread.

But the chances are that if this is what you're doing, then you're trying to use the wrong syscall for sceKernelExitGame.

If you're on v2.5 or v2.6, then the syscalls aren't static - they're offset by a random amount from the number that is usually given in syscall tables - so if you need to use syscalls, then you have to try to work out what syscalls another app in memory is using for known functions, and then deduce the correct number from there.
Got a v2.0-v2.80 firmware PSP? Download the eLoader here to run homebrew on it!
The PSP Homebrew Database needs you!
_mcinek
Posts: 5
Joined: Thu Jan 26, 2006 9:21 pm

Post by _mcinek »

Ok, thanks tyranid - i've got it now.

I'm using 1.50 firmware and syscalls are ok, everything is working now :)

However I've got another question... What exactly are NIDs? As far I undestand you can call system functions by them instead of syscalls.
But because I don't really know what they are I don't know how to use them :) (of course without PSPSDK)
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

NIDs are just the way Sony use to identify individual module function entries for when you are importing libraries. that are actually (for at least 99% of the functions) the first 32bits of the SHA1 hash of the function name, in reality all you need to know is they should be unique with a single library.

The PSP kernel when loading your ELF scans these unique identifiers and fixes up the stubs you provide in your code so that you can call the desired function. As a user mode app cannot directly call a kernel mode address they implemented a syscall gateway so that kernel only functions can be called, which is where the syscall number comes in.
_mcinek
Posts: 5
Joined: Thu Jan 26, 2006 9:21 pm

Post by _mcinek »

Right, so the important things in all this 'discovering NIDs' action for different firmwares are really function names, not nids themselves?

If I undestand correct, all I have to do to call a PSP function is write a function with correct name in my code which does nothing and then while PSP kernel loads my code it will replace calls from my 'virtual' function to the real one in psp firmware?
Post Reply