Rizin
unix-like reverse engineering framework and cli tools
analysis_msp430.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2014 Fedor Sakharov <fedor.sakharov@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <string.h>
5 #include <rz_types.h>
6 #include <rz_lib.h>
7 #include <rz_asm.h>
8 #include <rz_analysis.h>
9 #include <rz_util.h>
10 
11 #include <msp430_disas.h>
12 
13 static int msp430_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask) {
14  int ret;
15  struct msp430_cmd cmd;
16 
17  memset(&cmd, 0, sizeof(cmd));
18  // op->id = ???;
19  op->size = -1;
20  op->nopcode = 1;
22  op->family = RZ_ANALYSIS_OP_FAMILY_CPU;
23 
24  ret = op->size = msp430_decode_command(buf, len, &cmd);
25 
26  if (ret < 0) {
27  return ret;
28  }
29 
30  op->addr = addr;
31 
32  switch (cmd.type) {
33  case MSP430_ONEOP:
34  switch (cmd.opcode) {
35  case MSP430_RRA:
36  case MSP430_RRC:
38  break;
39  case MSP430_PUSH:
41  break;
42  case MSP430_CALL:
44  op->fail = addr + op->size;
45  op->jump = rz_read_at_le16(buf, 2);
46  break;
47  case MSP430_RETI:
49  break;
50  }
51  break;
52  case MSP430_TWOOP:
53  switch (cmd.opcode) {
54  case MSP430_BIT:
55  case MSP430_BIC:
56  case MSP430_BIS:
57  case MSP430_MOV:
59  if ((cmd.instr)[0] == 'b' && (cmd.instr)[1] == 'r') {
60  // Emulated branch instruction, moves source operand to PC register.
62  }
63  break;
64  case MSP430_DADD:
65  case MSP430_ADDC:
66  case MSP430_ADD: op->type = RZ_ANALYSIS_OP_TYPE_ADD; break;
67  case MSP430_SUBC:
68  case MSP430_SUB: op->type = RZ_ANALYSIS_OP_TYPE_SUB; break;
69  case MSP430_CMP: op->type = RZ_ANALYSIS_OP_TYPE_CMP; break;
70  case MSP430_XOR: op->type = RZ_ANALYSIS_OP_TYPE_XOR; break;
71  case MSP430_AND: op->type = RZ_ANALYSIS_OP_TYPE_AND; break;
72  }
73  break;
74  case MSP430_JUMP:
75  if (cmd.jmp_cond == MSP430_JMP) {
77  } else {
79  }
80  op->jump = addr + cmd.jmp_addr;
81  op->fail = addr + 2;
82  break;
83  case MSP430_INV:
85  break;
86  default:
88  }
89 
90  return ret;
91 }
92 
94  .name = "msp430",
95  .desc = "TI MSP430 code analysis plugin",
96  .license = "LGPL3",
97  .arch = "msp430",
98  .bits = 16,
99  .op = msp430_op,
100 };
size_t len
Definition: 6502dis.c:15
#define mask()
RzAnalysisPlugin rz_analysis_plugin_msp430
static int msp430_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
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
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
return memset(p, 0, total)
int msp430_decode_command(const ut8 *in, int len, struct msp430_cmd *cmd)
Definition: msp430_disas.c:441
@ MSP430_JUMP
Definition: msp430_disas.h:58
@ MSP430_INV
Definition: msp430_disas.h:59
@ MSP430_TWOOP
Definition: msp430_disas.h:57
@ MSP430_ONEOP
Definition: msp430_disas.h:56
@ MSP430_SUBC
Definition: msp430_disas.h:37
@ MSP430_MOV
Definition: msp430_disas.h:34
@ MSP430_CMP
Definition: msp430_disas.h:39
@ MSP430_BIC
Definition: msp430_disas.h:42
@ MSP430_XOR
Definition: msp430_disas.h:44
@ MSP430_SUB
Definition: msp430_disas.h:38
@ MSP430_DADD
Definition: msp430_disas.h:40
@ MSP430_BIS
Definition: msp430_disas.h:43
@ MSP430_ADD
Definition: msp430_disas.h:35
@ MSP430_BIT
Definition: msp430_disas.h:41
@ MSP430_AND
Definition: msp430_disas.h:45
@ MSP430_ADDC
Definition: msp430_disas.h:36
@ MSP430_RRA
Definition: msp430_disas.h:13
@ MSP430_RRC
Definition: msp430_disas.h:11
@ MSP430_PUSH
Definition: msp430_disas.h:15
@ MSP430_CALL
Definition: msp430_disas.h:16
@ MSP430_RETI
Definition: msp430_disas.h:17
@ MSP430_JMP
Definition: msp430_disas.h:29
@ RZ_ANALYSIS_OP_FAMILY_CPU
Definition: rz_analysis.h:312
RzAnalysisOpMask
Definition: rz_analysis.h:439
@ RZ_ANALYSIS_OP_TYPE_CMP
Definition: rz_analysis.h:399
@ RZ_ANALYSIS_OP_TYPE_SUB
Definition: rz_analysis.h:402
@ RZ_ANALYSIS_OP_TYPE_UNK
Definition: rz_analysis.h:388
@ RZ_ANALYSIS_OP_TYPE_JMP
Definition: rz_analysis.h:368
@ RZ_ANALYSIS_OP_TYPE_AND
Definition: rz_analysis.h:411
@ RZ_ANALYSIS_OP_TYPE_UJMP
Definition: rz_analysis.h:369
@ RZ_ANALYSIS_OP_TYPE_ROR
Definition: rz_analysis.h:419
@ RZ_ANALYSIS_OP_TYPE_CALL
Definition: rz_analysis.h:378
@ RZ_ANALYSIS_OP_TYPE_ADD
Definition: rz_analysis.h:401
@ RZ_ANALYSIS_OP_TYPE_PUSH
Definition: rz_analysis.h:397
@ RZ_ANALYSIS_OP_TYPE_CJMP
Definition: rz_analysis.h:373
@ RZ_ANALYSIS_OP_TYPE_MOV
Definition: rz_analysis.h:390
@ RZ_ANALYSIS_OP_TYPE_ILL
Definition: rz_analysis.h:387
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385
@ RZ_ANALYSIS_OP_TYPE_XOR
Definition: rz_analysis.h:412
static ut16 rz_read_at_le16(const void *src, size_t offset)
Definition: rz_endian.h:214
Definition: dis.c:32
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58