Skip to content
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 operands access support for TriCore #2034

Merged
merged 4 commits into from
May 30, 2023

Conversation

imbillow
Copy link
Contributor

@imbillow imbillow commented May 27, 2023

Some additional work has been done:

  • Add operands access supoort for TriCore
  • Checked in some necessary changes from the https://github.com/Rot127/capstone/tree/auto-sync branch (cs_simple_types.h, MCInst.{c,h}, MCInstrDesc.{c,h}, utils.{c,h})
  • Fixed some compilation warnings under CMake -Wall -DCMAKE_COMPILE_WARNING_AS_ERROR=ON
  • Updated the .clang-format file (modified from the Linux Kernel repository), but this .clang-format configuration is not completely identical to the existing code style.

NOTE: MCInst.writeback should be removed, but I've kept it for compatibility with the current version

cstool -d tc162 8fff8381
 0  8f ff 83 81  xor    %d8, %d15, 0x3f
        ID: 390 (xor.t)
        op_count: 3
                operands[0].type: REG = d8
                        .access: WRITE
                operands[1].type: REG = d15
                        .access: READ
                operands[2].type: IMM = 0x3f
                        .access: READ
        Registers read: d15
        Registers modified: d8
cstool -d tc162 a900c005
 0  a9 00 c0 05  st.da  [%p0+c]0, %p0
        ID: 345 (st.da)
        op_count: 2
                operands[0].type: MEM
                        .mem.base: REG = p0
                        .mem.disp: 0x0
                        .access: WRITE
                operands[1].type: REG = p0
                        .access: READ
        Registers read: p0
        Registers modified: p0

@imbillow imbillow marked this pull request as ready for review May 27, 2023 23:47
@imbillow imbillow force-pushed the tc-reg-rw branch 2 times, most recently from 779f910 to a4bca6c Compare May 28, 2023 03:54
@XVilka
Copy link
Contributor

XVilka commented May 28, 2023

@Rot127 @kabeor please take a look

Copy link
Collaborator

@Rot127 Rot127 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! Thanks a lot for making the effort to look into the auto-sync PRs!
The many requested changes are mostly because more stuff was already done.

@kabeor What is the progress with version v5?
Because #1949 and #2013 implement and refactor almost all necessary things for auto-sync. Having them merged soon will at least at a proper reference point for the work of others.

.clang-format Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kabeor Formatting is in general inconsistent in CS because the previous .clang-forma did not work properly. We should consider to format all files before the next release (or the release afterwards) with this.

arch/TriCore/TriCoreInstPrinter.c Outdated Show resolved Hide resolved
arch/TriCore/TriCoreDisassembler.c Show resolved Hide resolved
#include "TriCoreGenCSMappingInsnOp.inc"
};

static inline cs_op_type TriCore_get_op_type(MCInst *MI, unsigned OpNum)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following commits implement generic functions and macros for accessing the mapping tables, detail operands and check for flags (doing_mem, detail is set):

3cade5a, b8cf7ff, 0352ed9, 0352ed9, 066168d, c13e7c2

Would recommend to pull those in as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw that you already did this partially. Some of them are possibly still useful. Also see the comment below regarding Mapping.c

write_count = detail->regs_write_count;

// implicit registers
memcpy(regs_read, detail->regs_read,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a assert(sizeof(cs_regs) <= sizeof(insn->detail->regs_read)); here. Also below.
Just in case someone plays with the arrays sizes in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this assertion is not True

/// Type of array to keep the list of registers
typedef uint16_t cs_regs[64];
uint16_t regs_read
	[MAX_IMPL_R_REGS=20]; ///< list of implicit registers read by this insn

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, was in a rush. Meant it the other way around.

cstool/cstool_tricore.c Show resolved Hide resolved
include/capstone/tricore.h Outdated Show resolved Hide resolved
tricore_op_mem mem; // base/disp value for MEM operand
unsigned int reg; ///< register value for REG operand
int32_t imm; ///< immediate value for IMM operand
tricore_op_mem mem; ///< base/disp value for MEM operand
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me until here to understand how you fill memory operands :D
Doing it via fill_mem() is fine.

Nonetheless, please set the TRICORE_OP_MEM = CS_OP_MEM and update the operand type of the base register and disponent with TRICORE_OP_MEM (in fill_tricore_imm() via tricore->operands[tricore->op_count].type |= TRICORE_OP_MEM).

If we extend TriCore's td files in the future and define complex memory operands there (memory operands which have the base register and disponent as sub-operands defined), it is easier to modify the code here.

include/capstone/tricore.h Outdated Show resolved Hide resolved
utils.c Outdated Show resolved Hide resolved
@@ -19,160 +19,162 @@ typedef enum {
// If you change this numbering, you must change the values in
// ValueTypes.td as well!
CS_DATA_TYPE_Other = 1, // This is a non-standard value
CS_DATA_TYPE_i1 = 2, // This is a 1 bit integer value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these lines formatted with the .clang-format of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Collaborator

@Rot127 Rot127 May 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then please add the following options (if there is no objection from others):

For comment alignment

AlignTrailingComments:
  Kind: Always
  OverEmptyLines: 2

For escaped newlines (aligning them breaks for me. I guess because of the tabs?).

AlignEscapedNewlines: DontAlign

@XVilka
Copy link
Contributor

XVilka commented May 29, 2023

Do you think this should go into 5.0 release as well? @imbillow @kabeor

@kabeor
Copy link
Member

kabeor commented May 29, 2023

@XVilka Yes, I'm still reviewing the code, will merge soon.

@XVilka
Copy link
Contributor

XVilka commented May 30, 2023

@imbillow as Capstone tends to merge without squashing commits, please squash relevant commits semantically into multiple with descriptive commit messages.

@XVilka
Copy link
Contributor

XVilka commented May 30, 2023

@imbillow it's support not supoort by the way, in both PR title and commit message

@imbillow imbillow changed the title Add operands access supoort for TriCore Add operands access support for TriCore May 30, 2023
@kabeor
Copy link
Member

kabeor commented May 30, 2023

Everything looks great, thanks!

@kabeor kabeor merged commit 7729902 into capstone-engine:next May 30, 2023
7 checks passed
@peace-maker
Copy link
Contributor

Since the comment doesn't show up here - this broke accessing the instruction details in the python bindings.

I'm not sure if you're aware and that's the normal workflow - ignore if this is just bad timing on my side looking at the code :D

@Rot127
Copy link
Collaborator

Rot127 commented May 30, 2023

@peace-maker Nah, we just forgot about it. This must be fixed before the v5 release. If you find time, it would be great if you could open a PR.

peace-maker added a commit to peace-maker/capstone that referenced this pull request Jun 5, 2023
capstone-engine#2034 changed the `regs_read` array size and added a new `writeback`
element to the cs_detail struct.

Those changes weren't reflected in the Python bindings causing details
to be missing.
@imbillow imbillow deleted the tc-reg-rw branch November 20, 2023 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants