-
Notifications
You must be signed in to change notification settings - Fork 18
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
base: main
Are you sure you want to change the base?
Conversation
I just have a couple questions on this:
|
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: [ $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 [ # ...
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 This also handled the "not 0" case, since that's tied to the instruction variable. |
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.
|
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
|
Sorry I missed this PR when it was opened. I have been thinking about this on-and-off since I commented on #256 and we discussed this problem. I am coming around to the view that, for the ABI:
So I have come around to the view that there are different kinds of
Another good example might be the U-type immediate:
This means I like the "this instruction inherits this field from this definition we have elsewhere" approach, and then we can relate the relocations to that field specifically. Given things we discussed, like needing to use unused corners of the encoding space eventually, I'm ok with not assigning an overall type to every instruction. I'm not sure how we can verify that the instruction is using the field correctly, which feels like something we'd like to be able to do. I also haven't worked out how that would let us get linker relaxations defined in this document, and implemented correctly, but I don't think that should block this PR. Edited: |
@lenary However, I don't think I understand this part:
All those fields can be different in terms of what they happen to do, i.e. represent different values, but they all have the same encodings which we can use for verification, if we know what instruction type they match, right? |
I think you're maybe tripping over what one could mean by "verify". Implementers, when executing a binary, never have to care about more than encoding. They will ignore e.g. information about relocations in any specification, they don't have to care, they care about bits going in, and the right actions being done by the core itself. But if we're going to have relocation info in the riscv-unified-db, then it would be good to be able to use that to check that any relocatable objects have the right relocations applied to the right instructions. The relocations absolutely rely on how a specific instruction is using its operands, which is why we need to differentiate between e.g. the 12-bit immediate on an |
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.