mirror of
https://github.com/tuz358/cpu-emulator.git
synced 2025-12-18 13:04:35 +03:00
74 lines
2.0 KiB
C++
74 lines
2.0 KiB
C++
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "memory.h"
|
|
#include "utils.h"
|
|
|
|
const uint32_t ZF = 1 << 6;
|
|
|
|
class Instructions{
|
|
private:
|
|
void init_instructions();
|
|
void set_flag(int flag, uint32_t flag_type);
|
|
int get_flag(uint32_t flag_type);
|
|
public:
|
|
Memory memory;
|
|
uint32_t registers[8]; // eax, ecx, edx, ebx, esp, ebp, esi, edi
|
|
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 add_rm32_r32(); // 0x01
|
|
void xor_rm32_r32(); // 0x31
|
|
void inc_eax(); // 0x40
|
|
void inc_ecx(); // 0x41
|
|
void inc_edx(); // 0x42
|
|
void inc_ebx(); // 0x43
|
|
void inc_esp(); // 0x44
|
|
void inc_ebp(); // 0x45
|
|
void inc_esi(); // 0x46
|
|
void inc_edi(); // 0x47
|
|
void dec_eax(); // 0x48
|
|
void dec_ecx(); // 0x49
|
|
void dec_edx(); // 0x4a
|
|
void dec_ebx(); // 0x4b
|
|
void dec_esp(); // 0x4c
|
|
void dec_ebp(); // 0x4d
|
|
void dec_esi(); // 0x4e
|
|
void dec_edi(); // 0x4f
|
|
void push_eax(); // 0x50
|
|
void push_ecx(); // 0x51
|
|
void push_edx(); // 0x52
|
|
void push_ebx(); // 0x53
|
|
void push_esp(); // 0x54
|
|
void push_ebp(); // 0x55
|
|
void push_esi(); // 0x56
|
|
void push_edi(); // 0x57
|
|
void jne_imm8(); // 0x75
|
|
void opcode_83(); // 0x83
|
|
void mov_rm32_r32(); // 0x89
|
|
void nop(); // 0x90
|
|
void mov_eax_imm32(); // 0xb8
|
|
void mov_ecx_imm32(); // 0xb9
|
|
void mov_edx_imm32(); // 0xba
|
|
void mov_ebx_imm32(); // 0xbb
|
|
void mov_esp_imm32(); // 0xbc
|
|
void mov_ebp_imm32(); // 0xbd
|
|
void mov_esi_imm32(); // 0xbe
|
|
void mov_edi_imm32(); // 0xbf
|
|
void jmp_imm8(); // 0xeb
|
|
void hlt(); // 0xf4
|
|
void opcode_ff(); // 0xff
|
|
|
|
void cmp_rm32_imm8(); // called by opcode_83
|
|
};
|