Repository navigation
Expand file tree
/
Copy pathreg.cpp
More file actions
269 lines (236 loc) · 7.87 KB
/
Copy pathreg.cpp
File metadata and controls
269 lines (236 loc) · 7.87 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
/* KIRK IDP main and reg - (c) Proxima 2023
*/
#pragma warning ( disable : 4146)
#include "kirk.hpp"
int data_id;
//---------------------------------------------------------------------------------------------------------------------
static bool idaapi can_have_type(const op_t& x)
{
switch (x.type)
{
case o_void:
case o_reg:
case o_near:
return false;
default:
return true;
}
}
//---------------------------------------------------------------------------------------------------------------------
ssize_t idaapi idb_listener_t::on_event(ssize_t, va_list)
{
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(kirk_t));
return 0;
}
void kirk_t::load_from_idb()
{
ioh.restore_device(IORESP_NONE);
if (ioh.ports.empty() && ioh.device.empty())
{
ioh.device = "KIRK";
ioh.apply_config_file(IORESP_NONE);
}
}
//---------------------------------------------------------------------------------------------------------------------
const char* kirk_t::find_ioport_bit_name(ea_t port, size_t bit) const
{
const ioport_bit_t* b = find_ioport_bit(ioh.ports, port, bit);
if (b != nullptr && !b->name.empty())
return b->name.c_str();
return nullptr;
}
//---------------------------------------------------------------------------------------------------------------------
bool kirk_t::kirk_find_ioport_bit(outctx_t& ctx, ea_t port, size_t bit)
{
const char* name = find_ioport_bit_name(port, bit);
if (name != nullptr)
{
ctx.out_line(name, COLOR_IMPNAME);
return true;
}
return false;
}
//---------------------------------------------------------------------------------------------------------------------
ssize_t idaapi kirk_t::on_event(ssize_t msgid, va_list va)
{
int code = 0;
switch (msgid)
{
case processor_t::ev_newfile:
{
char cfgfile[QMAXFILE];
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);
break;
}
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 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_ana_insn:
{
insn_t* out = va_arg(va, insn_t*);
return kirk_ana(out);
}
case processor_t::ev_emu_insn:
{
const insn_t* insn = va_arg(va, const insn_t*);
return kirk_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;
}
default:
break;
}
return code;
}
//---------------------------------------------------------------------------------------------------------------------
static const asm_t kirkasm =
{
ASH_HEXF3 | AS_COLON | ASB_BINF0 | ASO_OCTF1 | AS_NCMAS,
0,
"KIRK assembler",
0,
NULL,
".org",
".end",
";", // comment string
'"', // string delimiter
'\'', // char delimiter (no char consts)
"'\"", // special symbols in char and string constants
".ascii", // ascii string directive
".byte", // byte directive
".word", // word directive
".dword", // dword (4 bytes)
".qword", // qword (8 bytes)
".oword", // 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", // uninited arrays
".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[] = { &kirkasm, NULL };
//---------------------------------------------------------------------------------------------------------------------
static const uchar retcode_1[] = { 0xF0, 0x00, 0x00, 0x00 };
//---------------------------------------------------------------------------------------------------------------------
static const bytes_t retcodes[] =
{
{ sizeof(retcode_1), retcode_1 },
{ 0, NULL }
};
//---------------------------------------------------------------------------------------------------------------------
#define FAMILY "Star Trek PSP Processors:"
static const char* const shnames[] = { "KIRK", NULL };
static const char* const lnames[] = { FAMILY"KIRK big endian", NULL };
//-----------------------------------------------------------------------
// Processor Definition
//-----------------------------------------------------------------------
#define PLFM_KIRK (0x8000 + 0x1701)
static const char* const RegNames[] =
{
"cs",
"ds",
};
processor_t LPH =
{
IDP_INTERFACE_VERSION, // version
PLFM_KIRK, // id
// flag
PR_USE32 | PR_DEFSEG32 | PRN_HEX | PR_RNAMESOK | PR_ALIGN,
0, // flag2
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
0, // first segment register
1, // last segment register
0, // size of a segment register
0, // virtual CS
1, // virtual DS
NULL, // no known code start sequences
retcodes, // 'Return' instruction codes
0, // first instruction
KIRK_INSN_LAST, // last instruction
Instructions, // instruc
0, // int tbyte_size; -- doesn't exist
{ 0, 0, 0, 0 }, // char real_width[4];
KIRK_INSN_F0_RET, // icode of return instruction
};