From 8a683f5816a4aa2d78f168ddcb33828a9578b68c Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Sat, 30 Jul 2016 00:58:04 -0400 Subject: [PATCH] Change a few flags (for now) and fix a bunch of warnings --- common.mk | 4 ++-- source/display.c | 13 ++++++++----- source/firm/firm.c | 13 +++++++------ source/interp.c | 2 +- source/menu.c | 6 +++--- source/patch/module.c | 5 +++-- source/patch/reboot.c | 3 +++ source/patch/svc.c | 5 +++-- source/patcher.c | 2 -- source/std/abort.c | 1 - source/std/draw.c | 6 +++++- 11 files changed, 35 insertions(+), 25 deletions(-) diff --git a/common.mk b/common.mk index 403e7cc..8417af2 100644 --- a/common.mk +++ b/common.mk @@ -9,10 +9,10 @@ REVISION := $(shell git rev-parse HEAD | head -c10)+$(shell git rev-list --count AM_CFLAGS= -std=gnu11 -Os -g -fomit-frame-pointer -ffast-math \ -Wpedantic -Wall -Wextra -Wcast-align -Wcast-qual \ -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op \ - -Wmissing-declarations -Wmissing-include-dirs -Wredundant-decls \ + -Wmissing-include-dirs -Wredundant-decls \ -Wshadow -Wsign-conversion -Wstrict-overflow=5 -Wswitch-default \ -Wundef -Wno-unused $(THUMBFLAGS) $(SIZE_OPTIMIZATION) $(INCPATHS) $(C9FLAGS) \ - -fshort-wchar -fno-builtin -std=gnu11 -DVERSION=\"$(REVISION)\" \ + -fshort-wchar -fno-builtin -std=gnu11 -DREVISION=\"$(REVISION)\" \ -DFW_NAME=\"corbenik\" $(PATHARGS) diff --git a/source/display.c b/source/display.c index a58dd00..ab70d45 100644 --- a/source/display.c +++ b/source/display.c @@ -28,7 +28,9 @@ show_menu(struct options_s *options, uint8_t *toggles) int cursor_min = -1; int cursor_max = -1; int exit = 0; - int window_size = (TOP_HEIGHT / font_h) - 3; + + // Font height is user-controlled. Realistically, if it's higher than a signed int, that's not my fault. + int window_size = (TOP_HEIGHT / (int)font_h) - 3; int window_top = 0, window_bottom = window_size; int less_mode = 0; @@ -82,12 +84,12 @@ show_menu(struct options_s *options, uint8_t *toggles) header("A:Enter B:Back DPAD:Nav Select:Info"); - int i = window_top; - while (options[i].index != -1) { // -1 Sentinel. + for (int i = window_top; options[i].index != -1; ++i) { // -1 Sentinel. if (i > window_bottom) break; - set_cursor(TOP_SCREEN, 0, i-window_top+2); + // NOTE - Signed to unsigned conversion here. Again, not an issue. + set_cursor(TOP_SCREEN, 0, (unsigned int)(i - window_top + 2) ); if (options[i].allowed == boolean_val || (is_n3ds && options[i].allowed == boolean_val_n3ds)) { if (cursor_y == i) { @@ -120,7 +122,6 @@ show_menu(struct options_s *options, uint8_t *toggles) accent_color(TOP_SCREEN, 1); fprintf(TOP_SCREEN, "%s\x1b[0m", options[i].name); } - ++i; } uint32_t key = wait_key(1); @@ -192,6 +193,8 @@ show_menu(struct options_s *options, uint8_t *toggles) clear_disp(TOP_SCREEN); } break; + default: + break; } if (cursor_y < cursor_min) diff --git a/source/firm/firm.c b/source/firm/firm.c index 0a54d64..07a03b8 100644 --- a/source/firm/firm.c +++ b/source/firm/firm.c @@ -37,10 +37,11 @@ int decrypt_arm9bin(arm9bin_h *header, uint64_t firm_title, uint8_t version); void dump_firm(firm_h** buffer, uint8_t index) { if (*buffer != NULL) return; - uint32_t firm_offset = 0x0B130000 + (index % 2) * 0x400000, - firm_size = 0x00100000; // 1MB, because + // NOTE - Cast, because GCC is making assumptions about 'index'. + uint32_t firm_offset = (uint32_t)(0x0B130000 + (index % 2) * 0x400000), + firm_b_size = 0x00100000; // 1MB, because - buffer[0] = static_allocate(firm_size); + buffer[0] = static_allocate(firm_b_size); uint8_t ctr[0x10], cid[0x10], @@ -48,7 +49,7 @@ void dump_firm(firm_h** buffer, uint8_t index) { firm_h* firm = buffer[0]; - if (sdmmc_nand_readsectors(firm_offset / SECTOR_SIZE, firm_size / SECTOR_SIZE, (uint8_t*)firm)) + if (sdmmc_nand_readsectors(firm_offset / SECTOR_SIZE, firm_b_size / SECTOR_SIZE, (uint8_t*)firm)) abort(" Failed to read NAND!\n"); fprintf(stderr, " Read FIRM%u off NAND.\n", index); @@ -60,7 +61,7 @@ void dump_firm(firm_h** buffer, uint8_t index) { use_aeskey(0x06); set_ctr(ctr); - aes(firm, firm, firm_size / AES_BLOCK_SIZE, ctr, AES_CTR_MODE); + aes(firm, firm, firm_b_size / AES_BLOCK_SIZE, ctr, AES_CTR_MODE); fprintf(stderr, " AES decrypted FIRM%u.\n", index); @@ -489,7 +490,7 @@ find_proc9(firm_h *firm, firm_section_h *process9, exefs_h **p9exefs) *p9exefs = (exefs_h *)(p9exheader + 1); process9->address = p9exheader->sci.textCodeSet.address; process9->size = (*p9exefs)->fileHeaders[0].size; - process9->offset = (void *)((*p9exefs) + 1) - (void *)firm; + process9->offset = (uint32_t)((*p9exefs) + 1) - (uint32_t)firm; fprintf(stderr, " Found process9 offset\n"); return 0; } diff --git a/source/interp.c b/source/interp.c index dbcfdba..aff6857 100644 --- a/source/interp.c +++ b/source/interp.c @@ -440,7 +440,7 @@ exec_bytecode(uint8_t *bytecode, uint32_t len, uint8_t* stack, uint32_t stack_si break; case OP_SEEK: // Jump to offset if greater than or equal code++; - offset = code[0] + (code[1] << 8) + (code[2] << 16) + (code[3] << 24); + offset = (uint32_t)(code[0] + (code[1] << 8) + (code[2] << 16) + (code[3] << 24)); if (debug) { #ifdef LOADER log("seek\n"); diff --git a/source/menu.c b/source/menu.c index 36adf09..e2ef4e3 100644 --- a/source/menu.c +++ b/source/menu.c @@ -56,7 +56,7 @@ static struct options_s options[] = { // { IGNORE_BROKEN_SHIT, "Allow unsafe options", boolean_val, 0, 0 }, // Sentinel. - { -1, "", "", 0, -1, -1 }, // cursor_min and cursor_max are stored in the last two. + { -1, "", "", 0, 0, 0 }, // cursor_min and cursor_max are stored in the last two. }; extern unsigned int font_w; @@ -187,7 +187,7 @@ static struct options_s info_d[] = { { 0, " Native FIRM: ", "The version of NATIVE_FIRM in use.", not_option, 0, 0}, { 0, " AGB FIRM: ", "The version of AGB_FIRM in use. This is used to run GBA games.", not_option, 0, 0}, { 0, " TWL FIRM: ", "The version of TWL_FIRM in use. This is used to run DS games and DSiWare.", not_option, 0, 0}, - { 0, " " FW_NAME ": " VERSION " (" REL ")", FW_NAME "'s version.", not_option, 0, 0}, + { 0, " " FW_NAME ": " REVISION " (" REL ")", FW_NAME "'s version.", not_option, 0, 0}, { -1, "", "", not_option, 0, 0 } }; static int is_setup_info = 0; @@ -296,7 +296,7 @@ static struct options_s main_s[] = { { 0, "Boot Firmware", "Generates caches, patches the firmware, and boots it.\nMake sure to 'Save Configuration' first if any options changed.", break_menu, 0, 0 }, // Sentinel. - { -1, "", "", 0, -1, -1 }, // cursor_min and cursor_max are stored in the last two. + { -1, "", "", 0, 0, 0 }, // cursor_min and cursor_max are stored in the last two. }; void diff --git a/source/patch/module.c b/source/patch/module.c index 2643944..f630c49 100644 --- a/source/patch/module.c +++ b/source/patch/module.c @@ -2,7 +2,8 @@ /* Not possible to be implemented as bytecode. Hey, can't win em all. */ -PATCH(modules) +int +patch_modules() { // TODO - load other module cxis here FILE *f = fopen(PATH_MODULES "/loader.cxi", "r"); @@ -71,7 +72,7 @@ PATCH(modules) // Copy the module into the firm memcpy(sysmodule, module, module->contentSize * 0x200); } - sysmodule = (ncch_h *)((uintptr_t)sysmodule + sysmodule->contentSize * 0x200); + sysmodule = (ncch_h *)((uint32_t)sysmodule + sysmodule->contentSize * 0x200); } fprintf(stderr, "Module: injected modules.\n"); diff --git a/source/patch/reboot.c b/source/patch/reboot.c index e787c6d..00765d0 100644 --- a/source/patch/reboot.c +++ b/source/patch/reboot.c @@ -1,3 +1,6 @@ +/* This code was all nicked from Luma (before the GPL headers were corrected by TuxSH) + Someone please remind me to fix this code.*/ + #include #include diff --git a/source/patch/svc.c b/source/patch/svc.c index 97cca80..5d40e7c 100644 --- a/source/patch/svc.c +++ b/source/patch/svc.c @@ -6,7 +6,8 @@ int svc_offs_init = 0; // This code handles restoration of backdoor -PATCH(services) +int +patch_services() { if (svc_offs_init == 0) { arm11Section1 = (uint8_t *)firm_loc + firm_loc->section[1].offset; @@ -41,7 +42,7 @@ PATCH(services) fclose(data); // memcpy(svc_tab_open, svcbackdoor, sizeof(svcbackdoor)); - svcTable[0x7B] = 0xFFFF0000 + ((uint8_t *)svc_tab_open - (uint8_t *)exceptionsPage); + svcTable[0x7B] = 0xFFFF0000 + (uint32_t)((uint8_t *)svc_tab_open - (uint8_t *)exceptionsPage); svc_tab_open += size; diff --git a/source/patcher.c b/source/patcher.c index 2d6f9c5..46029ae 100644 --- a/source/patcher.c +++ b/source/patcher.c @@ -3,8 +3,6 @@ // TODO - Basically all this needs to move to patcher programs. -uint32_t wait_key(int sleep); - extern int patch_services(); extern int patch_modules(); extern int patch_reboot(); diff --git a/source/std/abort.c b/source/std/abort.c index d217950..4a71952 100644 --- a/source/std/abort.c +++ b/source/std/abort.c @@ -5,7 +5,6 @@ #include void poweroff(); -uint32_t wait_key(int sleep); void abort(const char* x, ...) { va_list ap; diff --git a/source/std/draw.c b/source/std/draw.c index 8b60297..dc7582c 100644 --- a/source/std/draw.c +++ b/source/std/draw.c @@ -622,7 +622,11 @@ vfprintf(void *channel, const char *format, va_list ap) } break; case 's': - // Using puts isn't correct here... + // 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 *)); disable_format = 0; // Reenable. -- 2.39.5