-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathout.cpp
133 lines (120 loc) · 3.57 KB
/
out.cpp
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* IDA MCORE Plugin
* Copyright (c) 2004-05
* rshade@hushmail.com
*
*/
#include "mcore.hpp"
#include "idp.hpp"
#include "name.hpp"
//----------------------------------------------------------------------
inline void OutReg(outctx_t *ctx, int rgnum) {
if ((rgnum >= 0) && (rgnum < ph.regs_num)) {
ctx->out_register(ph.reg_names[rgnum]);
} else {
ctx->out_line("r???", COLOR_ERROR);
}
}
inline void OutBadReg(outctx_t *ctx, int rgnum) {
const char *reg;
if ((rgnum >= 0) && (rgnum < ph.regs_num)) {
reg = ph.reg_names[rgnum];
} else {
reg = "r???";
}
ctx->out_line(ph.reg_names[rgnum], COLOR_ERROR);
}
//----------------------------------------------------------------------
bool outop(outctx_t *ctx, const op_t &x) {
switch (x.type) {
case o_void:
return 0;
case o_imm:
if (x.specflag1 == 1) ctx->out_symbol('#');
ctx->out_value(x, 0);
break;
case o_regrange:
OutReg(ctx, x.reg);
ctx->out_symbol('-');
if (x.specval < x.reg) {
// bad!
OutBadReg(ctx, x.specval);
} else {
OutReg(ctx, x.specval);
}
break;
case o_reg:
OutReg(ctx, x.reg);
break;
case o_displ:
ctx->out_symbol('(');
OutReg(ctx, x.reg);
ctx->out_symbol(',');
ctx->out_char(' ');
ctx->out_value(x, 0);
ctx->out_symbol(')');
break;
case o_near: {
// stolen from m7900 code
// NO IDEA if this is right
ea_t v = to_ea(ctx->insn.cs, x.addr);
qstring str;
if (get_name_expr(&str, ctx->insn.ea, x.n, v, x.addr) > 0) {
ctx->out_value(x, OOF_ADDR | OOFS_NOSIGN);
} else {
ctx->out_line(str.c_str());
}
} break;
case o_mem: {
ea_t v = to_ea(ctx->insn.cs, x.addr);
qstring str;
if (get_name_expr(&str, ctx->insn.ea, x.n, v, x.addr) > 0) {
ctx->out_value(x, OOF_ADDR | OOFS_NOSIGN);
} else {
ctx->out_line(str.c_str());
}
} break;
default:
break;
}
return 1;
}
//----------------------------------------------------------------------
void out(outctx_t *ctx) {
char buf[MAXSTR];
int i;
insn_t *cmd = &ctx->insn;
// some instructions need to be special cased here...
ctx->out_mnemonic();
if ((cmd->Op1.type != o_void) && (cmd->Op1.shown())) {
ctx->out_one_operand(0);
}
for (i = 1; (i < UA_MAXOP) && (cmd->ops[i].type != o_void); i++) {
if (!cmd->ops[i].shown()) continue;
if (cmd->ops[i].ind_op != 2) {
// normal operand, nothing special here
ctx->out_symbol(',');
ctx->out_line(" ");
ctx->out_one_operand(i);
} else {
// part of an "indirect operand" pair
// 1st one was the assembler-friendly operand
// this one would be invisible to the assembler
// but we'll put it in { } for the disassembler to see
ctx->out_line(" {");
ctx->out_one_operand(i);
ctx->out_line("}");
}
}
ctx->out_immchar_cmts();
ctx->flush_outbuf();
}
//--------------------------------------------------------------------------
void header(outctx_t *ctx) {
ctx->gen_cmt_line("Processor: %s", inf_get_procname().c_str());
ctx->gen_cmt_line("Target assembler: %s", ash.name);
}
//--------------------------------------------------------------------------
void footer(outctx_t *ctx) {
ctx->gen_cmt_line("end of file");
}