forked from capstone-engine/capstone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
117 additions
and
1 deletion.
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
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,99 @@ | ||
// | ||
// Created by hoshinoaya on 11/24/23. | ||
// | ||
|
||
#include "test_tricore.h" | ||
#include <capstone/capstone.h> | ||
#include <capstone/tricore.h> | ||
#include <folly/Executor.h> | ||
#include <folly/executors/CPUThreadPoolExecutor.h> | ||
#include <folly/ThreadCachedInt.h> | ||
#include <folly/synchronization/Latch.h> | ||
|
||
static void print_insn_detail(csh handle, cs_insn *ins) | ||
{ | ||
cs_tricore *tricore; | ||
int i; | ||
|
||
// detail can be NULL on "data" instruction if SKIPDATA option is turned ON | ||
if (ins->detail == NULL) | ||
return; | ||
|
||
tricore = &(ins->detail->tricore); | ||
if (tricore->op_count) | ||
printf("\top_count: %u\n", tricore->op_count); | ||
|
||
for (i = 0; i < tricore->op_count; i++) { | ||
cs_tricore_op *op = &(tricore->operands[i]); | ||
switch ((int)op->type) { | ||
default: | ||
break; | ||
case TRICORE_OP_REG: | ||
printf("\t\toperands[%u].type: REG = %s\n", i, | ||
cs_reg_name(handle, op->reg)); | ||
break; | ||
case TRICORE_OP_IMM: | ||
printf("\t\toperands[%u].type: IMM = 0x%x\n", i, | ||
op->imm); | ||
break; | ||
case TRICORE_OP_MEM: | ||
printf("\t\toperands[%u].type: MEM\n", i); | ||
if (op->mem.base != TRICORE_REG_INVALID) | ||
printf("\t\t\toperands[%u].mem.base: REG = %s\n", | ||
i, cs_reg_name(handle, op->mem.base)); | ||
if (op->mem.disp != 0) | ||
printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, | ||
op->mem.disp); | ||
|
||
break; | ||
} | ||
} | ||
|
||
printf("\n"); | ||
} | ||
|
||
int main() | ||
{ | ||
auto q = folly::CPUThreadPoolExecutor(60); | ||
folly::ThreadCachedInt<uint32_t> counter; | ||
for (; counter.readFull() < std::numeric_limits<uint32_t>::max(); | ||
counter += 1) { | ||
auto f = [&]() -> void { | ||
csh handle; | ||
uint64_t address = 0x1000; | ||
cs_insn *insn; | ||
size_t count; | ||
cs_err err = cs_open(CS_ARCH_TRICORE, | ||
CS_MODE_TRICORE_162, &handle); | ||
if (err) { | ||
printf("Failed on cs_open() with error returned: %u\n", | ||
err); | ||
} | ||
cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON); | ||
|
||
uint32_t x = counter.readFull(); | ||
count = cs_disasm(handle, | ||
reinterpret_cast<const uint8_t *>(&x), | ||
sizeof(x), address, 0, &insn); | ||
if (count) { | ||
size_t j; | ||
for (j = 0; j < count; j++) { | ||
printf("0x%" PRIx64 ":\t%s\t%s\n", | ||
insn[j].address, | ||
insn[j].mnemonic, | ||
insn[j].op_str); | ||
print_insn_detail(handle, &insn[j]); | ||
} | ||
printf("0x%" PRIx64 ":\n", | ||
insn[j - 1].address + insn[j - 1].size); | ||
|
||
// free memory allocated by cs_disasm() | ||
cs_free(insn, count); | ||
} | ||
cs_close(&handle); | ||
}; | ||
q.add(f); | ||
} | ||
q.join(); | ||
return 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,8 @@ | ||
// | ||
// Created by hoshinoaya on 11/24/23. | ||
// | ||
|
||
#ifndef CAPSTONE_TEST_TRICORE_H | ||
#define CAPSTONE_TEST_TRICORE_H | ||
|
||
#endif //CAPSTONE_TEST_TRICORE_H |