-
Notifications
You must be signed in to change notification settings - Fork 170
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
Replace command-line-switch model configuration with RISCV-Config #175
base: master
Are you sure you want to change the base?
Conversation
|
for #1: we need to communicate to everyone exactly which changes (in
plugin's I think) they will need to make, and that they must provide a
YAML file if they don't already
We need to do this even before the PR is merged, and we should provide a
script that pulls in riscv-config and checks it for errors so they know
they're doing it right.
#5 Could you give me an example of something that isn't being handled with
this PR, but is handled now? (outside of CSR configuration which is coning)
#8: I'm not sure what we can do about Spike. It's primarily needed to
ensure that Sail is correct - but, even if we do, we're not writing tests
that expose that.
There are 100's of options, and we don't even pretend to test that every
value of every option functions correctly compared to Spike even if Spike
could do that.
That's a problem in itself, but it is not primarily a Sail issue. We
are effectively crowd sourcing that testing by letting vendors complain if
they think we are doing it wrong.
WE probably should have tests written for Sail architectural option
testing, but they'd probably self testing unless Spike handles all of the
architectural options.
#9 RVFI? Is that the google open source DV framework? I'm not sure how that
is affected by this change, because this PR only affects the reference
signature (effectively) right?
…On Mon, Aug 15, 2022 at 3:50 PM Bill McSpadden ***@***.***> wrote:
This Pull Request will probably not be ratified on the first go-round,
but we need to start discussing it because it introduces some new
functionality.
1. I am changing the Sail model configuration method from
command line arguments to using the RISCV Config YAML
files. This gives us a consistent method for configuring
the ACTs (Arch Compatability Tests) along with the Sail
model. THE COMMAND LINE SWITCHES THAT HAVE TO DO WITH MODEL
CONFIGURATION HAVE BEEN REMOVED. Comments?
2. I am adding an API such that the Sail portion of the model
and the C portion of the model can query the settings in the
YAML files. The API functions begin with rv_cfg_c_ (for the
C implementation) and rv_cfg_s_ (for the Sail implementation).
Note: the Sail implementation is just a shim to the C API.
Not all desired functions are implemented. They should be
easy to add.
3. I have perturbed the order in which things get initialized.
Command line switches need to be processed first in order to get
pointers to the RISCV-Config YAML files. Then I process the YAML
files and set the rv_* variables. Most of this work is done
in riscv_sim.c.
3. C Coding style: I use Whitesmith for the new files that I've
added. Comments?
4. The API uses the libfyaml and pcre libraries to parse the
parse the YAML files (libyaml) and to provide regular
expression functionality (pcre). This leads to questions
about using 2 new libraries in the build process and the
risks involved.
5. So far, I have only added support for the existing command
line switches. All new code should utilize the API. I
have been directing the Vector Sail team to do so.
6. I have begun work on configuring the CSR implementations in the
model, but I have not completed the work.
7. I've been doing work at the same time on the cookbook. I have
included it in this pull request because this is the area
where I've been working on my simulation examples. If you
look at cookbook/functional_code_examples/platform_configuration/,
you'll see a working example of a bit of assembly language code
along with the YAML files for configuring the model.
THE TEXT OF THE COOKBOOK IS NOT COMPLETE AND SHOULD NOT BE REVIEWED.
Perhaps it should be removed from the pull-request.
8. Concern: Spike is not configured with RISCV-Config YAML files.
Also, I have done no testing with Spike.
9. Concern: I've done no testing with RVFI.
------------------------------
You can view, comment on, or merge this pull request online at:
#175
Commit Summary
- 55aab0d
<55aab0d>
adding cookbook for RISC-V golden model
- 0ab4b85
<0ab4b85>
things compile, but can't correctly access yaml settings from Sail
- 84ea6fb
<84ea6fb>
forgot to add cfunc.c and cfunc.h to repo. bah. things compile and start to
run, but the loading of ROM doesn't work.
- f9b795e
<f9b795e>
things are back to working, sort of. the test, platform_configuration, is
executing.
- ae26f5b
<ae26f5b>
intermediate checkin in preparation for renaming of cfunc files and
functions.
- 9c1341c
<9c1341c>
naming change only. no functional changes. cfunc -> rv_cfg
- b50c4ae
<b50c4ae>
can now process strings
- b77c1b2
<b77c1b2>
getting closer...
- df115f9
<df115f9>
config work continues.
- bbf15ae
<bbf15ae>
got rid of C command line switch
- c320615
<c320615>
updated cookbook wrt main loop comment. fixed some compiler warnings
- d1afe6d
<d1afe6d>
intermediate checkin
- 260e497
<260e497>
non-functional changes only. renamed functions to rv_cfg_c (for C routines)
and rv_cfg_s (for Sail routines). removed commented-out code.
- 516c906
<516c906>
stdout formating changes for messages. clean-up. nearly ready (ready?) for
a pull-request?
- 03b2e52
<03b2e52>
updated the README to add the cookbook to the directory structure
description
- b8bfc0b
<b8bfc0b>
Merge branch 'riscv:master' into master
- aa9a220
<aa9a220>
got rid of personal path to executable
File Changes
(27 files <https://github.com/riscv/sail-riscv/pull/175/files>)
- *M* Makefile
<https://github.com/riscv/sail-riscv/pull/175/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52>
(16)
- *M* README.md
<https://github.com/riscv/sail-riscv/pull/175/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5>
(32)
- *M* c_emulator/riscv_platform_impl.c
<https://github.com/riscv/sail-riscv/pull/175/files#diff-4a737f162bb33b9a645875323182a167db71ee1603a7e0b2b69ad45e006cc853>
(6)
- *M* c_emulator/riscv_platform_impl.h
<https://github.com/riscv/sail-riscv/pull/175/files#diff-b8ca9c413288aca4760beeb4153266a2832e6fbcb714463c1954b9cc5b09d8a5>
(9)
- *M* c_emulator/riscv_sim.c
<https://github.com/riscv/sail-riscv/pull/175/files#diff-6c055f3c60e99346ccba11c821c5a97e86542a33459036341860ff71d36d11f0>
(155)
- *A* c_emulator/rv_cfg_func.c
<https://github.com/riscv/sail-riscv/pull/175/files#diff-ef25ff4c568a148e2607247e27cda379a02c440dd090668992bc69ee0023e815>
(452)
- *A* c_emulator/rv_cfg_func.h
<https://github.com/riscv/sail-riscv/pull/175/files#diff-5ba51bf78cd893f1778c26dd6563c64752fa2b7cbadaad98d14c36eaca333937>
(85)
- *A* cookbook/doc/Makefile
<https://github.com/riscv/sail-riscv/pull/175/files#diff-570106431c5eafd66d933ab0e8978dae64adc0928377c4f48a4f611dc5e26f7b>
(80)
- *A* cookbook/doc/RISCV_model_FAQ.adoc
<https://github.com/riscv/sail-riscv/pull/175/files#diff-00e20823d63436c5e9671fba36131f4cc7b3b33b6766d07cb771a184c34a59db>
(95)
- *A* cookbook/doc/TheRISCVSailCookbook_Complete.adoc
<https://github.com/riscv/sail-riscv/pull/175/files#diff-b4490e9d483f3c5ccd591dafdea8ed02e2538dc2f127b17c72eeea5159a24e30>
(202)
- *A* cookbook/doc/TheRISCVSailCookbook_Complete.pdf
<https://github.com/riscv/sail-riscv/pull/175/files#diff-0f49e868cf0ab0a507790056060568664775378cfb5f1514ea6862f23ddb7f03>
(0)
- *A* cookbook/doc/TheRISCVSailCookbook_Main.adoc
<https://github.com/riscv/sail-riscv/pull/175/files#diff-2e0848eb5255736da13e7d9c150b3a0c81a7bb05667f8fa496bb02177b47ab94>
(109)
- *A* cookbook/functional_code_examples/br_j_asm/CMakeLists.txt
<https://github.com/riscv/sail-riscv/pull/175/files#diff-e2b5c043b94f01b99b0386981fe5a12eba36c028185a9e22074ef4304ec0158e>
(40)
- *A* cookbook/functional_code_examples/br_j_asm/LICENSE
<https://github.com/riscv/sail-riscv/pull/175/files#diff-795dc9be01dc59419c747994869b48520721b76acb19289ff81d20abaf01f26c>
(202)
- *A* cookbook/functional_code_examples/br_j_asm/Makefile
<https://github.com/riscv/sail-riscv/pull/175/files#diff-41127001daf6de60d3aaa7a7c40ffdbe4cc1dee4a7c23fb259fecf477305316e>
(154)
- *A* cookbook/functional_code_examples/br_j_asm/riscv_test.ld
<https://github.com/riscv/sail-riscv/pull/175/files#diff-bf8d19dfa2d344262c6c14bd92569651fded870ee5147d4a7edec1b5b08036c4>
(76)
- *A* cookbook/functional_code_examples/br_j_asm/riscv_test.ld.spike
<https://github.com/riscv/sail-riscv/pull/175/files#diff-774e2b23237edb7df60522cfcb850bbb074f68b462454e3363883d78fdfed998>
(73)
- *A* cookbook/functional_code_examples/br_j_asm/test.S
<https://github.com/riscv/sail-riscv/pull/175/files#diff-36577ee2840d86954db88533e26eac148fe6fbb059c1c8b943beb85764bdc9ba>
(482)
- *A* cookbook/functional_code_examples/platform_configuration/Makefile
<https://github.com/riscv/sail-riscv/pull/175/files#diff-db768721d1a96eb7900fca138f4ae049342a75c4f9e670dc9fc5abc71bdbe9c3>
(141)
- *A*
cookbook/functional_code_examples/platform_configuration/riscv_test.ld
<https://github.com/riscv/sail-riscv/pull/175/files#diff-ca26a1937fff78b4587fd47e9a15079a206858878547d5b2933c98cb858ee249>
(84)
- *A*
cookbook/functional_code_examples/platform_configuration/rv32i_isa.yaml
<https://github.com/riscv/sail-riscv/pull/175/files#diff-d9111f3895597188b307e945c2fe43164c03289ff28cbac0c8da3dab3abac81f>
(3096)
- *A*
cookbook/functional_code_examples/platform_configuration/rv32i_platform.yaml
<https://github.com/riscv/sail-riscv/pull/175/files#diff-71edcdbeb90345e19b7655c824199deeedf6aaaecfe0fcca7b37b80d551bcec5>
(15)
- *A* cookbook/functional_code_examples/platform_configuration/test.S
<https://github.com/riscv/sail-riscv/pull/175/files#diff-1d144a891eebd7e22d00b730fdc3d66a1c15e1f101110427c2206b192df8b879>
(162)
- *M* model/main.sail
<https://github.com/riscv/sail-riscv/pull/175/files#diff-1ce66ec0393ee5303b1ff71a7a266fb47a8c817444b9662d14708edaa33b6217>
(11)
- *M* model/prelude.sail
<https://github.com/riscv/sail-riscv/pull/175/files#diff-28bd1858b2cf208fbd0aed9363c6cb0eb8149603284c78a93f33f13b0edc5cc7>
(5)
- *M* model/riscv_step.sail
<https://github.com/riscv/sail-riscv/pull/175/files#diff-70c1d1f1c37b1072f5d820b144a404f553ef933eb653c34a805def0614b442a7>
(5)
- *A* model/rv_cfg_func_sigs.sail
<https://github.com/riscv/sail-riscv/pull/175/files#diff-2a6519464eb5583e020e91cc5127067c822c5fd7a9536956fe2aadebc19b1efa>
(78)
Patch Links:
- https://github.com/riscv/sail-riscv/pull/175.patch
- https://github.com/riscv/sail-riscv/pull/175.diff
—
Reply to this email directly, view it on GitHub
<#175>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHPXVJXA5FXIE65CUFBHXYTVZLCSHANCNFSM56TXHS4Q>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Hi Scott. Thanks for the feedback. I agree with your points about
frivolous commit
comments.
How would you recommend that I proceed? Should I withdraw the pull
request,
rebase my code, and then generate another PR?
Bill Mc.
…On Mon, Aug 15, 2022 at 5:59 PM Scott Johnson ***@***.***> wrote:
1. Git best practices. You seem to be using Git as a work log instead
of as a recipe. For example, commits named "intermediate checkin" and
"getting closer..." are not constructive. See Work Log vs Recipe
<https://www.bitsnbites.eu/git-history-work-log-vs-recipe/>, Understanding
the Git Workflow <https://sandofsky.com/workflow/git-workflow/>, and Writing
Reviewable Code
<https://secure.phabricator.com/book/phabflavor/article/writing_reviewable_code/>
for more.
—
Reply to this email directly, view it on GitHub
<#175 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXROLOEQL65NFRWQTD6RX73VZLDTTANCNFSM56TXHS4Q>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Bill McSpadden
Formal Verification Engineer
RISC-V International
mobile: 503-807-9309
|
Force pushing to this branch after cleaning up the history should fix that, there should be no need to create a new PR. |
|
||
//This macro must be defined before including pcre2.h. For a program that uses | ||
//only one code unit width, it makes it possible to use generic function names | ||
//such as pcre2_compile(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pcre2 and libfyaml are not used in this file?
//This macro must be defined before including pcre2.h. For a program that uses | ||
//only one code unit width, it makes it possible to use generic function names | ||
//such as pcre2_compile(). | ||
#define PCRE2_CODE_UNIT_WIDTH 8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PCRE2 is an implementation detail so this include should move to the source file.
|
||
#include "sail.h" | ||
#include <libfyaml.h> | ||
#include <sys/stat.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unnecessary?
#pragma once | ||
|
||
#include "sail.h" | ||
#include <libfyaml.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libfyaml is an implementation detail so this include should move to the source file.
|
||
// ============================================================================ | ||
int | ||
rv_cfg_c_ext_enable(char * isa_str, char * ext_pattern) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function only receives string constants, so there should be no need for pcre2? strstr() should be sufficient?
1) Initial checkin of cookbook with numerous code examples. 2) Integration of libfyaml and a regex library for use in reading RISCV-Config YAML configuration files (for configuration of the Golden Model).
aa9a220
to
64631b2
Compare
It should also be documented explicitly that the "validated" yaml generated by riscv-config should be supplied as input to the simulator in the command line. To check whether the yaml is a "validated" yaml, one can look for the "fields" node under any csr. This node is added after validation. Maybe there is a need to add an additional field at the root level of the yaml schema to indicate that it is a validated yaml or we should check for the existence of a comment in the yaml? Thoughts @neelgala? |
the model. Sail code compiles and executes as expected.
…s examples. model compiles and runs
…ine_switch_experimental
…ook). assembly define was inconsistent with Sail implementation
Don’t create unnecessary merge commits, rebase your branch, otherwise the history becomes a mess |
This is making even more of a mess of the history; please don't |
I don't really like the approach of letting Sail code just blindly read values from a YAML file by path. It isn't type checked and it means we're going to end up with YAML path strings scattered all over the codebase. Not a very robust approach in my experience. I would suggest taking the riscv-config YAML schema and using it to generate a proper Sail type that represents the configuration of the model. The schema contains default values so I think we will need to use it anyway. This probably isn't as simple as I've made it sound for a few reasons:
To get the actual config value into the Sail model we can autogenerate code that calls platform callbacks similar to what you have done here manually. So the final solutions would look something like this:
What do you think? This is fairly high priority for us so I may have a go at prototyping it (no promises though!). |
Also we should definitely parse the ISA string properly rather than hacking it with a regex. Not adding another dependency would be nice too. |
I was also thinking that the right way to go is to essentially generate Sail from the config yaml, rather than consume the yaml directly. There are a few ergonomic problems with that still, so I think we might need a few additional language features to support that nicely. The schema is a bit more problematic. We need the schema in Sail as it defines the envelope of permitted architectural state, but its current form is an ad-hoc python specific yaml schema library which we can't easily use. When I investigated possible existing schema options none seemed like a good fit:
So yeah, I'm not sure what we can do on the schema side of things. |
Let me make sure I understand what you're proposing. It seems like
you might be missing part of the problem.
1. Take the schema YAML file and convert it, via a 'generate_config'
script, into a Sail file (riscv_config.sail) which would get compiled
into the model. This
gives us a representation of the legal values allowed in the model.
It doesn't give us the *actual* values, just the allowed values. This
is in the form of a Sail struct, which can be read like any other
struct.
Yes?
2. Here's the missing part: where is the user's YAML config file loaded?
These are the actual values of the user's configuration and the ones we
want to use for configuration. (The schema file just gives us what the
legal options are. It says nothing about the actual values.)
3. I don't know what init_config() does. Is it supposed to load the
user's
YAML file and legalize the values?
Bill Mc.
…On Wed, Nov 15, 2023 at 4:50 AM Tim Hutt ***@***.***> wrote:
Also we should definitely parse the ISA string properly rather than
hacking it with a regex. Not adding another dependency would be nice too.
—
Reply to this email directly, view it on GitHub
<#175 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXROLOBOJ7BHLYN2DHERV5DYES3B5AVCNFSM56TXHS42U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBRGI2DQMJWGA2A>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Bill McSpadden
Formal Verification Engineer
RISC-V International
mobile: 503-807-9309
|
Several comments on Alasdair's response:
1. I don't think it's important that the schema be sucked into the
Sail model. It can be assumed that a user's config YAML file is legal
based on the tooling of RISCV-Config. There is a python script that
checks the legality of a user's config file.
2. ASN.1 has been proposed as the format for a platform's runtime
"unified discovery". I do not believe it has been ratified yet. The
technical working group (tech-config) has gone through a bit of a
thrash over the past several years and I'm not sure they're any
closer to having a ratified spec. (I attended the meetings for several
years until they started meeting in the middle of the night, my time.)
I don't know of any other place where ASN.1 is being used.
3. I very much agree that having Sail read the config file natively is
the right solution. However, in the meantime, we need a solution
that gets us moving. (I'd offer to work on the native support, but I
think this is a language problem. And I'm not a language guy. I'm
sure I'd get it wrong.)
Bill Mc.
…On Wed, Nov 15, 2023 at 6:51 AM Bill McSpadden ***@***.***> wrote:
Let me make sure I understand what you're proposing. It seems like
you might be missing part of the problem.
1. Take the schema YAML file and convert it, via a 'generate_config'
script, into a Sail file (riscv_config.sail) which would get compiled
into the model. This
gives us a representation of the legal values allowed in the model.
It doesn't give us the *actual* values, just the allowed values. This
is in the form of a Sail struct, which can be read like any other
struct.
Yes?
2. Here's the missing part: where is the user's YAML config file
loaded?
These are the actual values of the user's configuration and the ones we
want to use for configuration. (The schema file just gives us what
the
legal options are. It says nothing about the actual values.)
3. I don't know what init_config() does. Is it supposed to load the
user's
YAML file and legalize the values?
Bill Mc.
On Wed, Nov 15, 2023 at 4:50 AM Tim Hutt ***@***.***> wrote:
> Also we should definitely parse the ISA string properly rather than
> hacking it with a regex. Not adding another dependency would be nice too.
>
> —
> Reply to this email directly, view it on GitHub
> <#175 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AXROLOBOJ7BHLYN2DHERV5DYES3B5AVCNFSM56TXHS42U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBRGI2DQMJWGA2A>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
--
Bill McSpadden
Formal Verification Engineer
RISC-V International
mobile: 503-807-9309
--
Bill McSpadden
Formal Verification Engineer
RISC-V International
mobile: 503-807-9309
|
More responses to Tim's comments:
- We don't want to autogenerate code derived from a user's YAML file.
This would be a burden on the user. We already have many complaints
about the difficulty of compiling and using the Sail model. I want to
distribute the Sail model as a binary and have the model read in the
user's config file.
- I don't know how to get around the problem of using YAML paths.
There is an inherent hierarchy in the structure of RISC-V features.
RISCV-Config codifies this. It may not be the best codification, but
it exists.
- Parsing the ISA string. Jessica also complained about using a regex
to examine the ISA string in another PR. And yes, adding another
dependency sucks. However, I was pretty certain we're going to need
regex functionality in other places as well (say, for reading range
values,
which YAML doesn't support), so I went ahead and added it in.
Bill Mc.
…On Wed, Nov 15, 2023 at 4:50 AM Tim Hutt ***@***.***> wrote:
Also we should definitely parse the ISA string properly rather than
hacking it with a regex. Not adding another dependency would be nice too.
—
Reply to this email directly, view it on GitHub
<#175 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXROLOBOJ7BHLYN2DHERV5DYES3B5AVCNFSM56TXHS42U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBRGI2DQMJWGA2A>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Bill McSpadden
Formal Verification Engineer
RISC-V International
mobile: 503-807-9309
|
In the narrow case where we just generate an emulator this is true, but for some of the other use cases we have like theorem proving/verification and symbolic execution we need to work with the model w.r.t. an arbitrary (but still legal!) configuration, so we need the Sail to have a notion of what an arbitrary legal configuration is. |
OK. Got it.
Bill Mc.
…On Wed, Nov 15, 2023 at 8:23 AM Alasdair Armstrong ***@***.***> wrote:
I don't think it's important that the schema be sucked into the
Sail model. It can be assumed that a user's config YAML file is legal
based on the tooling of RISCV-Config. There is a python script that
checks the legality of a user's config file.
In the narrow case where we just generate an emulator this is true, but
for some of the other use cases we have like theorem proving/verification
and symbolic execution we need to work with the model w.r.t. an arbitrary
(but still legal!) configuration, so we need the Sail to have a notion of
what an arbitrary legal configuration is.
—
Reply to this email directly, view it on GitHub
<#175 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXROLOBLSWXXAEMCNXGGWO3YETT7FAVCNFSM56TXHS42U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBRGI4DKMZUGMYQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Bill McSpadden
Formal Verification Engineer
RISC-V International
mobile: 503-807-9309
|
There was talk of writing an ISA string parser in C for portability, was there any progress on this? Otherwise it might be a fun weekend project I could do |
No progress on that front.
Spike has an implementation written in C++. If memory serves, it was
mostly C,
nothing particularly "C++" about it.
Bill Mc.
…On Wed, Nov 15, 2023 at 9:16 AM Alasdair Armstrong ***@***.***> wrote:
There was talk of writing an ISA string parser in C for portability, was
there any progress on this? Otherwise it might be a fun weekend project I
could do
—
Reply to this email directly, view it on GitHub
<#175 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXROLOBTLOQPD7X5BMMS5OLYET2FXAVCNFSM56TXHS42U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBRGI4TIMZYGY4A>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Bill McSpadden
Formal Verification Engineer
RISC-V International
mobile: 503-807-9309
|
@billmcspadden-riscv Only the YAML schema file would be used to generate Sail code. The user's specific @Alasdair can you give an example of the way in which the Sail model needs to know that the config is legal? Do you just mean on a type level (i.e. the spec version can't be I wonder if it is possible to parse the ISA string in Sail. |
Most of the YAML is actually pretty simple: does something exists or not ==
a Boolean.
This completely breaks down when it comes to CSRs (which can exist or not
also) primarily - probably only - because of the concepts of WARL fields.
From simplest to (perhaps ) more complex:
The simplest cases of WARL fields are bitmasked fields, where any bit can
be 0, 1, or be writable to either 0 or 1.
Or they might be an enum, with a set of legal values.
Or they might be an enum with a set of legal ranges.
They can be combinations of the all above at arbitrary bit boundaries -
that's a bit more complicated (e.g. lower N bits must be zero, upper 64-N
bits must be a signed value with some range)
They can be combinations of that with different bit boundaries, or
different values, that are dependent on other architectural state or values
(yes, some of those are defined in the architecture!).
Finally for all of these, if an illegal value is written, there must be a
mapping from illegal->legal value which is completely, utterly
implementation defined (except it must be deterministic)
The simplest - and what I recommend - is that the attempt to write is
ignored and the previous legal value is retained.
The YAML schema also allows the largest, smallest, closest larger, and
closest smaller value be used (with various options in case of a tie), but
the WARL definition allows a rather infinite range of mappings.
Finally, when the legal value is dependent on other architectural state or
values, and those state variables change to make the current legal value
illegal, that behavior must be described
The YAML schema is designed to allow all of the above, and that's just the
set of behaviors we could conceive; a legal implementation could do
something else
(and if that happens, they'll just have to file a wair for any tests they
fail)
So, I don't think YAML is the problem. Each CSR for each implementation is
genuinely a different type, from the point of view of the Sail model.
IF that's the case, we can't distribute a single Sail model, but it has to
be a different model for each individual implementation.
This is something that doesn't play well with strong typing, and I don't
see how this can be encapsulated inside a single distribution of the Sail
model,
as opposed to some per-CSR legalization function that can interpret a data
structure defining the type - be that YAML or ASN.1 or something that I'm
not conceiving.
Ideally, that function is written in Sail, and that, as Tim says, means
shipping not just the Sail C-model, but the Sail compiler and a YAML->Sail
compiler.
I suppose some subset of Sail that just compiles types might simplify
things, but that's above my pay grade,and is still another dependency or
two.
…On Wed, Nov 15, 2023 at 10:18 AM Tim Hutt ***@***.***> wrote:
@billmcspadden-riscv <https://github.com/billmcspadden-riscv>
init_config() would read the user's YAML file via FFI callbacks (
rv_cfg_string() in the example).
Only the YAML *schema* file would be used to generate Sail code. The
user's specific isa.yaml would be read at runtime.
@Alasdair <https://github.com/Alasdair> can you give an example of the
way in which the Sail model needs to know that the config is legal? Do you
just mean on a type level (i.e. the spec version can't be "brocolli"), or
in a more constrained way ("if User or Supervisor mode are implemented than
foo must be read-only" or whatever).
I wonder if it is possible to parse the ISA string in Sail.
—
Reply to this email directly, view it on GitHub
<#175 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHPXVJTQYI6XYGZWXWX36NLYEUBNXAVCNFSM56TXHS42U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBRGMYDGMBQGY3Q>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Had a quick go at this. Sail's not really the right language for this but it's not too bad. It does allocate a new string for every
Output:
|
On Wed, Nov 15, 2023 at 1:13 PM Tim Hutt ***@***.***> wrote:
Had a quick go at this. Sail's not really the right language for this but
it's not too bad. It does allocate a new string for every string_drop()
in the C code, so this is horribly inefficient (N^2) but that doesn't
really matter for a string that's like 100 characters at most.
Have you seen the list of extensions have been ratified so far?
There are currently more than 100 of them, and they're mostly not a single
character.
… Message ID: ***@***.***>
|
Toolchains take -march as a lowercase string, so that should definitely be supported. Probably it should be parsed case-insensitively so people can use uppercase strings, which seem more common in the hardware world (and written prose). |
I wrote a thing, see: https://github.com/Alasdair/rv-isa-string-parse/blob/main/src/rv_isa_string_parser.h and https://github.com/Alasdair/rv-isa-string-parse/blob/main/src/rv_isa_string_parser.c There's also a little program in that repository that builds a small executable you can play with on the command line:
it should chunk the ISA string into it's various extensions, while handling version numbers and case-sensitivity correctly. Some validation is performed, but not everything. The ISA manual uses 'should' and 'must' ambiguously for some parts of the ISA string parsing, so it's unclear how strictly order should really be enforced between the components. The ambiguity around the 'p' extension and 'p' in version numbers is also handled as per the manual. I looked at the spike source, and it's quite C++. It also seems to only support extensions spike knows about, whereas the above will happily parse anything custom you want like Handling the additional logic for extensions that imply other extensions is currently left as an exercise for the reader 😛 |
Lots of good comments.
It's O(N^2) in the length of the ISA string, not the length of possible ISA strings. If the O(N^2) performance did become a problem it could be fixed in Sail e.g. by reference counting strings.
Yeah I omitted case insensitivity since it was just a PoC and is trivial to handle. The spec does say that it is case insensitive, however as you said toolchains require lowercase, and
This is great, but it means you need to also write it in OCaml and add FFI to get the information into Sail. That was mainly what I was trying to avoid by writing the parser in Sail.
Does validation of the format itself really need to be performed at all? I think I would leave that to
Yeah very annoying - see riscv/riscv-isa-manual#1144 Anyway I think I may have derailed the discussion a bit! The main conclusion is that we should parse the ISA string in some way other than regex. I think the core of the issue which is how do we represent the config in Sail, particularly the many many CSRs, given that the schema gives a different type for each one. |
I made a discussion to continue to discuss the ISA string parsing if anyone wants to: #347 |
This Pull Request will probably not be ratified on the first go-round,
but we need to start discussing it because it introduces some new
functionality.