From 1c2a05cd96148a578af33d547afad2fde7596607 Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Thu, 4 Aug 2016 01:44:19 -0400 Subject: [PATCH] Because people still have yet to learn their lesson regarding pointers shoved in weird places --- Makefile.am | 3 +++ autogen.sh | 1 - configure.ac | 2 -- include/std/draw.h | 7 +++++-- source/main.c | 15 ++------------- source/option.c | 22 +--------------------- source/screeninit.c | 7 +++++++ source/std/allocator.c | 2 ++ 8 files changed, 20 insertions(+), 39 deletions(-) diff --git a/Makefile.am b/Makefile.am index 7b893a1..1bf6203 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,3 +43,6 @@ all-local: echo "wget http://nus.cdn.c.shop.nintendowifi.net/ccs/download/0004013820000202/cetk -O .@datarootdir@/keys/agb.cetk" >> out/n3ds_firm.sh chmod 755 out/*.sh cp README.md LICENSE.txt out/ + +clean-local: + rm -rf out diff --git a/autogen.sh b/autogen.sh index fad27d8..28a183b 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,3 +1,2 @@ #!/bin/sh -mkdir -p m4 autoreconf -fi diff --git a/configure.ac b/configure.ac index 82f672b..bf60672 100644 --- a/configure.ac +++ b/configure.ac @@ -1,8 +1,6 @@ AC_INIT([Corbenik], [0.1.2], [https://github.com/chaoskagami/corbenik], [corbenik]) AM_INIT_AUTOMAKE([foreign no-dist-gzip dist-xz subdir-objects]) -AC_CONFIG_MACRO_DIRS([m4]) - # Find AR and RANLIB for lto support before initializing libtool AC_CHECK_TOOL([AR],gcc-ar) AC_CHECK_TOOL([RANLIB],gcc-ranlib) diff --git a/include/std/draw.h b/include/std/draw.h index dbc88a6..ea6ed75 100644 --- a/include/std/draw.h +++ b/include/std/draw.h @@ -25,12 +25,15 @@ enum screen screen_bottom }; -_UNUSED static struct framebuffers +struct framebuffers { uint8_t *top_left; uint8_t *top_right; uint8_t *bottom; -} *framebuffers = (struct framebuffers *)0x23FFFE00; +}; + +_UNUSED static struct framebuffers *framebuffers_cakehax = (struct framebuffers *)0x23FFFE00; +extern struct framebuffers *framebuffers; // This is marked unused since it occurs in all files. #define TOP_FB framebuffers->top_left diff --git a/source/main.c b/source/main.c index 3da3db2..01d0ed9 100644 --- a/source/main.c +++ b/source/main.c @@ -19,19 +19,8 @@ main(int argc, char** argv) std_init(); - int c = fmount(); - - if (c) { - // Failed to mount SD. Bomb out. - // TODO - What the hell does one even do in this situation? - // Spin until the card is available to mount, maybe? - abort("Failed to mount SD card.\n"); - } - - if (argc >= 1 && argc < 2) { - // Valid argc passed. - fprintf(stderr, "Chainloaded. Path: %s\n", argv[0]); - } + if (fmount()) + poweroff(); // Failed to mount SD. Bomb out. set_font(PATH_TERMFONT); // Read the font before all else. diff --git a/source/option.c b/source/option.c index 88924d5..c75fe99 100644 --- a/source/option.c +++ b/source/option.c @@ -17,12 +17,10 @@ regenerate_config() config->options[OPTION_BRIGHTNESS] = 3; if (!(conf_handle = fopen(PATH_CONFIG, "w"))) - abort("Failed to open config for write?\n"); + poweroff(); fwrite(config, 1, sizeof(struct config_file), conf_handle); fclose(conf_handle); - - fprintf(BOTTOM_SCREEN, "Config file written.\n"); } void @@ -60,7 +58,6 @@ update_config() int updated = 0; if (config->options[OPTION_ACCENT_COLOR] == 0) { - fprintf(stderr, "Config update: accent color\n"); config->options[OPTION_ACCENT_COLOR] = 2; updated = 1; } @@ -80,31 +77,17 @@ load_config() // Zero on success. if (!(conf_handle = fopen(PATH_CONFIG, "r"))) { - fprintf(BOTTOM_SCREEN, "Config file is missing:\n" - " %s\n" - "Regenerating with defaults.\n", - PATH_CONFIG); regenerate_config(); } else { fread(config, 1, sizeof(struct config_file), conf_handle); fclose(conf_handle); 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]); f_unlink(PATH_CONFIG); regenerate_config(); } if (config->config_ver < config_version) { - fprintf(BOTTOM_SCREEN, "Config file has outdated version:\n" - " %s\n" - "Regenerating with defaults.\n", - PATH_CONFIG); f_unlink(PATH_CONFIG); regenerate_config(); } @@ -112,9 +95,6 @@ load_config() list_patches_build(PATH_PATCHES, 0); - if (!config->options[OPTION_SILENCE]) - fprintf(BOTTOM_SCREEN, "Config file loaded.\n"); - update_config(); } diff --git a/source/screeninit.c b/source/screeninit.c index 9b1e255..4f8b3a7 100644 --- a/source/screeninit.c +++ b/source/screeninit.c @@ -7,6 +7,8 @@ static volatile uint32_t *const a11_entry = (volatile uint32_t *)0x1FFFFFF8; +struct framebuffers* framebuffers = NULL; + void screen_mode(uint32_t mode) { @@ -39,6 +41,11 @@ screen_mode(uint32_t mode) while (*a11_entry); + if (!framebuffers) { + framebuffers = malloc(sizeof(struct framebuffers)); + memcpy(framebuffers, framebuffers_cakehax, sizeof(struct framebuffers)); + } + // Turn on backlight i2cWriteRegister(I2C_DEV_MCU, 0x22, 1 << 1); } diff --git a/source/std/allocator.c b/source/std/allocator.c index 7cda16e..b6b380d 100644 --- a/source/std/allocator.c +++ b/source/std/allocator.c @@ -14,6 +14,8 @@ void* sbrk(size_t incr) { heap_end = &__end__; } + // FIXME - Make sure heap isn't leaking into stack here. That would be bad. + prev_heap_end = heap_end; heap_end += incr; -- 2.39.5