From 441811a9cacd10a37935abb7f6274d43f1424d74 Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Thu, 16 Jun 2016 17:34:58 -0400 Subject: [PATCH] Minor updates - fix locemu path, start work on reverse (back of disk) emunand --- external/loader/source/exheader.h | 8 ++++++-- external/loader/source/loader.c | 27 ++++----------------------- source/config.h | 11 +++++++++++ source/menu.c | 1 + source/patch/emunand.c | 6 ++++++ source/patch_format.h | 3 ++- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/external/loader/source/exheader.h b/external/loader/source/exheader.h index c1bf9be..8ea6792 100644 --- a/external/loader/source/exheader.h +++ b/external/loader/source/exheader.h @@ -17,7 +17,7 @@ typedef struct typedef struct { u8 reserved[5]; - u8 flag; + u8 flag; // Maybe a feature - Bits 2-7 are unused. We could allow uh, custom flags here. Like zlib compression on code rather than lzss. u8 remasterversion[2]; } PACKED exheader_systeminfoflags; @@ -67,7 +67,11 @@ typedef struct typedef struct { u64 programid; - u8 flags[8]; + u8 coreVersion[4]; // Kernel version required for this. + u8 flag2; + u8 flag1; + u8 flag0; // CPU speed settings. + u8 priority; u16 resourcelimitdescriptor[0x10]; exheader_storageinfo storageinfo; u64 serviceaccesscontrol[0x20]; diff --git a/external/loader/source/loader.c b/external/loader/source/loader.c index 2a35ef3..5353073 100644 --- a/external/loader/source/loader.c +++ b/external/loader/source/loader.c @@ -114,14 +114,6 @@ loader_GetProgramInfo(exheader_header *exheader, u64 prog_handle) } } -static void -ConfigureNew3DSCPU(u8 mode) -{ - // Note that this is untested as of yet - I haven't got around to it. - - svcKernelSetState(10, mode, 0, 0); // Set N3DS CPU speed. -} - static Result loader_LoadProcess(Handle *process, u64 prog_handle) { @@ -172,19 +164,6 @@ loader_LoadProcess(Handle *process, u64 prog_handle) logu64(progid); logstr(" validated params\n"); - // Check and set the CPU mode. Possible values: 0 - Keep o3ds speed, 1 - - // n3ds speed, -1 force o3ds - // This is A-OK because the CPU speed parameter isn't passed through to any - // kernel function; meaning it has already been set. - u8 n3ds_mode = g_exheader.arm11systemlocalcaps.flags[1] & 0x3; // 0x3 -> L2+800Mhz - u8 cpu_mode = get_cpumode(progid); - if (cpu_mode != 0xFF) { // Skip? - u8 mode = n3ds_mode | cpu_mode; // Keep flags set by exheader. - ConfigureNew3DSCPU(mode); // We do not use PXIPM because we are a - // sysmodule. It doesn't make sense. - // Therefore, we directly call CPU setup. - } - // TODO - clean up this shit below. Not only is it unoptimized but it reads like garbage. // What the addressing info would be if not for expansion. This is passed to @@ -229,10 +208,12 @@ loader_LoadProcess(Handle *process, u64 prog_handle) codesetinfo.rw_size_total = data_mem_size; res = svcCreateCodeSet(&codeset, &codesetinfo, (void *)shared_addr.text_addr, (void *)shared_addr.ro_addr, (void *)shared_addr.data_addr); if (res >= 0) { - closeLogger(); - res = svcCreateProcess(process, codeset, g_exheader.arm11kernelcaps.descriptors, count); + logstr("Created process\n"); + + closeLogger(); + svcCloseHandle(codeset); if (res >= 0) { return 0; // Succeeded in loading process. diff --git a/source/config.h b/source/config.h index 1a8f58f..c960925 100644 --- a/source/config.h +++ b/source/config.h @@ -110,6 +110,17 @@ struct options_s // (e.g. SaltySD) #define OPTION_LOADER_LOADCODE 21 +// Calculate EmuNAND at the back of the disk, rather than the front. +// There's many good reasons for this to be supported: +// - Resizable FAT partition +// - Shrink to add EmuNAND +// = Grow to delete EmuNAND +// - Doesn't require copying fucktons of data to manage multiemunand +// This isn't supported by ANY tools like D9 at the moment +// (Though I hope they'll consider it - +// there's only benefits to users with multiple EmuNANDs) +#define OPTION_EMUNAND_REVERSE 22 + // Save log files during boot and from loader. // This will slow things down a bit. #define OPTION_SAVE_LOGS 253 diff --git a/source/menu.c b/source/menu.c index 6d9b874..c8b55bb 100644 --- a/source/menu.c +++ b/source/menu.c @@ -16,6 +16,7 @@ static struct options_s options[] = { { OPTION_EMUNAND, "Use EmuNAND", "Redirects NAND write/read to the SD.", boolean_val, 0, 0 }, { OPTION_EMUNAND_INDEX, " Index", "Which EmuNAND to use. Currently, 10 maximum (but this is arbitrary)", ranged_val, 0, 0x9 }, + { OPTION_EMUNAND_REVERSE, " Reverse mode", "EmuNAND is at the back of the disk, not the front.", boolean_val, 0, 0x9 }, { OPTION_AUTOBOOT, "Autoboot", "Boot the system automatically, unless the R key is held.", boolean_val, 0, 0 }, { OPTION_SILENCE, " Silent mode", "Suppress all debug output during autoboot. You'll see the screen turn on, then off.", boolean_val, 0, 0 }, diff --git a/source/patch/emunand.c b/source/patch/emunand.c index 7b45153..fc796da 100644 --- a/source/patch/emunand.c +++ b/source/patch/emunand.c @@ -12,6 +12,7 @@ #include "../fatfs/sdmmc.h" #include "../firm/headers.h" #include "../patch_format.h" +#include "../config.h" uint8_t *emunand_temp = (uint8_t *)FCRAM_JUNK_LOC; @@ -20,6 +21,7 @@ verify_loop_emunand(char *filename) { // FIXME - This won't work unless the NAND file is completely contiguous on disk, sadly. // Technically speaking if I were to defrag my SD this would work, I suspect. + // For now, this will remain as dead code. uint32_t offset = get_file_sector(filename); // Get the sector of the file @@ -42,6 +44,10 @@ verify_emunand(uint32_t index, uint32_t *off, uint32_t *head) else offset = 0x200000 * index; + if (config.options[OPTION_EMUNAND_REVERSE]) { + // Subtract offset from back of disk. + } + // Check for RedNAND/Normal physical layout on SD if (!sdmmc_sdcard_readsectors(offset + 1, 1, emunand_temp) && *(uint32_t *)(emunand_temp + 0x100) == NCSD_MAGIC) { *off = offset + 1; diff --git a/source/patch_format.h b/source/patch_format.h index d217a0d..02e63ae 100644 --- a/source/patch_format.h +++ b/source/patch_format.h @@ -32,9 +32,10 @@ #define PATH_CONFIG_DIR PATH_CFW "/config" // Config file directory. #define PATH_CONFIG PATH_CONFIG_DIR "/main.conf" // Config file. -#define PATH_LOCEMU PATH_CONFIG_DIR "/locale" // Locale emulation config #define PATH_CPU_CFG PATH_CONFIG_DIR "/cpu.conf" // CPU settings config +#define PATH_LOCEMU PATH_CFW "/locale" // Locale emulation config + #define PATH_PATCHES PATH_CFW "/patch" // Patch binary folder. #define PATH_FIRMWARES PATH_CFW "/firmware" // Firmware folder. #define PATH_MODULES PATH_CFW "/module" // Sysmodule location -- 2.39.5