]> Chaos Git - corbenik/corbenik.git/commitdiff
Backend work.
authorchaoskagami <chaos.kagami@gmail.com>
Sat, 2 Jul 2016 06:10:14 +0000 (02:10 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Sat, 2 Jul 2016 06:10:14 +0000 (02:10 -0400)
 * Get some bits in place to implement stack instructions in the VM.
 * Some functions we provide an implementation of are in ctrulib or newlib
   and therefore uneeded by loader

external/loader/source/interp.c
external/loader/source/memory.c
external/loader/source/memory.h
external/loader/source/patcher.c
source/interp.c
source/main.c

index b36ef1aeb2f33ac1670ebdb780a39d9f31089f63..59aa1f3fcb903ac9ee55cf1ba65bd515a7d4f451 100644 (file)
@@ -3,6 +3,7 @@
 // so it's temporarliy #if'd 0.
 #include <3ds.h>
 #include "patcher.h"
+#include "exheader.h"
 #include "fsldr.h"
 #include "internal.h"
 #include "memory.h"
index d0cb84dfce0cb53055850a15c220ec4b5f269af8..82c07f96cce0b7c50bfd73b37474e59ab019569e 100644 (file)
@@ -1,4 +1,5 @@
 #include <3ds.h>
+#include <string.h>
 #include "patcher.h"
 #include "fsldr.h"
 #include "internal.h"
@@ -9,7 +10,7 @@
 #endif
 #include "../../../source/config.h"
 #include "../../../source/patch_format.h"
-
+/*
 int
 memcmp(const void *buf1, const void *buf2, u32 size)
 {
@@ -24,6 +25,7 @@ memcmp(const void *buf1, const void *buf2, u32 size)
 
     return 0;
 }
+*/
 
 // Quick Search algorithm, adapted from
 // http://igm.univ-mlv.fr/~lecroq/string/node19.html#SECTION00190
index c7b77f3a7af7ca0f873dbbc4d6d5bca98c7975d5..f0c81e5ba2f6e12080af3dd1522e8ae365d53c5c 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __MEMORY_H
 #define __MEMORY_H
 
-int memcmp(const void *buf1, const void *buf2, u32 size);
+//int memcmp(const void *buf1, const void *buf2, u32 size);
 u8 *memfind(u8 *startPos, u32 size, const void *pattern, u32 patternSize);
 u32 patchMemory(u8 *start, u32 size, const void *pattern, u32 patSize, int offset, const void *replace, u32 repSize, u32 count);
 size_t strnlen(const char *string, size_t maxlen);
index c1a14c03086eea475f67a5c614fc64ad90cc5a24..68a9659a883b460e80f23bf885d957ef37b9d7b5 100644 (file)
@@ -1,4 +1,5 @@
 #include <3ds.h>
+#include <string.h>
 #include "patcher.h"
 #include "exheader.h"
 #include "fsldr.h"
index d936c4242f48a2f4f0b373046665b87085c9e33d..855d21f482e628e4a63624b728e8b39b4a373c9d 100644 (file)
@@ -1,11 +1,15 @@
 #include <stdint.h>
 #include <stddef.h>
-#ifndef LOADER
 #include "std/unused.h"
-#include "std/memory.h"
-#include "firm/firm.h"
-#include "config.h"
-#include "common.h"
+
+#ifndef LOADER
+  #include "std/memory.h"
+  #include "firm/firm.h"
+  #include "config.h"
+  #include "common.h"
+  #include "firm/fcram.h"
+#else
+  #include <string.h>
 #endif
 
 #define OP_NOP 0x00
@@ -72,8 +76,15 @@ static const char hexDigits[] = "0123456789ABCDEF";
 int is_n3ds = 1; // TODO - We don't really need to care, but it should still work from loader
 #endif
 
+#define STACK_SIZE 4096
+#ifdef LOADER
+  static uint8_t stack_glob[STACK_SIZE];
+#else
+  static uint8_t *stack_glob = NULL;
+#endif
+
 int
-exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug)
+exec_bytecode(uint8_t *bytecode, uint32_t len, uint8_t* stack, uint32_t stack_size, uint16_t ver, int debug)
 {
     if (!init_bytecode) {
 #ifndef LOADER
@@ -142,6 +153,10 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug)
         init_bytecode = 1;
     }
 
+    memset(stack, 0, stack_size); // Clear stack.
+
+    _UNUSED size_t top = stack_size - 1;
+
 #ifdef LOADER
     size_t set_mode = 18;
 #else
@@ -494,6 +509,9 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug)
                 }
                 found = gt = lt = eq = 0;
 
+                memset(stack, 0, stack_size); // Clear stack.
+                top = stack_size - 1;
+
                 bytecode = code + 1;
 #ifndef LOADER
                 set_mode = 3;
@@ -697,5 +715,11 @@ execb(char *filename, int build_cache)
         debug = 1;
     }
 
-    return exec_bytecode(patch_mem, ver, patch_len, debug);
+#ifndef LOADER
+    if (stack_glob == NULL) {
+        stack_glob = static_allocate(STACK_SIZE);
+    }
+#endif
+
+    return exec_bytecode(patch_mem, patch_len, stack_glob, STACK_SIZE, ver, debug);
 }
index a32a418188dbe0276944b152d6c029fbaf057a04..9a5e5c7d8bd319f5fd440aab27df2e76d8d83d19 100644 (file)
@@ -24,7 +24,7 @@ main(int argc, char** argv)
     screen_init();
     clear_bg();
     load_bg_top(PATH_BITS "/top.bin");
-    load_bg_bottom(PATH_BITS "/bottom.bin"); // This is basically a menuhax splash (90deg rotated RGB8 pixel data)
+    load_bg_bottom(PATH_BITS "/bottom.bin"); // This is basically a menuhax splash (90deg rotated BGR8 pixel data)
     clear_disp(TOP_SCREEN);
     clear_disp(BOTTOM_SCREEN);