forked from ish-app/ish
-
Notifications
You must be signed in to change notification settings - Fork 12
/
modrm.h
85 lines (76 loc) · 2 KB
/
modrm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef MODRM_H
#define MODRM_H
#include "debug.h"
#include "misc.h"
#include "emu/cpu.h"
#undef DEFAULT_CHANNEL
#define DEFAULT_CHANNEL instr
struct regptr {
// offsets into the cpu_state structure
reg_id_t reg8_id;
reg_id_t reg16_id;
reg_id_t reg32_id;
reg_id_t reg128_id;
};
#if defined(DEBUG_instr) || defined(LOG_OVERRIDE)
static const char *regptr_name(struct regptr regptr) {
static char buf[15];
sprintf(buf, "%s/%s/%s",
reg8_name(regptr.reg8_id),
reg16_name(regptr.reg16_id),
reg32_name(regptr.reg32_id));
return buf;
}
#endif
struct modrm_info {
// MOD/RM BITS
bool sib;
enum {
mod_disp0,
mod_disp8,
mod_disp32,
mod_reg,
} type;
struct regptr modrm_regid;
byte_t rm_opcode;
// REG BITS
// offsets of the register into the cpu_state structure
struct regptr reg;
// for when it's not a register
byte_t opcode;
};
#ifdef DISABLE_MODRM_TABLE
#define modrm_get_info modrm_compute_info
struct modrm_info modrm_compute_info(byte_t byte);
#else
struct modrm_info modrm_table[0x100];
static inline struct modrm_info modrm_get_info(byte_t byte) {
struct modrm_info info = modrm_table[byte];
TRACE("reg %s opcode %d ", regptr_name(info.reg), info.opcode);
switch (info.type) {
case mod_reg:
TRACE("mod_reg ");
break;
case mod_disp0:
TRACE("mod_disp0 ");
break;
case mod_disp8:
TRACE("mod_disp8 ");
break;
case mod_disp32:
TRACE("mod_disp32 ");
break;
}
if (info.sib) {
TRACE("with sib ");
} else {
TRACE("%s ", regptr_name(info.modrm_regid));
}
return info;
}
#endif
#define MOD(byte) ((byte & 0b11000000) >> 6)
#define REG(byte) ((byte & 0b00111000) >> 3)
#define RM(byte) ((byte & 0b00000111) >> 0)
void modrm_decode32(struct cpu_state *cpu, struct tlb *tlb, addr_t *addr_out, struct modrm_info *info_out);
#endif