diff --git a/include/instructions.h b/include/instructions.h index e9e6ef2..08ce355 100644 --- a/include/instructions.h +++ b/include/instructions.h @@ -13,9 +13,13 @@ public: uint32_t eflags; // EFLAGS register uint32_t eip; // Instruction pointer + uint8_t modrm, mod, R, M; // ModRM + void (Instructions::*instructions[256])(void); void init(uint32_t eip, uint32_t esp, Memory memory); + void init_modrm(); + void calc_modrm(); void execute_opcode(uint8_t opcode); void nop(); diff --git a/instructions.cpp b/instructions.cpp index e360bdd..ee73a52 100644 --- a/instructions.cpp +++ b/instructions.cpp @@ -14,6 +14,7 @@ void Instructions::init(uint32_t eip, uint32_t esp, Memory memory){ this->memory = memory; this->init_instructions(); + this->init_modrm(); } void Instructions::init_instructions(){ @@ -23,6 +24,19 @@ void Instructions::init_instructions(){ this->instructions[0xf4] = &Instructions::hlt; } +void Instructions::init_modrm(){ + this->modrm = 0; + this->mod = 0; + this->R = 0; + this->M = 0; +} + +void Instructions::calc_modrm(){ + this->mod = (this->modrm & 0xc0) >> 6; + this->R = (this->modrm & 0x38) >> 3; + this->M = this->modrm & 0x07; +} + void Instructions::execute_opcode(uint8_t opcode){ (this->*instructions[opcode])(); }