From: chaoskagami Date: Thu, 18 Aug 2016 17:50:39 +0000 (-0400) Subject: Use newlib memory functions X-Git-Tag: v0.3.0~55 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=d49e18765d15d97b3c99d1e8ffe83aa8066b5b30;p=corbenik%2Fcorbenik.git Use newlib memory functions --- diff --git a/include/std/memory.h b/include/std/memory.h index 7546d74..ecb541e 100644 --- a/include/std/memory.h +++ b/include/std/memory.h @@ -3,17 +3,10 @@ #include #include +#include -size_t strlen(char *string); -void memcpy(void *dest, const void *src, size_t size); -void memmove(void *dest, const void *src, size_t size); -void memset(void *dest, const int filler, size_t size); -int memcmp(const void *buf1, const void *buf2, const size_t size); -void strncpy(void *dest, const void *src, const size_t size); -int strncmp(const void *buf1, const void *buf2, const size_t size); int atoi(const char *str); uint8_t *memfind(uint8_t *startPos, uint32_t size, const void *pattern, uint32_t patternSize); int isprint(char c); -size_t strnlen(const char *string, size_t maxlen); #endif diff --git a/source/menu.c b/source/menu.c index 4905a4e..84207c5 100644 --- a/source/menu.c +++ b/source/menu.c @@ -16,10 +16,10 @@ static struct options_s options[] = { { OPTION_EMUNAND, "Use EmuNAND", "Redirects NAND write/read to the SD. This supports both Gateway and redirected layouts.", boolean_val, 0, 0, 0 }, { OPTION_EMUNAND_INDEX, "Index", "Which EmuNAND to use. If you only have one, you want 0. Currently the maximum supported is 10 (0-9), but this is arbitrary.", ranged_val, 0, 0x9, 1 }, -// { OPTION_EMUNAND_REVERSE, " Reverse layout", "(Warning - Experimental!) Calculate EmuNAND sector from the end of the disk, not the start. This isn't supported by tools like Decrypt9, but has some advantages.", boolean_val, 0, 0x9 }, { OPTION_AUTOBOOT, "Autoboot", "Boot the system automatically, unless the R key is held while booting.", boolean_val, 0, 0, 0 }, { OPTION_SILENCE, "Silent mode", "Suppress all debug output during autoboot. You'll see the screen turn on and then off once.", boolean_val, 0, 0, 1 }, + { OPTION_DIM_MODE, "Dim Background", "Experimental! Dims colors on lighter backgrounds to improve readability with text. You won't notice the change until scrolling or exiting the current menu due to the way rendering works.", boolean_val, 0, 0, 0 }, { OPTION_ACCENT_COLOR, "Accent color", "Changes the accent color in menus.", ranged_val, 1, 7, 0}, @@ -76,11 +76,11 @@ void patch_func(char* fpath) { if (memcmp(p.magic, "AIDA", 4)) return; - strncpy(patches[current_menu_index_patches].name, p.name, 64); + memcpy(patches[current_menu_index_patches].name, p.name, 64); if (desc_is_fname_sto) - strncpy(patches[current_menu_index_patches].desc, fpath, 255); + memcpy(patches[current_menu_index_patches].desc, fpath, 255); else - strncpy(patches[current_menu_index_patches].desc, p.desc, 255); + memcpy(patches[current_menu_index_patches].desc, p.desc, 255); patches[current_menu_index_patches].index = (int64_t)p.uuid; patches[current_menu_index_patches].allowed = boolean_val; patches[current_menu_index_patches].a = 0; diff --git a/source/start.s b/source/start.s index 3d32ba9..a2cc084 100644 --- a/source/start.s +++ b/source/start.s @@ -210,8 +210,9 @@ disable_mpu_and_caching: bx lr enable_mpu_and_caching: - // Enable caches and MPU + // Enable caches, MPU, and itcm mrc p15, 0, r0, c1, c0, 0 // read control register + orr r0, r0, #(1<<18) // - itcm enable orr r0, r0, #(1<<12) // - instruction cache enable orr r0, r0, #(1<<2) // - data cache enable orr r0, r0, #(1<<0) // - mpu enable diff --git a/source/std/fs.c b/source/std/fs.c index 8599810..814d09e 100644 --- a/source/std/fs.c +++ b/source/std/fs.c @@ -24,7 +24,7 @@ recurse_call_back(char *fpath, void (*call_fun_param)(char*)) fname++; while (f_readdir(&pdir, &fno) == FR_OK) { - strncpy(fname, fno.fname, strlen(fno.fname)); + strcpy(fname, fno.fname); if (fno.fname[0] == 0) break; @@ -59,9 +59,7 @@ void recurse_call(char *name, void (*call_fun_param)(char*)) { int rrmdir(char *name) { - char fpath[256]; - strncpy(fpath, name, 256); - recurse_call(fpath, (void (*)(char*))f_unlink); + recurse_call(name, (void (*)(char*))f_unlink); return 0; } diff --git a/source/std/memory.c b/source/std/memory.c index 6609d6c..dc91fa7 100644 --- a/source/std/memory.c +++ b/source/std/memory.c @@ -3,26 +3,6 @@ #include #include -size_t -strlen(char *string) -{ - char *string_end = string; - while (string_end[0]) - string_end++; - return (size_t)(string_end - string); -} - -size_t -strnlen(const char *string, size_t maxlen) -{ - size_t size; - - for (size = 0; *string && size < maxlen; string++, size++) - ; - - return size; -} - int isprint(char c) { @@ -31,99 +11,6 @@ isprint(char c) return 0; } -void -memcpy(void *dest, const void *src, size_t size) -{ - uint8_t *destc = (uint8_t *)dest; - const uint8_t *srcc = (const uint8_t *)src; - - for(size_t i=0; i < size; i++) { - destc[i] = srcc[i]; - } -} - -void -memmove(void *dest, const void *src, size_t size) -{ - // memcpy does the job of moving backwards just fine - if (dest < src || (const uint8_t*)src + size <= (uint8_t*)dest) { - memcpy(dest, src, size); - return; - } - - // Moving forward is just a reverse memcpy - uint8_t *destc = (uint8_t *)dest; - const uint8_t *srcc = (const uint8_t *)src; - - // Finish by copying the leftovers - for(size_t i=size; i > 0; i--) { - destc[i-1] = srcc[i-1]; - } -} - -void -memset(void *dest, const int filler, size_t size) -{ - char *destc = (char *)dest; - - // Finish - for(size_t i = 0; i < size; i++) { - destc[i] = filler; - } -} - -int -memcmp(const void *buf1, const void *buf2, const size_t size) -{ - const char *buf1c = (const char *)buf1; - const char *buf2c = (const char *)buf2; - for (size_t i = 0; i < size; i++) { - int cmp = buf1c[i] - buf2c[i]; - if (cmp) { - return cmp; - } - } - - return 0; -} - -void -strncpy(void *dest, const void *src, const size_t size) -{ - char *destc = (char *)dest; - const char *srcc = (const char *)src; - - size_t i; - for (i = 0; i < size && srcc[i] != 0; i++) { - destc[i] = srcc[i]; - } - - // Make sure the resulting string is terminated. - destc[i] = 0; -} - -int -strncmp(const void *buf1, const void *buf2, const size_t size) -{ - const char *buf1c = (const char *)buf1; - const char *buf2c = (const char *)buf2; - - size_t i; - for (i = 0; i < size && buf1c[i] != 0 && buf2c[i] != 0; i++) { - int cmp = buf1c[i] - buf2c[i]; - if (cmp) { - return cmp; - } - } - - // Make sure the strings end at the same offset, if they end. - if ((buf1c[i] == 0 || buf2c[i] == 0) && (buf1c[i] != 0 || buf2c[i] != 0)) { - return -1; - } - - return 0; -} - int atoi(const char *str) {