Skip to content

Commit

Permalink
Add some more parameters to reflects options in mstatus
Browse files Browse the repository at this point in the history
  • Loading branch information
dhower-qc committed Oct 3, 2024
1 parent 85ea0fe commit 67d9fc0
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 16 deletions.
74 changes: 65 additions & 9 deletions arch/csr/mstatus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,29 @@ mstatus:
*`hfence.vvma`, `sfence.w.inval`, or `sfence.inval.ir` to trap.
* Any additional traps in VS-mode (controlled via `hstatus.VTVM` instead).
type: RW
type(): |
if (CSR[misa].S == 1'b0) {
return CsrFieldType::RO;
} else {
return CsrFieldType::RW;
}
definedBy: S
reset_value: UNDEFINED_LEGAL
reset_value(): |
if (CSR[misa].S == 1'b0) {
return 0;
} else if (MSTATUS_TVM_IMPLEMENTED) {
return UNDEFINED_LEGAL;
} else {
return 0;
}
sw_write(csr_value): |
if (CSR[misa].S == 1'b0) {
return 0;
} else if (MSTATUS_TVM_IMPLEMENTED) {
return csr_value.TVM;
} else {
return 0;
}
MXR:
location: 19
description: |
Expand Down Expand Up @@ -286,7 +306,8 @@ mstatus:
`mstatus.MPRV` is cleared on any exception return (`mret` or `sret` instruction, regardless of the trap handler privilege mode).
definedBy: U
type: RW-H
type(): |
return (CSR[misa].U == 1'b1) ? CsrFieldType::RWH : CsrFieldType::RO;
reset_value: 0
XS:
location: 16-15
Expand All @@ -308,9 +329,40 @@ mstatus:
When a floating point register, or the fCSR register is written, FS obtains the value 3.
Values 1 and 2 are valid write values for software, but are not interpreted by hardware
other than to possibly enable a previously-disabled floating point unit.
type: RW-H
type(): |
if (CSR[misa].F == 1'b1){
return CsrFieldType::RWH;
} else if ((CSR[misa].S == 1'b0) && (CSR[misa].F == 1'b0)) {
# must be read-only-0
return CsrFieldType::RO;
} else {
assert (CSR[misa].S == 1'b1);
# there will be no hardware update in this case because we know the F extension isn't implemented
return MSTATUS_FS_WRITEABLE ? CsrFieldType::RW : CsrFieldType::RO;
}
definedBy: F
reset_value: UNDEFINED_LEGAL
reset_value(): |
if (CSR[misa].F == 1'b1){
return UNDEFINED_LEGAL;
} else if ((CSR[misa].S == 1'b0) && (CSR[misa].F == 1'b0)) {
# must be read-only-0
return 0;
} else {
assert (CSR[misa].S == 1'b1);
# there will be no hardware update in this case because we know the F extension isn't implemented
return MSTATUS_FS_WRITEABLE ? UNDEFINED_LEGAL : 0;
}
sw_write(csr_value): |
if (CSR[misa].F == 1'b1){
return ary_includes?(MSTATUS_FS_LEGAL_VALUES, csr_value.FS) ? csr_value.FS : UNDEFINED_LEGAL_DETERMINISTIC;
} else if ((CSR[misa].S == 1'b0) && (CSR[misa].F == 1'b0)) {
# must be read-only-0
return 0;
} else {
assert (CSR[misa].S == 1'b1);
# there will be no hardware update in this case because we know the F extension isn't implemented
return ary_includes?(MSTATUS_FS_LEGAL_VALUES, csr_value.FS) ? csr_value.FS : UNDEFINED_LEGAL_DETERMINISTIC;
}
MPP:
location: 12-11
description: |
Expand Down Expand Up @@ -449,9 +501,11 @@ mstatus:
Can also be written by software without immediate side effect.
Other than serving as a record of nested traps as described above, `mstatus.SPIE` does not affect execution.
type: RW-H
type(): |
return (CSR[misa].S == 1'b1) ? CsrFieldType::RWH : CsrFieldType::RO;
definedBy: S
reset_value: UNDEFINED_LEGAL
reset_value(): |
return (CSR[misa].S == 1'b1) ? UNDEFINED_LEGAL : 0;
MIE:
location: 3
description: |
Expand Down Expand Up @@ -484,6 +538,8 @@ mstatus:
* When 0, all (H)S-mode interrupts are disabled when the current privilege level is (H)S (M-mode interrupts are still enabled).
* When 1, (H)S-mode interrupts that are not otherwise disabled with a field in `sie` are enabled.
type: RW-H
type(): |
return (CSR[misa].S == 1'b1) ? CsrFieldType::RWH : CsrFieldType::RO;
definedBy: S
reset_value: UNDEFINED_LEGAL
reset_value(): |
return (CSR[misa].S == 1'b1) ? UNDEFINED_LEGAL : 0;
15 changes: 14 additions & 1 deletion arch/ext/F.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,17 @@ F:
description: |
Indicates whether or not the `F` extension can be disabled with the `misa.F` bit.
schema:
type: boolean
type: boolean
MSTATUS_FS_LEGAL_VALUES:
description: |
The set of values that mstatus.FS will accept from a software write.
schema:
type: array
items:
type: integer
enum: [0,1,2,3]
maxItems: 4
uniqueItems: true
also_defined_in: S
extra_validation: |
assert MSTATUS_FS_LEGAL_VALUES.include?(0) && MSTATUS_FS_LEGAL_VALUES.include?(3) if ext?(:F)
31 changes: 30 additions & 1 deletion arch/ext/S.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,33 @@ S:
type: boolean
default: false
extra_validation:
assert TRAP_ON_SFENCE_VMA_WHEN_SATP_MODE_IS_READ_ONLY == false if ext?(:Sv32) || ext?(:Sv39) || ext?(:Sv48) || ext?(:Sv57)
assert TRAP_ON_SFENCE_VMA_WHEN_SATP_MODE_IS_READ_ONLY == false if ext?(:Sv32) || ext?(:Sv39) || ext?(:Sv48) || ext?(:Sv57)
MSTATUS_FS_WRITEABLE:
description: |
When `S` is enabled but `F` is not, mstatus.FS is optionally writeable.
This parameter only has an effect when both S and F mode are disabled.
schema:
type: boolean
extra_validation:
assert MSTATUS_FS_WRITEABL == true if ext?(:F)
MSTATUS_FS_LEGAL_VALUES:
description: |
The set of values that mstatus.FS will accept from a software write.
schema:
type: array
items:
type: integer
enum: [0,1,2,3]
maxItems: 4
uniqueItems: true
also_defined_in: F
extra_validation: |
assert MSTATUS_FS_LEGAL_VALUES.include?(0) && MSTATUS_FS_LEGAL_VALUES.include?(3) if ext?(:F)
MSTATUS_TVM_IMPLEMENTED:
description: |
Whether or not mstatus.TVM is implemented.
When not implemented mstatus.TVM will be read-only-zero.
schema:
type: boolean
12 changes: 7 additions & 5 deletions lib/idl/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,17 @@ def equal_to?(type)

case @kind
when :boolean
return type.kind == :boolean
type.kind == :boolean
when :enum_ref
return type.kind == :enum_ref && type.name == @enum_class.name
type.kind == :enum_ref && type.name == @enum_class.name
when :dontcare
return true
true
when :bits
return type.kind == :bits && type.width == @width
type.kind == :bits && type.width == @width
when :string
return type.kind == :string && type.width == @width
type.kind == :string && type.width == @width
when :array
type.kind == :array && type.sub_type.equal_to?(@sub_type)
else
raise "unimplemented type '#{@kind}'"
end
Expand Down

0 comments on commit 67d9fc0

Please sign in to comment.