]> Chaos Git - corbenik/corbenik.git/commitdiff
More malloc'ing (and linker script adjustments)
authorchaoskagami <chaos.kagami@gmail.com>
Wed, 3 Aug 2016 09:38:17 +0000 (05:38 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Wed, 3 Aug 2016 09:38:17 +0000 (05:38 -0400)
include/option.h
source/display.c
source/firm/firm.c
source/interp.c
source/linker.ld
source/main.c
source/menu.c
source/option.c
source/patcher.c
source/std/draw.c
source/std/fs.c

index ba5f154ac71438e784123fb3ddca607748228fd6..9057b271ef4ee87b741a79ecdcc75725ee4c3c27 100644 (file)
@@ -26,7 +26,11 @@ struct patch_state
     uint8_t state;
 } __attribute__((packed));
 
+#ifdef LOADER
 extern struct config_file config;
+#else
+extern struct config_file *config;
+#endif
 
 enum type
 {
index a58dd00d2ed086af5c17bddd7625f59c80acf217..96dacc00b00ffbe28ce4c2c3d874e4aaf8fcb5dd 100644 (file)
@@ -17,7 +17,7 @@ void show_help(char* help) {
 void accent_color(void* screen, int fg) {
     char color[] = "\x1b[30m";
     if (!fg) color[2] = '4';
-    color[3] = ("01234567")[config.options[OPTION_ACCENT_COLOR]];
+    color[3] = ("01234567")[config->options[OPTION_ACCENT_COLOR]];
     fprintf(screen, "%s", color);
 }
 
index dadcf7d6518026ed8b73beb65b366d2286b56d04..f8ab2dae14bf4b967fb89e97828db441b9c76e62 100644 (file)
@@ -557,7 +557,7 @@ boot_cfw()
 
     load_firms();
 
-    if (config.options[OPTION_RECONFIGURED]) {
+    if (config->options[OPTION_RECONFIGURED]) {
         fprintf(stderr, "Generating patch cache...\n");
         generate_patch_cache();
     }
@@ -566,7 +566,7 @@ boot_cfw()
     if (patch_firm_all() != 0)
         return;
 
-    if (config.options[OPTION_REBOOT] && config.options[OPTION_RECONFIGURED]) {
+    if (config->options[OPTION_REBOOT] && config->options[OPTION_RECONFIGURED]) {
         fprintf(stderr, "Saving FIRM for reboot...\n");
         if (!write_file(firm_loc, PATH_NATIVE_P, firm_size))
             abort("Failed to save prepatched native\n");
index eed4b4552a8eeea8c6ee605f21914520c99347b0..716d0e27b181aa482a6fe9642d5db5d8dcd849d7 100644 (file)
@@ -721,7 +721,11 @@ execb(char *filename, int build_cache)
 #endif
 
     int debug = 0;
+#ifdef LOADER
     if (config.options[OPTION_OVERLY_VERBOSE]) {
+#else
+    if (config->options[OPTION_OVERLY_VERBOSE]) {
+#endif
         debug = 1;
     }
 
index aba1eaada27fc1b868083c3d1c759cc0271969e0..ce3aa9e6743d0578a4b9a70622f67e9b5091c5e2 100644 (file)
@@ -8,24 +8,45 @@ SECTIONS
         *(.text.start)
     }
 
+    . = ALIGN(4);
+
     .text : {
         *(.text)
     }
 
+    . = ALIGN(4);
+
     .data : {
         *(.data)
     }
 
+    . = ALIGN(4);
+
+    .rodata : {
+        *(.rodata)
+    }
+
+    . = ALIGN(4);
+
+    .rel : {
+        *(.rel)
+    }
+
+    . = ALIGN(4);
+
+    .symtab : {
+        *(.symtab)
+    }
+
+    . = ALIGN(4);
+
     .bss : {
         __bss_start = .;
         *(.bss COMMON)
     }
     __bss_end = .;
 
-    .rodata : {
-        *(.rodata)
-    }
-
     . = ALIGN(4);
+
     __end__ = 0x20400000;
 }
index c3a2da5854aa1158c1a6c64633b4c62c9da455fe..cc8844cf9624363727d88bcb6e90a012daa646ea 100644 (file)
@@ -51,12 +51,12 @@ main(int argc, char** argv)
 
     if (CFG_BOOTENV == 7) {
         fprintf(stderr, "Rebooted from AGB, disabling EmuNAND.\n");
-        config.options[OPTION_EMUNAND] = 0;
+        config->options[OPTION_EMUNAND] = 0;
     }
 
     // Autoboot. Non-standard code path.
-    if (config.options[OPTION_AUTOBOOT] && !(ctr_hid_get_buttons() & CTR_HID_RT)) {
-        if (config.options[OPTION_SILENCE])
+    if (config->options[OPTION_AUTOBOOT] && !(ctr_hid_get_buttons() & CTR_HID_RT)) {
+        if (config->options[OPTION_SILENCE])
             shut_up(); // This does exactly what it sounds like.
         doing_autoboot = 1;
     } else {
index 3743a87e3f0df9e7ff3badd0f0faf6717be293db..fa9a4e1f751f42880f8d86029f910a07e242f241 100644 (file)
@@ -66,7 +66,7 @@ void
 header(char *append)
 {
     set_cursor(TOP_SCREEN, 0, 0);
-    fill_line(stdout, 0, config.options[OPTION_ACCENT_COLOR]);
+    fill_line(stdout, 0, config->options[OPTION_ACCENT_COLOR]);
     accent_color(TOP_SCREEN, 0);
     fprintf(stdout, "\x1b[30m ." FW_NAME " // %s\x1b[0m\n\n", append);
 }
@@ -181,7 +181,7 @@ menu_patches()
 void
 menu_options()
 {
-    show_menu(options, config.options);
+    show_menu(options, config->options);
 }
 
 #ifndef REL
index 0125d49910e0b25763947e4c8d3a8cefee2a1e8b..1d8d710f175447d8a0bc36b9733faf8629d469db 100644 (file)
@@ -2,22 +2,23 @@
 
 FILE *conf_handle;
 
-struct config_file config;
+struct config_file *config;
 extern uint8_t *enable_list;
 void list_patches_build(char *name, int desc_is_fname);
 
 void
 regenerate_config()
 {
-    memset(&config, 0, sizeof(config));
-    memcpy(&(config.magic), CONFIG_MAGIC, 4);
-    config.config_ver = config_version;
-    config.options[OPTION_ACCENT_COLOR] = 2;
+    for(int i=0; i < 4; i++)
+        config->magic[i] = CONFIG_MAGIC[i];
+
+    config->config_ver = config_version;
+    config->options[OPTION_ACCENT_COLOR] = 2;
 
     if (!(conf_handle = fopen(PATH_CONFIG, "w")))
         abort("Failed to open config for write?\n");
 
-    fwrite(&config, 1, sizeof(config), conf_handle);
+    fwrite(config, 1, sizeof(struct config_file), conf_handle);
     fclose(conf_handle);
 
     fprintf(BOTTOM_SCREEN, "Config file written.\n");
@@ -57,9 +58,9 @@ update_config()
 {
     int updated = 0;
 
-    if (config.options[OPTION_ACCENT_COLOR] == 0) {
+    if (config->options[OPTION_ACCENT_COLOR] == 0) {
         fprintf(stderr, "Config update: accent color\n");
-        config.options[OPTION_ACCENT_COLOR] = 2;
+        config->options[OPTION_ACCENT_COLOR] = 2;
         updated = 1;
     }
 
@@ -71,6 +72,9 @@ update_config()
 void
 load_config()
 {
+    config = (struct config_file*)malloc(sizeof(struct config_file));
+    memset(config, 0, sizeof(struct config_file));
+
     mk_structure(); // Make directory structure if needed.
 
     // Zero on success.
@@ -81,21 +85,21 @@ load_config()
                 PATH_CONFIG);
         regenerate_config();
     } else {
-        fread(&config, 1, sizeof(config), conf_handle);
+        fread(config, 1, sizeof(struct config_file), conf_handle);
         fclose(conf_handle);
 
-        if (memcmp(&(config.magic), CONFIG_MAGIC, 4)) {
+        if (memcmp(&(config->magic), CONFIG_MAGIC, 4)) {
             fprintf(BOTTOM_SCREEN, "Config file at:\n"
                                    "  %s\n"
                                    "has incorrect magic:\n"
                                    "  '%c%c%c%c'\n"
                                    "Regenerating with defaults.\n",
-                    PATH_CONFIG, config.magic[0], config.magic[1], config.magic[2], config.magic[3]);
+                    PATH_CONFIG, config->magic[0], config->magic[1], config->magic[2], config->magic[3]);
             f_unlink(PATH_CONFIG);
             regenerate_config();
         }
 
-        if (config.config_ver < config_version) {
+        if (config->config_ver < config_version) {
             fprintf(BOTTOM_SCREEN, "Config file has outdated version:\n"
                                    "  %s\n"
                                    "Regenerating with defaults...\n",
@@ -107,7 +111,7 @@ load_config()
 
     list_patches_build(PATH_PATCHES, 0);
 
-    if (!config.options[OPTION_SILENCE])
+    if (!config->options[OPTION_SILENCE])
         fprintf(BOTTOM_SCREEN, "Config file loaded.\n");
 
     update_config();
@@ -125,10 +129,10 @@ save_config()
     if (!(conf_handle = fopen(PATH_CONFIG, "w")))
         abort("Failed to open config for write?\n");
 
-    config.options[OPTION_RECONFIGURED] = 0; // This should not persist to disk.
+    config->options[OPTION_RECONFIGURED] = 0; // This should not persist to disk.
 
-    fwrite(&config, 1, sizeof(config), conf_handle);
+    fwrite(config, 1, sizeof(struct config_file), conf_handle);
     fclose(conf_handle);
 
-    config.options[OPTION_RECONFIGURED] = 1; // Save caches on boot.
+    config->options[OPTION_RECONFIGURED] = 1; // Save caches on boot.
 }
index dc919af5b2808db48a54d36d8f9f9078655808eb..375307d018b02b121d0df93f16cfa9684d143dbd 100644 (file)
@@ -18,7 +18,7 @@ extern struct options_s* patches;
 void
 wait()
 {
-    if (config.options[OPTION_TRACE] && !doing_autoboot) {
+    if (config->options[OPTION_TRACE] && !doing_autoboot) {
         fprintf(stderr, "[Waiting...]");
         wait_key(0); // No delay on traces.
     }
@@ -58,22 +58,22 @@ patch_firm_all()
     fprintf(stderr, "VM exited without issue\n");
 
     // Hook firmlaunch?
-    if (config.options[OPTION_REBOOT]) {
+    if (config->options[OPTION_REBOOT]) {
         patch_reboot();
 
         wait();
     }
 
     // Use EmuNAND?
-    if (config.options[OPTION_EMUNAND]) {
+    if (config->options[OPTION_EMUNAND]) {
         // Yes.
-        patch_emunand(config.options[OPTION_EMUNAND_INDEX]);
+        patch_emunand(config->options[OPTION_EMUNAND_INDEX]);
 
         wait();
     }
 
     // Inject services?
-    if (config.options[OPTION_SVCS]) {
+    if (config->options[OPTION_SVCS]) {
         if (patch_services()) {
             abort("Fatal. Svc inject has failed.");
         }
@@ -81,7 +81,7 @@ patch_firm_all()
     }
 
     // Replace loader?
-    if (config.options[OPTION_LOADER]) {
+    if (config->options[OPTION_LOADER]) {
         if (patch_modules()) {
             abort("Fatal. Loader inject has failed.");
         }
@@ -90,7 +90,7 @@ patch_firm_all()
     }
 
     // Use ARM9 hook thread?
-    if (config.options[OPTION_ARM9THREAD]) {
+    if (config->options[OPTION_ARM9THREAD]) {
         // Yes.
 
         // FIXME - NYI
index 410b21959bdf9a50b96eafd25545241d5c51e809..8157300a64bbd835cd8a41f7a7b22b7d69f959b2 100644 (file)
@@ -209,7 +209,7 @@ void set_font(const char* filename) {
 }
 
 void dump_log(unsigned int force) {
-    if(!config.options[OPTION_SAVE_LOGS])
+    if(!config->options[OPTION_SAVE_LOGS])
         return;
 
     if (force == 0 && log_size < LOG_BUFFER_SIZE-1)
@@ -241,7 +241,7 @@ clear_disp(uint8_t *screen)
             screen[j + 1] = top_bg[i];
             screen[j + 2] = top_bg[i + 1];
             screen[j + 3] = top_bg[i + 2];
-            if (!kill_output && config.options[OPTION_DIM_MODE]) {
+            if (!kill_output && config->options[OPTION_DIM_MODE]) {
                 screen[j + 1] = alphamap[screen[j + 1]];
                 screen[j + 2] = alphamap[screen[j + 2]];
                 screen[j + 3] = alphamap[screen[j + 3]];
@@ -256,7 +256,7 @@ clear_disp(uint8_t *screen)
             screen[j + 1] = bottom_bg[i];
             screen[j + 2] = bottom_bg[i + 1];
             screen[j + 3] = bottom_bg[i + 2];
-            if (!kill_output && config.options[OPTION_DIM_MODE]) {
+            if (!kill_output && config->options[OPTION_DIM_MODE]) {
                 screen[j + 1] = alphamap[screen[j + 1]];
                 screen[j + 2] = alphamap[screen[j + 2]];
                 screen[j + 3] = alphamap[screen[j + 3]];
@@ -327,7 +327,7 @@ draw_character(uint8_t *screen, const uint32_t character, int ch_x, int ch_y, co
                 screen[pos + 1] = buffer_bg[pos_b];
                 screen[pos + 2] = buffer_bg[pos_b + 1];
                 screen[pos + 3] = buffer_bg[pos_b + 2];
-                if (config.options[OPTION_DIM_MODE]) {
+                if (config->options[OPTION_DIM_MODE]) {
                     screen[pos + 1] = alphamap[screen[pos + 1]];
                     screen[pos + 2] = alphamap[screen[pos + 2]];
                     screen[pos + 3] = alphamap[screen[pos + 3]];
@@ -343,7 +343,7 @@ draw_character(uint8_t *screen, const uint32_t character, int ch_x, int ch_y, co
                     screen[pos + 1] = buffer_bg[pos_b];
                     screen[pos + 2] = buffer_bg[pos_b + 1];
                     screen[pos + 3] = buffer_bg[pos_b + 2];
-                    if (config.options[OPTION_DIM_MODE]) {
+                    if (config->options[OPTION_DIM_MODE]) {
                         screen[pos + 1] = alphamap[screen[pos + 1]];
                         screen[pos + 2] = alphamap[screen[pos + 2]];
                         screen[pos + 3] = alphamap[screen[pos + 3]];
index fb5d4da67bc9e28b29678b902929117974948e83..9ef5e1e26cc04cc6d649caea13f19759abc28c22 100644 (file)
@@ -80,7 +80,7 @@ fumount(void)
     if (f_mount(NULL, "SD:", 1))
         return 1;
 
-    config.options[OPTION_SAVE_LOGS] = 0; // FS unmounted, can't log anymore
+    config->options[OPTION_SAVE_LOGS] = 0; // FS unmounted, can't log anymore
 
     return 0;
 }