Skip to content

Commit

Permalink
Lift MSP430 machine language to RzIL: first 3 instructions and 1 addr…
Browse files Browse the repository at this point in the history
…essing mode
  • Loading branch information
moste00 committed Jun 23, 2024
1 parent 3a33626 commit e63f202
Show file tree
Hide file tree
Showing 13 changed files with 1,228 additions and 108 deletions.
176 changes: 129 additions & 47 deletions librz/arch/isa/msp430/msp430_disas.c

Large diffs are not rendered by default.

61 changes: 54 additions & 7 deletions librz/arch/isa/msp430/msp430_disas.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,39 @@ enum msp430_twoop_opcodes {
MSP430_AND,
};

enum msp430_addr_modes {
MSP430_DIRECT,
MSP430_INDEXED,
MSP430_INDIRECT,
MSP430_INDIRECT_INC,
enum msp430_emulated_opcodes {
MSP430_ADC,
MSP430_BR,
MSP430_CLR,
MSP430_CLRC,
MSP430_CLRN,
MSP430_CLRZ,
MSP430_DADC,
MSP430_DEC,
MSP430_DECD,
MSP430_DINT,
MSP430_EINT,
MSP430_INC,
MSP430_INCD,
MSP430_INV,
MSP430_NOP,
MSP430_POP,
MSP430_RET,
MSP430_RLA,
MSP430_RLC,
MSP430_SBC,
MSP430_SETC,
MSP430_SETN,
MSP430_SETZ,
MSP430_TST
};

enum msp430_cmd_type {
MSP430_ONEOP,
MSP430_TWOOP,
MSP430_JUMP,
MSP430_INV,
MSP430_EMULATE,
MSP430_INVALID,
};

enum msp430_registers {
Expand All @@ -78,22 +99,48 @@ enum msp430_registers {
MSP430_R15,
};

typedef enum Msp430AddressingMode {
// register: Rn, contents of Rn
MSP430_REG,
// indexed: offset(Rn), contents of Memory[offset + Rn]
MSP430_INDX,
// symbolic: offset, contents of Memory[offset + PC] (as if indexed with Rn = PC)
MSP430_SYM,
// absolute: &addr, contents of Memory[addr] (as if indexed with a zeroed Rn)
MSP430_ABS,
// indirect register: @Rn, contents of Memory[Rn] (as if indexed with offset = 0)
MSP430_IND_REG,
// indirect register auto-increment: @Rn+, same as with indirect register but automatically increments Rn
MSP430_IND_AUTOINC,
// immediate: #literal, the literal value itself is the argument
MSP430_IMM
} Msp430AddressingMode;

struct msp430_cmd {
ut8 type;
ut8 opcode;

st16 jmp_addr;
ut16 call_addr;
ut8 jmp_cond;

// Null-delimited string representation of an assembly operation mnemonic.
// Length of array: 'i', 'n', 'v', 'a', 'l', 'i', 'd', '\0'
// (This is longer than any real assembly mnemonic.)
char instr[7 + 1];
// does it have a .b ?
bool is_byte;

// Null-delimited string representation of assembly operands.
// Length of array: 2 * ('0', 'x', 4-digit hexadecimal numeral, '(', 'r', 2-digit
// decimal numeral, ')'), ',', ' ', '\0'
char operands[2 * (2 + 4 + 2 + 3) + 2 + 1];

// The source and the dst of the operands, along with their modes
// This info is contained in the strings above, but parsing strings to obtain it is ugly so we replicate it here
ut32 src;
ut32 dst;
Msp430AddressingMode src_mode;
Msp430AddressingMode dst_mode;
};

int msp430_decode_command(const ut8 *instr, int len, struct msp430_cmd *cmd);
Expand Down
Loading

0 comments on commit e63f202

Please sign in to comment.