Load ELF files with sceKernelLoadExec

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

Moderators: cheriff, TyRaNiD

pspkrazy
Posts: 49
Joined: Mon Jul 04, 2005 1:31 am

thanks

Post by pspkrazy »

Thanks shazz for your great explanation.

It seems that I missed some things!

I was sure that BOOT.BIN was an ELF file ?!

I will shut up next time ! :)
User avatar
Shazz
Posts: 244
Joined: Tue Aug 31, 2004 11:42 pm
Location: Somewhere over the rainbow
Contact:

Post by Shazz »

no no !!!! Thanks to your idea, I leanrt plenty of things and as Tyranid told me, we never thought it could be possible to run an plain elf using Load/StartModule... either if it seems to be redirected to LoadExec...

By the way, with Placasoft, we played with it and we have a UMD game screenshot dumper which nearly works (the image is corrupted due to the 'slowness' of writing a file) for games (as BOOT.BIN is not a plain elf but a true PRX)

So the future is simple, stop creating ELF ! Time to learn how to create PRX !!!!

So PSPKrazy, don't shut up :D Continue to have such good ideas !
- TiTAN Art Division -
http://www.titandemo.org
CyberBill
Posts: 86
Joined: Tue Jul 26, 2005 3:53 pm
Location: Redmond, WA

Post by CyberBill »

I'm trying to figure out this stuff. Will this work:

Code: Select all


PSP_MODULE_INFO("Blah", 0x1000, 1, 1);   // 0x1000 = Kernel MODE
PSP_MAIN_THREAD_ATTR(0); // 0 for kernel mode too

int main(void)
{  
        //THIS??
	//sceKernelLoadExec("ms0:/PSP_GAME/SYSDIR/boot.elf",0);

        //Or this??
	int exec_p = sceKernelLoadModule("ms0:/PSP_GAME/SYSDIR/boot.elf", 0, 0);
	sceKernelStartModule(exec_p, 0, 0, 0, 0);

	return 0;
}

Well, no, it wont.. but I dont know why. hehe :)

-Bill
reigel
Posts: 14
Joined: Fri Jul 15, 2005 10:41 pm

Post by reigel »

both will work!
CyberBill
Posts: 86
Joined: Tue Jul 26, 2005 3:53 pm
Location: Redmond, WA

Post by CyberBill »

The first one *does* work... not sure what I was doing wrong the last time. The 2nd one doesnt... not sure why.

Oh, and it loads .elf files.

I didnt try to load any pbp files.... whats the point. :P

-Bill
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

About this:

Code: Select all

int exec_p = sceKernelLoadModule("ms0:/PSP_GAME/SYSDIR/boot.elf", 0, 0);
I know you're going to fool around with it anyway, but could you at least pretend you're not trying to run a game you've copied to the memory card? Maybe change the path a little when you're pasting code to these forums?

You know, attempt to follow the rules or something?

Unbelievable.
MiKA-
Posts: 6
Joined: Sat Mar 04, 2006 12:06 am

Post by MiKA- »

Hi, I have a little problem loading .elf's from Memory Stick, and I hope that somebody could help me.

Ok, so I was going to make myself a little sample program which would load an emulator from Memory Stick. I extracted the DATA.PSP from the EBOOT.PBP of the emulator, and renamed that to EMU.ELF (Isn't this right?). Now, my code looks like this:

Code: Select all

// Kernel Mode
PSP_MODULE_INFO("EMULATOR", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0); 

.
.
.

and in main it's just like this:

sceKernelLoadExec("ms0:/EMULATORS/EMU.ELF",0);
The program compiles OK, no errors or anything, but it doesn't work on my 1.5 PSP. All I have is a black screen, memstick light flashes couple of times, then it gets back to XMB. For some emus it doesn't give any error, but with some it gives "80020001". Does somebody know what's wrong and how I could succesfully load that .ELF -file?


EDIT:
It would help if I'd get a sample code somewhere which would just load an .ELF/.PBP from memory stick, so if somebody knows where to get that kind of source, please post it here :)
MiKA-
Posts: 6
Joined: Sat Mar 04, 2006 12:06 am

Post by MiKA- »

Could anybody help me and tell me an answer to the question above this post, how could I load my emulators from memory stick with my own program?.
MiKA-
Posts: 6
Joined: Sat Mar 04, 2006 12:06 am

Post by MiKA- »

Sorry for double posting, but what should I put into my code so it would print "File doesn't exist" or something like that if the file doesn't actually exist? In my code, I'm loading ms0:/EBOOT.PBP with SceKernelLoadExec when pressing X.
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

MiKA- wrote:Sorry for double posting, but what should I put into my code so it would print "File doesn't exist" or something like that if the file doesn't actually exist? In my code, I'm loading ms0:/EBOOT.PBP with SceKernelLoadExec when pressing X.

Code: Select all

int FileExists(char *path)
{
    SceIoStat stat;

    return (sceIoGetstat(path, &stat) >= 0)
	
}

void yourfunction(char *yourfile)
{
    struct SceKernelLoadExecParam param;

    if (!FileExists(yourfile))
    {
        printf("File doesn't exist");
        return;
    }

    memset(&param, 0, sizeof(param));
    param.size = sizeof(param);
    param.args = strlen(yourfile) + 1;
    param.argp = yourfile;

    sceKernelLoadExec(yourfile, &param);
}
Well, more or less.
MiKA-
Posts: 6
Joined: Sat Mar 04, 2006 12:06 am

Post by MiKA- »

moonlight wrote:

Code: Select all

Some code
.
.
.
Well, more or less.
As I'm just a beginner, I don't actually know how to use this code :( I've read all the Yeldarb tutorials and just borrowed a C-programming book from the library, so I don't know much about coding, yet. And because of that, I don't understand how do I define the path "ms0:/EBOOT.PBP" to this piece of code? If somebody can still teach me little more, I'll be happy.
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

in your C book look up how pointers are
used in a functions argument list and why

but example lets use first function moonlight posted

Code: Select all

int FileExists(char *path)
{
    SceIoStat stat;

    return (sceIoGetstat(path, &stat) >= 0)
   
}
the function argument char *path is a string pointer
to path of your file to check if it exists
and anytime the pointer path is used your string
array is replaced ... using ms0:/EBOOT.PBP for example
the above function works like this

Code: Select all

int FileExists("ms0:/EBOOT.PBP")
{
    SceIoStat stat;

    return (sceIoGetstat("ms0:/EBOOT.PBP", &stat) >= 0)
   
}
so if you add above function before main()
then you will be able to use it like so in your program
using pseudo code below

Code: Select all

int main(int argc, char* argv[]) { 
....
//check if file exists at root of psp
FileExists("ms0:/EBOOT.PBP");
...
//if it does run the file
yourfunction("ms0:/EBOOT.PBP");
...
you must take into affect the return status of one of the
sceIoGetstat() status return codes and if file exist from
returned success code then making a simple check against
this number is simple and and yourfunction() can run only
if FileExists() returned positive return ...that i leave to you
and keep reading on with C book and dont just read one
and go by it religiously ...read as many articles and books
on the language as time should allow ...any language takes
practice and so does C
10011011 00101010 11010111 10001001 10111010
Post Reply