-
Notifications
You must be signed in to change notification settings - Fork 188
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 ad-hoc model configuration with Sail-native configuration #758
base: master
Are you sure you want to change the base?
Conversation
0e08c2e
to
f5e8f41
Compare
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 is fantastic.
@@ -431,6 +304,12 @@ static int process_args(int argc, char **argv) | |||
break; | |||
} | |||
} | |||
|
|||
if (!have_config) { | |||
fprintf(stderr, "No configuration file provided.\n"); |
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.
I think it might be nice to have default.json
built-in and used by default? We can probably just embed it as a string literal in a header or whatever.
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.
Does CMake have a built in way to do that?
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.
Could probably do this using objcopy or .incbin although that isn't too portable. I imagine a custom_command() that runs something like:
(echo 'extern "C" const char default_data[] = R"(' && ${CMAKE} -E cat ${CMAKE_SOURCE_DIR}/default.json && echo ')";')> file.cc
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.
Not in an especially nice way but something like this might work I guess? I think @arichardson has the misfortune of being more of a CMake expert than me.
file(READ "default.json" DEFAULT_JSON)
configure_file("default_json.h.in" "default_json.h" ESCAPE_QUOTES @ONLY)
# Ensure this runs again if `default.json` is changed.
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "default_json.h.in")
// default_json.h.in
#pragma once
const char* DEFAULT_JSON = "@DEFAULT_JSON@";
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.
That avoids the need for c++ but I'm not sure if changes to default.json will be noticed by an incremental build without rerunning cmake.
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.
That's what the CMAKE_CONFIGURE_DEPENDS
does (in theory).
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.
Did not know about that! Sounds like the best solution then
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.
Though if we change the code to be C++ I would be in favour of just having it hard-coded as a string literal:
#pragma once
constexpr DEFAULT_JSON = r#"
...
"#;
Much simpler and still very easy to copy/paste if people want to use it as a base.
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.
I guess the advantage of having both the file and the builtin default is that you can pass the file with --config=. But if we add something like --print-default-config
you could run $(SIM) --config <($(SIM) --print-default-config) ...
.
I guess the main advantage of having it as a real file in the repository is that we can get syntax highlighting+json formatting in IDEs.
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.
So I think the suggestion in https://github.com/riscv/sail-riscv/pull/758/files#r1972488749 is probably best?
sail_config_key rom_size_key = {"platform", "rom", "size"}; | ||
if (rom_base != get_config_uint64(3, rom_base_key)) { | ||
fprintf(stderr, | ||
"Configuration value platform.rom.base does not match %" PRIu64 |
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.
Would be nice to print both values. Also I haven't followed the flow but why do you have to have two matching values?
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.
The way it used to work is it would set rv_rom_base
, overriding the default value in the configuration (such as it existed previously). Now it's just checking the configuration setting is correct, not sure if it's the best thing to do.
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.
Oh I see. The whole ROM/RAM thing is wrong anyway so maybe we should just not worry about it too much for now. Once this is merged we can easily add a proper PMA memory map.
Because passing in a configuration file is something we need to do every time, re-purpose the '-c' short option from the optional SAILCOV feature.
This is the first in a series of PRs (and probably patches to this PR) aiming to replace the ad-hoc C stubs used for configuration with a Sail-native configuration system using a separate configuration file. This is a draft PR as it needs a new release of Sail to work.
This PR is split into two commits:
-c
short option away from the sail coverage option, as it isn't even built in by default.rom_base
androm_size
is slightly different, in that it'll just print if the configuration values don't match what the C code that creates the reset vector and writes the DTB expect rather than setting the values.Note that this PR isn't aiming to add all the configuration we want for MC100 or beyond, it's just a direct port of existing functionality.
With this adding a new configurable option to the model is easy, add
config x.y.z : T
anywhere in the model, and then addx.y.z
into the JSON file, and it'll just work.TODOs: