Add support for calls(0xE8) in 8086 emulation
This commit is contained in:
parent
b93c498d8c
commit
8879c0e432
@ -7,7 +7,7 @@
|
||||
namespace bio {
|
||||
namespace emu {
|
||||
|
||||
using instruction_set = std::vector<native_callable<int, int, unsigned char*, bool*>>;
|
||||
using instruction_set = std::vector<native_callable<int, int, unsigned char*, bool*, std::vector<int>*>>;
|
||||
|
||||
memory_dependent using mem_buffer = unsigned char[memsize];
|
||||
|
||||
@ -31,6 +31,7 @@ namespace bio {
|
||||
instruction_set isa;
|
||||
mem_buffer<memsize> memory;
|
||||
std::vector<symbol> symbols;
|
||||
std::vector<int> 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");
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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)) {
|
||||
|
||||
@ -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<std::vector<int>> callstack)
|
||||
// position = current instruction pointer position
|
||||
// memory = memory buffer
|
||||
// emureturn = end of symbol
|
||||
// callstack = callstack pointer
|
||||
|
||||
#define memory_dependent template<int memsize>
|
||||
#define memory_passdown(x) x<memsize>
|
||||
|
||||
|
||||
Binary file not shown.
@ -1,7 +1,4 @@
|
||||
global main
|
||||
section .text
|
||||
func:
|
||||
mov eax, 1
|
||||
ret
|
||||
main:
|
||||
call func
|
||||
call 0
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user