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

Add concept of partially configured arch def #67

Closed
wants to merge 10 commits into from
5 changes: 3 additions & 2 deletions arch/csr/misa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ misa:
long_name: Machine ISA Control
address: 0x301
priv_mode: M
length: 64
length: MXLEN
description: Reports the XLEN and "major" extensions supported by the ISA.
definedBy: Sm
fields:
MXL:
location: 63-62
location_rv32: 31-30
location_rv64: 63-62
description: XLEN in M-mode.
type: RO
reset_value: 2
Expand Down
71 changes: 62 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,37 @@ 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 {
# 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 {
# 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?<$array_size(MSTATUS_FS_LEGAL_VALUES), 2>(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 {
# there will be no hardware update in this case because we know the F extension isn't implemented
return ary_includes?<$array_size(MSTATUS_FS_LEGAL_VALUES), 2>(MSTATUS_FS_LEGAL_VALUES, csr_value.FS) ? csr_value.FS : UNDEFINED_LEGAL_DETERMINISTIC;
}
MPP:
location: 12-11
description: |
Expand Down Expand Up @@ -449,9 +498,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 +535,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_WRITEABLE == 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
2 changes: 1 addition & 1 deletion arch/ext/Svade.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Svade:
- name: Paul Donahue
- name: Ved Shanbhogue
company: Rivos, Inc.
conflicts: Svadu
conflicts: Svadu
doc_license:
name: Creative Commons Attribution 4.0 International License (CC-BY 4.0)
url: https://creativecommons.org/licenses/by/4.0/
Expand Down
2 changes: 1 addition & 1 deletion arch/ext/Svadu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Svadu:
- name: Paul Donahue
- name: Ved Shanbhogue
company: Rivos, Inc.
conflicts: Svade
conflicts: Svade
doc_license:
name: Creative Commons Attribution 4.0 International License (CC-BY 4.0)
url: https://creativecommons.org/licenses/by/4.0/
Expand Down
1 change: 1 addition & 0 deletions backends/arch_gen/lib/arch_gen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ def gen_arch_def
end.to_h

arch_def = {
"type" => "fully configured",
"params" => params,
"instructions" => inst_hash,
"implemented_instructions" => @implemented_instructions,
Expand Down
9 changes: 7 additions & 2 deletions backends/arch_gen/tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ def arch_def_for(config_name)

@arch_defs[config_name] =
if config_name == "_"
ArchDef.new
ArchDef.new("_", $root / "gen" / "_" / "arch" / "arch_def.yaml")
else
ImplArchDef.new(config_name)
ArchDef.new(
config_name,
$root / "gen" / config_name / "arch" / "arch_def.yaml",
overlay_path: $root / "cfgs" / config_name / "arch_overlay"
)
end
end

Expand Down Expand Up @@ -103,6 +107,7 @@ file "#{$root}/.stamps/arch-gen.stamp" => (
end.to_h

arch_def = {
"type" => "unconfigured",
"instructions" => inst_hash,
"extensions" => ext_hash,
"csrs" => csr_hash,
Expand Down
6 changes: 3 additions & 3 deletions backends/cfg_html_doc/templates/csr.adoc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ h| Privilege Mode | <%= csr.priv_mode %>
.<%= csr.name %> format
[wavedrom, ,svg,subs='attributes',width="100%"]
....
<%= JSON.dump csr.wavedrom_desc(arch_def, arch_def.param_values["XLEN"]) %>
<%= JSON.dump csr.wavedrom_desc(arch_def, arch_def.param_values["XLEN"], exclude_unimplemented: true) %>
....
<%- else -%>
<%# CSR has a dynamic length, or a field has a dynamic location,
Expand All @@ -39,13 +39,13 @@ This CSR format changes dynamically.
.<%= csr.name %> Format when <%= csr.length_cond32 %>
[wavedrom, ,svg,subs='attributes',width="100%"]
....
<%= JSON.dump csr.wavedrom_desc(arch_def, 32) %>
<%= JSON.dump csr.wavedrom_desc(arch_def, 32, exclude_unimplemented: true) %>
....

.<%= csr.name %> Format when <%= csr.length_cond64 %>
[wavedrom, ,svg,subs='attributes',width="100%"]
....
<%= JSON.dump csr.wavedrom_desc(arch_def, 64) %>
<%= JSON.dump csr.wavedrom_desc(arch_def, 64, exclude_unimplemented: true) %>
....


Expand Down
3 changes: 2 additions & 1 deletion backends/manual/tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,10 @@ end
Dir.glob($root / "arch" / "manual" / "**" / "contents.yaml") do |content_fn|
file "#{File.dirname(content_fn)}/riscv-isa-manual/README.md" => ($root / "ext" / "riscv-isa-manual" / "README.md").to_s do |t|
content_obj = YAML.load_file(content_fn)
git_dir = `git rev-parse --git-dir`.strip
cmd = [
"git",
"--git-dir=#{$root}/.git/modules/ext/riscv-isa-manual",
"--git-dir=#{git_dir}/modules/ext/riscv-isa-manual",
"worktree add",
File.dirname(t.name),
content_obj["isa_manual_tree"],
Expand Down
6 changes: 6 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ else
SINGULARITY_CACHE=
fi

if [ -f $ROOT/.git ]; then
# if this is a worktree, need to add the parent git repo in, too
GIT_PATH=`git rev-parse --git-common-dir | tr -d '\n' | xargs dirname`
HOME_OPT="${HOME_OPT} --bind ${GIT_PATH}:${GIT_PATH}"
fi

if [ ! -d $ROOT/.home ]; then
mkdir $ROOT/.home
fi
Expand Down
4 changes: 3 additions & 1 deletion cfgs/generic_rv64/params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,6 @@ params:
TINST_VALUE_ON_LOAD_PAGE_FAULT: "always zero"
TINST_VALUE_ON_STORE_AMO_PAGE_FAULT: "always zero"
MTVEC_MODES: [0, 1]

MSTATUS_FS_LEGAL_VALUES: [0,1,2,3]
MSTATUS_FS_WRITEABLE: true
MSTATUS_TVM_IMPLEMENTED: true
Loading
Loading