Arguments to main()

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

Moderators: cheriff, TyRaNiD

Post Reply
Fanjita
Posts: 217
Joined: Wed Sep 28, 2005 9:31 am

Arguments to main()

Post by Fanjita »

I'm trying to replicate the argument-passing that the kernel does to _startup(), for the EBOOT loader.

But I'm a bit confused about what it actually passes.

The PSPSDK API docs claim that the arguments passed to a thread via StartThread() are:

SceSize arglen (size of argp data in bytes)
void * argp

That seems to correlate with the code for _start() in crt0.c too.

My question is: should this be the same as the classic argc, argv? Clearly argc is normally a count of elements in the argv[] array, so would be a count of 32-bit words rather than bytes.

And regardless of that, when I pass:

arglen = 4
argp = { char * => "test" }

I don't seem to get anything like those params passed to main.

Can anyone shed any light on what's going on? What gets passed to argc, argv on a 1.5 PSP?
User avatar
groepaz
Posts: 305
Joined: Thu Sep 01, 2005 7:44 am
Contact:

Post by groepaz »

if you are calling crt0 directly from your code, and not through a kernel function such as sceLoadExec, i would think that you need to pass argc=0 and argv[0]="ms0:/path/to/eboot". the description in the pspsdk probably relates to how those params are passed via loadexec, which is a bit different. (it takes a struct with some info about the params)
Fanjita
Posts: 217
Joined: Wed Sep 28, 2005 9:31 am

Post by Fanjita »

I do pass the EBOOT path in argv[0] - because I figured out that the problem with some EBOOTs is that they use that to determine their working directory.

But that parameter never actually reaches the app, and I don't understand why not.

I'll take a look at the KernelLoadExec params - maybe that will offer some clues.
Fanjita
Posts: 217
Joined: Wed Sep 28, 2005 9:31 am

Post by Fanjita »

Ah, yes, the LoadExec params gave me the right clue.

The argp argument to _start() is just a pointer to the argv[0] string. The args argument is the length.

Now it works just fine.

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

Post by CyberBill »

Yeah, it was very confusing the first time I used it too. You expect it to use the COUNT in number of arguments, but it doesnt. Its just the count in bytes.

Internally it does a copy, too, which can throw you off but is expected.
Post Reply