]> Chaos Git - corbenik/corbenik.git/commitdiff
Multiple things (again)
authorchaoskagami <chaos.kagami@gmail.com>
Sun, 5 Jun 2016 07:10:41 +0000 (03:10 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Sun, 5 Jun 2016 07:11:11 +0000 (03:11 -0400)
 * Replace all instances of 'service' with 'svc' or 'svc call' to get my terminology straight
 * Make logging in loader toggleable, add boot logging, and add an option to the menu. Hopefully this will cut down on improper issue reporting.

16 files changed:
external/loader/Makefile
external/loader/source/config.h [deleted file]
external/loader/source/interp.c
external/loader/source/loader.c
external/loader/source/logger.c
external/loader/source/memory.c
external/loader/source/patcher.c
source/config.c
source/config.h
source/firm/firm.c
source/menu.c
source/patch/svc.c
source/patch_format.h
source/patcher.c
source/std/draw.c
source/std/draw.h

index 3f2ec9afbc7b08a3b12d9c4da2596c86991fbcec..15fd374170648618ec026f2cda3e119aead27aad 100644 (file)
@@ -36,7 +36,7 @@ CFLAGS        := -flto -Wall -Os -mword-relocations $(ERROR) \
                        -fomit-frame-pointer -ffunction-sections -fdata-sections -fshort-wchar \
                        $(ARCH)
 
-CFLAGS +=      $(INCLUDE) -DARM11 -D_3DS
+CFLAGS +=      $(INCLUDE) -DARM11 -D_3DS -DLOADER=1
 
 CXXFLAGS       := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu99
 
diff --git a/external/loader/source/config.h b/external/loader/source/config.h
deleted file mode 100644 (file)
index a9bb6ae..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef __CONFIG_H
-#define __CONFIG_H
-
-__attribute__((unused)) static unsigned int config_version = 1;
-
-#define CONFIG_MAGIC "OVAN"
-
-// Structure of config file
-struct config_file
-{
-    char magic[4]; // "OVAN" for shits and giggles again.
-
-    uint32_t config_ver; // Config file version.
-
-    uint8_t options[256]; // Options in the menu - deliberately large to avoid
-                          // config version bumps.
-
-    uint64_t patch_ids[256]; // What patches are enabled by UUID. 256 is an
-                             // arbitrary limit - contact me if you hit it.
-} __attribute__((packed));
-
-#define OPTION_LOADER_CPU_L2 11     // Enable L2 cache.
-#define OPTION_LOADER_CPU_800MHZ 12 // Enable 800Mhz mode.
-#define OPTION_LOADER_LANGEMU 13    // Enable 800Mhz mode.
-
-#endif
index 92440af32bc02b022b55026e3573b507a990859e..512f51be0c741c2d642ca8595d45d23fa1b56b60 100644 (file)
@@ -1,8 +1,6 @@
 // 'Tis not ready for the world at large yet.
 // I don't want to delete it since I'm working on it though,
 // so it's temporarliy #if'd 0.
-#define LOADER 1
-
 #include <3ds.h>
 #include "patcher.h"
 #include "fsldr.h"
@@ -14,7 +12,7 @@
 #define PATH_MAX 255
 #define _MAX_LFN 255
 #endif
-#include "config.h"
+#include "../../../source/config.h"
 #include "../../../source/patch_format.h"
 
 // Because I want to avoid malloc.
index 722d0ffe6a658a4b6294da12289cb0de8eaea773..1b76653a68a43433f6f1916609fb65bf156f9b89 100644 (file)
@@ -153,7 +153,8 @@ loader_LoadProcess(Handle *process, u64 prog_handle)
     u32 text_grow, data_grow, ro_grow;
     u16 progver;
 
-    openLogger();
+    load_config(); // First order of business - we need the config file.
+    openLogger();  // Open logs if enabled in config.
 
     // make sure the cached info corrosponds to the current prog_handle
     if (g_cached_prog_handle != prog_handle) {
@@ -184,8 +185,6 @@ loader_LoadProcess(Handle *process, u64 prog_handle)
     logu64(progid);
     logstr("  validated params\n");
 
-    load_config(); // First order of business - we need the config file.
-
     // 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
index 9b8708f3955e4fadb9b327aa2e46b06bd30bbe82..6555cdbb9000f30a8820b4c42761a9aaee66217a 100644 (file)
@@ -8,15 +8,20 @@
 #define PATH_MAX 255
 #define _MAX_LFN 255
 #endif
-#include "config.h"
+#include "../../../source/config.h"
 #include "../../../source/patch_format.h"
 
 Handle log_file_hdl;
 int logger_is_initd = 0;
 
+extern struct config_file config;
+
 void
 openLogger()
 {
+    if (config.options[OPTION_SAVE_LOGS] == 0) {
+        logger_is_initd = -1; // Setting -1 effectively disables logs.
+    }
     Result r;
 
     if (logger_is_initd)
index eb294b70b8db15fc399df1e05a9f813cb7029ca1..d0cb84dfce0cb53055850a15c220ec4b5f269af8 100644 (file)
@@ -7,7 +7,7 @@
 #define PATH_MAX 255
 #define _MAX_LFN 255
 #endif
-#include "config.h"
+#include "../../../source/config.h"
 #include "../../../source/patch_format.h"
 
 int
index aa32f54df553f6f339c9e473f129867742e3447d..598a072788b5c40d7d9699df9052d3ee05246bcf 100644 (file)
@@ -11,7 +11,7 @@
 #define PATH_MAX 255
 #define _MAX_LFN 255
 #endif
-#include "config.h"
+#include "../../../source/config.h"
 
 int
 fileOpen(Handle *file, FS_ArchiveID id, const char *path, int flags)
@@ -30,7 +30,7 @@ fileOpen(Handle *file, FS_ArchiveID id, const char *path, int flags)
     return FSLDR_OpenFileDirectly(file, id, apath, ppath, flags, 0);
 }
 
-static struct config_file config;
+struct config_file config;
 static int failed_load_config = 1;
 
 void
index 541e730812cbc7196851a2f422b8fd6a0d9bcfd6..e391c4f55937a4748a47c1a334ea52a3c6c24492 100644 (file)
@@ -30,7 +30,7 @@ mk_structure()
     f_mkdir(PATH_PATCHES);
     f_mkdir(PATH_FIRMWARES);
     f_mkdir(PATH_MODULES);
-    f_mkdir(PATH_SERVICES);
+    f_mkdir(PATH_SVC);
     f_mkdir(PATH_KEYS);
     f_mkdir(PATH_EXEFS);
     f_mkdir(PATH_TEMP);
index 5e08761541dc7c4c610a053f5c59663888924a4d..e612267ddc12877650746d947cfbf3958adc1692 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __CONFIG_H
 #define __CONFIG_H
 
-_UNUSED static unsigned int config_version = 1;
+#define config_version 1
 
 #define CONFIG_MAGIC "OVAN"
 
@@ -54,8 +54,8 @@ struct options_s
 // Use builtin loader module replacer.
 #define OPTION_LOADER 2
 
-// Inject services (including backdoor for 11)
-#define OPTION_SERVICES 3
+// Inject svc calls (including backdoor for 11)
+#define OPTION_SVCS 3
 
 // Use builtin ARM9 thread injector.
 #define OPTION_ARM9THREAD 4
@@ -87,7 +87,7 @@ struct options_s
 // Enable language emulation.
 #define OPTION_LOADER_LANGEMU 13
 
-// Force replacement of services. Normally you don't want this.
+// Force replacement of non-null svcs. Normally you don't want this.
 #define OPTION_REPLACE_ALLOCATED_SVC 14
 
 // Ignore patch UUID dependencies. Not recommended.
@@ -107,24 +107,15 @@ struct options_s
 // change and causes caches to be regenerated.
 #define OPTION_RECONFIGURED 255
 
-// TODO - Every option beyond here is a patch now, so once I get listing
-// implemented, these shall go.
-
-#define OPTION_SIGPATCH 0 // Use builtin signature patch.
-#define OPTION_FIRMPROT 1 // Protect firmware from writes.
-
-#define OPTION_AADOWNGRADE 16 // Anti-anti-downgrade.
-#define OPTION_MEMEXEC 17     // Prevent MPU from disabling execute permissions.
-#define OPTION_UNITINFO 18    // Dev UNITINFO. Note that this is overkill.
-
 //#define HEADER_COLOR        12 // Color of header text.
 //#define BG_COLOR            13 // Color of background.
 //#define TEXT_COLOR          14 // Color of most text.
 //#define ARROW_COLOR         15 // Color of Arrow.
 
+#ifndef LOADER
 void load_config();
 void save_config();
-
+#endif
 /*
 [CORBENIK]
 version=1
index 98d24c678174a7c8b9b75d8be3a55c8e8415057c..8dcc59ab291da8b83b8aed64b730ffaebf8fcc0d 100644 (file)
@@ -286,9 +286,6 @@ boot_firm()
         fprintf(BOTTOM_SCREEN, "Updated keyX keyslots\n");
     }
 
-    fumount(); // Unmount SD. No longer needed.
-    fprintf(BOTTOM_SCREEN, "SD Unmounted.\n");
-
     for (firm_section_h *section = firm_loc->section; section < firm_loc->section + 4 && section->address != 0; section++) {
         memcpy((void *)section->address, (void *)firm_loc + section->offset, section->size);
     }
@@ -296,6 +293,10 @@ boot_firm()
 
     wait();
 
+    clear_disp(BOTTOM_SCREEN);
+
+    fumount(); // Unmount SD. No longer needed.
+
     // No fprintf will work from here on out.
 
     *a11_entry = (uint32_t)arm11_preboot_halt;
index 76b843630f0e1ba066adc3294a769aff3cdbafc8..e02f36dd6224ef858e9d500f0b207359e98b390f 100644 (file)
@@ -21,14 +21,14 @@ static struct options_s options[] = {
     // Patches.
     { 0, "\x1b[32;40mOptions\x1b[0m", "", not_option, 0, 0 },
 
-    { OPTION_LOADER, "System Modules", "Replaces system modules (including loader)", boolean_val, 0, 0 },
+    { OPTION_LOADER, "Loader Replacement", "Replaces loader with one capable of the below and also applying bytecode patches.", boolean_val, 0, 0 },
     { OPTION_LOADER_CPU_L2, "  CPU - L2 cache", "Forces the system to use the L2 cache. Ignored if not a N3DS.", boolean_val, 0, 0 },
     { OPTION_LOADER_CPU_800MHZ, "  CPU - 800Mhz", "Forces the system to run in 800Mhz mode. Ignored if not a N3DS.", boolean_val, 0, 0 },
     { OPTION_LOADER_LANGEMU, "  Language Emulation", "Reads language emulation configuration and imitates the region/language.", boolean_val, 0, 0 },
 
     { 0, "", "", not_option, 0, 0 },
 
-    { OPTION_SERVICES, "Service Replacement", "Replaces ARM11 services, including svcBackdoor. With 11.0 NATIVE_FIRM, you need this.", boolean_val, 0, 0 },
+    { OPTION_SVCS, "SVC Replacement", "Replaces ARM11 svc calls, including svcBackdoor. With 11.0 NATIVE_FIRM, you probably want this.", boolean_val, 0, 0 },
 
     { 0, "", "", not_option, 0, 0 },
 
@@ -44,10 +44,14 @@ static struct options_s options[] = {
     // Patches.
     { 0, "\x1b[32;40mDeveloper Options\x1b[0m", "", not_option, 0, 0 },
 
-    { OPTION_REPLACE_ALLOCATED_SVC, "Force service replace", "Replace ARM11 services even if they exist. Don't use unless you know what you're doing.",
+    { OPTION_REPLACE_ALLOCATED_SVC, "Force svc replace", "Replace ARM11 svc calls even if they exist. Don't use this unless you know what you're doing.",
       boolean_val, 0, 0 },
-    { OPTION_TRACE, "Debug Pauses", "After each important step, [WAIT] will be shown and you'll need to press a key. Debug.", boolean_val, 0, 0 },
+    { OPTION_TRACE, "Step Through", "After each important step, [WAIT] will be shown and you'll need to press a key. Debug.", boolean_val, 0, 0 },
     { OPTION_OVERLY_VERBOSE, "Verbose", "Output more debug information than the average user needs.", boolean_val, 0, 0 },
+    { OPTION_SAVE_LOGS, "Logging", "Save logs to the corbenik folder. Slows operation a bit.", boolean_val, 0, 0 },
+
+    { OPTION_RECONFIGURED, "Reconfigured (DO NOT UNCHECK)", "If patches were reconfigured, this will be set. Do not untick this if ticked.", boolean_val, 0,
+      0 },
 
     //    { OPTION_ARM9THREAD,        "ARM9 Thread", boolean_val, 0, 0 },
     //    { IGNORE_PATCH_DEPS,   "Ignore dependencies", boolean_val, 0, 0 },
index 7ec806e68996f4ef96c59b8d365fd5782c6ef60e..281f9a6748294f546f58cfa21caf8e1b5ae28a76 100644 (file)
@@ -33,7 +33,7 @@ PATCH(services)
 
     fprintf(stderr, "Svc: table at %x\n", (uint32_t)svcTable);
 
-    char str[] = PATH_SERVICES "/00.bin";
+    char str[] = PATH_SVC "/00.bin";
     char *at = str + (strlen(str) - 6);
     // FIXME - This is really slow. Some way to optimize it?
     for (uint32_t i = 0; i <= 0xf; i++) {
index b2f76a3ae7a603f63b5b5ccf759bb03b70a69925..c9af51b3d37a37ff40ee5f5a12400f179e851da1 100644 (file)
@@ -38,7 +38,7 @@
 #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
-#define PATH_SERVICES PATH_CFW "/svc"       // Svc code location.
+#define PATH_SVC PATH_CFW "/svc"            // Svc code location.
 
 #define PATH_TEMP PATH_CFW "/cache"           // Files that are transient and used to speed operation
 #define PATH_LOADER_CACHE PATH_TEMP "/loader" // Cached patch bytecode for loader.
index 64dd5b6ea950c13ea5badfdeaf69c3a78af05f08..b8ae1edb18badc5fd9d4792f7465874e87f7f72f 100644 (file)
@@ -62,16 +62,16 @@ patch_firm_all()
     // Replace loader?
     if (config.options[OPTION_LOADER]) {
         if (patch_modules()) {
-            abort("Fatal. Service patch has failed.");
+            abort("Fatal. Loader inject has failed.");
         }
         // This requires OPTION_SIGPATCH.
         wait();
     }
 
     // Inject services?
-    if (config.options[OPTION_SERVICES]) {
+    if (config.options[OPTION_SVCS]) {
         if (patch_services()) {
-            abort("Fatal. Service patch has failed.");
+            abort("Fatal. Svc inject has failed.");
         }
         wait();
     }
index d8bff70ec35523543838f13f445a43ebbdc461b5..08f62830f123d15daab04a48c888c3bd933360db 100644 (file)
@@ -8,14 +8,16 @@
 #include "../fatfs/ff.h"
 #include "fs.h"
 #include "unused.h"
+#include "../config.h"
+#include "../patch_format.h"
 
 static unsigned int top_cursor_x = 0, top_cursor_y = 0;
 static unsigned int bottom_cursor_x = 0, bottom_cursor_y = 0;
 
-#ifdef BUFFER
-static char text_buffer_top[TEXT_TOP_HEIGHT * TEXT_TOP_WIDTH + 1];
 static char text_buffer_bottom[TEXT_BOTTOM_HEIGHT * TEXT_BOTTOM_WIDTH + 1];
 
+#ifdef BUFFER
+static char text_buffer_top[TEXT_TOP_HEIGHT * TEXT_TOP_WIDTH + 1];
 static char color_buffer_top[TEXT_TOP_HEIGHT * TEXT_TOP_WIDTH + 1];
 static char color_buffer_bottom[TEXT_BOTTOM_HEIGHT * TEXT_BOTTOM_WIDTH + 1];
 #endif
@@ -42,6 +44,22 @@ static uint32_t colors[16] = {
 void
 clear_disp(uint8_t *screen)
 {
+    // There's a reason the logging code is here rather than putc:
+    // writing a batch is faster.
+    if (screen == BOTTOM_SCREEN && config.options[OPTION_SAVE_LOGS]) {
+        FILE *f = fopen(PATH_CFW "/boot.log", "w");
+        fseek(f, 0, SEEK_END);
+        for (int i = 0; i < TEXT_BOTTOM_HEIGHT; i++) {
+            char *text = text_buffer_bottom + (TEXT_BOTTOM_WIDTH * i);
+            if (text[0] == 0)
+                break;
+            fwrite(text, 1, strnlen(text, TEXT_BOTTOM_WIDTH), f);
+            fwrite("\n", 1, 1, f);
+        }
+        fclose(f);
+        memset(text_buffer_bottom, 0, TEXT_BOTTOM_WIDTH * TEXT_BOTTOM_HEIGHT);
+    }
+
     if (screen == TOP_SCREEN)
         screen = framebuffers->top_left;
     else if (screen == BOTTOM_SCREEN)
@@ -224,6 +242,7 @@ putc(void *buf, const int c)
             clear_disp(buf);
             cursor_x[0] = 0;
             cursor_y[0] = 0;
+
 /*                     uint32_t col = SCREEN_TOP_HEIGHT * SCREEN_DEPTH;
             uint32_t one_c = 8 * SCREEN_DEPTH;
             for (unsigned int x = 0; x < width * 8; x++) {
@@ -254,6 +273,8 @@ putc(void *buf, const int c)
                 }
 
 #else
+                if (buf == BOTTOM_SCREEN)
+                    text_buffer_bottom[cursor_y[0] * width + cursor_x[0]] = c;
                 draw_character(screen, c, cursor_x[0], cursor_y[0], colors[(*color >> 4) & 0xF], colors[*color & 0xF]);
 #endif
 
index f3c7641157f0af47c74ec0d496a5c616cae4b35c..bc5d864ab067933a439eef76b8dc940c41e1aed3 100644 (file)
@@ -66,6 +66,8 @@ void fflush(void *channel);
 
 void set_cursor(void *channel, unsigned int x, unsigned int y);
 
+void clear_disp(uint8_t *screen);
+
 // Like printf. Supports the following format specifiers:
 //  %s - char*
 //  %c - char