aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2024-02-05Improve PMP supportTim Hutt17-297/+275
This implements a lot of missing functionality for PMPs. * Support 64 PMPs as well as 0 and 16. * Support setting PMP grain * Return correct address bits on read (some read as 0 or 1 depending on the grain and match type) * Unlock PMPs on reset * Implement pmpcfg WARL legalisation Co-authored-by: Ben Fletcher <benjamin.fletcher@codasip.com>
2024-02-05Rename string_of_int to dec_strTim Hutt9-21/+17
And string_of_bits to bits_str. These are the names that Sail uses so it makes sense to use them.
2024-02-01Simplify prelude.sail by including generic_equality.sail and mapping.sailTim Hutt7-863/+268
This change includes `generic_equality.sail` and `mapping.sail` from the Sail standard library which defines a lot of things that were defined in `prelude.sail`. I also removed `reg_deref` which is no longer required. The `mapping.sail` and `hex_bits.sail` files are in Sail 0.18 which is not yet released, so they have been temporarily copied here.
2024-01-31Update bitfield update syntaxAlasdair2-103/+83
Bitfields allow [<bitfield> with field = value], like bitvectors, so use that instead of the old-style `update_field` overloads.
2024-01-31Update bitfield syntaxAlasdair36-504/+506
Use newer bitfield syntax, which has been part of Sail for a while now. Should in theory be more efficient as it removes a level of indirection for bitfield accesses. It's also much more friendly to `sail -fmt`, which has no idea how to handle the old bitfield syntax.
2023-12-19lem: Fix issues created by vector extensionAlasdair8-699/+149
Switch to bitlist representation because the machine words can't handle the vector code currently Remove RMEM target from default set of targets in Makefile. This is only interesting for RMEM maintainers. There's no reason for it to be generated by default, and it's also broken. While we are hacking on these files purge the duplicate versions for Sail 0.11+
2023-12-19lem: Fix use of 'class' in riscv_insts_vext_utilsAlasdair1-24/+12
class is a reserved keyword in lem, so the use of class as a variable name was causing issues. While ultimately this should be fixed in Sail this can easily be worked around here. Fortunately the code in questions was ultimately using a pattern like let class = f(x); let y = match class { ... }; y which can be simplified to match f(x) { ... } removing the variable entirely, and making the code simpler so a win-win overall!
2023-12-12Update CODE_STYLE.mdAlasdair Armstrong1-0/+2
Add a line to CODE_STYLE.md saying that tabs should not be used Signed-off-by: Alasdair Armstrong <alasdair.armstrong@cl.cam.ac.uk>
2023-12-06Fix kext warningAlasdair1-13/+11
Use fixed-length vectors for AES tables Note that because we have `default Order dec`, Sail vectors are indexed the same as bitvectors, in decreasing order, hence why the indexing in sbox_lookup becomes ``` table[255 - unsigned(x)] ``` rather than ``` table[unsigned(x)] ``` The alternative would be to flip all the literals
2023-12-06Makefile: Set OPAMCLI to 2.0Alasdair1-0/+3
This removes the warning about `opam config var`. Setting OPAMCLI in this way is the correct thing to do if we want to continue supporting opam 2.0. If we decide to require opam 2.1+ then all `opam var` invocations should become `opam --cli=2.1 var`, as per the opam CLI versioning spec: https://github.com/ocaml/opam/wiki/Spec-for-opam-CLI-versioning
2023-12-06Remove effect annotations from vector extensionAlasdair6-79/+79
2023-11-29Make consistent operand namesPaul A. Clarke3-6/+6
There are a few places where operand/field names are not consistent across scattered definitions for an instruction. Here, parameter `rs2` is used for encode/decode and execute, but `rd` is used for the same purpose in the assembly clause: ``` mapping clause encdec_compressed = C_SWSP(ui76 @ ui52, rs2) <-> 0b110 @ ui52 : bits(4) @ ui76 : bits(2) @ rs2 : regidx @ 0b10 function clause execute (C_SWSP(uimm, rs2)) = { let imm : bits(12) = zero_extend(uimm @ 0b00); execute(STORE(imm, rs2, sp, WORD, false, false)) } mapping clause assembly = C_SWSP(uimm, rd) <-> "c.swsp" ^ spc() ^ reg_name(rd) ^ sep() ^ hex_bits_6(uimm) ``` Fix these by using the operand names found in "The RISC-V Instruction Set Manual, Volume I: Unprivileged ISA", document version 20191213, and "RISC-V Cryptography Extensions Volumn I: Scalar & Entropy Source Instructions", version v1.0.1.
2023-11-29Fix Store-Conditional assembly operand order and add parensPaul A. Clarke2-4/+4
The operand order for Store-Conditional assembly has the second and third operands reversed. The RISC-V Instruction Set Manual states: > ``` > SC.W conditionally writes a word in rs2 to the address in rs1 [...] > If the SC.W succeeds, the instruction writes the word in rs2 to memory, > and it writes zero to rd. If the SC.W fails, the instruction does not > write to memory, and it writes a nonzero value to rd. > ``` `rd` is for the return code, `rs2` is the value, and `rs1` is the memory address. For the syntax `sc.w A,B,(C)`: - `A` is where the result is stored, per convention. So, this is `rd`. - `B` is the value to be stored. So, this is `rs2`. - `C` is the address at which to store the value. So, this is `rs1`. The resulting syntax would be `stc.w rd,rs2,(rs1)`. The current assembly representation is: ``` "sc." ^ size_mnemonic(size) [...] reg_name(rd) ^ sep() ^ reg_name(rs1) ^ sep() ^ reg_name(rs2) ``` Note that the order is wrong. In addition, parentheses are missing around `rs2`. Fix this instance, as well as two other instances where parentheses are missing. Fixes #338. Fixes #344. Suggested-by: Tim Hutt <timothy.hutt@codasip.com>
2023-11-29Some simple CI housekeepingAlasdair2-6/+6
Update the versions of some of the Github actions, as some of the older action versions used parts of the github API that are deprecated and due to be removed.
2023-11-28Rewrite the implementation of vsetvli and vsetvl instructions to fix #337Xinlai Wan2-81/+98
The issue shows that the encoding and assembly definitions of vsetvl and vsetvli are incorrectly mixed together, but they actually differ a lot and therefore cannot have a unified definition as the old implementation did, so this section has been rewritten to split their definitions and executions. And because these instructions have similar functional behavior after the decoding stage, some common code is further extracted to be helper functions in this commit.
2023-11-13csim: Fix issue with trace_log FILE * in printfAlasdair1-1/+1
Fixes a warning introduced by commit 5725f3f
2023-11-10Use separators, not spaces, between operandsPaul A. Clarke1-40/+40
In `model/riscv_insts_zfa.sail`, there are quite a few cases where spaces (`spc()`) are utilized instead of separators (`sep()`) between operands: ``` mapping clause assembly = RISCV_FMAXM_D(rs2, rs1, rd) <-> "fmaxm.d" ^ spc() ^ freg_name(rd) ^ spc() ^ freg_name(rs1) ^ spc() ^ freg_name(rs2) ``` In the assembly representation, spaces are between the mnemonic and its operands, and separators are between operands. Fix the errant cases. Signed-off-by: Paul A. Clarke <pclarke@ventanamicro.com>
2023-10-25Remove duplicate shift definitionsTim Hutt2-44/+6
SHIFTW and SHIFTIWOP were duplicated. This did not cause any harm except that the disassembly for the SHIFTW version was incorrect. Therefore I removed that version. The `execute()` functions were identical but the SHIFTW version is slightly neater (only one `[31..0]`) so I applied that to the SHIFTIWOP version. This should cause no functional changes to the model except that the disassembly will have the extra `w` which is correct.
2023-10-25Simplify softfloat interface by removing write_fflagsTim Hutt9-108/+92
Instead of keeping a mirror register in sync with fflags, just return the new flags.
2023-10-17RISC-V Vector Extension SupportXinlai Wan28-11/+8547
This PR adds the following: General Framework and Configurations: * Introduced the V extension's general framework and configuration setting instructions. * Updated model/riscv_insts_vext_vset.sail and effect matching functions in riscv_vlen.sail. * Addressed code formatting issues and made revisions post the Nov 22 meeting. * Co-authored by Nicolas Brunie and Jessica Clarke. Vector Load/Store Instructions: * Integrated vector load and store instructions. * Enhanced the implementation of SEW, LMUL, VLEN and removed real numbers from the code. * Updated vstart settings and removed unnecessary assert statements. * Rectified bugs in vleff instructions and overhauled coding styles. * Incorporated guards for vector encdec clauses and optimized memory access post vector load/store failures. Vector Integer/Fixed-Point Instructions: * Added vector integer/fixed-point arithmetic and mask instructions. * Improved vector EEW and EMUL checking functions and introduced illegal instruction check functions. * Fine-tuned code formatting for vector instruction checks. Vector Floating-Point Instructions: * Rolled out vector floating-point instructions and updated their conversion counterparts. * Refreshed copyright headers specific to the vector extension code. Vector Reduction and Mask Instructions: * Integrated vector mask and reduction instructions. * Addressed register overlap checks for vector mask instructions. Miscellaneous Enhancements and Fixes: * Updated vector CSR vtype.vill settings and judgements. * Systematized patterns for vector illegal instruction checks. * Rectified issues in vector load/store and reduction operations. * Purged redundant elements from the V extension code and vector floating-point functions. * Cleaned up softfloat makefiles and renamed EXTZ and EXTS within the V extension code. * Addressed a clang-format check issue and NaN boxing anomalies. Provided annotations for pending RVV configurations. * Initialized default VLEN value and set vlenb CSR. * Set constraints for vector variable initialization and added mstatus.VS settings specific to the vector extension.
2023-10-11Rename enable-fiom to enable-writable-fiomTim Hutt11-46/+46
This is a much clearer name because the option allows code to enable FIOM, it doesn't enable FIOM itself.
2023-10-11Implement menvcfgTim Hutt14-0/+104
This implements the m/senvcfg(h) CSRs. This CSR is used to enable/disable extensions and behaviours for lower privilege modes. Currently the only implemented bit is FIOM which affects how fences work. It also affects how atomic memory accesses work in non-cacheable regions, but the model does not currently support PMAs so that can't easily be implemented.
2023-10-10Fix lem build errorAlasdair1-1/+1
The speculate_conditional should be marked monadic. It would seem like the various _reservation functions should be also, but it seems like perhaps they are not implemented in lem right now.
2023-10-10Fix fmaxm.d definitionPaul A. Clarke1-1/+1
Likely a cut-and-paste error, the definition for fmaxm.d uses the fmaxm.s mnemonic, which is already used earlier in the same file.
2023-09-26Per section 3.1.1 of the Privileged Spec (Machine ISA Register misa): F/D ↵ahadali50001-3/+3
both should be disabled if F=0
2023-09-20Allow loading more than one ELF binaryAlex Richardson1-12/+21
This makes it easier to use a separate M-mode bootloader and kernel payload (e.g. OpenSBI fw_jump). It also makes it easier to test booting systems such as FreeBSD without bundling the kernel with the bootloader.
2023-09-20Refactor process_args to return the argv index instead of the valueAlex Richardson1-3/+8
This makes it possible for a follow-up commit to add logic that allows loading more than one ELF file (e.g. M-mode firmware and S-mode kernel).
2023-09-20Report the faulting virtual address in tvalAlex Richardson2-6/+6
In some cases we were reporting the translated value instead, but the privileged spec text requires the virtual address: ``` If mtval is written with a nonzero value when a breakpoint, address-misaligned, access-fault, or page-fault exception occurs on an instruction fetch, load, or store, then mtval will contain the faulting virtual address. ```
2023-09-12Remove effectsTim Hutt32-189/+189
Since Sail 0.15 (released Nov 2022), effects have had no effect. They now generate a deprecation warning. This commit removes all the effect annotations from the model, thus fixing the compiler warnings.
2023-09-12Remove non-existent function from overloadAlasdair1-2/+2
2023-09-12Remove redundant type annotations on w_pte & add explicit `var`.Tim Hutt3-5/+5
These are given on the previous line already. Sail does not let you change the type of a variable like Rust does. The `var` ensures this definitely refers to a local rather than global variable.
2023-09-12Fix some stray tabsTim Hutt2-4/+4
2023-09-12Add z3_problems to .gitignoreTim Hutt1-0/+1
This file seems to be created on every build.
2023-09-12Remove redundant _ match caseTim Hutt1-1/+0
2023-09-12Remove duplicate xor_vecTim Hutt1-2/+0
This is already provided by Sail.
2023-08-28If C cannot be disabled, all changes to misa must be suppressedahadali50001-15/+12
2023-08-28Avoid unnecessary empty lines when instruction tracing is onAlex Richardson1-2/+0
These empty lines don't add to the readability of the trace and in fact when trace redirection is enabled they result in lots of empty lines being printed to stderr which makes it impossible to read the OS boot messages.
2023-08-28Fix --help output for options without a short flagAlex Richardson1-1/+5
Previously --help printed the following: ``` -V --no-trace -� --trace-output -l --inst-limit ``` With the new change it is: ``` -V --no-trace --trace-output -l --inst-limit ```
2023-08-28csim: Allow redirecting trace output to a file using command line flagAlex Richardson3-29/+52
This is useful when booting an operating system with tracing enabled as it allows showing the printed messages on the terminal and storing the trace log to a separate file. All categorized trace messages are now redirected to the --trace-output file when passed. If this option is not gived, the current behaviour of using stdout is retained. Example usage: `./c_emulator/riscv_sim_RV64 -b os-boot/rv64-64mb.dtb --trace-output /dev/stderr os-boot/linux-rv64-64mb.bbl --trace-output /tmp/linux.log`
2023-08-01Rename EXTZ and EXTSAlasdair42-256/+256
Rename EXTZ to zero_extend and EXTS to sign_extend. Two main reasons for doing this - it means that the source more closely follows the descriptions in the documentation with more readable names, and EXTS and EXTZ are visually very close to each other with just the S and Z. They are also following an odd convention where they are ALLCAPS rather than snake_case like other functions in the spec. I think this convention comes from early Power specs in Sail, which influenced Sail MIPS and CHERI-MIPS, but I don't think it's a very good convention we should be keeping in sail-riscv
2023-07-04Adjust Makefile to only use posix options for sedBrian Campbell1-4/+10
Allows for (e.g.) BSD sed, which uses -i differently.
2023-06-27Add Sail documentation target to MakefileAlasdair1-0/+6
2023-06-19Add clang-format to the pre-commit hooksAlex Richardson1-0/+5
This formats the code with clang-format 15 since the pre-commit hook for clang-format 16 would require a newer version of pre-commit.
2023-06-19Update pre-commit-hooks versionAlex Richardson1-1/+2
The template that I used when adding it uses hooks from 2020. Update this to the latest version and add a minimum pre-commit version check to ensure we get sensible error messages rather than obscure failures. The minimum chosen here is 2.10 as that is the version shipping with Debian 11 and most other distributions have newer versions. If needed a newer version can always be installed using pip.
2023-06-15Run the pre-commit checks as part of CIAlex Richardson1-4/+6
Do this before installing sail or building the model to avoid wasting CI time if these basic checks are failing.
2023-06-15Run the pre-commit hook on all filesAlex Richardson28-115/+115
This strips trailing whitespace and fixes line endings. I had to add the *.dump files to the exclude list to avoid excessive changes, but ideally these would not be part of the repository since they can just be generated by running objdump manually.
2023-06-15Add a basic pre-commit hook and update CONTRIBUTING.mdAlex Richardson2-0/+16
Recommend installation of this basic pre-commit hook that ensures that all files are free of trailing whitespace and have a final newline. It also checks that no large files are added and that YAML files are valid.
2023-06-15Add a clang-format configuration and reformat C code (#261)Alexander Richardson11-236/+413
* Add a clang-format configuration and reformat C code From my testing it turns out the built-in WebKit style is the closest to the current style. I added a few config options to further reduce the diff and I think the current output looks reasonable. In the future it would be good to add a CI and pre-commit check to enforce that all C code is consistently formatted to reduce the need for reviewers to look for formatting issues. * Fix formatting of commented-out reservation debug code Use an empty-by-default macro instead of commented-out fprintf calls. This way clang-format can format the calls sensibly and it's easier to enable the debug prints. * Improve formatting of fprintf call in set_config_print() Clang-format does not like long string literals, so split this manually to format the call sensibly. * Fix formatting of function pointer typedef Clang-format gets this wrong `*` is part of the typedef. * Improve formatting of getopt_long call * Fix odd fprintf continuation by splitting long string literal
2023-06-12CODE_STYLE: Explicitly ban strings for non-textJessica Clarke1-0/+2
Apparently this needs stating and isn't obvious. Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com>
2023-05-31Fix build for Coq 8.17Michael Sammler1-1/+1