Rizin
unix-like reverse engineering framework and cli tools
msp430_disas.h File Reference

Go to the source code of this file.

Classes

struct  msp430_cmd
 

Enumerations

enum  msp430_oneop_opcodes {
  MSP430_RRC , MSP430_SWPB , MSP430_RRA , MSP430_SXT ,
  MSP430_PUSH , MSP430_CALL , MSP430_RETI , MSP430_UNUSED
}
 
enum  msp430_jumps {
  MSP430_JNE , MSP430_JEQ , MSP430_JNC , MSP430_JC ,
  MSP430_JN , MSP430_JGE , MSP430_JL , MSP430_JMP
}
 
enum  msp430_twoop_opcodes {
  MSP430_JMP_OPC = 0x1 , MSP430_MOV = 0x4 , MSP430_ADD , MSP430_ADDC ,
  MSP430_SUBC , MSP430_SUB , MSP430_CMP , MSP430_DADD ,
  MSP430_BIT , MSP430_BIC , MSP430_BIS , MSP430_XOR ,
  MSP430_AND
}
 
enum  msp430_addr_modes { MSP430_DIRECT , MSP430_INDEXED , MSP430_INDIRECT , MSP430_INDIRECT_INC }
 
enum  msp430_cmd_type { MSP430_ONEOP , MSP430_TWOOP , MSP430_JUMP , MSP430_INV }
 
enum  msp430_registers {
  MSP430_PC , MSP430_SP , MSP430_SR , MSP430_R3 ,
  MSP430_R4 , MSP430_R5 , MSP430_R6 , MSP430_R7 ,
  MSP430_R8 , MSP430_R9 , MSP430_R10 , MSP430_R11 ,
  MSP430_R12 , MSP430_R13 , MSP430_R14 , MSP430_R15
}
 

Functions

int msp430_decode_command (const ut8 *instr, int len, struct msp430_cmd *cmd)
 

Enumeration Type Documentation

◆ msp430_addr_modes

Enumerator
MSP430_DIRECT 
MSP430_INDEXED 
MSP430_INDIRECT 
MSP430_INDIRECT_INC 

Definition at line 48 of file msp430_disas.h.

48  {
53 };
@ MSP430_INDIRECT
Definition: msp430_disas.h:51
@ MSP430_INDIRECT_INC
Definition: msp430_disas.h:52
@ MSP430_INDEXED
Definition: msp430_disas.h:50
@ MSP430_DIRECT
Definition: msp430_disas.h:49

◆ msp430_cmd_type

Enumerator
MSP430_ONEOP 
MSP430_TWOOP 
MSP430_JUMP 
MSP430_INV 

Definition at line 55 of file msp430_disas.h.

55  {
59  MSP430_INV,
60 };
@ 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_jumps

Enumerator
MSP430_JNE 
MSP430_JEQ 
MSP430_JNC 
MSP430_JC 
MSP430_JN 
MSP430_JGE 
MSP430_JL 
MSP430_JMP 

Definition at line 21 of file msp430_disas.h.

21  {
22  MSP430_JNE,
23  MSP430_JEQ,
24  MSP430_JNC,
25  MSP430_JC,
26  MSP430_JN,
27  MSP430_JGE,
28  MSP430_JL,
29  MSP430_JMP,
30 };
@ MSP430_JMP
Definition: msp430_disas.h:29
@ MSP430_JL
Definition: msp430_disas.h:28
@ MSP430_JEQ
Definition: msp430_disas.h:23
@ MSP430_JGE
Definition: msp430_disas.h:27
@ MSP430_JN
Definition: msp430_disas.h:26
@ MSP430_JNE
Definition: msp430_disas.h:22
@ MSP430_JC
Definition: msp430_disas.h:25
@ MSP430_JNC
Definition: msp430_disas.h:24

◆ msp430_oneop_opcodes

Enumerator
MSP430_RRC 
MSP430_SWPB 
MSP430_RRA 
MSP430_SXT 
MSP430_PUSH 
MSP430_CALL 
MSP430_RETI 
MSP430_UNUSED 

Definition at line 10 of file msp430_disas.h.

10  {
11  MSP430_RRC,
13  MSP430_RRA,
14  MSP430_SXT,
19 };
@ MSP430_RRA
Definition: msp430_disas.h:13
@ MSP430_SXT
Definition: msp430_disas.h:14
@ MSP430_RRC
Definition: msp430_disas.h:11
@ MSP430_PUSH
Definition: msp430_disas.h:15
@ MSP430_UNUSED
Definition: msp430_disas.h:18
@ MSP430_CALL
Definition: msp430_disas.h:16
@ MSP430_RETI
Definition: msp430_disas.h:17
@ MSP430_SWPB
Definition: msp430_disas.h:12

◆ msp430_registers

Enumerator
MSP430_PC 
MSP430_SP 
MSP430_SR 
MSP430_R3 
MSP430_R4 
MSP430_R5 
MSP430_R6 
MSP430_R7 
MSP430_R8 
MSP430_R9 
MSP430_R10 
MSP430_R11 
MSP430_R12 
MSP430_R13 
MSP430_R14 
MSP430_R15 

Definition at line 62 of file msp430_disas.h.

62  {
63  MSP430_PC,
64  MSP430_SP,
65  MSP430_SR,
66  MSP430_R3,
67  MSP430_R4,
68  MSP430_R5,
69  MSP430_R6,
70  MSP430_R7,
71  MSP430_R8,
72  MSP430_R9,
73  MSP430_R10,
74  MSP430_R11,
75  MSP430_R12,
76  MSP430_R13,
77  MSP430_R14,
78  MSP430_R15,
79 };
@ MSP430_SR
Definition: msp430_disas.h:65
@ MSP430_R7
Definition: msp430_disas.h:70
@ MSP430_R13
Definition: msp430_disas.h:76
@ MSP430_R8
Definition: msp430_disas.h:71
@ MSP430_R5
Definition: msp430_disas.h:68
@ MSP430_R11
Definition: msp430_disas.h:74
@ MSP430_SP
Definition: msp430_disas.h:64
@ MSP430_R14
Definition: msp430_disas.h:77
@ MSP430_R10
Definition: msp430_disas.h:73
@ MSP430_R9
Definition: msp430_disas.h:72
@ MSP430_R6
Definition: msp430_disas.h:69
@ MSP430_R12
Definition: msp430_disas.h:75
@ MSP430_PC
Definition: msp430_disas.h:63
@ MSP430_R3
Definition: msp430_disas.h:66
@ MSP430_R15
Definition: msp430_disas.h:78
@ MSP430_R4
Definition: msp430_disas.h:67

◆ msp430_twoop_opcodes

Enumerator
MSP430_JMP_OPC 
MSP430_MOV 
MSP430_ADD 
MSP430_ADDC 
MSP430_SUBC 
MSP430_SUB 
MSP430_CMP 
MSP430_DADD 
MSP430_BIT 
MSP430_BIC 
MSP430_BIS 
MSP430_XOR 
MSP430_AND 

Definition at line 32 of file msp430_disas.h.

32  {
33  MSP430_JMP_OPC = 0x1,
34  MSP430_MOV = 0x4,
35  MSP430_ADD,
38  MSP430_SUB,
39  MSP430_CMP,
41  MSP430_BIT,
42  MSP430_BIC,
43  MSP430_BIS,
44  MSP430_XOR,
45  MSP430_AND,
46 };
@ 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_JMP_OPC
Definition: msp430_disas.h:33
@ MSP430_ADDC
Definition: msp430_disas.h:36

Function Documentation

◆ msp430_decode_command()

int msp430_decode_command ( const ut8 instr,
int  len,
struct msp430_cmd cmd 
)

Definition at line 441 of file msp430_disas.c.

441  {
442  int ret = -1;
443  ut16 operand1 = 0, operand2 = 0;
444  if (len < 2) {
445  return -1;
446  }
447  ut16 instr = rz_read_le16(in);
448  ut8 opcode = get_twoop_opcode(instr);
449 
450  switch (opcode) {
452  // Invalid opcode.
453  break;
455  // Single operand instructions or invalid opcode.
456  if ((instr & 0x0f80) <= 0x0300) {
457  // Single operand instructions.
458  if (len >= 4) {
459  operand1 = rz_read_at_le16(in, 2);
460  }
461  ret = decode_oneop_opcode(instr, operand1, cmd);
462  }
463  break;
466  // Jumps.
467  decode_jmp(instr, cmd);
468  ret = 2;
469  break;
470  default:
471  // Double operand instructions.
472  cmd->type = MSP430_TWOOP;
473  if (len >= 4) {
474  operand1 = rz_read_at_le16(in, 2);
475  if (len >= 6) {
476  operand2 = rz_read_at_le16(in, 4);
477  }
478  }
479  ret = decode_twoop_opcode(instr, operand1, operand2, cmd);
480  break;
481  }
482 
483  /* if ret < 0, it's an invalid opcode.Say so and return 2 since
484  * all MSP430 opcodes are of 16 bits,valid or invalid */
485  if (ret < 0) {
486  cmd->type = MSP430_INV;
487  snprintf(cmd->instr, sizeof(cmd->instr), "invalid");
488  cmd->operands[0] = '\0';
489  ret = 2;
490  }
491 
492  return ret;
493 }
size_t len
Definition: 6502dis.c:15
const lzma_allocator const uint8_t * in
Definition: block.h:527
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
uint8_t ut8
Definition: lh5801.h:11
@ MSP430_TWOOP_OPCODE_JUMP3
Definition: msp430_disas.c:438
@ MSP430_TWOOP_OPCODE_INVALID
Definition: msp430_disas.c:435
@ MSP430_TWOOP_OPCODE_JUMP2
Definition: msp430_disas.c:437
@ MSP430_TWOOP_OPCODE_SINGLEOP
Definition: msp430_disas.c:436
static ut8 get_twoop_opcode(ut16 instr)
Definition: msp430_disas.c:67
static void decode_jmp(ut16 instr, struct msp430_cmd *cmd)
Definition: msp430_disas.c:329
static int decode_oneop_opcode(ut16 instr, ut16 op, struct msp430_cmd *cmd)
Definition: msp430_disas.c:349
static int decode_twoop_opcode(ut16 instr, ut16 op1, ut16 op2, struct msp430_cmd *cmd)
Definition: msp430_disas.c:309
static ut16 rz_read_at_le16(const void *src, size_t offset)
Definition: rz_endian.h:214
static ut16 rz_read_le16(const void *src)
Definition: rz_endian.h:206

References cmd, decode_jmp(), decode_oneop_opcode(), decode_twoop_opcode(), get_twoop_opcode(), in, len, MSP430_INV, MSP430_TWOOP, MSP430_TWOOP_OPCODE_INVALID, MSP430_TWOOP_OPCODE_JUMP2, MSP430_TWOOP_OPCODE_JUMP3, MSP430_TWOOP_OPCODE_SINGLEOP, rz_read_at_le16(), rz_read_le16(), and snprintf.

Referenced by disassemble(), and msp430_op().