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

i#3544 riscv64, part 1: add instruction codec #5666

Merged
merged 9 commits into from
Oct 13, 2022

Conversation

semihalf-kardach-stanislaw
Copy link
Contributor

@semihalf-kardach-stanislaw semihalf-kardach-stanislaw commented Sep 30, 2022

Add the main source file for instruction codec whose goal is to decode and encode all RISC-V instructions. At the moment only the decoding part is implemented.

The decoding process is based on instr_info_t structures and is separated into two stages:

  1. Instruction opcode decoding to retrieve a corresponding rv_instr_info_t. This gives the codec information on the number and type of source and destination operands.
  2. Instruction operand decoding. All operands are decoded utilizing the data from instr_info_t and a set of operand decoder functions gathered in the opnd_decoders array indexed by the operand field type.

Note:
The codec.c file is not yet added to the build system as it relies on a set of generated files with opcode and instr_info_t data. The script for that as well as Instruction Set Listing files will follow in later commits.

Note 2:
There is currently no support for decoding of translated instructions and hence orig_pc is never used. In fact all base+disp operands utilize opnd_create_mem_instr() which is described as a PC-relative memory reference, so it "should" be resistant to the change in base address.

Issue #3544

Signed-off-by: Stanislaw Kardach kda@semihalf.com

Add the main source file for instruction codec whose goal is to decode
and encode all RISC-V instructions. At the moment only the decoding part
is implemented.

The decoding process is based on instr_info_t structures and is
separated into two stages:

1. Instruction opcode decoding to retrieve a corresponding
   rv_instr_info_t. This gives the codec information on the number and
   type of source and destination operands.
2. Instruction operand decoding. All operands are decodec utilizing the
   data from instr_info_t and a set of operand decoder functions
   gathered in the opnd_decoders array indexed by the operand field
   type.

Note:
   The codec.c file is not yet added to the build system as it relies
   on a set of generated files with opcode and instr_info_t data. The
   script for that as well as Instruction Set Listing files will follow
   in later commits.

Note 2:
   There is currently no support for decoding of translated instructions
   and hence orig_pc is never used. In fact all base+disp operands
   utilize opnd_create_mem_instr() which id described as a PC-relative
   memory reference, so it "should" be resistant to the change in base
   address.

Issue #3544

Signed-off-by: Stanislaw Kardach <kda@semihalf.com>
@semihalf-kardach-stanislaw
Copy link
Contributor Author

Note to self. The error reported in ci-clang-format run is:

debug-internal-64: **** 3 build errors ****
	/.../dynamorio/core/ir/riscv64/codec.c:68: error space_after_call: Extra space after function name: "architectures ".

Though at the beginning of the log (line 16) I see clang-format check passed. Also the line in question is:

#    error RISC-V codec only supports 64-bit architectures (mask+match -> code).

So that is definitely not a "function name". I'll change the line though.

Signed-off-by: Stanislaw Kardach <kda@semihalf.com>
@derekbruening
Copy link
Contributor

Note to self. The error reported in ci-clang-format run is:

debug-internal-64: **** 3 build errors ****
	/.../dynamorio/core/ir/riscv64/codec.c:68: error space_after_call: Extra space after function name: "architectures ".

Though at the beginning of the log (line 16) I see clang-format check passed. Also the line in question is:

#    error RISC-V codec only supports 64-bit architectures (mask+match -> code).

So that is definitely not a "function name". I'll change the line though.

FYI, this is from vera++ which apparently does not recognize preprocessor lines? If you wanted to try to tweak the checker instead -- easier to make the change you already made though.

core/ir/riscv64/codec.h Outdated Show resolved Hide resolved
core/ir/riscv64/codec.h Outdated Show resolved Hide resolved
core/ir/riscv64/codec.c Show resolved Hide resolved
core/ir/riscv64/codec.c Outdated Show resolved Hide resolved
core/ir/riscv64/codec.c Outdated Show resolved Hide resolved
core/ir/riscv64/codec.h Outdated Show resolved Hide resolved
core/ir/riscv64/codec.h Outdated Show resolved Hide resolved
core/ir/riscv64/codec.c Outdated Show resolved Hide resolved
core/ir/riscv64/codec.c Outdated Show resolved Hide resolved
core/ir/riscv64/codec.c Outdated Show resolved Hide resolved
- Use GET_FIELD() where possible.
- Use TESTALL() for bit tests.
- Use BUFFER_SIZE_ELEMENTS() instead of ARRAY_SIZE().
- Rename rv_instr_info_t::nfo -> rv_instr_info_t::info.
- Add layout comments to fields decoders and format enums.
- Remove doxygen comment headers from the internal code.
- Fix spelling.
- Use opnd_create_pc() for decoding PC-relative branch targets.

Signed-off-by: Stanislaw Kardach <kda@semihalf.com>
@semihalf-kardach-stanislaw
Copy link
Contributor Author

run arm tests

@semihalf-kardach-stanislaw
Copy link
Contributor Author

semihalf-kardach-stanislaw commented Oct 6, 2022

Sorry for pressing the "update branch" button by mistake. Unfortunate result of a trackpad miss-click.

core/ir/riscv64/codec.c Show resolved Hide resolved
core/ir/riscv64/codec.c Show resolved Hide resolved
core/ir/riscv64/codec.c Show resolved Hide resolved
core/ir/riscv64/codec.c Outdated Show resolved Hide resolved
core/ir/riscv64/codec.c Outdated Show resolved Hide resolved
core/ir/riscv64/codec.c Show resolved Hide resolved
@semihalf-kardach-stanislaw semihalf-kardach-stanislaw merged commit 7bc0b6a into master Oct 13, 2022
@semihalf-kardach-stanislaw semihalf-kardach-stanislaw deleted the i3544-riscv64-p1-add-instr-codec branch October 13, 2022 17:37
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.

3 participants