diff --git a/biosandbox/Emulation.h b/biosandbox/Emulation.h index 4812fa5..df82271 100644 --- a/biosandbox/Emulation.h +++ b/biosandbox/Emulation.h @@ -7,7 +7,7 @@ namespace bio { namespace emu { - using instruction_set = std::vector>; + using instruction_set = std::vector*>>; memory_dependent using mem_buffer = unsigned char[memsize]; @@ -31,6 +31,7 @@ namespace bio { instruction_set isa; mem_buffer memory; std::vector symbols; + std::vector callStack; virtual void load_app(application& app) = 0; virtual void run_symbol(int symbol) = 0; @@ -66,7 +67,7 @@ namespace bio { bool returned = false; until(returned || instructionPointer >= memsize) { this->instructionPointer += - this->isa[this->memory[instructionPointer]](instructionPointer, this->memory, &returned); + this->isa[this->memory[instructionPointer]](instructionPointer, this->memory, &returned, &this->callStack); if (instructionPointer < 0 || instructionPointer > memsize) { throw std::out_of_range("Symbol causes instruction pointer to err out of memory"); diff --git a/biosandbox/Intel.cpp b/biosandbox/Intel.cpp index 685d1fe..6abf0dd 100644 --- a/biosandbox/Intel.cpp +++ b/biosandbox/Intel.cpp @@ -13,4 +13,10 @@ isa_instruction(bio::Intel::ISAs::iAPX86::invalid) { isa_instruction(bio::Intel::ISAs::iAPX86::nop) { return 1; +} + +isa_instruction(bio::Intel::ISAs::iAPX86::call_e8) { + short jump; + memcpy(&jump, memory + (position + 1), 2); + return jump + 3; } \ No newline at end of file diff --git a/biosandbox/Intel.h b/biosandbox/Intel.h index 31dcb71..4e6994e 100644 --- a/biosandbox/Intel.h +++ b/biosandbox/Intel.h @@ -11,6 +11,7 @@ namespace bio { namespace iAPX86 { isa_instruction(invalid); isa_instruction(nop); + isa_instruction(call_e8); } } @@ -26,6 +27,8 @@ namespace bio { this->isa.push_back(ISAs::iAPX86::invalid); } + + this->isa[0xE8] = ISAs::iAPX86::call_e8; this->isa[0x90] = ISAs::iAPX86::nop; times(sizeof(this->memory)) { diff --git a/biosandbox/bsuml.h b/biosandbox/bsuml.h index 94a2891..0eb21f2 100644 --- a/biosandbox/bsuml.h +++ b/biosandbox/bsuml.h @@ -18,7 +18,12 @@ using native_callable = T(*)(args...); // emulation-related definitions -#define isa_instruction(x) int x(int position, unsigned char* memory, bool* emu_return) +#define isa_instruction(x) int x(int position, unsigned char* memory, bool* emu_return, ptr> callstack) + // position = current instruction pointer position + // memory = memory buffer + // emureturn = end of symbol +// callstack = callstack pointer + #define memory_dependent template #define memory_passdown(x) x diff --git a/gameenv/code/test b/gameenv/code/test index 97781c5..0fa0477 100644 Binary files a/gameenv/code/test and b/gameenv/code/test differ diff --git a/gameenv/code/test.asm b/gameenv/code/test.asm index 80ecbaa..129c28d 100644 --- a/gameenv/code/test.asm +++ b/gameenv/code/test.asm @@ -1,7 +1,4 @@ global main section .text -func: -mov eax, 1 -ret main: -call func \ No newline at end of file +call 0 \ No newline at end of file diff --git a/gameenv/code/test.exe b/gameenv/code/test.exe deleted file mode 100644 index fa204e4..0000000 Binary files a/gameenv/code/test.exe and /dev/null differ