]> Chaos Git - corbenik/corbenik.git/commitdiff
Use newlib memory functions
authorchaoskagami <chaos.kagami@gmail.com>
Thu, 18 Aug 2016 17:50:39 +0000 (13:50 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Thu, 18 Aug 2016 17:50:39 +0000 (13:50 -0400)
include/std/memory.h
source/menu.c
source/start.s
source/std/fs.c
source/std/memory.c

index 7546d74b0bb040c37844522c9f42a734c97c320d..ecb541e6aebfe03244e77a3c8af4f0ac91e0557d 100644 (file)
@@ -3,17 +3,10 @@
 
 #include <stdint.h>
 #include <stddef.h>
+#include <string.h>
 
-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
index 4905a4e9e55443f5ae2a29191a3f50277e73a4f0..84207c5655c1b25ef7755679be582d6348cbb6bc 100644 (file)
@@ -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;
index 3d32ba93848a7f7e3bb9c653088b87f38e4471c4..a2cc08495774cd7c71f552a4024e795be90fff1a 100644 (file)
@@ -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
index 85998101cd05b893c93903226206192992a18c1b..814d09ed7277a2bab26d9a562338cd8af93f7e73 100644 (file)
@@ -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;
 }
 
index 6609d6c312f8e3c7dda4dfd18b4e901ff4bd8769..dc91fa7f201402cd3824a5f8d1f9ac96cfa9c7be 100644 (file)
@@ -3,26 +3,6 @@
 #include <stdint.h>
 #include <stddef.h>
 
-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)
 {