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 RV64: Added an encoder and some fixes and improvments to the decoder #6095

Merged
merged 36 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b0284f1
RV64: Added skeleton code for encoder
ksco May 29, 2023
8e3e355
RV64: Fixed disassemble
ksco May 29, 2023
160a962
RV64: Optimize disassembled immediates format
ksco May 29, 2023
126170c
RV64: Added an encoder
ksco May 30, 2023
d9d162a
Clang format
ksco May 30, 2023
4e2d8f6
RV64: Fixed sizeof(opnd_t)
ksco May 31, 2023
754110a
RV64: Supported instr target for branch instr
ksco May 31, 2023
be310dd
i#3544 RV64: Fixed codec issue
ksco Jun 1, 2023
2f2d615
Added DR_OPND_IMM_PRINT_DECIMAL
ksco Jun 7, 2023
97b0d15
Clang format
ksco Jun 7, 2023
2fe186b
Clang format
ksco Jun 7, 2023
6ecff17
Merge branch 'master' into encoder
ksco Jun 14, 2023
da65eff
Start working on tests
ksco Jun 14, 2023
8de5d59
Added a simple case
ksco Jun 15, 2023
fc35f0e
Always use init_array for RISC-V
ksco Jun 15, 2023
330c996
A simple test works
ksco Jun 16, 2023
6d8b730
Dynamic linking test works
ksco Jun 16, 2023
57e48a0
Added integer load/store tests
ksco Jun 16, 2023
eab93f1
Added float load/store tests
ksco Jun 17, 2023
4d15ec1
Added atomic tests
ksco Jun 17, 2023
e143945
Added fcvt tests
ksco Jun 17, 2023
5a9d242
Added fmv tests
ksco Jun 17, 2023
ab114b2
Added float arith tests
ksco Jun 17, 2023
f8f264d
Added more tests
ksco Jun 17, 2023
7c922ce
Fixed branch tests
ksco Jun 17, 2023
4b854fa
Open RISCV64 tests
ksco Jun 17, 2023
4d6ff79
Setup QEMU_LD_PREFIX
ksco Jun 17, 2023
0939932
Added DR_DISASM_RISCV for syntax control
ksco Jun 21, 2023
4dc5fb5
Minor fixes
ksco Jun 21, 2023
f6aacbe
Use opnd_add_flags instead
ksco Jun 21, 2023
b127d66
Added comments
ksco Jun 21, 2023
9b7072f
Minor fixes
ksco Jun 21, 2023
746285c
Removed trailling spaces
ksco Jun 21, 2023
2d92a74
Fixed a typo
ksco Jun 21, 2023
38927e8
Fixed a typo
ksco Jun 22, 2023
7c30881
Merge branch 'master' into encoder
ksco Jun 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci-riscv64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ jobs:
DYNAMORIO_CROSS_RISCV64_LINUX_ONLY: yes
CI_TRIGGER: ${{ github.event_name }}
CI_BRANCH: ${{ github.ref }}
QEMU_LD_PREFIX: /usr/riscv64-linux-gnu/

- name: Send failure mail to dynamorio-devs
if: failure() && github.ref == 'refs/heads/master'
Expand Down
2 changes: 1 addition & 1 deletion clients/drdisas/drdisas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ droption_t<bool> op_show_bytes(DROPTION_SCOPE_FRONTEND, "show_bytes", true,
"Display the instruction encoding bytes.",
"Display the instruction encoding bytes.");

#if defined(AARCH64) || defined(ARM)
#if defined(AARCH64) || defined(ARM) || defined(RISCV64)
# define MAX_INSTR_LENGTH 4
#else
# define MAX_INSTR_LENGTH 17
Expand Down
3 changes: 2 additions & 1 deletion core/drlibc/drlibc_module_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ is_elf_so_header_common(app_pc base, size_t size, bool memory)
ASSERT_CURIOSITY(!memory ||
#ifdef X64
elf_header.e_machine == EM_X86_64 ||
elf_header.e_machine == EM_AARCH64
elf_header.e_machine == EM_AARCH64 ||
elf_header.e_machine == EM_RISCV
#else
elf_header.e_machine == EM_386 || elf_header.e_machine == EM_ARM
#endif
Expand Down
6 changes: 6 additions & 0 deletions core/ir/disassemble_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ opnd_base_disp_disassemble(char *buf, size_t bufsz, size_t *sofar INOUT, opnd_t
print_to_buffer(buf, bufsz, sofar, "-");
}
}
#if defined(RISCV64)
ksco marked this conversation as resolved.
Show resolved Hide resolved
const char *fmt =
TEST(opnd_get_flags(opnd), DR_OPND_IMM_PRINT_DECIMAL) ? "%d" : "0x%x";
print_to_buffer(buf, bufsz, sofar, fmt, disp);
#else
if (TEST(DR_DISASM_ARM, DYNAMO_OPTION(disasm_mask)))
print_to_buffer(buf, bufsz, sofar, "%d", disp);
else if ((unsigned)disp <= 0xff && !opnd_is_disp_force_full(opnd))
Expand All @@ -407,6 +412,7 @@ opnd_base_disp_disassemble(char *buf, size_t bufsz, size_t *sofar INOUT, opnd_t
print_to_buffer(buf, bufsz, sofar, "0x%04x", disp);
else /* there are no 64-bit displacements */
print_to_buffer(buf, bufsz, sofar, "0x%08x", disp);
#endif
}

if (!TESTANY(DR_DISASM_INTEL | DR_DISASM_ARM, DYNAMO_OPTION(disasm_mask))) {
Expand Down
2 changes: 1 addition & 1 deletion core/ir/encode_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ instr_encode_arch(dcontext_t *dcontext, instr_t *instr, byte *copy_pc, byte *fin
bool *has_instr_opnds /*OUT OPTIONAL*/
_IF_DEBUG(bool assert_reachable));

#ifdef AARCH64
#if defined(AARCH64) || defined(RISCV64)
/* exported
*/
bool
Expand Down
4 changes: 2 additions & 2 deletions core/ir/instr_inline_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,12 @@ opnd_create_pc(app_pc pc)
.value.reg_and_element_size.reg)
# define opnd_get_reg OPND_GET_REG

# if defined(X86) || defined(RISCV64)
# if defined(X86)
# define OPND_GET_FLAGS(opnd) \
(CLIENT_ASSERT_( \
opnd_is_reg(opnd) || opnd_is_base_disp(opnd) || opnd_is_immed_int(opnd), \
"opnd_get_flags called on non-reg non-base-disp non-immed-int opnd") 0)
# elif defined(AARCHXX)
# elif defined(AARCHXX) || defined(RISCV64)
# define OPND_GET_FLAGS(opnd) \
(CLIENT_ASSERT_( \
opnd_is_reg(opnd) || opnd_is_base_disp(opnd) || \
Expand Down
50 changes: 44 additions & 6 deletions core/ir/opnd_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,6 @@ enum {
DR_REG_X29, /**< The x29(t4) register. */
DR_REG_X30, /**< The x30(t5) register. */
DR_REG_X31, /**< The x31(t6) register. */
DR_REG_PC, /**< The program counter. */
/* GPR aliases */
DR_REG_ZERO = DR_REG_X0, /**< The hard-wired zero (x0) register. */
DR_REG_RA = DR_REG_X1, /**< The return address (x1) register. */
Expand Down Expand Up @@ -1209,6 +1208,7 @@ enum {
DR_REG_T4 = DR_REG_X29, /**< The 5th temporary (x29) register. */
DR_REG_T5 = DR_REG_X30, /**< The 6th temporary (x30) register. */
DR_REG_T6 = DR_REG_X31, /**< The 7th temporary (x31) register. */
DR_REG_PC, /**< The program counter. */
/* Floating point registers */
DR_REG_F0, /**< The f0(ft0) floating-point register. */
DR_REG_F1, /**< The f1(ft1) floating-point register. */
Expand Down Expand Up @@ -1284,10 +1284,10 @@ enum {
DR_REG_LAST_VALID_ENUM = DR_REG_FCSR, /**< Last valid register enum. */
DR_REG_LAST_ENUM = DR_REG_FCSR, /**< Last value of register enums. */

DR_REG_START_64 = DR_REG_X0, /**< Start of 64-bit general register enum values. */
ksco marked this conversation as resolved.
Show resolved Hide resolved
DR_REG_STOP_64 = DR_REG_X31, /**< End of 64-bit general register enum values. */
DR_REG_START_32 = DR_REG_X0, /**< Start of 32-bit general register enum values. */
DR_REG_STOP_32 = DR_REG_X31, /**< End of 32-bit general register enum values. */
DR_REG_START_64 = DR_REG_X0, /**< Start of 64-bit register enum values. */
DR_REG_STOP_64 = DR_REG_F31, /**< End of 64-bit register enum values. */
DR_REG_START_32 = DR_REG_X0, /**< Start of 32-bit register enum values. */
DR_REG_STOP_32 = DR_REG_F31, /**< End of 32-bit register enum values. */
DR_REG_START_GPR = DR_REG_X0, /**< Start of general register registers. */
DR_REG_STOP_GPR = DR_REG_X31, /**< End of general register registers. */
DR_REG_XSP = DR_REG_SP, /**< Platform-independent way to refer to stack pointer. */
Expand Down Expand Up @@ -1780,6 +1780,11 @@ typedef enum _dr_opnd_flags_t {
* SVE predicate constraint
*/
DR_OPND_IS_PREDICATE_CONSTRAINT = 0x800,

/**
* This is used by RISCV64 for immediates display format.
*/
DR_OPND_IMM_PRINT_DECIMAL = 0x1000,
} dr_opnd_flags_t;

#ifdef DR_FAST_IR
Expand Down Expand Up @@ -2003,6 +2008,18 @@ DR_API
opnd_t
opnd_create_immed_int(ptr_int_t i, opnd_size_t data_size);

#ifdef RISCV64
DR_API
/**
* Returns a signed immediate integer operand with value \p i and size
* \p data_size; \p data_size must be a OPSZ_ constant.
*
* The integer will be formatted as a decimal when disassemble.
ksco marked this conversation as resolved.
Show resolved Hide resolved
*/
opnd_t
opnd_create_immed_int_decimal(ptr_int_t i, opnd_size_t data_size);
ksco marked this conversation as resolved.
Show resolved Hide resolved
#endif

DR_API
/**
* Returns an unsigned immediate integer operand with value \p i and size
Expand Down Expand Up @@ -2147,6 +2164,26 @@ opnd_t
opnd_create_base_disp(reg_id_t base_reg, reg_id_t index_reg, int scale, int disp,
opnd_size_t data_size);

#ifdef RISCV64
DR_API
/**
* Returns a memory reference operand that refers to the address:
* - disp(base_reg, index_reg, scale)
*
* or, in other words,
* - base_reg + index_reg*scale + disp
*
* The operand has data size data_size (must be a OPSZ_ constant).
* Both \p base_reg and \p index_reg must be DR_REG_ constants.
* \p scale must be either 0, 1, 2, 4, or 8.
*
* The integer will be formatted as a decimal when disassemble.
*/
opnd_t
opnd_create_base_disp_decimal(reg_id_t base_reg, reg_id_t index_reg, int scale, int disp,
ksco marked this conversation as resolved.
Show resolved Hide resolved
opnd_size_t data_size);
#endif

DR_API
/**
* Returns a memory reference operand that refers to the address:
Expand All @@ -2171,7 +2208,8 @@ DR_API
* needs to be specified for an absolute address; otherwise, simply
* use the desired short registers for base and/or index).
*
* (The encoding optimization flags are all false when using opnd_create_base_disp()).
* (The encoding optimization flags are all false when using
* opnd_create_base_disp()).
*/
opnd_t
opnd_create_base_disp_ex(reg_id_t base_reg, reg_id_t index_reg, int scale, int disp,
Expand Down
21 changes: 21 additions & 0 deletions core/ir/opnd_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,16 @@ opnd_create_immed_int(ptr_int_t i, opnd_size_t size)
return opnd;
}

#ifdef RISCV64
opnd_t
opnd_create_immed_int_decimal(ptr_int_t i, opnd_size_t size)
{
opnd_t opnd = opnd_create_immed_int(i, size);
opnd.aux.flags |= DR_OPND_IMM_PRINT_DECIMAL;
return opnd;
}
#endif

opnd_t
opnd_create_immed_uint(ptr_uint_t i, opnd_size_t size)
{
Expand Down Expand Up @@ -653,6 +663,17 @@ opnd_create_base_disp(reg_id_t base_reg, reg_id_t index_reg, int scale, int disp
false, false, false);
}

#ifdef RISCV64
opnd_t
opnd_create_base_disp_decimal(reg_id_t base_reg, reg_id_t index_reg, int scale, int disp,
opnd_size_t size)
{
opnd_t opnd = opnd_create_base_disp(base_reg, index_reg, scale, disp, size);
opnd.aux.flags |= DR_OPND_IMM_PRINT_DECIMAL;
return opnd;
}
#endif

static inline void
opnd_set_disp_helper(opnd_t *opnd, int disp)
{
Expand Down
Loading