From: chaoskagami Date: Mon, 8 Aug 2016 04:22:58 +0000 (-0400) Subject: Fixups and renames for accuracy X-Git-Tag: v0.3.0~65 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=314f569354ef128aae8f514655d0e4b9d362a21c;p=corbenik%2Fcorbenik.git Fixups and renames for accuracy --- diff --git a/external/loader/source/interp.c b/external/loader/source/interp.c index 5344aff..28bc338 100644 --- a/external/loader/source/interp.c +++ b/external/loader/source/interp.c @@ -25,7 +25,7 @@ #define MAX_PATCHSIZE 16384 // Yes, we're including a C file. Problem? -#include "../../../source/interp.c" +#include "../../../source/interpreter.c" #if 0 diff --git a/include/screeninit.h b/include/arm11.h similarity index 99% rename from include/screeninit.h rename to include/arm11.h index 0a27794..4dfeac4 100644 --- a/include/screeninit.h +++ b/include/arm11.h @@ -1,7 +1,6 @@ #ifndef __SCREENINIT_H #define __SCREENINIT_H - #define PDN_GPU_CNT (*(volatile uint32_t*)0x10141200) #define LCD_REG(offset) (*((volatile uint32_t*)(0x10202000 + (offset)))) diff --git a/include/common.h b/include/common.h index 4f2e521..53c1788 100644 --- a/include/common.h +++ b/include/common.h @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include #include diff --git a/include/menu-backend.h b/include/menu-backend.h new file mode 100644 index 0000000..3d16475 --- /dev/null +++ b/include/menu-backend.h @@ -0,0 +1,7 @@ +#ifndef __MENU_BACKEND_H__ +#define __MENU_BACKEND_H__ + +void accent_color(void* screen, int fg); +int show_menu(struct options_s *options, uint8_t *toggles); + +#endif diff --git a/source/Makefile.am b/source/Makefile.am index 6f9bc98..0e28efd 100644 --- a/source/Makefile.am +++ b/source/Makefile.am @@ -19,4 +19,4 @@ corbenikdir = $(top_srcdir)/source inc_dir = $(top_srcdir)/include -corbenik_SOURCES = patch/reboot.c patch/svc.c patch/module.c patch/emunand.c main.c option.c std/fs.c std/draw.c std/memory.c std/abort.c menu.c chain.c firm/version.c firm/firm.c firm/decryptor.c std/allocator.c interp.c input.c patcher.c display.c start.s interrupt.c screeninit.c +corbenik_SOURCES = patch/reboot.c patch/svc.c patch/module.c patch/emunand.c main.c std/fs.c std/draw.c std/memory.c std/abort.c std/allocator.c menu.c firm/version.c firm/firm.c firm/decryptor.c interpreter.c input.c patcher.c chainloader.c config-file.c menu-backend.c start.s interrupt.c arm11.c diff --git a/source/screeninit.c b/source/arm11.c similarity index 97% rename from source/screeninit.c rename to source/arm11.c index 5be8d08..2115a2c 100644 --- a/source/screeninit.c +++ b/source/arm11.c @@ -149,8 +149,10 @@ void screen_mode(uint32_t mode) { init_top = MAKE_FRAMEBUFFER_PIXFMT(mode, 0, 1); init_bottom = MAKE_FRAMEBUFFER_PIXFMT(mode, 0, 0); - // We literally just discard the previous state - for sanity's sake. if (!framebuffers) { + // Look ma, dynamically allocating the CakeHax struct! (joking) + // We literally just discard the previous state - for sanity's sake. + // On chainload, it is needed to copy the framebuffer struct. framebuffers = malloc(sizeof(struct framebuffers)); } @@ -243,7 +245,7 @@ void screen_mode(uint32_t mode) { PDC1_FRAMEBUFFER_SETUP_FBA_ADDR_1 = 0x1835dc00; PDC1_FRAMEBUFFER_SETUP_FBA_ADDR_2 = 0x1835dc00; - //Set CakeBrah framebuffers + // Set not-actually cakebrah framebuffers. Meh. framebuffers->top_left = (uint8_t *)0x18300000; framebuffers->top_right = (uint8_t *)0x18300000; framebuffers->bottom = (uint8_t *)0x1835dc00; diff --git a/source/chain.c b/source/chainloader.c similarity index 90% rename from source/chain.c rename to source/chainloader.c index 7a102c4..82557a9 100644 --- a/source/chain.c +++ b/source/chainloader.c @@ -2,9 +2,6 @@ #if defined(CHAINLOADER) && CHAINLOADER == 1 #include -#include -#include -#include uint32_t current_chain_index = 0; @@ -16,7 +13,9 @@ int show_menu(struct options_s *options, uint8_t *toggles); // be better to have a recursive listing that calls a function for // each entry (it would cut code density) -void chainload_file(char* chain_file_data) { +__attribute__ ((noreturn)) +void chainload_file(char* chain_file_data) +{ // We copy because it's possible the payload will overwrite us in memory. char chain_file[256]; strncpy(chain_file, chain_file_data, 255); @@ -67,10 +66,15 @@ void chainload_file(char* chain_file_data) { argc_off[0] = 1; argv_off[0] = (uint32_t)off; - fprintf(stderr, "Chaining to copy payload...\n"); + fprintf(stderr, "Changing display mode and chainloading...\n"); screen_mode(1); // TODO - Because RGBA8 screeninit is non-standard...ugh + // Copy CakeHax struct where it is expected (at 0x23FFFE00) + // It's very very likely we'll corrupt memory with this, but we aren't coming back anyways as of the + // next call, so not my problem + memcpy((void*)0x23FFFE00, framebuffers, sizeof(struct framebuffers)); + ((void(*)(void*, uint32_t))0x24F00000)(chain_data, size + 256 + 8); // Size of payload + argv. } diff --git a/source/option.c b/source/config-file.c similarity index 100% rename from source/option.c rename to source/config-file.c diff --git a/source/firm/firm.c b/source/firm/firm.c index 51dce83..1be1a4d 100644 --- a/source/firm/firm.c +++ b/source/firm/firm.c @@ -429,6 +429,7 @@ void __attribute__((naked)) arm11_preboot_halt() extern void wait(); +__attribute__ ((noreturn)) void boot_firm() { diff --git a/source/interp.c b/source/interpreter.c similarity index 100% rename from source/interp.c rename to source/interpreter.c diff --git a/source/display.c b/source/menu-backend.c similarity index 96% rename from source/display.c rename to source/menu-backend.c index 1130e55..93e516c 100644 --- a/source/display.c +++ b/source/menu-backend.c @@ -1,11 +1,18 @@ #include -void header(char *append); - extern int is_n3ds; - +extern unsigned int font_w; extern unsigned int font_h; +void +header(char *append) +{ + set_cursor(TOP_SCREEN, 0, 0); + 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); +} + void show_help(char* help) { clear_disp(TOP_SCREEN); set_cursor(TOP_SCREEN, 0, 0); diff --git a/source/menu.c b/source/menu.c index 36f07be..73622a1 100644 --- a/source/menu.c +++ b/source/menu.c @@ -60,19 +60,6 @@ static struct options_s options[] = { { -1, "", "", 0, 0, 0 }, // cursor_min and cursor_max are stored in the last two. }; -extern unsigned int font_w; - -void accent_color(void* screen, int fg); - -void -header(char *append) -{ - set_cursor(TOP_SCREEN, 0, 0); - 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); -} - static int current_menu_index_patches = 0; // This function is based on PathDeleteWorker from GodMode9. @@ -172,8 +159,6 @@ list_patches_build(char *name, int desc_is_fname) } } -int show_menu(struct options_s *options, uint8_t *toggles); - void menu_patches() { diff --git a/source/std/draw.c b/source/std/draw.c index bab7f48..a595482 100644 --- a/source/std/draw.c +++ b/source/std/draw.c @@ -379,6 +379,7 @@ int stdout_state = TEXT, stderr_state = TEXT; int stdout_val = 0, stderr_val = 0; // Returns 1 if state machine is parsing - and will not output. +// This is how colors are now handled. int ansi_statemach(void* buf, const int c) { @@ -671,10 +672,6 @@ vfprintf(void *channel, const char *format, va_list ap) } break; case 's': - // FIXME - Substring ANSI colors will screw up hard, so don't do that. - // once the color handling is moved to putc as a state machine this - // will no longer be an issue. - // For now, this warning stays. disable_format = 1; // Disable format strings. fprintf(channel, va_arg(ap, char *)); @@ -727,3 +724,14 @@ fprintf(void *channel, const char *format, ...) va_end(ap); } + +void +printf(void *channel, const char *format, ...) +{ + va_list ap; + va_start(ap, format); + + vfprintf(stdout, format, ap); + + va_end(ap); +}