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
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 8 additions & 7 deletions arch/inst/I/add.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$schema: "inst_schema.json#"
kind: instruction
name: add
format: { $ref: inst_format/rtype.yaml# }
long_name: Integer add
description: |
Add the value in rs1 to rs2, and store the result in rd.
Expand All @@ -12,19 +13,19 @@ assembly: xd, xs1, xs2
encoding:
match: 0000000----------000-----0110011
variables:
- name: rs2
location: 24-20
- name: rs1
location: 19-15
- name: rd
location: 11-7
- field: { $ref: inst_format/rtype.yaml#/fields/name=rs2 }
name: xs2
- field: { $ref: inst_format/rtype.yaml#/fields/name=rs1 }
name: xs1
- field: { $ref: inst_format/rtype.yaml#/fields/name=rd }
name: xd
access:
s: always
u: always
vs: always
vu: always
data_independent_timing: true
operation(): X[rd] = X[rs1] + X[rs2];
operation(): X[xd] = X[xs1] + X[xs2];



Expand Down
15 changes: 8 additions & 7 deletions arch/inst/I/addi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
$schema: "inst_schema.json#"
kind: instruction
name: addi
format: { $ref: inst_format/itype.yaml# }
long_name: Add immediate
description: Add an immediate to the value in rs1, and store the result in rd
definedBy: I
assembly: xd, xs1, imm
encoding:
match: -----------------000-----0010011
variables:
- name: imm
$inherits: common/inst_variable_types.yaml#/itype_imm
- name: rs1
location: 19-15
- name: rd
location: 11-7
- field: { $ref: inst_format/itype.yaml#/fields/name=imm }
name: imm
- field: { $ref: inst_format/itype.yaml#/fields/name=rs1 }
name: xs1
- field: { $ref: inst_format/itype.yaml#/fields/name=rd }
name: xd
access:
s: always
u: always
vs: always
vu: always
data_independent_timing: true
operation(): X[rd] = X[rs1] + imm;
operation(): X[xd] = X[xs1] + sext(imm, 31);



Expand Down
16 changes: 8 additions & 8 deletions arch/inst/I/bne.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$schema: "inst_schema.json#"
kind: instruction
name: bne
format: { $ref: inst_format/btype.yaml# }
long_name: Branch if not equal
description: |
Branch to PC + imm if
Expand All @@ -14,13 +15,12 @@ assembly: xs1, xs2, imm
encoding:
match: -----------------001-----1100011
variables:
- name: imm
location: 31|7|30-25|11-8
left_shift: 1
- name: rs2
location: 24-20
- name: rs1
location: 19-15
- field: { $ref: inst_format/btype.yaml#/fields/name=imm }
name: offset
- field: { $ref: inst_format/btype.yaml#/fields/name=rs2}
name: xs2
- field: { $ref: inst_format/btype.yaml#/fields/name=rs1}
name: rs1
access:
s: always
u: always
Expand All @@ -31,7 +31,7 @@ operation(): |
XReg rhs = X[rs2];

if (lhs != rhs) {
jump_halfword($pc + imm);
jump_halfword($pc + sext(imm, 31));
}


Expand Down
15 changes: 7 additions & 8 deletions arch/inst/I/jal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ $schema: "inst_schema.json#"
kind: instruction
name: jal
long_name: Jump and link
format: { $ref: inst_format/jtype.yaml# }
description: |
Jump to a PC-relative offset and store the return
address in rd.
Expand All @@ -12,12 +13,10 @@ assembly: xd, imm
encoding:
match: -------------------------1101111
variables:
- name: imm
location: 31|19-12|20|30-21
left_shift: 1
sign_extend: true
- name: rd
location: 11-7
- field: { $ref: inst_format/jtype.yaml#/fields/name=imm }
name: imm
- field: { $ref: inst_format/jtype.yaml#/fields/name=rd }
name: xd
access:
s: always
u: always
Expand All @@ -26,8 +25,8 @@ access:
operation(): |
XReg retrun_addr = $pc + 4;

jump_halfword($pc + imm);
X[rd] = retrun_addr;
jump_halfword($pc + sext(imm, 31));
X[xd] = retrun_addr;



Expand Down
19 changes: 10 additions & 9 deletions arch/inst/I/lb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,31 @@ $schema: "inst_schema.json#"
kind: instruction
name: lb
long_name: Load byte
format: { $ref: inst_format/itype.yaml# }
description: |
Load 8 bits of data into register `rd` from an
address formed by adding `rs1` to a signed offset.
Sign extend the result.
definedBy: I
assembly: xd, imm(rs1)
assembly: xd, offset(rs1)
encoding:
match: -----------------000-----0000011
variables:
- name: imm
location: 31-20
- name: rs1
location: 19-15
- name: rd
location: 11-7
- format: { $ref: inst_format/itype.yaml#/fields/name=imm }
name: offset
- format: { $ref: inst_format/itype.yaml#/fields/name=rs1 }
name: xs1
- format: { $ref: inst_format/itype.yaml#/fields/name=rs1 }
name: xd
access:
s: always
u: always
vs: always
vu: always
operation(): |
XReg virtual_address = X[rs1] + imm;
XReg virtual_address = X[xs1] + sext(imm, 31);

X[rd] = sext(read_memory<8>(virtual_address, $encoding), 8);
X[xd] = sext(read_memory<8>(virtual_address, $encoding), 8);



Expand Down
12 changes: 6 additions & 6 deletions arch/inst/I/lui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
$schema: "inst_schema.json#"
kind: instruction
name: lui
format: { $ref: inst_format/utype.yaml# }
long_name: Load upper immediate
description: Load the zero-extended imm into rd.
definedBy: I
assembly: xd, imm
encoding:
match: -------------------------0110111
variables:
- name: imm
location: 31-12
left_shift: 12
- name: rd
location: 11-7
- field: { $ref: inst_format/utype.yaml#/fields/name=imm }
name: imm
- field: { $ref: inst_format/utype.yaml#/fields/name=rd }
name: xd
access:
s: always
u: always
vs: always
vu: always
data_independent_timing: true
operation(): X[rd] = imm;
operation(): X[xd] = sext(imm, 32);



Expand Down
23 changes: 23 additions & 0 deletions arch/inst_format/btype.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

$schema: inst_format.json#
kind: instruction format
name: B-type
size: 32
fields:
- location: 31|7|30-25|11-8
name: imm
kind: immediate
left_shift: 1
sign_extend: true
relocations:
- $ref: relocation/R_RISCV_BRANCH.yaml#
- location: 24-20
name: rs2
kind: x source register
- location: 19-15
name: rs1
kind: x source register
- location: 6-0
name: opcode
kind: opcode
opcode: true
28 changes: 28 additions & 0 deletions arch/inst_format/itype.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

$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
21 changes: 21 additions & 0 deletions arch/inst_format/jtype.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@


$schema: inst_format.json#
kind: instruction format
name: J-type
size: 32
fields:
- location: 31|19-12|20|30-21
name: imm
kind: immediate
left_shift: 1
sign_extend: true
relocations:
- $ref: relocation/R_RISCV_JAL.yaml#
- location: 11-7
name: rd
kind: x destination register
- location: 6-0
name: opcode
kind: opcode
opcode: true
26 changes: 26 additions & 0 deletions arch/inst_format/rtype.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


$schema: inst_format.json#
kind: instruction format
name: R-type
size: 32
fields:
- location: 31-25
name: funct7
kind: opcode
- location: 24-20
name: rs2
kind: x source register
- 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
23 changes: 23 additions & 0 deletions arch/inst_format/utype.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

$schema: inst_format.json#
kind: instruction format
name: U-type
fields:
- location: 31-12
name: imm
kind: immediate
sign_extend: true
left_shift: 12
relocations:
- $ref: relocation/R_RISCV_GOT_HI20.yaml#
- $ref: relocation/R_RISCV_TLS_GOT_HI20.yaml#
- $ref: relocation/R_RISCV_TLS_GD_HI20.yaml#
- $ref: relocation/R_RISCV_PCREL_HI20.yaml#
- $ref: relocation/R_RISCV_TPREL_HI20.yaml#
- $ref: relocation/R_RISCV_TLSDESC_HI20.yaml#
- location: 11-7
name: rd
kind: x destination register
- location: 6-0
name: opcode
kind: opcode
8 changes: 8 additions & 0 deletions arch/relocation/R_RISCV_BRANCH.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$schema: reolaction_schema.json#
kind: relocation
relocation_type: R_RISCV_BRANCH
relocation_description: |
12-bit PC-relative branch offset
calculation: S + A - P # calculation, using symbols defined in ABI doc 8.4.1
number: 16 # the number of the relocation, encoded in the r_info field
type: static # relocation type (static, dynamic, both)
9 changes: 9 additions & 0 deletions arch/relocation/R_RISCV_JAL.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$schema: reolaction_schema.json#
kind: relocation
location: 31|19-12|20|30-21
relocation_type: R_RISCV_JAL
relocation_description: |
20-bit PC-relative jump offset
calculation: S + A - P # calculation, using symbols defined in ABI doc 8.4.1
number: 17 # the number of the relocation, encoded in the r_info field
type: static # relocation type (static, dynamic, both)
11 changes: 11 additions & 0 deletions arch/relocation/R_RISCV_PCREL_L012_I.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$schema: reolaction_schema.json#
kind: relocation
location: 31-20 # location in the instruction encoding
relocation_type: R_RISCV_PCREL_LO12_I
relocation_description: |
Low 12 bits of a 32-bit PC-relative,
`%pcrel_lo(address of %pcrel_hi)`, the
addend must be 0.
calculation: S - P # calculation, using symbols defined in ABI doc 8.4.1
number: 24 # the number of the relocation, encoded in the r_info field
type: static # relocation type (static, dynamic, both)
Loading