Rizin
unix-like reverse engineering framework and cli tools
|
#include <rz_asm.h>
#include <rz_analysis.h>
#include <rz_util.h>
#include "hexagon.h"
#include "hexagon_insn.h"
#include "hexagon_arch.h"
Go to the source code of this file.
Functions | |
static bool | is_last_instr (const ut8 parse_bits) |
static bool | is_endloop0_pkt (const ut8 pb_hi_0, const ut8 pb_hi_1) |
Checks if packet ends hardware loop 0. More... | |
static bool | is_undoc_endloop0_pkt (const ut8 pb_hi_0, const ut8 pb_hi_1) |
Checks if packet ends hardware loop 0. But for an undocumented variant where the packet has only two instructions and the last one is a Duplex. More... | |
static bool | is_endloop1_pkt (const ut8 pb_hi_0, const ut8 pb_hi_1) |
Checks if packet ends hardware loop 1. More... | |
static bool | is_endloop01_pkt (const ut8 pb_hi_0, const ut8 pb_hi_1) |
Checks if packet ends hardware loop 0 and hw-loop 1. More... | |
static HexInsn * | hex_get_instr_at_addr (HexState *state, const ut32 addr) |
Gives the instruction at a given address from the state. More... | |
RZ_API ut8 | hexagon_get_pkt_index_of_addr (const ut32 addr, const HexPkt *p) |
Returns the index of an addr in a given packet. More... | |
static void | hex_clear_pkt (RZ_NONNULL HexPkt *p) |
Clears a packet and sets its attributes to invalid values. More... | |
static HexPkt * | hex_get_stale_pkt (HexState *state) |
Gives the least used packet. More... | |
static HexPkt * | hex_get_pkt (HexState *state, const ut32 addr) |
Returns the packet which covers the given address. More... | |
RZ_API void | hex_insn_free (RZ_NULLABLE HexInsn *i) |
Frees an instruction. More... | |
RZ_API void | hex_const_ext_free (RZ_NULLABLE HexConstExt *ce) |
Frees an constant extender. More... | |
static ut8 | get_state_pkt_index (HexState *state, const HexPkt *p) |
Get the index of a packet in the state. More... | |
RZ_API HexState * | hexagon_get_state () |
Initializes each packet of the state once. More... | |
static bool | is_pkt_full (const HexPkt *p) |
Checks if the packet has 4 instructions set. More... | |
static char * | get_pkt_indicator (const bool utf8, const bool sdk, const bool prefix, HexPktSyntaxIndicator ind_type) |
Get the pkt indicator string. More... | |
static void | hex_set_pkt_info (const RzAsm *rz_asm, RZ_INOUT HexInsn *hi, const HexPkt *p, const ut8 k, const bool update_mnemonic) |
Sets the packet related information in an instruction. More... | |
RZ_API HexLoopAttr | hex_get_loop_flag (const HexPkt *p) |
Returns the loop type of a packet. Though only if this packet is the last packet in last packet in a hardware loop. Otherwise it returns HEX_NO_LOOP. More... | |
static void | make_next_packet_valid (HexState *state, const HexPkt *pkt) |
Sets the packet after pkt to valid and updates its mnemonic. More... | |
RZ_API HexInsn * | alloc_instr () |
Allocates a new instruction on the heap. More... | |
static HexInsn * | hex_add_to_pkt (HexState *state, const HexInsn *new_ins, RZ_INOUT HexPkt *p, const ut8 k) |
Copies an instruction to the packet p at position k. More... | |
static HexInsn * | hex_to_new_pkt (HexState *state, const HexInsn *new_ins, const HexPkt *p, RZ_INOUT HexPkt *new_p) |
Cleans the packet new_p , copies the instruction new_ins and the attributes of p to it. More... | |
static HexInsn * | hex_add_to_stale_pkt (HexState *state, const HexInsn *new_ins) |
Cleans the least accessed packet and copies the given instruction into it. More... | |
static HexInsn * | hex_add_instr_to_state (HexState *state, const HexInsn *new_ins) |
Copies the given instruction to a state packet it belongs to. If the instruction does not fit to any packet, it will be written to a stale one. More... | |
static void | setup_new_instr (HexInsn *hi, const HexReversedOpcode *rz_reverse, const ut32 addr, const ut8 parse_bits) |
Set the up new instr. More... | |
static bool | imm_is_scaled (const HexOpAttr attr) |
static HexConstExt * | get_const_ext_from_addr (const RzList *ce_list, const ut32 addr) |
Searched the constant extender in the ce_list, where addr is the key. More... | |
RZ_API void | hex_extend_op (HexState *state, RZ_INOUT HexOp *op, const bool set_new_extender, const ut32 addr) |
Applies the constant extender to the immediate value in op. More... | |
RZ_API void | hexagon_reverse_opcode (const RzAsm *rz_asm, HexReversedOpcode *rz_reverse, const ut8 *buf, const ut64 addr) |
Reverses a given opcode and copies the result into one of the rizin structs in rz_reverse. More... | |
Allocates a new instruction on the heap.
Definition at line 507 of file hexagon_arch.c.
References calloc(), hi(), and RZ_LOG_FATAL.
Referenced by hex_add_to_pkt(), hex_add_to_stale_pkt(), and hex_to_new_pkt().
|
static |
Searched the constant extender in the ce_list, where addr is the key.
ce_list | The list with constant extender values. |
addr | The address of the instruction which gets the constant extender applied. |
Definition at line 719 of file hexagon_arch.c.
References HexConstExt::addr, addr, and NULL.
Referenced by hex_extend_op().
|
static |
Get the pkt indicator string.
utf8 | True: Return UTF8 string. False: Return ASCII. |
sdk | True: Return SDK conforming string ('{', '}', ':endloop0' etc.). False: Returns a non SDK conforming string |
prefix | True: Return the prefix indicator. False: Return the postfix. If there is no prefix/postfix for a given indicator type (e.g. for the utf8 version of 'endloop01') it returns an empty string. |
ind_type | The |
prefix |
Definition at line 262 of file hexagon_arch.c.
References ELOOP_01_PKT, ELOOP_0_PKT, ELOOP_1_PKT, FIRST_IN_PKT, HEX_PKT_ELOOP_0, HEX_PKT_ELOOP_01, HEX_PKT_ELOOP_01_SDK, HEX_PKT_ELOOP_01_UTF8, HEX_PKT_ELOOP_0_SDK, HEX_PKT_ELOOP_0_UTF8, HEX_PKT_ELOOP_1, HEX_PKT_ELOOP_1_SDK, HEX_PKT_ELOOP_1_UTF8, HEX_PKT_FIRST, HEX_PKT_FIRST_SDK, HEX_PKT_FIRST_UTF8, HEX_PKT_LAST, HEX_PKT_LAST_SDK, HEX_PKT_LAST_UTF8, HEX_PKT_MID, HEX_PKT_MID_UTF8, HEX_PKT_SDK_PADDING, HEX_PKT_SINGLE, HEX_PKT_SINGLE_UTF8, LAST_IN_PKT, MID_IN_PKT, prefix, and SINGLE_IN_PKT.
Referenced by hex_set_pkt_info().
Get the index of a packet in the state.
state | The state to operade on. |
p | The packet whichs index should be determined. |
Definition at line 201 of file hexagon_arch.c.
References HEXAGON_STATE_PKTS, i, p, sp, and UT8_MAX.
Referenced by hex_add_instr_to_state().
Copies the given instruction to a state packet it belongs to. If the instruction does not fit to any packet, it will be written to a stale one.
The instruction must have its address and parse bits set!
state | The state to operade on. |
new_ins | The instruction to be copied. |
Definition at line 615 of file hexagon_arch.c.
References HexInsn::addr, get_state_pkt_index(), hex_add_to_pkt(), hex_add_to_stale_pkt(), hex_to_new_pkt(), HEXAGON_STATE_PKTS, i, is_last_instr(), is_pkt_full(), k, NULL, p, and HexInsn::parse_bits.
Referenced by hexagon_reverse_opcode().
|
static |
Copies an instruction to the packet p at position k.
state | The state to operade on. |
new_ins | The instruction to copy. |
p | The packet in which the instruction will hold the instruction. |
k | The index of the instruction in the packet. |
Definition at line 525 of file hexagon_arch.c.
References alloc_instr(), hex_set_pkt_info(), hi(), is_last_instr(), k, make_next_packet_valid(), memcpy(), p, rz_list_get_n(), rz_list_insert(), rz_list_length(), RZ_LOG_FATAL, and rz_time_now().
Referenced by hex_add_instr_to_state().
Cleans the least accessed packet and copies the given instruction into it.
state | The state to operade on. |
new_ins | The instruction to copy. |
Definition at line 586 of file hexagon_arch.c.
References HexInsn::addr, alloc_instr(), hex_clear_pkt(), hex_get_stale_pkt(), hex_set_pkt_info(), hi(), is_last_instr(), make_next_packet_valid(), memcpy(), p, rz_list_insert(), and rz_time_now().
Referenced by hex_add_instr_to_state().
|
static |
Clears a packet and sets its attributes to invalid values.
p | The packet to clear. |
Definition at line 123 of file hexagon_arch.c.
References p, and rz_list_purge().
Referenced by hex_add_to_stale_pkt(), hex_to_new_pkt(), and hexagon_get_state().
RZ_API void hex_const_ext_free | ( | RZ_NULLABLE HexConstExt * | ce | ) |
Frees an constant extender.
ce | The constant extender to be freed. |
Definition at line 187 of file hexagon_arch.c.
References free().
Referenced by hexagon_get_state().
RZ_API void hex_extend_op | ( | HexState * | state, |
RZ_INOUT HexOp * | op, | ||
const bool | set_new_extender, | ||
const ut32 | addr | ||
) |
Applies the constant extender to the immediate value in op.
state | The state to operade on. |
op | The operand the extender is applied to or taken from. |
set_new_extender | True if the immediate value of the op comes from immext() and sets the a new constant extender. False otherwise. |
addr | The address of the currently disassembled instruction. |
Definition at line 738 of file hexagon_arch.c.
References HexConstExt::addr, addr, calloc(), HexConstExt::const_ext, get_const_ext_from_addr(), HEX_OP_TYPE_IMM, imm_is_scaled(), MAX_CONST_EXT, rz_list_append(), rz_list_delete_data(), rz_list_length(), and rz_list_purge().
Referenced by hex_disasm_with_templates().
Gives the instruction at a given address from the state.
state | The state to operade on. |
addr | The address of the instruction. |
Definition at line 80 of file hexagon_arch.c.
References HexInsn::addr, addr, HEXAGON_STATE_PKTS, i, NULL, p, and rz_time_now().
Referenced by hexagon_reverse_opcode().
RZ_API HexLoopAttr hex_get_loop_flag | ( | const HexPkt * | p | ) |
Returns the loop type of a packet. Though only if this packet is the last packet in last packet in a hardware loop. Otherwise it returns HEX_NO_LOOP.
p | The instruction packet. |
Definition at line 446 of file hexagon_arch.c.
References HEX_LOOP_0, HEX_LOOP_01, HEX_LOOP_1, HEX_NO_LOOP, is_endloop01_pkt(), is_endloop0_pkt(), is_endloop1_pkt(), is_undoc_endloop0_pkt(), p, rz_list_get_n(), rz_list_length(), and RZ_LOG_VERBOSE.
Referenced by hex_set_pkt_info(), and hexagon_disasm_instruction().
Returns the packet which covers the given address.
state | The state to operade on. |
addr | The address of an instruction. |
Definition at line 155 of file hexagon_arch.c.
References HexInsn::addr, addr, HEXAGON_STATE_PKTS, i, NULL, and p.
Referenced by hexagon_reverse_opcode().
Gives the least used packet.
state | The state to operade on. |
Definition at line 136 of file hexagon_arch.c.
References HEXAGON_STATE_PKTS, i, ut64(), and UT64_MAX.
Referenced by hex_add_to_stale_pkt().
RZ_API void hex_insn_free | ( | RZ_NULLABLE HexInsn * | i | ) |
Frees an instruction.
i | The instruction to be freed. |
Definition at line 175 of file hexagon_arch.c.
Referenced by hexagon_get_state().
|
static |
Sets the packet related information in an instruction.
hi | The instruction. |
p | The packet the instruction belongs to. |
k | The index of the instruction within the packet. |
Definition at line 371 of file hexagon_arch.c.
References ELOOP_01_PKT, ELOOP_0_PKT, ELOOP_1_PKT, FIRST_IN_PKT, HexPktInfo::first_insn, get_pkt_indicator(), hex_get_loop_flag(), HEX_LOOP_0, HEX_LOOP_01, HEX_LOOP_1, HEX_PKT_UNK, hexagon_get_state(), hi(), is_last_instr(), k, LAST_IN_PKT, HexPktInfo::last_insn, MID_IN_PKT, HexPktInfo::mnem_postfix, HexPktInfo::mnem_prefix, p, rz_config_get_b(), rz_return_if_fail, SINGLE_IN_PKT, sprintf, and rz_asm_t::utf8.
Referenced by hex_add_to_pkt(), hex_add_to_stale_pkt(), hex_to_new_pkt(), and make_next_packet_valid().
|
static |
Cleans the packet new_p
, copies the instruction new_ins
and the attributes of p
to it.
state | The state to operade on. |
new_ins | The instruction to copy. |
p | The old packet which attributes are copied to the new one. |
new_p | The new packet will hold the instruction. |
Definition at line 559 of file hexagon_arch.c.
References alloc_instr(), hex_clear_pkt(), hex_set_pkt_info(), hi(), is_last_instr(), make_next_packet_valid(), memcpy(), p, rz_list_insert(), and rz_time_now().
Referenced by hex_add_instr_to_state().
Returns the index of an addr in a given packet.
addr | Address of an instruction. |
p | The packet. to search in. |
Definition at line 103 of file hexagon_arch.c.
References addr, hi(), i, NULL, p, rz_return_val_if_fail, and UT8_MAX.
Referenced by resolve_n_register().
Initializes each packet of the state once.
Definition at line 217 of file hexagon_arch.c.
References calloc(), hex_clear_pkt(), hex_const_ext_free(), hex_insn_free(), HEXAGON_STATE_PKTS, i, NULL, rz_list_newf(), and RZ_LOG_FATAL.
Referenced by hex_set_pkt_info(), and hexagon_reverse_opcode().
RZ_API void hexagon_reverse_opcode | ( | const RzAsm * | rz_asm, |
HexReversedOpcode * | rz_reverse, | ||
const ut8 * | buf, | ||
const ut64 | addr | ||
) |
Reverses a given opcode and copies the result into one of the rizin structs in rz_reverse.
rz_reverse | Rizin core structs which store asm and analysis information. |
buf | The buffer which stores the current opcode. |
addr | The address of the current opcode. |
Definition at line 772 of file hexagon_arch.c.
References HexReversedOpcode::action, addr, HexReversedOpcode::ana_op, HexReversedOpcode::asm_op, rz_asm_op_t::asm_toks, rz_asm_op_t::buf_asm, hex_add_instr_to_state(), hex_get_instr_at_addr(), hex_get_pkt(), HEXAGON_ANALYSIS, HEXAGON_DISAS, hexagon_disasm_instruction(), hexagon_get_state(), hi(), memcpy(), RzAsmTokenString::op_type, p, rz_asm_tokenize_asm_regex(), RZ_LOG_FATAL, rz_read_le32(), rz_strbuf_set(), and setup_new_instr().
Referenced by hexagon_v6_op().
Definition at line 708 of file hexagon_arch.c.
References HEX_OP_IMM_SCALED.
Referenced by hex_extend_op().
Checks if packet ends hardware loop 0 and hw-loop 1.
pb_hi_0 | Parse bits instruction 0. |
pb_hi_1 | Parse bits instruction 1. |
Definition at line 69 of file hexagon_arch.c.
Referenced by hex_get_loop_flag().
Checks if packet ends hardware loop 0.
pb_hi_0 | Parse bits instruction 0. |
pb_hi_1 | Parse bits instruction 1. |
Definition at line 32 of file hexagon_arch.c.
Referenced by hex_get_loop_flag().
Checks if packet ends hardware loop 1.
pb_hi_0 | Parse bits instruction 0. |
pb_hi_1 | Parse bits instruction 1. |
Definition at line 57 of file hexagon_arch.c.
Referenced by hex_get_loop_flag().
Definition at line 19 of file hexagon_arch.c.
Referenced by hex_add_instr_to_state(), hex_add_to_pkt(), hex_add_to_stale_pkt(), hex_set_pkt_info(), and hex_to_new_pkt().
Checks if the packet has 4 instructions set.
p | The packet to check. |
Definition at line 245 of file hexagon_arch.c.
References p, and rz_list_length().
Referenced by hex_add_instr_to_state().
Checks if packet ends hardware loop 0. But for an undocumented variant where the packet has only two instructions and the last one is a Duplex.
pb_hi_0 | Parse bits instruction 0. |
pb_hi_1 | Parse bits instruction 1 (duplex and end of packet). |
Definition at line 45 of file hexagon_arch.c.
Referenced by hex_get_loop_flag().
Sets the packet after pkt to valid and updates its mnemonic.
state | The state to operade on. |
pkt | The packet which predecessor will be updated. |
Definition at line 474 of file hexagon_arch.c.
References hex_set_pkt_info(), HEXAGON_STATE_PKTS, hi(), i, HexPkt::insn, k, NULL, p, rz_list_get_top(), rz_time_now(), and autogen_x86imm::tmp.
Referenced by hex_add_to_pkt(), hex_add_to_stale_pkt(), and hex_to_new_pkt().
|
static |
Set the up new instr.
hi | The instruction to set up. |
rz_reverse | RzAsmOp and RzAnalysisOp which could have some data, which needs to be copied. |
addr | The address of the instruction. |
parse_bits | The parse bits of the instruction |
Definition at line 685 of file hexagon_arch.c.
References addr, HexReversedOpcode::ana_op, HexReversedOpcode::asm_op, HEX_INS_INVALID_DECODE, hi(), i, memcpy(), ST64_MAX, and UT64_MAX.
Referenced by hexagon_reverse_opcode().