Rizin
unix-like reverse engineering framework and cli tools
propeller_disas.c File Reference
#include <rz_types.h>
#include <rz_util.h>
#include "propeller_disas.h"

Go to the source code of this file.

Functions

static ut16 get_opcode (ut32 instr)
 
static ut16 get_opcode_ext (ut32 instr)
 
static ut16 get_src (ut32 instr)
 
static ut16 get_dst (ut32 instr)
 
static int is_immediate (ut32 instr)
 
static int decode_ext_cmd (struct propeller_cmd *cmd, ut32 instr)
 
static ut8 get_zcri (ut32 instr)
 
static ut8 get_con (ut32 instr)
 
static void decode_prefix (struct propeller_cmd *cmd, ut32 instr)
 
static int decode_jmp (struct propeller_cmd *cmd, ut32 instr)
 
int propeller_decode_command (const ut8 *instr, struct propeller_cmd *cmd)
 

Variables

static const char * instrs []
 
static const char * ext_instrs []
 
static const char * conditions []
 

Function Documentation

◆ decode_ext_cmd()

static int decode_ext_cmd ( struct propeller_cmd cmd,
ut32  instr 
)
static

Definition at line 119 of file propeller_disas.c.

119  {
120  ut16 opcode;
121 
122  opcode = get_opcode_ext(instr);
123 
124  switch (opcode) {
125  case PROP_CLKSET:
126  case PROP_COGID:
127  case PROP_COGINIT:
128  case PROP_COGSTOP:
129  case PROP_LOCKCLR:
130  case PROP_LOCKNEW:
131  case PROP_LOCKRET:
132  case PROP_LOCKSET:
133  snprintf(cmd->instr, PROP_INSTR_MAXLEN - 1,
134  "%s", ext_instrs[PROP_CLKSET]);
135  snprintf(cmd->operands, PROP_INSTR_MAXLEN - 1,
136  "%d", get_dst(instr));
137  return 4;
138  break;
139  }
140 
141  return -1;
142 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
Definition: sflib.h:79
uint16_t ut16
snprintf
Definition: kernel.h:364
static ut16 get_opcode_ext(ut32 instr)
static const char * ext_instrs[]
static ut16 get_dst(ut32 instr)
#define PROP_INSTR_MAXLEN
@ PROP_LOCKNEW
@ PROP_CLKSET
@ PROP_COGSTOP
@ PROP_LOCKRET
@ PROP_LOCKSET
@ PROP_COGINIT
@ PROP_LOCKCLR
@ PROP_COGID

References cmd, ext_instrs, get_dst(), get_opcode_ext(), PROP_CLKSET, PROP_COGID, PROP_COGINIT, PROP_COGSTOP, PROP_INSTR_MAXLEN, PROP_LOCKCLR, PROP_LOCKNEW, PROP_LOCKRET, PROP_LOCKSET, and snprintf.

Referenced by propeller_decode_command().

◆ decode_jmp()

static int decode_jmp ( struct propeller_cmd cmd,
ut32  instr 
)
static

Definition at line 159 of file propeller_disas.c.

159  {
160  ut16 opcode;
161  ut8 zcri;
162  int ret = 1;
163  opcode = get_opcode(instr);
164  switch (opcode) {
165  case PROP_JMP:
166  zcri = get_zcri(instr);
167  if (zcri & 0x2) {
168  snprintf(cmd->instr, PROP_INSTR_MAXLEN - 1,
169  "%s", "jmpret");
170  if (zcri & 1) {
171  cmd->dst = get_dst(instr) << 2;
172  cmd->src = get_src(instr) << 2;
173 
174  snprintf(cmd->operands, PROP_INSTR_MAXLEN - 1,
175  "0x%x, #0x%x", get_dst(instr), get_src(instr) << 2);
176  } else {
177  cmd->src = get_src(instr) << 2;
178  cmd->dst = get_dst(instr) << 2;
179  snprintf(cmd->operands, PROP_INSTR_MAXLEN - 1,
180  "0x%x, 0x%x", get_dst(instr), get_src(instr) << 2);
181  }
182  } else {
183  snprintf(cmd->instr, PROP_INSTR_MAXLEN - 1,
184  "%s", "jmp");
185  if (zcri & 1) {
186  cmd->src = get_src(instr) << 2;
187  cmd->immed = 1;
188  snprintf(cmd->operands, PROP_INSTR_MAXLEN - 1,
189  "#0x%x", get_src(instr) << 2);
190  } else {
191  cmd->immed = 0;
192  cmd->src = get_src(instr) << 2;
193  snprintf(cmd->operands, PROP_INSTR_MAXLEN - 1,
194  "0x%x", get_src(instr) << 2);
195  }
196  }
197 
198  ret = 4;
199  break;
200  }
201 
202  return ret;
203 }
uint8_t ut8
Definition: lh5801.h:11
static ut8 get_zcri(ut32 instr)
static ut16 get_src(ut32 instr)
static ut16 get_opcode(ut32 instr)
@ PROP_JMP

References cmd, get_dst(), get_opcode(), get_src(), get_zcri(), PROP_INSTR_MAXLEN, PROP_JMP, and snprintf.

Referenced by propeller_decode_command().

◆ decode_prefix()

static void decode_prefix ( struct propeller_cmd cmd,
ut32  instr 
)
static

Definition at line 152 of file propeller_disas.c.

152  {
153  ut8 prefix = (instr >> 18) & 0xF;
154 
155  snprintf(cmd->prefix, 15, "%s", conditions[prefix]);
156  cmd->prefix[15] = '\0';
157 }
unsigned short prefix[65536]
Definition: gun.c:163
static const char * conditions[]

References cmd, conditions, prefix, and snprintf.

Referenced by propeller_decode_command().

◆ get_con()

static ut8 get_con ( ut32  instr)
static

Definition at line 148 of file propeller_disas.c.

148  {
149  return (instr >> 18) & 0xf;
150 }

Referenced by propeller_decode_command().

◆ get_dst()

static ut16 get_dst ( ut32  instr)
static

Definition at line 111 of file propeller_disas.c.

111  {
112  return ((instr >> 9) & 0x1FF) << 2;
113 }

Referenced by decode_ext_cmd(), decode_jmp(), and propeller_decode_command().

◆ get_opcode()

static ut16 get_opcode ( ut32  instr)
static

Definition at line 99 of file propeller_disas.c.

99  {
100  return instr >> 26;
101 }

Referenced by decode_jmp(), and propeller_decode_command().

◆ get_opcode_ext()

static ut16 get_opcode_ext ( ut32  instr)
static

Definition at line 103 of file propeller_disas.c.

103  {
104  return (instr & 0x7) | (instr >> 23);
105 }

Referenced by decode_ext_cmd().

◆ get_src()

static ut16 get_src ( ut32  instr)
static

Definition at line 107 of file propeller_disas.c.

107  {
108  return instr & 0x1FF;
109 }

Referenced by decode_jmp(), and propeller_decode_command().

◆ get_zcri()

static ut8 get_zcri ( ut32  instr)
static

Definition at line 144 of file propeller_disas.c.

144  {
145  return (instr >> 22) & 0xf;
146 }

Referenced by decode_jmp(), and propeller_decode_command().

◆ is_immediate()

static int is_immediate ( ut32  instr)
static

Definition at line 115 of file propeller_disas.c.

115  {
116  return instr & 0x00400000;
117 }

Referenced by _6502_op(), msr(), propeller_decode_command(), query_step__new(), and ts_query__parse_pattern().

◆ propeller_decode_command()

int propeller_decode_command ( const ut8 instr,
struct propeller_cmd cmd 
)

Definition at line 205 of file propeller_disas.c.

205  {
206  int ret = -1;
207  ut32 in;
208  ut16 opcode;
209 
210  in = rz_read_be32(instr);
211 
212  opcode = get_opcode(in);
213 
214  if (!get_con(in)) {
215  snprintf(cmd->instr, PROP_INSTR_MAXLEN, "nop");
216  cmd->operands[0] = '\0';
217  return 4;
218  }
219 
220  switch (opcode) {
221  case PROP_ABS:
222  case PROP_ABSNEG:
223  case PROP_ADD:
224  case PROP_ADDABS:
225  case PROP_ADDS:
226  case PROP_ADDSX:
227  case PROP_ADDX:
228  case PROP_AND:
229  case PROP_ANDN:
230  case PROP_CMP:
231  case PROP_CMPS:
232  case PROP_CMPSUB:
233  case PROP_CMPSX:
234  case PROP_CMPX:
235  case PROP_DJNZ:
236  case PROP_MAX:
237  case PROP_MAXS:
238  case PROP_MIN:
239  case PROP_MINS:
240  case PROP_MOV:
241  case PROP_MOVD:
242  case PROP_MOVI:
243  case PROP_MOVS:
244  case PROP_MUXC:
245  case PROP_MUXNC:
246  case PROP_MUXNZ:
247  case PROP_MUXZ:
248  case PROP_NEG:
249  case PROP_NEGC:
250  case PROP_NEGNC:
251  case PROP_NEGNZ:
252  case PROP_NEGZ:
253  case PROP_OR:
254  case PROP_RCL:
255  case PROP_RCR:
256  case PROP_RDBYTE:
257  case PROP_RDLONG:
258  case PROP_RDWORD:
259  // case PROP_RET:
260  case PROP_REV:
261  case PROP_ROL:
262  case PROP_ROR:
263  case PROP_SAR:
264  case PROP_SHL:
265  case PROP_SHR:
266  case PROP_SUBABS:
267  case PROP_SUBS:
268  case PROP_SUBSX:
269  // case PROP_SUBX:
270  case PROP_SUMC:
271  case PROP_SUMNC:
272  case PROP_SUMNZ:
273  case PROP_SUMZ:
274  // case PROP_TEST:
275  case PROP_TJZ:
276  case PROP_WAITCNT:
277  case PROP_WAITPEQ:
278  case PROP_WAITPNE:
279  case PROP_WAITVID:
280  case PROP_XOR:
281  snprintf(cmd->instr, sizeof cmd->instr, "%s", instrs[opcode]);
282 
283  if ((opcode == PROP_RDBYTE || opcode == PROP_RDLONG ||
284  opcode == PROP_RDWORD) &&
285  (!(get_zcri(in) & 0x2))) {
286  cmd->instr[0] = 'w';
287  cmd->instr[1] = 'r';
288  }
289 
290  if (opcode == PROP_SUB && in & 0x08000000) {
291  snprintf(cmd->instr, PROP_INSTR_MAXLEN - 1, "sub");
292  } else if (opcode == PROP_SUBX && in & 0x08000000) {
293  snprintf(cmd->instr, PROP_INSTR_MAXLEN - 1, "subx");
294  }
295 
296  if (is_immediate(in)) {
297  cmd->src = get_src(in);
298  cmd->dst = get_dst(in);
299  snprintf(cmd->operands, PROP_INSTR_MAXLEN - 1, "0x%x, #%d",
300  get_dst(in), get_src(in));
301  } else {
302  cmd->src = get_src(in) << 2;
303  cmd->dst = get_dst(in);
304  snprintf(cmd->operands, PROP_INSTR_MAXLEN - 1, "0x%x, 0x%x",
305  get_dst(in), get_src(in) << 2);
306  }
307 
308  ret = 4;
309  break;
310  case PROP_HUBOP:
311  ret = decode_ext_cmd(cmd, in);
312  if (ret == -1) {
313  snprintf(cmd->instr, PROP_INSTR_MAXLEN - 1, "%s",
314  instrs[opcode]);
315 
316  if (is_immediate(in)) {
317  cmd->src = get_src(in);
318  cmd->dst = get_dst(in);
319 
320  snprintf(cmd->operands, PROP_INSTR_MAXLEN - 1, "0x%x, #%d",
321  get_dst(in) << 2, get_src(in));
322  } else {
323  cmd->src = get_src(in);
324  cmd->dst = get_dst(in);
325 
326  snprintf(cmd->operands, PROP_INSTR_MAXLEN - 1, "0x%x, 0x%x",
327  get_dst(in), get_src(in));
328  }
329 
330  ret = 4;
331  }
332  break;
333  case PROP_JMP:
334  ret = decode_jmp(cmd, in);
335  break;
336  }
337 
338  cmd->opcode = opcode;
339 
340  if (ret > 0) {
341  decode_prefix(cmd, in);
342  }
343 
344  return ret;
345 }
const lzma_allocator const uint8_t * in
Definition: block.h:527
uint32_t ut32
static const char * instrs[]
static int decode_jmp(struct propeller_cmd *cmd, ut32 instr)
static int decode_ext_cmd(struct propeller_cmd *cmd, ut32 instr)
static ut8 get_con(ut32 instr)
static void decode_prefix(struct propeller_cmd *cmd, ut32 instr)
static int is_immediate(ut32 instr)
@ PROP_WAITPEQ
@ PROP_MOVS
@ PROP_MOVD
@ PROP_SUMNZ
@ PROP_MIN
@ PROP_RDWORD
@ PROP_CMPSUB
@ PROP_ANDN
@ PROP_RCR
@ PROP_ADDX
@ PROP_SUMNC
@ PROP_REV
@ PROP_SUBX
@ PROP_XOR
@ PROP_NEG
@ PROP_MOVI
@ PROP_NEGZ
@ PROP_CMPX
@ PROP_SHL
@ PROP_RDBYTE
@ PROP_ADDSX
@ PROP_ABSNEG
@ PROP_TJZ
@ PROP_SHR
@ PROP_RCL
@ PROP_NEGC
@ PROP_NEGNC
@ PROP_MUXC
@ PROP_NEGNZ
@ PROP_SUBABS
@ PROP_SAR
@ PROP_CMP
@ PROP_MUXZ
@ PROP_ROR
@ PROP_MAXS
@ PROP_AND
@ PROP_MINS
@ PROP_WAITPNE
@ PROP_RDLONG
@ PROP_ADDABS
@ PROP_ADDS
@ PROP_MOV
@ PROP_WAITCNT
@ PROP_MUXNZ
@ PROP_MUXNC
@ PROP_SUMZ
@ PROP_WAITVID
@ PROP_HUBOP
@ PROP_ADD
@ PROP_SUMC
@ PROP_SUBS
@ PROP_ROL
@ PROP_OR
@ PROP_MAX
@ PROP_DJNZ
@ PROP_CMPS
@ PROP_SUB
@ PROP_SUBSX
@ PROP_CMPSX
@ PROP_ABS
static ut32 rz_read_be32(const void *src)
Definition: rz_endian.h:87

References cmd, decode_ext_cmd(), decode_jmp(), decode_prefix(), get_con(), get_dst(), get_opcode(), get_src(), get_zcri(), in, instrs, is_immediate(), PROP_ABS, PROP_ABSNEG, PROP_ADD, PROP_ADDABS, PROP_ADDS, PROP_ADDSX, PROP_ADDX, PROP_AND, PROP_ANDN, PROP_CMP, PROP_CMPS, PROP_CMPSUB, PROP_CMPSX, PROP_CMPX, PROP_DJNZ, PROP_HUBOP, PROP_INSTR_MAXLEN, PROP_JMP, PROP_MAX, PROP_MAXS, PROP_MIN, PROP_MINS, PROP_MOV, PROP_MOVD, PROP_MOVI, PROP_MOVS, PROP_MUXC, PROP_MUXNC, PROP_MUXNZ, PROP_MUXZ, PROP_NEG, PROP_NEGC, PROP_NEGNC, PROP_NEGNZ, PROP_NEGZ, PROP_OR, PROP_RCL, PROP_RCR, PROP_RDBYTE, PROP_RDLONG, PROP_RDWORD, PROP_REV, PROP_ROL, PROP_ROR, PROP_SAR, PROP_SHL, PROP_SHR, PROP_SUB, PROP_SUBABS, PROP_SUBS, PROP_SUBSX, PROP_SUBX, PROP_SUMC, PROP_SUMNC, PROP_SUMNZ, PROP_SUMZ, PROP_TJZ, PROP_WAITCNT, PROP_WAITPEQ, PROP_WAITPNE, PROP_WAITVID, PROP_XOR, rz_read_be32(), and snprintf.

Referenced by disassemble(), and propeller_op().

Variable Documentation

◆ conditions

const char* conditions[]
static
Initial value:
= {
[PROP_IF_NEVER] = "",
[PROP_IF_E] = "if_e",
[PROP_IF_NE] = "if_ne",
[PROP_IF_A] = "if_a",
[PROP_IF_B] = "if_b",
[PROP_IF_AE] = "if_ae",
[PROP_IF_BE] = "if_be",
[PROP_IF_C_EQ_Z] = "if_c_eq_z",
[PROP_IF_C_NE_Z] = "if_c_ne_z",
[PROP_IF_C_AND_Z] = "if_c_and_z",
[PROP_IF_C_AND_NZ] = "if_c_and_nz",
[PROP_IF_NC_AND_Z] = "if_nc_and_z",
[PROP_IF_NZ_OR_NC] = "if_nc_or_nz",
[PROP_IF_NZ_OR_C] = "if_nz_or_c",
[PROP_IF_Z_OR_NC] = "if_z_or_c",
}
@ PROP_IF_BE
@ PROP_IF_B
@ PROP_IF_C_NE_Z
@ PROP_IF_NZ_OR_C
@ PROP_IF_ALWAYS
@ PROP_IF_E
@ PROP_IF_AE
@ PROP_IF_C_AND_Z
@ PROP_IF_C_AND_NZ
@ PROP_IF_Z_OR_NC
@ PROP_IF_NC_AND_Z
@ PROP_IF_C_EQ_Z
@ PROP_IF_NEVER
@ PROP_IF_NE
@ PROP_IF_NZ_OR_NC
@ PROP_IF_A

Definition at line 80 of file propeller_disas.c.

Referenced by decode_prefix(), gdbr_set_bp(), gdbr_set_hwa(), gdbr_set_hwbp(), gdbr_set_hwr(), gdbr_set_hww(), qnxr_set_bp(), and qnxr_set_hwbp().

◆ ext_instrs

const char* ext_instrs[]
static
Initial value:
= {
[PROP_CLKSET] = "clkset",
[PROP_COGID] = "cogid",
[PROP_COGINIT] = "coginit",
[PROP_COGSTOP] = "cogstop",
[PROP_LOCKCLR] = "lockclr",
[PROP_LOCKNEW] = "locknew",
[PROP_LOCKRET] = "lockret",
[PROP_LOCKSET] = "lockset",
}

Definition at line 69 of file propeller_disas.c.

Referenced by decode_ext_cmd().

◆ instrs

const char* instrs[]
static

Definition at line 9 of file propeller_disas.c.

Referenced by propeller_decode_command().