-
-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Xtensa arch support #4654
Open
imbillow
wants to merge
19
commits into
dev
Choose a base branch
from
xtensa-support
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Xtensa arch support #4654
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0d974d9
Add xtensa arch capstone plugin
imbillow 930d626
Remove xtensa-gnu
imbillow 01a9948
fix: `asm.cpu` is not set correctly, when there is no “,” in asm plug…
imbillow 8e6b4b5
fix: xtensa tests
imbillow 3840931
fix: xtensa_analyze_op
imbillow 7727496
fix core_disassembly when n_bytes==0
imbillow 6491c55
fix xtensa_analyze_op_esil
imbillow 82320c9
fix xtensa esil pc mod
imbillow 87d7f6e
fix xtensa esil l32r
imbillow 35614fc
fix xtensa esil call0
imbillow 62231db
fix xtensa esil extui
imbillow 43377af
fix xtensa esil store
imbillow 4b3a654
fmt
imbillow c31e2d4
fix xtensa test
imbillow 96cbff4
fix xtensa stack inc and ret
imbillow e3eada2
keep `asm.cpu` when valid in cb_asmarch
imbillow 509c504
fix cb_asmarch
imbillow 92eb1a4
fix cb_asmarch
imbillow 9b56ddc
fix max op size
imbillow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-FileCopyrightText: 2024 billow <[email protected]> | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
#include "xtensa.h" | ||
|
||
bool xtensa_init(void **user) { | ||
if (*user) { | ||
return true; | ||
} | ||
XtensaContext *ctx = RZ_NEW0(XtensaContext); | ||
if (!ctx) { | ||
return false; | ||
} | ||
*user = ctx; | ||
return true; | ||
} | ||
|
||
bool xtensa_fini(void *user) { | ||
XtensaContext *ctx = user; | ||
cs_close(&ctx->handle); | ||
free(ctx); | ||
return true; | ||
} | ||
|
||
bool xtensa_open(XtensaContext *ctx, const char *cpu, bool big_endian) { | ||
if (!ctx) { | ||
return false; | ||
} | ||
if (RZ_STR_ISNOTEMPTY(cpu) && RZ_STR_NE(cpu, "xtensa")) { | ||
return false; | ||
} | ||
cs_mode mode = big_endian ? CS_MODE_BIG_ENDIAN : CS_MODE_LITTLE_ENDIAN; | ||
mode |= CS_MODE_XTENSA_ESP32; | ||
if (cs_open(CS_ARCH_XTENSA, mode, &ctx->handle) != CS_ERR_OK) { | ||
return false; | ||
} | ||
if (cs_option(ctx->handle, CS_OPT_DETAIL, CS_OPT_ON) != CS_ERR_OK) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool xtensa_disassemble(XtensaContext *self, const ut8 *buf, int len, ut64 addr) { | ||
self->count = cs_disasm(self->handle, buf, len, addr, 1, &self->insn); | ||
if (self->count == 0) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
void xtensa_disassemble_fini(XtensaContext *self) { | ||
if (!self->insn) | ||
return; | ||
cs_free(self->insn, self->count); | ||
self->insn = NULL; | ||
self->count = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-FileCopyrightText: 2024 billow <[email protected]> | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
#ifndef RIZIN_XTENSA_H | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could use just |
||
#define RIZIN_XTENSA_H | ||
|
||
#include <capstone/capstone.h> | ||
#include <rz_asm.h> | ||
|
||
typedef struct xtensa_context_t { | ||
csh handle; | ||
cs_insn *insn; | ||
size_t count; | ||
} XtensaContext; | ||
|
||
bool xtensa_init(void **user); | ||
bool xtensa_fini(void *user); | ||
bool xtensa_open(XtensaContext *ctx, const char *cpu, bool big_endian); | ||
bool xtensa_disassemble(XtensaContext *self, const ut8 *buf, int len, ut64 addr); | ||
void xtensa_disassemble_fini(XtensaContext *self); | ||
void xtensa_analyze_op_esil(XtensaContext *ctx, RzAnalysisOp *op); | ||
|
||
static inline cs_xtensa_op_mem *xtensa_op_mem(cs_insn *insn, unsigned int index) { | ||
cs_xtensa_op *op = &insn->detail->xtensa.operands[index]; | ||
rz_warn_if_fail(op->type == XTENSA_OP_MEM); | ||
return &op->mem; | ||
} | ||
|
||
static inline xtensa_reg xtensa_op_reg(cs_insn *insn, unsigned int index) { | ||
cs_xtensa_op *op = &insn->detail->xtensa.operands[index]; | ||
rz_warn_if_fail(op->type == XTENSA_OP_REG); | ||
return op->reg; | ||
} | ||
|
||
static inline int32_t xtensa_op_imm(cs_insn *insn, unsigned int index) { | ||
cs_xtensa_op *op = &insn->detail->xtensa.operands[index]; | ||
rz_warn_if_fail(op->type == XTENSA_OP_IMM); | ||
return op->imm; | ||
} | ||
|
||
static inline int32_t xtensa_op_l32r(cs_insn *insn, unsigned int index) { | ||
cs_xtensa_op *op = &insn->detail->xtensa.operands[index]; | ||
rz_warn_if_fail(op->type == XTENSA_OP_L32R); | ||
return op->imm; | ||
} | ||
|
||
#define MEM(I) xtensa_op_mem(ctx->insn, I) | ||
#define REGI(I) xtensa_op_reg(ctx->insn, I) | ||
#define REGN(I) cs_reg_name(ctx->handle, (xtensa_op_reg(ctx->insn, I))) | ||
#define IMM(I) xtensa_op_imm(ctx->insn, I) | ||
#define L32R(I) xtensa_op_l32r(ctx->insn, I) | ||
#define INSN_SIZE (ctx->insn->size) | ||
|
||
#endif // RIZIN_XTENSA_H |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
{}