-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathreg.cpp
More file actions
357 lines (324 loc) · 9.54 KB
/
reg.cpp
File metadata and controls
357 lines (324 loc) · 9.54 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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#pragma warning ( disable : 4146)
#include "lm32.hpp"
int data_id;
//---------------------------------------------------------------------------------------------------------------------
static bool idaapi can_have_type(const op_t& x) // returns 1 - operand can have
{
switch (x.type)
{
case o_void:
case o_reg:
case o_near:
return 0;
//case o_phrase: can have type because of ASI or 0 struct offsets
}
return 1;
}
//---------------------------------------------------------------------------------------------------------------------
ssize_t idaapi idb_listener_t::on_event(ssize_t code, va_list)
{
/*
switch (code)
{
// add stuff here...
default: break;
}
*/
return 0;
}
//---------------------------------------------------------------------------------------------------------------------
// This old-style callback only returns the processor module object.
static ssize_t idaapi notify(void*, int msgid, va_list)
{
if (msgid == processor_t::ev_get_procmod) return size_t(SET_MODULE_DATA(LM32_t));
return 0;
}
void LM32_t::load_from_idb()
{
ioh.restore_device();
}
//---------------------------------------------------------------------------------------------------------------------
bool LM32_t::LM32_find_ioport_bit(outctx_t& ctx, int port, int bit)
{
const ioport_bit_t* b = find_ioport_bit(ioh.ports, port, bit);
if (b != nullptr && !b->name.empty()) ctx.out_line(b->name.c_str(), COLOR_IMPNAME); return true;
return false;
}
//---------------------------------------------------------------------------------------------------------------------
ssize_t idaapi LM32_t::on_event(ssize_t msgid, va_list va)
{
int code = 0;
switch (msgid)
{
case processor_t::ev_newfile:
{
char cfgfile[QMAXFILE];
//warning("In newfile");
ioh.get_cfg_filename(cfgfile, sizeof(cfgfile));
iohandler_t::parse_area_line0_t cb(ioh);
if (choose_ioport_device2(&ioh.device, cfgfile, &cb))
ioh.set_device_name(ioh.device.c_str(), IORESP_ALL);
}
case processor_t::ev_ending_undo:
case processor_t::ev_oldfile:
{
load_from_idb();
break;
}
case processor_t::ev_get_frame_retsize:
{
int* frsize = va_arg(va, int*);
*frsize = 0;
return 1;
}
case processor_t::ev_init:
{
hook_event_listener(HT_IDB, &idb_listener, &LPH);
// Set a big endian mode of the IDA kernel
inf_set_be(true);
helper.create(PROCMOD_NODE_NAME);
break;
}
case processor_t::ev_term:
{
unhook_event_listener(HT_IDB, &idb_listener);
ioh.ports.clear();
clr_module_data(data_id);
break;
}
/*
case processor_t::ev_creating_segm:
{
segment_t* s = va_arg(va, segment_t*);
// Set default value of DS register for all segments
set_default_dataseg(s->sel);
break;
}
*/
case processor_t::ev_is_switch:
{
switch_info_t* si = va_arg(va, switch_info_t*);
const insn_t* insn = va_arg(va, const insn_t*);
return LM32_is_switch(si, *insn) ? 1 : -1;
}
case processor_t::ev_ana_insn:
{
insn_t* out = va_arg(va, insn_t*);
return LM32_ana(out);
}
case processor_t::ev_emu_insn:
{
const insn_t* insn = va_arg(va, const insn_t*);
return LM32_emu(*insn) ? 1 : -1;
}
case processor_t::ev_out_insn:
{
outctx_t* ctx = va_arg(va, outctx_t*);
out_insn(*ctx);
return 1;
}
case processor_t::ev_out_operand:
{
outctx_t* ctx = va_arg(va, outctx_t*);
const op_t* op = va_arg(va, const op_t*);
return out_opnd(*ctx, *op) ? 1 : -1;
}
case processor_t::ev_can_have_type:
{
const op_t* op = va_arg(va, const op_t*);
return can_have_type(*op) ? 1 : -1;
}
case processor_t::ev_loader_elf_machine:
{
linput_t* li = va_arg(va, linput_t*);
int machine_type = va_arg(va, int);
const char** p_procname = va_arg(va, const char**);
(void)li; // unused variable
if (machine_type == 0x8A)
{
*p_procname = "LM32";
code = 0xBABE;
}
break;
}
default:
break;
}
va_end(va);
return code;
}
//---------------------------------------------------------------------------------------------------------------------
static const asm_t lm32asm =
{
ASH_HEXF3 | AS_COLON | ASB_BINF0 | ASO_OCTF1 | AS_NCMAS,
0,
"LM32 assembler",
0,
NULL,
".org",
".end",
";", // comment string
'"', // string delimiter
'\'', // char delimiter (no char consts)
"\\\"'", // special symbols in char and string constants
".ascii", // string literal directive
".byte", // byte directive
".word", // word directive
".dword", // dword (4 bytes)
".qword", // qword (8 bytes)
NULL, // oword (16 bytes)
".float", // float (4 bytes)
".double", // double (8 bytes)
NULL, // tbyte (10/12 bytes)
NULL, // packed decimal real
"#d dup(#v)", // array keyword (#h,#d,#v,#s(...))
".block %s", // uninitialized data directive
".equ", // equ
NULL, // seg prefix
NULL, // comment close
NULL, // low 8 bits
NULL, // high 8 bits
NULL, // low 16 bits
NULL, // high 16 bits
NULL, // preline
NULL, // start of bold text
NULL, // start of normal text
NULL, // start of literal text
NULL, // end of comment
NULL, // get_type_name
NULL, // align
NULL, // left brace
NULL, // right brace
NULL, // modulo operator
NULL, // and operator
NULL, // or operator
NULL, // xor operator
NULL, // not operator
NULL, // shift left operator
NULL, // shift right operator
NULL // sizeof operator
};
//---------------------------------------------------------------------------------------------------------------------
static const asm_t* const asms[] = { &lm32asm, NULL };
//---------------------------------------------------------------------------------------------------------------------
static const uchar retcode_1[] = { 0xc3, 0xa0, 0x00, 0x00 };
static const uchar retcode_2[] = { 0xc3, 0xc0, 0x00, 0x00 };
static const uchar retcode_3[] = { 0xc3, 0xe0, 0x00, 0x00 };
//---------------------------------------------------------------------------------------------------------------------
static const bytes_t retcodes[] =
{
{ sizeof(retcode_1), retcode_1 },
{ sizeof(retcode_2), retcode_2 },
{ sizeof(retcode_3), retcode_3 },
{ 0, NULL }
};
//---------------------------------------------------------------------------------------------------------------------
#define FAMILY "LatticeMico Processors:"
static const char* const shnames[] = { "LM32", NULL };
static const char* const lnames[] = { FAMILY"LatticeMico32 big endian", NULL };
//---------------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------
// Processor Definition
//-----------------------------------------------------------------------
#define PLFM_LM32 0xBABE
static const char* const RegNames[] =
{
"r0",
"r1",
"r2",
"r3",
"r4",
"r5",
"r6",
"r7",
"r8",
"r9",
"r10",
"r11",
"r12",
"r13",
"r14",
"r15",
"r16",
"r17",
"r18",
"r19",
"r20",
"r21",
"r22",
"r23",
"r24",
"r25",
"gp",
"fp",
"sp",
"ra",
"ea",
"ba",
"IE", // 32
"IM",
"IP",
"ICC",
"DCC",
"CC",
"CFG",
"EBA",
"DC",
"DEBA",
"CFG2",
"h-csr-b",
"h-csr-c",
"h-csr-d",
"JTX",
"JRX",
"BP0",
"BP1",
"BP2",
"BP3",
"h-csr-14",
"h-csr-15",
"h-csr-16",
"h-csr-17",
"WP0",
"WP1",
"WP2",
"WP3",
"h-csr-1c",
"PSW",
"TLBVAD",
"TLBPAD",
};
processor_t LPH =
{
IDP_INTERFACE_VERSION, // version
PLFM_LM32, // id
// flag
PR_USE32|PR_DEFSEG32|PRN_HEX|PR_RNAMESOK|PR_ALIGN,
0, // the module has processor-specific configuration options
8, // 8 bits in a byte for code segments
8, // 8 bits in a byte for other segments
shnames,
lnames,
asms,
notify,
RegNames,
qnumber(RegNames), // number of registers
qnumber(RegNames) - 2, // first
qnumber(RegNames) - 1, // last
0, // size of a segment register
qnumber(RegNames) - 2, // virtual CS
qnumber(RegNames) - 1, // virtual DS
NULL, // no known code start sequences
retcodes, // 'Return' instruction codes
0, //
LM32_INSN_NOP + 1, //
Instructions, // instruc
0, // int tbyte_size; -- doesn't exist
{ 0, 0, 0, 0 }, // char real_width[4];
// number of symbols after decimal point
// 2byte float (0-does not exist)
// normal float
// normal double
// long double
LM32_INSN_RET, // icode of return instruction. It is ok to give any of possible return instructions
};