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

New instruction schema #285

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

New instruction schema #285

wants to merge 2 commits into from

Conversation

dhower-qc
Copy link
Collaborator

This PR is a WIP to discuss the structure of ELF relocations in the database. Eventually, we will tie these to the variables in instruction encodings.

@AFOliveira AFOliveira marked this pull request as ready for review November 19, 2024 19:27
@AFOliveira AFOliveira marked this pull request as draft November 19, 2024 19:28
@AFOliveira
Copy link
Collaborator

I just have a couple questions on this:

  • Couldn't ABI version be a parameter so that we would allow more than 1 ABI?
  • Couldn't "Not 0 " be a parameter or should the immediate have this defined elsewhere?

@dhower-qc
Copy link
Collaborator Author

dhower-qc commented Nov 19, 2024

Good questions. I think both of these can be addressed in how this relocation data gets tied to an encoding. For example, if we had something like:

[common/inst_variable/itype_imm.yaml]

$schema: inst_variable_schema.json
kind: instruction variable
location: 31-20
# ...
elf_psabi_relocation: { $ref: relocation/R_RISCV_PCREL_LO12_I.yaml# }
pe_abi_relocation: # { ... }  future Windows ABI

[inst/addi.yaml]

# ...
encoding:
  fields:
    imm: { $ref: common/inst_variable/itype_imm.yaml# }

Then we can tie as many relocations as needed to an instruction variable. We do probably need to add an abi key to the relocation object.

This also handled the "not 0" case, since that's tied to the instruction variable.

@apazos
Copy link

apazos commented Nov 20, 2024

We should document the new relocations only. What is already documented in the RISC-V psABI (https://github.com/riscv-non-isa/riscv-elf-psabi-doc), we should skip.

We should follow the psABI document format for recording the info, so that the resulting PDF has the same look and feel of the RISC-V psABI.

  • A table with Vendor relocation types, their vendor enum, and their descriptions (See Table 13. Relocation types in the RISC-V psABI)
  • Examples of code sequence
  • Relaxation Types with Target Relocation, Description, Condition, Extensions Required, Relaxation result

@dhower-qc dhower-qc changed the title Mock-up of a relocation New instruction schema Nov 22, 2024
@dhower-qc dhower-qc requested a review from drom November 22, 2024 20:01
@dhower-qc
Copy link
Collaborator Author

I've added a new attempt at an instruction schema. Here is an example:

$schema: "inst_schema.json#"
kind: instruction
name: lb
long_name: Load byte
format: { $ref: inst_format/itype.yaml# } # the instruction format 'I-type'
# ...
assembly: xd, offset(rs1)
encoding:
  match: -----------------000-----0000011
  variables:
  - field: { $ref: inst_format/itype.yaml#/fields/name=imm }
    name: offset
  - field: { $ref: inst_format/itype.yaml#/fields/name=rs1 }
    name: xs1
  - field: { $ref: inst_format/itype.yaml#/fields/name=rs1 }
    name: xd
# ...

and itype:

$schema: inst_format.json#
kind: instruction format
name: I-type
size: 32
fields:
- location: 31-20
  name: imm
  kind: immediate
  sign_extend: true
  relocations:
  - $ref: relocation/R_RISCV_PCREL_LO12_I.yaml#
  - $ref: relocation/R_RISCV_TPREL_LO12_I.yaml#
  - $ref: relocation/R_RISCV_TLSDESC_ADD_LO12.yaml#
  - $ref: relocation/R_RISCV_LO12_I.yaml#
- location: 19-15
  name: rs1
  kind: x source register
- location: 14-12
  name: funct3
  kind: opcode
- location: 11-7
  name: rd
  kind: x destination register
- location: 6-0
  name: opcode
  kind: opcode
  opcode: true

@dhower-qc dhower-qc linked an issue Nov 22, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Adding instruction type as a parameter for instruction definition
3 participants