-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmisc.c
More file actions
82 lines (66 loc) · 1.58 KB
/
misc.c
File metadata and controls
82 lines (66 loc) · 1.58 KB
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
#include "inst.h"
#include "reg.h"
#include "misc.h"
#include "branch.h"
static inline uint32_t getop2(uint32_t inst)
{
return (inst & 0x0f0) >> 4;
}
int bx_reg(struct CPUState *env, uint32_t inst)
{
uint32_t rm = getrm(inst);
set_pc(env, get_reg(env, rm));
return 0;
}
int clz_reg(struct CPUState *env, uint32_t inst)
{
uint32_t rd = getrd(inst);
uint32_t rm = getrm(inst);
uint32_t bits = __builtin_clz(get_reg(env, rm));
set_reg(env, rd, bits);
return 0;
}
int blx_reg(struct CPUState *env, uint32_t inst)
{
uint32_t rm = getrm(inst);
set_reg(env, REG_LR, get_reg(env, REG_PC) - BRANCH_PC_OFFSET);
set_pc(env, get_reg(env, rm));
return 0;
}
int misc_reg_inst(struct CPUState *env, uint32_t inst)
{
uint32_t op2 = getop2(inst);
switch (op2) {
case 0:
if (getbit(inst, BIT21) == 0) {
mrs_reg(env, inst);
} else {
printf("Unsupport instruction @ 0x%x\n", get_reg(env, REG_PC));
}
break;
case 1:
if (getbit(inst, BIT22) == 0)
bx_reg(env, inst);
else
clz_reg(env, inst);
break;
case 3:
blx_reg(env, inst);
break;
default:
printf("Unsupport instruction @ 0x%x\n", get_reg(env, REG_PC));
break;
}
return 0;
}
int mrs_reg(struct CPUState *env, uint32_t inst)
{
uint32_t rd = getrd(inst);
int mode = get_mode(env);
if (mode == MODE_USR) {
set_reg(env, rd, get_cpsr(env));
} else {
printf("Unsupport mode @ 0x%x\n", get_reg(env, REG_PC));
}
return 0;
}