Fix itcm sections overwriting argv
This commit is contained in:
parent
0bb82feb81
commit
0195ab34e9
@ -39,6 +39,8 @@
|
|||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "fatfs/sdmmc/sdmmc.h"
|
#include "fatfs/sdmmc/sdmmc.h"
|
||||||
|
|
||||||
|
extern u8 __itcm_start__[], __itcm_lma__[], __itcm_bss_start__[], __itcm_end__[];
|
||||||
|
|
||||||
extern CfgData configData;
|
extern CfgData configData;
|
||||||
extern ConfigurationStatus needConfig;
|
extern ConfigurationStatus needConfig;
|
||||||
extern FirmwareSource firmSource;
|
extern FirmwareSource firmSource;
|
||||||
@ -53,13 +55,13 @@ void main(int argc, char **argv, u32 magicWord)
|
|||||||
isSafeMode = false,
|
isSafeMode = false,
|
||||||
needToInitSd = false,
|
needToInitSd = false,
|
||||||
isNoForceFlagSet = false,
|
isNoForceFlagSet = false,
|
||||||
|
isInvalidLoader = false,
|
||||||
isNtrBoot;
|
isNtrBoot;
|
||||||
FirmwareType firmType;
|
FirmwareType firmType;
|
||||||
FirmwareSource nandType;
|
FirmwareSource nandType;
|
||||||
const vu8 *bootMediaStatus = (const vu8 *)0x1FFFE00C;
|
const vu8 *bootMediaStatus = (const vu8 *)0x1FFFE00C;
|
||||||
const vu32 *bootPartitionsStatus = (const vu32 *)0x1FFFE010;
|
const vu32 *bootPartitionsStatus = (const vu32 *)0x1FFFE010;
|
||||||
|
char firmlaunchTid[16+1];
|
||||||
I2C_init();
|
|
||||||
|
|
||||||
//Shell closed, no error booting NTRCARD, NAND paritions not even considered
|
//Shell closed, no error booting NTRCARD, NAND paritions not even considered
|
||||||
isNtrBoot = bootMediaStatus[3] == 2 && !bootMediaStatus[1] && !bootPartitionsStatus[0] && !bootPartitionsStatus[1];
|
isNtrBoot = bootMediaStatus[3] == 2 && !bootMediaStatus[1] && !bootPartitionsStatus[0] && !bootPartitionsStatus[1];
|
||||||
@ -82,6 +84,8 @@ void main(int argc, char **argv, u32 magicWord)
|
|||||||
for(i = 0; i < sizeof(launchedPath)/2 - 1 && p[i] != 0; i++)
|
for(i = 0; i < sizeof(launchedPath)/2 - 1 && p[i] != 0; i++)
|
||||||
launchedPath[i] = p[i];
|
launchedPath[i] = p[i];
|
||||||
launchedPath[i] = 0;
|
launchedPath[i] = 0;
|
||||||
|
|
||||||
|
strncpy(firmlaunchTid, argv[1], 16);
|
||||||
}
|
}
|
||||||
else if(magicWord == 0xB002) //FIRM/NTRCARD boot
|
else if(magicWord == 0xB002) //FIRM/NTRCARD boot
|
||||||
{
|
{
|
||||||
@ -106,7 +110,16 @@ void main(int argc, char **argv, u32 magicWord)
|
|||||||
|
|
||||||
setupKeyslots();
|
setupKeyslots();
|
||||||
}
|
}
|
||||||
else error("Launched using an unsupported loader.");
|
else isInvalidLoader = true;
|
||||||
|
|
||||||
|
// Set up the additional sections, overwrites argc
|
||||||
|
memcpy(__itcm_start__, __itcm_lma__, __itcm_bss_start__ - __itcm_start__);
|
||||||
|
memset(__itcm_bss_start__, 0, __itcm_end__ - __itcm_bss_start__);
|
||||||
|
I2C_init();
|
||||||
|
if(isInvalidLoader) error("Launched using an unsupported loader.");
|
||||||
|
|
||||||
|
detectAndProcessExceptionDumps();
|
||||||
|
installArm9Handlers();
|
||||||
|
|
||||||
if(memcmp(launchedPath, u"sdmc", 8) == 0)
|
if(memcmp(launchedPath, u"sdmc", 8) == 0)
|
||||||
{
|
{
|
||||||
@ -151,10 +164,10 @@ void main(int argc, char **argv, u32 magicWord)
|
|||||||
{
|
{
|
||||||
if(needConfig == CREATE_CONFIGURATION) mcuPowerOff();
|
if(needConfig == CREATE_CONFIGURATION) mcuPowerOff();
|
||||||
|
|
||||||
switch(argv[1][14])
|
switch(firmlaunchTid[14])
|
||||||
{
|
{
|
||||||
case '2':
|
case '2':
|
||||||
firmType = (FirmwareType)(argv[1][10] - '0');
|
firmType = (FirmwareType)(firmlaunchTid[10] - '0');
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '3':
|
||||||
firmType = SAFE_FIRM;
|
firmType = SAFE_FIRM;
|
||||||
@ -171,9 +184,6 @@ void main(int argc, char **argv, u32 magicWord)
|
|||||||
goto boot;
|
goto boot;
|
||||||
}
|
}
|
||||||
|
|
||||||
detectAndProcessExceptionDumps();
|
|
||||||
installArm9Handlers();
|
|
||||||
|
|
||||||
firmType = NATIVE_FIRM;
|
firmType = NATIVE_FIRM;
|
||||||
isFirmProtEnabled = bootType != NTR;
|
isFirmProtEnabled = bootType != NTR;
|
||||||
|
|
||||||
|
@ -115,19 +115,6 @@ _start:
|
|||||||
sub r2, r0
|
sub r2, r0
|
||||||
bl memset
|
bl memset
|
||||||
|
|
||||||
@ Set additional sections up
|
|
||||||
ldr r0, =__itcm_start__
|
|
||||||
ldr r1, =__itcm_lma__
|
|
||||||
ldr r2, =__itcm_bss_start__
|
|
||||||
sub r2, r0
|
|
||||||
bl memcpy
|
|
||||||
|
|
||||||
ldr r0, =__itcm_bss_start__
|
|
||||||
mov r1, #0
|
|
||||||
ldr r2, =__itcm_end__
|
|
||||||
sub r2, r0
|
|
||||||
bl memset
|
|
||||||
|
|
||||||
bl __libc_init_array
|
bl __libc_init_array
|
||||||
|
|
||||||
mov r0, r9
|
mov r0, r9
|
||||||
|
Reference in New Issue
Block a user