<mnemonic> | <instruction-format> | [field] | <fixedbits>
The file name will become the extension. There is a convention to specify fields in the reverse order of the assembly. This way the instruction macros are generated properly.
If you want to add a new extension, add a new value to the riscv64_isa_ext_t enum in codec.h.
When adding a new instruction make sure to update the get_rvc_instr_info() function in codec.c to properly decode the opcode.
add | r | rs2 rs1 rd | 0000000..........000.....0110011 c.lwsp | ci | clwsp_imm crd | 010...........10
The instruction format should be one of the following:
This maps to riscv64_inst_fmt_t enum in codec.h and Format enum in codec.py generator. However at this point the format field is not put into generated instr_info_t structures. This may change in the future, so in case of a new format, keep the above definitions in sync.
The list of available fields are written below.
For non-compressed instructions:
For compressed instructions:
DynamoRIO requires the decoder to decode all implicit operands. These operands start with i, which means implicit.
This maps into riscv64_fld_t enum in codec.h and Field enum in codec.py generator.
If you want to add a new field:
In codec.py:
Add new value to the Field enum. The value definition has the following members:
value: Enum value (keep this in sync with riscv_fld_t type in codec.h).arg_name: Name to use in instruction creation macros.is_dest: True if it is a destination operand.is_implicit: True if it is an implicit operand.as_decimal: True if displayed as decimal.opsz_def: Operand size (OPSZ_* value) or if this field decodes into an operand of a different size depending on instruction - dictionary indexed by instruction mnemonic with operand size values.asm_name: Name used in assembly comments (if different than arg_name)arg_cmt: Comment for instruction creation macros for this field.In case the new field encodes an offset for an explicit GPR field-based memory reference, update an appropriate __fixup_*_inst() function. See the Field.V_L_RS1_DISP logic for overriding semantics of a field that is used as a normal immediate in other cases.
Add a new riscv64_fld_t enum value in codec.h.
In codec.c:
decode_rd_opnd() for reference). The decode function gets the operand size op_sz as defined in codec.py as well as the source or destination index idx of this operand.opnd_decoders array at the index equal to the new field's riscv64_fld_t value.