mirror of
https://github.com/switchbrew/libnx.git
synced 2025-08-06 00:19:22 +02:00
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:
parent
99e4a61492
commit
cb123dd579
@ -39,8 +39,10 @@ bss_loop:
|
||||
bl __libnx_init
|
||||
|
||||
// call entrypoint
|
||||
mov x0, #0 // argc
|
||||
mov x1, #0 // argv
|
||||
adrp x0, __system_argc // argc
|
||||
ldr w0, [x0, #:lo12:__system_argc]
|
||||
adrp x1, __system_argv // argv
|
||||
ldr x1, [x1, #:lo12:__system_argv]
|
||||
adrp x30, __libnx_exit
|
||||
add x30, x30, #:lo12:__libnx_exit
|
||||
b main
|
||||
|
@ -352,9 +352,9 @@ int fsdevUnmountDevice(const char *name)
|
||||
/*! Initialize SDMC device */
|
||||
Result fsdevInit(void)
|
||||
{
|
||||
/*ssize_t units;
|
||||
ssize_t units;
|
||||
uint32_t code;
|
||||
char *p;*/
|
||||
char *p;
|
||||
Result rc = 0;
|
||||
FsFileSystem fs;
|
||||
fsdev_fsdevice *device = NULL;
|
||||
@ -390,8 +390,7 @@ Result fsdevInit(void)
|
||||
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)
|
||||
{
|
||||
@ -426,7 +425,7 @@ Result fsdevInit(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,8 @@ void __nx_exit(int rc);
|
||||
void virtmemSetup();
|
||||
void newlibSetup(Handle main_thread);
|
||||
|
||||
void __system_initArgv(void);
|
||||
|
||||
#define INNER_HEAP_SIZE 0x200000
|
||||
__attribute__((weak)) size_t __nx_inner_heap_size = 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();
|
||||
_SetupHeap();
|
||||
|
||||
// Build argc/argv if present
|
||||
__system_initArgv();
|
||||
|
||||
// Initialize services.
|
||||
__appInit();
|
||||
|
||||
|
57
nx/source/system/initArgv.c
Normal file
57
nx/source/system/initArgv.c
Normal 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;
|
||||
*/
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user