Skip to content

Commit 4109d1c

Browse files
authored
Development (#6)
Numerous enhancements: * Added passes to detect which functions are reachable and which exceptions might occur in an AST * Add landing page for cfg html doc * Actually parsing CSR read/write functinos * Add htimedelta and hcountern CSRs * Only show the implemented functions in the cfg html docs * Show which exceptions might be raised for each instruction in cfg html docs * Add String types to IDL so that configuration parameter strings can be compared * Improve IDL documentation * Improved pruning * Add gen_adoc for all AstNodes * Add action to publich cfg_html example and YARD docs to GitHub pages * find/replace links on the entire adoc document, rather than specific sections * Completed refactoring to make AstNodes independent of SyntaxNodes
1 parent 214d580 commit 4109d1c

File tree

277 files changed

+5152
-2272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

277 files changed

+5152
-2272
lines changed

.github/workflows/pages.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Deploy pages
2+
on:
3+
push:
4+
branches:
5+
- main
6+
workflow_dispatch:
7+
permissions:
8+
contents: read
9+
pages: write
10+
id-token: write
11+
concurrency:
12+
group: "pages"
13+
cancel-in-progress: false
14+
jobs:
15+
pages:
16+
runs-on: ubuntu-latest
17+
environment:
18+
name: github-pages
19+
url: ${{ steps.deployment.outputs.page_url }}
20+
steps:
21+
- name: Clone Github Repo Action
22+
uses: actions/checkout@v4
23+
- name: Setup apptainer
24+
uses: eWaterCycle/setup-apptainer@v2.0.0
25+
- name: Get container from cache
26+
id: cache-sif
27+
uses: actions/cache@v3
28+
with:
29+
path: .singularity/image.sif
30+
key: ${{ hashFiles('container.def') }}
31+
- name: Get gems and node files from cache
32+
id: cache-bundle-npm
33+
uses: actions/cache@v3
34+
with:
35+
path: |
36+
.home/.gems
37+
node_modules
38+
key: ${{ hashFiles('Gemfile.lock') }}-${{ hashFiles('package-lock.json') }}
39+
- if: ${{ steps.cache-sif.outputs.cache-hit != 'true' }}
40+
name: Build container
41+
run: ./bin/build_container
42+
- name: Setup project
43+
run: ./bin/setup
44+
- name: Build html documentation for generic_rv64
45+
run: ./do gen:html[generic_rv64]
46+
- name: Generate YARD docs
47+
run: ./do gen:tool_doc
48+
- name: Create _site
49+
run: mkdir -p _site
50+
- name: Copy cfg html
51+
run: cp -R gen/cfg_html_doc/generic_rv64/html _site
52+
- name: Setup Pages
53+
uses: actions/configure-pages@v5
54+
- name: Upload artifact
55+
uses: actions/upload-pages-artifact@v3
56+
with:
57+
path: '_site'
58+
- name: Deploy to GitHub Pages
59+
id: deployment
60+
uses: actions/deploy-pages@v4

.yardopts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
-o docs/ruby --embed-mixins 'lib/**/*.rb'
1+
-o _site/ruby --embed-mixins 'lib/**/*.rb'

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ gem "yard"
2020
group :development do
2121
gem "solargraph"
2222
gem 'rubocop-minitest'
23+
gem 'ruby-prof'
2324
end

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ GEM
107107
rubocop-minitest (0.35.1)
108108
rubocop (>= 1.61, < 2.0)
109109
rubocop-ast (>= 1.31.1, < 2.0)
110+
ruby-prof (1.7.0)
110111
ruby-progressbar (1.13.0)
111112
ruby-rc4 (0.1.5)
112113
simpleidn (0.2.3)
@@ -154,6 +155,7 @@ DEPENDENCIES
154155
minitest
155156
rake (~> 13.0)
156157
rubocop-minitest
158+
ruby-prof
157159
slim (~> 5.1)
158160
solargraph
159161
treetop (= 1.6.12)

README.adoc

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# RISC-V Unified Database
1+
= RISC-V Unified Database
22

33
The RISC-V Unified Database is intended to hold *all* the information needed to describe RISC-V,
44
including a list of extensions, instruction specifications, CSR specifications, and documentation prose. The vision is that anything one would need for RISC-V can be generated from the information in this repository.
@@ -11,7 +11,32 @@ This repository contains:
1111
** [COMING SOON] A configuration-specific Instruction Set Simulator
1212
** More backends are planned
1313

14-
## Prerequisites
14+
== What can it do?
15+
16+
=== Working examples:
17+
18+
* Generate https://riscv-software-src.github.io/riscv-unified-db/html/index.html[configuration-specific documentation] taylored to the set of implemented extensions and unnamed implementation options (_e.g._, `./do gen:html[generic_rv64]`).
19+
** Only implemented extensions/instructions/CSRs are included
20+
** Unreachable/unimplmented parts of the formal specification are pruned away
21+
** A dedicated documentation page for every implemented instruction, including its encoding, pruned execution behavior, and what types of exceptions it may cause.
22+
** A dedication documentation page for every implemented CSR, including its (possibly runtime-changing) encoding, fields, and pruned behavior on reads and writes
23+
** Clickable links to all mentions of instructions, extensions, CSRs, CSR fields, and glossary terms.
24+
* Generate documentation for specific extensions (_e.g._, `./do gen:ext_pdf[B]`)
25+
** Automatically include a complete list of added instructions and CSRs
26+
** Per-instruction documentation
27+
** Per-CSR documentation
28+
** Formal specification
29+
* Generate a single YAML file containing *everything* knowable about a configuration (_e.g._, `./do gen:cfg_arch[generic_rv64]`).
30+
31+
=== Possibilities:
32+
33+
* Generate binutils files for an extension
34+
* Generate instruction tables for compilers
35+
* Generate https://github.com/riscv/riscv-opcodes[riscv-opcodes]
36+
* Generate the full RISC-V specification, along with an appendix of instructions and CSRs
37+
* ...
38+
39+
== Prerequisites
1540

1641
The only requirement is the `Singularity CE` or `Apptainer` container system. Either one will work (they are forks).
1742

@@ -24,7 +49,7 @@ If it is not installed, either as your IT admin or:
2449
You do *not* need root privileges to download or use the container. However, to modify/build the container,
2550
you will need either root privileges or the ability to run in `fakeroot` mode. See https://docs.sylabs.io/guides/4.1/user-guide/fakeroot.html[Singularity Fakeroot Documentation] for more information.
2651

27-
## Setup
52+
== Setup
2853

2954
Do once:
3055

@@ -39,7 +64,7 @@ Do once:
3964
[NOTE]
4065
If you forget, don't worry. Setup will be invoked by any program in bin/ if necessary.
4166

42-
### VSCode
67+
=== VSCode
4368

4469
If using Visual Studio Code and want to use development tools, you will need to restart the editor
4570
after setup.
@@ -54,7 +79,7 @@ Helpful extensions are
5479
The `.vscode/settings.json` file in the repo will ensure that Solargraph works without any additional
5580
configuration (assuming you've already run ./bin/setup).
5681

57-
## Tasks
82+
== Tasks
5883

5984
Quick start:
6085

@@ -67,7 +92,7 @@ Quick start:
6792
./do validate # validate against the schema
6893
----
6994

70-
## More info
95+
== More info
7196

7297
* xref:arch/README.adoc[Architecture specification format]
7398
* xref:arch/README.adoc[Documentation for the generator tool and IDL]

Rakefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,16 @@ file "#{$root}/arch/csr/S/scounteren.yaml" => [
178178
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
179179
end
180180

181+
file "#{$root}/arch/csr/H/hcounteren.yaml" => [
182+
"#{$root}/arch/csr/H/hcounteren.layout",
183+
__FILE__
184+
] do |t|
185+
puts "Generating #{Pathname.new(t.name).relative_path_from($root)}"
186+
erb = ERB.new(File.read($root / "arch/csr/H/hcounteren.layout"), trim_mode: "-")
187+
erb.filename = "#{$root}/arch/csr/H/hcounteren.layout"
188+
File.write(t.name, insert_warning(erb.result(binding), t.prerequisites.first))
189+
end
190+
181191
file "#{$root}/arch/csr/Zicntr/mcountinhibit.yaml" => [
182192
"#{$root}/arch/csr/Zicntr/mcountinhibit.layout",
183193
__FILE__
@@ -203,6 +213,7 @@ namespace :gen do
203213

204214
Rake::Task["#{$root}/arch/csr/I/mcounteren.yaml"].invoke
205215
Rake::Task["#{$root}/arch/csr/S/scounteren.yaml"].invoke
216+
Rake::Task["#{$root}/arch/csr/H/hcounteren.yaml"].invoke
206217
Rake::Task["#{$root}/arch/csr/Zicntr/mcountinhibit.yaml"].invoke
207218

208219
(0..63).each do |pmpaddr_num|

arch/csr/H/hcounteren.layout

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# yaml-language-server: $schema=../../../schemas/csr_schema.json
2+
3+
hcounteren:
4+
long_name: Hypervisor Counter Enable
5+
address: 0x606
6+
priv_mode: S
7+
length: 32
8+
description: |
9+
Together with `scounteren`, delegates control of the hardware performance-monitoring counters
10+
to VS/VU-mode
11+
12+
See `cycle` for a table describing how exceptions occur.
13+
definedBy: H
14+
fields:
15+
CY:
16+
location: 0
17+
description: |
18+
When all of `scounteren.CY`, `mcounteren.CY`, and `hcounteren.CY` are set,
19+
the `cycle` CSR (an alias of `mcycle`) is accessible to VU-mode.
20+
21+
When `mcounteren.CY` and `hcounteren.CY` are set,
22+
the `cycle` CSR (an alias of `mcycle`) is accessible to VS-mode.
23+
24+
This bit is read-only 0 when `mcounteren.CY` is clear.
25+
26+
Summary:
27+
28+
!===
29+
! `mcounteren.CY` ! `hcounteren.CY` behavior
30+
31+
! 0 ! read-only 0
32+
! 1 ! writeable
33+
!===
34+
definedBy: Zicntr
35+
type: RW-H
36+
reset_value: UNDEFINED_LEGAL
37+
IR:
38+
location: 2
39+
description: |
40+
When all of `scounteren.IR`, `mcounteren.IR`, and `hcounteren.IR` are set,
41+
the `instret` CSR (an alias of `minstret`) is accessible to VU-mode.
42+
43+
When `mcounteren.IR` and `hcounteren.IR` are set,
44+
the `instret` CSR (an alias of `minstret`) is accessible to VS-mode.
45+
46+
This bit is read-only 0 when `mcounteren.IR` is clear.
47+
48+
Summary:
49+
50+
!===
51+
! `mcounteren.IR` ! `hcounteren.IR` behavior
52+
53+
! 0 ! read-only 0
54+
! 1 ! writeable
55+
!===
56+
57+
58+
type: RW-H
59+
reset_value: UNDEFINED_LEGAL
60+
<%- (3..31).each do |hpm_num| -%>
61+
HPM<%= hpm_num %>:
62+
location: <%= hpm_num %>
63+
description: |
64+
When all of `scounteren.HPM<%= hpm_num %>`, `mcounteren.HPM<%= hpm_num %>`, and `hcounteren.HPM<%= hpm_num %>` are set,
65+
the `hpmcounter<%= hpm_num %>` CSR (an alias of `mhpmcounter<%= hpm_num %>`) is accessible to VU-mode.
66+
67+
When `mcounteren.HPM<%= hpm_num %>` and `hcounteren.HPM<%= hpm_num %>` are set,
68+
the `hpmcounter<%= hpm_num %>` CSR (an alias of `mhpmconuter<%= hpm_num %>`) is accessible to VS-mode.
69+
70+
This bit is read-only 0 when `mcounteren.HPM<%= hpm_num %>` is clear.
71+
72+
Summary:
73+
74+
!===
75+
! `mcounteren.HPM<%= hpm_num %>` ! `hcounteren.HPM<%= hpm_num %>` behavior
76+
77+
! 0 ! read-only 0
78+
! 1 ! writeable
79+
!===
80+
81+
type: RW
82+
reset_value: UNDEFINED_LEGAL
83+
<%- end -%>
84+
sw_read(): |
85+
if (!implemented?(ExtensionName::Zicntr) && !implemented?(ExtensionName::Zihpm)) {
86+
# this CSR isn't supposed to exist when Zicntr and Zihpm are not implemented
87+
raise(ExceptionCode::IllegalInstruction, $encoding);
88+
}
89+
90+
# any bit of mcounteren that is zero forces that same bit of hcounteren to 0
91+
return $bits(CSR[hcounteren]) & $bits(CSR[mcounteren]);

0 commit comments

Comments
 (0)