Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for args #13

Merged
merged 4 commits into from
Nov 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions newlib/libc/sys/vita/crt0.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* The maximum number of arguments that can be passed to main(). */
#define ARGC_MAX 19

int main(int argc, const char* argv[]);

void _init_vita_newlib(void) {
Expand All @@ -14,8 +17,32 @@ void _free_vita_newlib(void) {
_free_vita_heap();
}

void _start() {
/*
* Code below is based on the PSPSDK implementation
* Copyright (c) 2005 Marcus R. Brown <[email protected]>
*/

void _start(unsigned int args, void *argp)
{
char *argv[ARGC_MAX + 1] = {""}; // Program name
int argc = 1;
int loc = 0;
char *ptr = argp;

/* Turn our thread arguments into main()'s argc and argv[]. */
while(loc < args)
{
argv[argc] = &ptr[loc];
loc += strlen(&ptr[loc]) + 1;
argc++;
if(argc == ARGC_MAX)
{
break;
}
}

argv[argc] = 0;
_init_vita_newlib();
__libc_init_array();
exit(main(1, (const char*[]){"", 0}));
exit(main(argc, argv));
}