Imported initArgv from libctru. Load __system_argc/__system_argv in crt0. Enabled the __system_argc/__system_argv code in fsdev.

This commit is contained in:
yellows8 2017-11-29 21:30:40 -05:00
parent 99e4a61492
commit cb123dd579
4 changed files with 70 additions and 7 deletions

View File

@ -39,8 +39,10 @@ bss_loop:
bl __libnx_init bl __libnx_init
// call entrypoint // call entrypoint
mov x0, #0 // argc adrp x0, __system_argc // argc
mov x1, #0 // argv ldr w0, [x0, #:lo12:__system_argc]
adrp x1, __system_argv // argv
ldr x1, [x1, #:lo12:__system_argv]
adrp x30, __libnx_exit adrp x30, __libnx_exit
add x30, x30, #:lo12:__libnx_exit add x30, x30, #:lo12:__libnx_exit
b main b main

View File

@ -352,9 +352,9 @@ int fsdevUnmountDevice(const char *name)
/*! Initialize SDMC device */ /*! Initialize SDMC device */
Result fsdevInit(void) Result fsdevInit(void)
{ {
/*ssize_t units; ssize_t units;
uint32_t code; uint32_t code;
char *p;*/ char *p;
Result rc = 0; Result rc = 0;
FsFileSystem fs; FsFileSystem fs;
fsdev_fsdevice *device = NULL; fsdev_fsdevice *device = NULL;
@ -390,8 +390,7 @@ Result fsdevInit(void)
fsdev_fsdevice_cwd = fsdev_fsdevice_default; fsdev_fsdevice_cwd = fsdev_fsdevice_default;
} }
//TODO: Re-enable this once __system_argc/__system_argv are actually defined. if(__system_argc != 0 && __system_argv[0] != NULL)
/*if(__system_argc != 0 && __system_argv[0] != NULL)
{ {
if(FindDevice(__system_argv[0]) == dev) if(FindDevice(__system_argv[0]) == dev)
{ {
@ -426,7 +425,7 @@ Result fsdevInit(void)
} }
} }
} }
}*/ }
} }
} }

View File

@ -5,6 +5,8 @@ void __nx_exit(int rc);
void virtmemSetup(); void virtmemSetup();
void newlibSetup(Handle main_thread); void newlibSetup(Handle main_thread);
void __system_initArgv(void);
#define INNER_HEAP_SIZE 0x200000 #define INNER_HEAP_SIZE 0x200000
__attribute__((weak)) size_t __nx_inner_heap_size = INNER_HEAP_SIZE; __attribute__((weak)) size_t __nx_inner_heap_size = INNER_HEAP_SIZE;
__attribute__((weak)) char __nx_inner_heap[INNER_HEAP_SIZE]; __attribute__((weak)) char __nx_inner_heap[INNER_HEAP_SIZE];
@ -59,6 +61,9 @@ void __attribute__((weak)) __libnx_init(Handle main_thread)
virtmemSetup(); virtmemSetup();
_SetupHeap(); _SetupHeap();
// Build argc/argv if present
__system_initArgv();
// Initialize services. // Initialize services.
__appInit(); __appInit();

View File

@ -0,0 +1,57 @@
#include <switch.h>
#include <string.h>
// System globals we define here
int __system_argc;
char** __system_argv;
extern char* fake_heap_start;
extern char* fake_heap_end;
void __system_initArgv(void)
{
//TODO: How to load args?
__system_argc = 0;
__system_argv = NULL;
/*
int i;
const char* arglist = envGetSystemArgList();
const char* temp = arglist;
// Check if the argument list is present
if (!temp)
return;
// Retrieve argc
__system_argc = *(u32*)temp;
temp += sizeof(u32);
// Find the end of the argument data
for (i = 0; i < __system_argc; i ++)
{
for (; *temp; temp ++);
temp ++;
}
// Reserve heap memory for argv data
u32 argSize = temp - arglist - sizeof(u32);
__system_argv = (char**)fake_heap_start;
fake_heap_start += sizeof(char**)*(__system_argc + 1);
char* argCopy = fake_heap_start;
fake_heap_start += argSize;
// Fill argv array
memcpy(argCopy, &arglist[4], argSize);
temp = argCopy;
for (i = 0; i < __system_argc; i ++)
{
__system_argv[i] = (char*)temp;
for (; *temp; temp ++);
temp ++;
}
__system_argv[__system_argc] = NULL;
*/
}