-
Notifications
You must be signed in to change notification settings - Fork 33
/
out.cpp
executable file
·233 lines (209 loc) · 6.87 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include "stm8.hpp"
//----------------------------------------------------------------------
inline void outreg(int r)
{
out_register(ph.regNames[r]);
}
//----------------------------------------------------------------------
static void outmem(op_t &x, ea_t ea)
{
char buf[MAXSTR];
if ( get_name_expr(cmd.ea+x.offb, x.n, ea, BADADDR, buf, sizeof(buf)) <= 0 )
{
const ioport_t *p = find_sym(x.addr);
if ( p == NULL )
{
out_tagon(COLOR_ERROR);
OutLong(x.addr, 16);
out_tagoff(COLOR_ERROR);
QueueSet(Q_noName,cmd.ea);
}
else
{
out_line(p->name, COLOR_IMPNAME);
}
}
else
{
bool complex = strchr(buf, '+') || strchr(buf, '-');
if ( complex ) out_symbol(ash.lbrace);
OutLine(buf);
if ( complex ) out_symbol(ash.rbrace);
}
}
//----------------------------------------------------------------------
bool idaapi outop(op_t &x)
{
switch ( x.type )
{
case o_void:
return 0;
case o_reg:
outreg(x.reg);
break;
case o_imm:
out_symbol('#');
OutValue(x, OOFS_IFSIGN|OOFW_IMM);
break;
case o_displ:
// o_displ Short Direct Indexed ld A,($10,X) 00..1FE + 1
// o_displ Long Direct Indexed ld A,($1000,X) 0000..FFFF + 2
out_symbol('(');
OutValue(x, OOFS_IFSIGN|OOF_ADDR|OOFW_IMM);
out_symbol(',');
outreg(x.reg);
out_symbol(')');
break;
case o_phrase:
out_symbol('(');
outreg(x.reg);
out_symbol(')');
break;
case o_mem:
// o_mem Short Direct ld A,$10 00..FF + 1
// o_mem Long Direct ld A,$1000 0000..FFFF + 2
// o_mem Short Indirect ld A,[$10] 00..FF 00..FF byte + 2
// o_mem Long Indirect ld A,[$10.w] 0000..FFFF 00..FF word + 2
// o_mem Short Indirect Indexed ld A,([$10],X) 00..1FE 00..FF byte + 2
// o_mem Long Indirect Indexed ld A,([$10.w],X) 0000..FFFF 00..FF word + 2
// o_mem Relative Indirect jrne [$10] PC+/-127 00..FF byte + 2
// o_mem Bit Direct bset $10,#7 00..FF + 1
// o_mem Bit Indirect bset [$10],#7 00..FF 00..FF byte + 2
// o_mem Bit Direct Relative btjt $10,#7,skip 00..FF + 2
// o_mem Bit Indirect Relative btjt [$10],#7,skip 00..FF 00..FF byte + 3
if ( cmd.auxpref & aux_index ) out_symbol('(');
if ( cmd.auxpref & aux_indir ) out_symbol('[');
outmem(x, calc_mem(x.addr));
if ( cmd.auxpref & aux_long ) out_symbol('.');
if ( cmd.auxpref & aux_long ) out_symbol('w');
if ( cmd.auxpref & aux_extd ) out_symbol('.');
if ( cmd.auxpref & aux_extd ) out_symbol('e');
if ( cmd.auxpref & aux_indir ) out_symbol(']');
if ( cmd.auxpref & aux_index )
{
out_symbol(',');
outreg(x.reg);
out_symbol(')');
}
break;
case o_near:
outmem(x, calc_mem(x.addr));
break;
default:
interr("out");
break;
}
return 1;
}
//----------------------------------------------------------------------
void idaapi out(void)
{
char buf[MAXSTR];
init_output_buffer(buf, sizeof(buf));
OutMnem();
out_one_operand(0);
if ( cmd.Op2.type != o_void )
{
out_symbol(',');
OutChar(' ');
out_one_operand(1);
}
if ( cmd.Op3.type != o_void )
{
out_symbol(',');
OutChar(' ');
out_one_operand(2);
}
if ( isVoid(cmd.ea, uFlag, 0) ) OutImmChar(cmd.Op1);
if ( isVoid(cmd.ea, uFlag, 1) ) OutImmChar(cmd.Op2);
term_output_buffer();
gl_comm = 1;
MakeLine(buf);
}
//--------------------------------------------------------------------------
void idaapi segstart(ea_t ea)
{
char buf[MAXSTR];
char *const end = buf + sizeof(buf);
segment_t *Sarea = getseg(ea);
if ( is_spec_segm(Sarea->type) ) return;
const char *align;
switch ( Sarea->align )
{
case saAbs: align = "at: "; break;
case saRelByte: align = "byte"; break;
case saRelWord: align = "word"; break;
case saRelPara: align = "para"; break;
case saRelPage: align = "page"; break;
case saRel4K: align = "4k"; break;
case saRel64Bytes: align = "64"; break;
default: align = NULL; break;
}
if ( align == NULL )
{
gen_cmt_line("Segment alignment '%s' can not be represented in assembly",
get_segment_alignment(Sarea->align));
align = "";
}
char sname[MAXNAMELEN];
char sclas[MAXNAMELEN];
get_true_segm_name(Sarea, sname, sizeof(sname));
get_segm_class(Sarea, sclas, sizeof(sclas));
char *ptr = buf + qsnprintf(buf, sizeof(buf),
SCOLOR_ON SCOLOR_ASMDIR "%-*s segment %s ",
inf.indent-1,
sname,
align);
if ( Sarea->align == saAbs )
{
ea_t absbase = get_segm_base(Sarea);
ptr += btoa(ptr, end-ptr, absbase);
APPCHAR(ptr, end, ' ');
}
const char *comb;
switch ( Sarea->comb )
{
case scPub:
case scPub2:
case scPub3: comb = ""; break;
case scCommon: comb = "common"; break;
default: comb = NULL; break;
}
if ( comb == NULL )
{
gen_cmt_line("Segment combination '%s' can not be represented in assembly",
get_segment_combination(Sarea->comb));
comb = "";
}
ptr += qsnprintf(ptr, end-ptr, "%s '%s'", comb, sclas);
tag_off(ptr, end, COLOR_ASMDIR);
MakeLine(buf, 0);
}
//--------------------------------------------------------------------------
void idaapi segend(ea_t)
{
}
//--------------------------------------------------------------------------
void idaapi header()
{
gen_cmt_line("Processor : %-8.8s", inf.procName);
// gen_cmt_line("Target assembler: %s", ash.name);
// gen_cmt_line("Byte sex : %s", inf.mf ? "Big endian" : "Little endian");
if ( ash.header != NULL )
for ( char const *const *ptr=ash.header; *ptr != NULL; ptr++ )
printf_line(0,COLSTR("%s",SCOLOR_ASMDIR),*ptr);
MakeNull();
}
//--------------------------------------------------------------------------
void idaapi footer()
{
char name[MAXSTR];
get_colored_name(BADADDR, inf.beginEA, name, sizeof(name));
const char *end = ash.end;
if ( end == NULL )
printf_line(inf.indent,COLSTR("%s end %s",SCOLOR_AUTOCMT), ash.cmnt, name);
else
printf_line(inf.indent,COLSTR("%s",SCOLOR_ASMDIR)
" "
COLSTR("%s %s",SCOLOR_AUTOCMT), ash.end, ash.cmnt, name);
}