-
Notifications
You must be signed in to change notification settings - Fork 9
/
instructions_0FB0.c
83 lines (78 loc) · 1.72 KB
/
instructions_0FB0.c
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
#include <stdint.h>
#include "instruction_defs.h"
#include "emulator_functions.h"
#include "modrm.h"
/*
* mov r32 rm8: 2 bytes
* Copies value of zero-extended rm8 value to r32.
* 2 byte: op (0FB6)
* 1 byte: ModR/M
*/
void movzx_r32_rm8(Emulator *emu)
{
emu->eip += 2;
ModRM modrm = create_modrm();
parse_modrm(emu, &modrm);
uint32_t rm16 = 0 | get_rm8(emu, &modrm);
set_r32(emu, &modrm, rm16);
}
/*
* mov r32 rm16: 2 bytes
* Copies value of zero-extended rm16 value to r32.
* 2 byte: op (0FB7)
* 1 byte: ModR/M
*/
void movzx_r32_rm16(Emulator *emu)
{
emu->eip += 2;
ModRM modrm = create_modrm();
parse_modrm(emu, &modrm);
uint32_t rm16 = 0 | get_rm16(emu, &modrm);
set_r32(emu, &modrm, rm16);
}
/*
* movsx r32 rm8: 3 bytes
* Copies sign-extended rm8 value to r32.
* 2 byte: op (0FBE)
* 1 byte: ModR/M
*/
void movsx_r32_rm8(Emulator *emu)
{
emu->eip += 2;
ModRM modrm = create_modrm();
parse_modrm(emu, &modrm);
uint8_t rm8 = get_rm8(emu, &modrm);
uint8_t sign = rm8 >> 7 & 1;
if (sign == 1)
{
uint32_t sign_extended = 0xFFFFFF00 | rm8;
set_r32(emu, &modrm, sign_extended);
}
else
{
set_r32(emu, &modrm, (uint32_t)rm8);
}
}
/*
* movsx r32 rm16: 3 bytes
* Copies sign-extended rm16 value to r32.
* 2 byte: op (0FBF)
* 1 byte: ModR/M
*/
void movsx_r32_rm16(Emulator *emu)
{
emu->eip += 2;
ModRM modrm = create_modrm();
parse_modrm(emu, &modrm);
uint16_t rm16 = get_rm16(emu, &modrm);
uint8_t sign = rm16 >> 15 & 1;
if (sign == 1)
{
uint32_t sign_extended = 0xFFFF0000 | rm16;
set_r32(emu, &modrm, sign_extended);
}
else
{
set_r32(emu, &modrm, (uint32_t)rm16);
}
}