Skip to content

Commit 55dbf04

Browse files
Merge commit '02ccf9e5d066fbb8132ba712314558da974c3601'
2 parents bd7f1d0 + 02ccf9e commit 55dbf04

File tree

352 files changed

+8290
-4336
lines changed

Some content is hidden

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

352 files changed

+8290
-4336
lines changed

pythondata_cpu_ibex/system_verilog/.gitignore

-13
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,6 @@ ibex_simple_system_pcount.csv
1818
# Python cache files
1919
__pycache__
2020

21-
# This is generated by VCS when running DV simulations with WAVE=1.
22-
/dv/uvm/core_ibex/ucli.key
23-
24-
# This is generated by UVM when running simulations and doesn't seem
25-
# to be something you can disable.
26-
/dv/uvm/core_ibex/tr_db.log
27-
28-
# This is the default output directory in dv/uvm/core_ibex and
29-
# contains auto-generated files from building and running tests.
30-
/dv/uvm/core_ibex/out
31-
3221
# This is generated by Questa tool when running DV simulations
3322
modelsim.ini
3423

35-
# This is generated by Xcelium when running DV simulations, even with WAVE=0
36-
/dv/uvm/core_ibex/waves.shm

pythondata_cpu_ibex/system_verilog/__init__.py

Whitespace-only changes.

pythondata_cpu_ibex/system_verilog/ci/ibex-rtl-ci-steps.yml

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ steps:
6767
displayName: Run RISC-V Compliance test for Ibex RV32IMC for ${{ config }}
6868
6969
- bash: |
70+
source ci/setup-cosim.sh
7071
# Build simple system with co-simulation
7172
fusesoc --cores-root=. run --target=sim --setup --build lowrisc:ibex:ibex_simple_system_cosim $IBEX_CONFIG_OPTS
7273

pythondata_cpu_ibex/system_verilog/ci/install-build-deps.sh

+26-20
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ case "$ID-$VERSION_ID" in
3333
$SUDO_CMD apt-get update
3434

3535
# Make spike-cosim repository available
36-
curl -Ls https://download.opensuse.org/repositories/home:gac_lowrisc/xUbuntu_18.04/Release.key | $SUDO_CMD apt-key add -
37-
$SUDO_CMD sh -c "echo 'deb http://download.opensuse.org/repositories/home:/gac_lowrisc/xUbuntu_18.04/ /' > /etc/apt/sources.list.d/spike-cosim.list" sudo apt update
38-
$SUDO_CMD apt-get update
36+
#curl -Ls https://download.opensuse.org/repositories/home:gac_lowrisc/xUbuntu_18.04/Release.key | $SUDO_CMD apt-key add -
37+
#$SUDO_CMD sh -c "echo 'deb http://download.opensuse.org/repositories/home:/gac_lowrisc/xUbuntu_18.04/ /' > /etc/apt/sources.list.d/spike-cosim.list" sudo apt update
38+
#$SUDO_CMD apt-get update
3939

4040
# Packaged dependencies
4141
# Install python3-yaml through apt to get a version with libyaml bindings,
@@ -58,28 +58,34 @@ case "$ID-$VERSION_ID" in
5858
bison \
5959
libelf-dev \
6060
clang-format \
61+
wget \
6162
"verilator-$VERILATOR_VERSION" \
62-
"ibex-cosim-$IBEX_COSIM_VERSION" \
6363
xz-utils
6464

65-
# Python dependencies
66-
#
67-
# Updating pip and setuptools is required to have these tools properly
68-
# parse Python-version metadata, which some packages uses to specify that
69-
# an older version of a package must be used for a certain Python version.
70-
# If that information is not read, pip installs the latest version, which
71-
# then fails to run.
72-
$SUDO_CMD pip3 install -U pip setuptools
65+
wget https://storage.googleapis.com/ibex-cosim-builds/ibex-cosim-$IBEX_COSIM_VERSION.tar.gz
66+
$SUDO_CMD mkdir -p /tools/riscv-isa-sim
67+
$SUDO_CMD chmod 777 /tools/riscv-isa-sim
68+
$SUDO_CMD tar -C /tools/riscv-isa-sim -xvzf ibex-cosim-$IBEX_COSIM_VERSION.tar.gz --strip-components=1
69+
echo "##vso[task.prependpath]/tools/riscv-isa-sim/bin"
70+
71+
# Python dependencies
72+
#
73+
# Updating pip and setuptools is required to have these tools properly
74+
# parse Python-version metadata, which some packages uses to specify that
75+
# an older version of a package must be used for a certain Python version.
76+
# If that information is not read, pip installs the latest version, which
77+
# then fails to run.
78+
$SUDO_CMD pip3 install -U pip setuptools
7379

74-
$SUDO_CMD pip3 install -r python-requirements.txt
80+
$SUDO_CMD pip3 install -r python-requirements.txt
7581

76-
# Install Verible
77-
mkdir -p build/verible
78-
cd build/verible
79-
curl -Ls -o verible.tar.gz "https://github.com/google/verible/releases/download/$VERIBLE_VERSION/verible-$VERIBLE_VERSION-Ubuntu-$VERSION_ID-$VERSION_CODENAME-x86_64.tar.gz"
80-
$SUDO_CMD mkdir -p /tools/verible && $SUDO_CMD chmod 777 /tools/verible
81-
tar -C /tools/verible -xf verible.tar.gz --strip-components=1
82-
echo "##vso[task.prependpath]/tools/verible/bin"
82+
# Install Verible
83+
mkdir -p build/verible
84+
cd build/verible
85+
curl -Ls -o verible.tar.gz "https://github.com/google/verible/releases/download/$VERIBLE_VERSION/verible-$VERIBLE_VERSION-Ubuntu-$VERSION_ID-$VERSION_CODENAME-x86_64.tar.gz"
86+
$SUDO_CMD mkdir -p /tools/verible && $SUDO_CMD chmod 777 /tools/verible
87+
tar -C /tools/verible -xf verible.tar.gz --strip-components=1
88+
echo "##vso[task.prependpath]/tools/verible/bin"
8389
;;
8490

8591
*)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
export PKG_CONFIG_PATH=/tools/riscv-isa-sim/lib/pkgconfig:$PATH

pythondata_cpu_ibex/system_verilog/ci/vars.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
# end up as float otherwise).
88
variables:
99
VERILATOR_VERSION: "4.104"
10-
IBEX_COSIM_VERSION: "0.2"
10+
IBEX_COSIM_VERSION: "9b68f2f9"
1111
RISCV_TOOLCHAIN_TAR_VERSION: "20220210-1"
1212
RISCV_TOOLCHAIN_TAR_VARIANT: "lowrisc-toolchain-gcc-rv32imcb"
1313
RISCV_COMPLIANCE_GIT_VERSION: "844c6660ef3f0d9b96957991109dfd80cc4938e2"
1414
VERIBLE_VERSION: "v0.0-2135-gb534c1fe"
1515
# lowRISC-internal version numbers of Ibex-specific Spike builds.
16-
SPIKE_IBEX_VERSION: "20220308-git-20a886cba76dd80a23b548743ab3c73b19f65e41"
16+
SPIKE_IBEX_VERSION: "20220817-git-eccdcb15c3e51b4f7906c7b42fb824f24a4338a2"

pythondata_cpu_ibex/system_verilog/doc/01_overview/compliance.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Ibex is a standards-compliant 32 bit RISC-V processor.
55
It follows these specifications:
66

77
* `RISC-V Instruction Set Manual, Volume I: User-Level ISA, document version 20190608-Base-Ratified (June 8, 2019) <https://github.com/riscv/riscv-isa-manual/releases/download/Ratified-IMFDQC-and-Priv-v1.11/riscv-spec-20190608.pdf>`_
8-
* `RISC-V Instruction Set Manual, Volume II: Privileged Architecture, document version 20190608-Base-Ratified (June 8, 2019) <https://github.com/riscv/riscv-isa-manual/releases/download/Ratified-IMFDQC-and-Priv-v1.11/riscv-privileged-20190608.pdf>`_.
9-
Ibex implements the Machine ISA version 1.11.
8+
* `RISC-V Instruction Set Manual, Volume II: Privileged Architecture, document version 20211203 (December 4, 2021) <https://github.com/riscv/riscv-isa-manual/releases/download/Priv-v1.12/riscv-privileged-20211203.pdf>`_.
9+
Ibex implements the Machine ISA version 1.12.
1010
* `RISC-V External Debug Support, version 0.13.2 <https://content.riscv.org/wp-content/uploads/2019/03/riscv-debug-release.pdf>`_
1111
* `RISC-V Bit-Manipulation Extension, version 1.0.0 <https://github.com/riscv/riscv-bitmanip/releases/download/1.0.0/bitmanip-1.0.0-38-g865e7a7.pdf>`_ and `version 0.93 (draft from January 10, 2021) <https://github.com/riscv/riscv-bitmanip/blob/master/bitmanip-0.93.pdf>`_
1212
* `PMP Enhancements for memory access and execution prevention on Machine mode (Smepmp) version 0.9.3 <https://github.com/riscv/riscv-tee/blob/61455747230a26002d741f64879dd78cc9689323/Smepmp/Smepmp.pdf>`_

pythondata_cpu_ibex/system_verilog/doc/03_reference/exception_interrupts.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ The possible ``mcause`` values for an internal interrupt as listed below:
8181
+-------------+-------------------------------------------------------------------------------------------------------------+
8282
| ``mcause`` | Description |
8383
+-------------+-------------------------------------------------------------------------------------------------------------+
84-
| 0xFFFFFFFE0 | Load integrity error internal interrupt. |
84+
| 0xFFFFFFE0 | Load integrity error internal interrupt. |
8585
| | Only generated when SecureIbex == 0. |
8686
| | ``mtval`` gives the faulting address. |
8787
| | The interrupt will be taken at most one instruction after the faulting load. |
8888
| | In particular a load or store immediately after a faulting load may execute before the interrupt is taken. |
8989
+-------------+-------------------------------------------------------------------------------------------------------------+
90-
| 0x80000001F | External NMI |
90+
| 0x8000001F | External NMI |
9191
+-------------+-------------------------------------------------------------------------------------------------------------+
9292

9393
Recoverable Non-Maskable Interrupt

pythondata_cpu_ibex/system_verilog/dv/cosim/spike_cosim.cc

+62-10
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333

3434
SpikeCosim::SpikeCosim(const std::string &isa_string, uint32_t start_pc,
3535
uint32_t start_mtvec, const std::string &trace_log_path,
36-
bool secure_ibex, bool icache_en)
36+
bool secure_ibex, bool icache_en,
37+
uint32_t pmp_num_regions, uint32_t pmp_granularity)
3738
: nmi_mode(false), pending_iside_error(false) {
3839
FILE *log_file = nullptr;
3940
if (trace_log_path.length() != 0) {
@@ -52,11 +53,11 @@ SpikeCosim::SpikeCosim(const std::string &isa_string, uint32_t start_pc,
5253
isa_parser.get(), DEFAULT_VARCH, this, 0, false, log_file, std::cerr);
5354
#endif
5455

56+
processor->set_pmp_num(pmp_num_regions);
57+
processor->set_pmp_granularity(1 << (pmp_granularity + 2));
5558
processor->set_ibex_flags(secure_ibex, icache_en);
5659

57-
processor->set_mmu_capability(IMPL_MMU_SBARE);
58-
processor->get_state()->pc = start_pc;
59-
processor->get_state()->mtvec->write(start_mtvec);
60+
initial_proc_setup(start_pc, start_mtvec);
6061

6162
if (log) {
6263
processor->set_debug(true);
@@ -437,6 +438,21 @@ void SpikeCosim::leave_nmi_mode() {
437438
#endif
438439
}
439440

441+
void SpikeCosim::initial_proc_setup(uint32_t start_pc, uint32_t start_mtvec) {
442+
processor->get_state()->pc = start_pc;
443+
processor->get_state()->mtvec->write(start_mtvec);
444+
445+
processor->get_state()->csrmap[CSR_MARCHID] =
446+
std::make_shared<const_csr_t>(processor.get(), CSR_MARCHID, IBEX_MARCHID);
447+
448+
processor->set_mmu_capability(IMPL_MMU_SBARE);
449+
450+
for (int i = 0; i < processor->TM.count(); ++i) {
451+
processor->TM.tdata2_write(processor.get(), i, 0);
452+
processor->TM.tdata1_write(processor.get(), i, 0x28001048);
453+
}
454+
}
455+
440456
void SpikeCosim::set_mip(uint32_t mip) {
441457
processor->get_state()->mip->write_with_mask(0xffffffff, mip);
442458
}
@@ -461,11 +477,29 @@ void SpikeCosim::set_debug_req(bool debug_req) {
461477
}
462478

463479
void SpikeCosim::set_mcycle(uint64_t mcycle) {
464-
// TODO: Spike decrements mcycle on write to hack around an issue it has with
465-
// correctly writing minstret. Preferably this write would use a backdoor
466-
// access and avoid that decrement but backdoor access isn't part of the
467-
// public CSR interface.
468-
processor->get_state()->mcycle->write(mcycle + 1);
480+
uint32_t upper_mcycle = mcycle >> 32;
481+
uint32_t lower_mcycle = mcycle & 0xffffffff;
482+
483+
// Spike decrements the MCYCLE CSR when you write to it to hack around an
484+
// issue it has with incorrectly setting minstret/mcycle when there's an
485+
// explicit write to them. There's no backdoor write available via the public
486+
// interface to skip this. To complicate matters we can only write 32 bits at
487+
// a time and get a decrement each time.
488+
489+
// Write the lower half first, incremented twice due to the double decrement
490+
processor->get_state()->csrmap[CSR_MCYCLE]->write(lower_mcycle + 2);
491+
492+
if ((processor->get_state()->csrmap[CSR_MCYCLE]->read() & 0xffffffff) == 0) {
493+
// If the lower half is 0 at this point then the upper half will get
494+
// decremented, so increment it first.
495+
upper_mcycle++;
496+
}
497+
498+
// Set the upper half
499+
processor->get_state()->csrmap[CSR_MCYCLEH]->write(upper_mcycle);
500+
501+
// TODO: Do a neater job of this, a more recent spike release should allow us
502+
// to write all 64 bits at once at least.
469503
}
470504

471505
void SpikeCosim::set_csr(const int csr_num, const uint32_t new_val) {
@@ -500,7 +534,7 @@ void SpikeCosim::clear_errors() { errors.clear(); }
500534

501535
void SpikeCosim::fixup_csr(int csr_num, uint32_t csr_val) {
502536
switch (csr_num) {
503-
case CSR_MSTATUS:
537+
case CSR_MSTATUS: {
504538
reg_t mask =
505539
MSTATUS_MIE | MSTATUS_MPIE | MSTATUS_MPRV | MSTATUS_MPP | MSTATUS_TW;
506540

@@ -511,6 +545,24 @@ void SpikeCosim::fixup_csr(int csr_num, uint32_t csr_val) {
511545
processor->put_csr(csr_num, new_val);
512546
#endif
513547
break;
548+
}
549+
case CSR_MCAUSE: {
550+
uint32_t any_interrupt = csr_val & 0x80000000;
551+
uint32_t int_interrupt = csr_val & 0x40000000;
552+
553+
reg_t new_val = (csr_val & 0x0000001f) | any_interrupt;
554+
555+
if (any_interrupt && int_interrupt) {
556+
new_val |= 0x7fffffe0;
557+
}
558+
559+
#ifdef OLD_SPIKE
560+
processor->set_csr(csr_num, new_val);
561+
#else
562+
processor->put_csr(csr_num, new_val);
563+
#endif
564+
break;
565+
}
514566
}
515567
}
516568

pythondata_cpu_ibex/system_verilog/dv/cosim/spike_cosim.h

+12-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
#ifndef SPIKE_COSIM_H_
66
#define SPIKE_COSIM_H_
77

8+
#include <stdint.h>
9+
10+
#include <deque>
11+
#include <memory>
12+
#include <string>
13+
#include <vector>
14+
815
#include "cosim.h"
916
#include "riscv/devices.h"
1017
#include "riscv/log_file.h"
1118
#include "riscv/processor.h"
1219
#include "riscv/simif.h"
1320

14-
#include <stdint.h>
15-
#include <deque>
16-
#include <memory>
17-
#include <string>
18-
#include <vector>
21+
#define IBEX_MARCHID 22
1922

2023
class SpikeCosim : public simif_t, public Cosim {
2124
private:
@@ -66,12 +69,15 @@ class SpikeCosim : public simif_t, public Cosim {
6669

6770
void leave_nmi_mode();
6871

72+
void initial_proc_setup(uint32_t start_pc, uint32_t start_mtvec);
73+
6974
int insn_cnt;
7075

7176
public:
7277
SpikeCosim(const std::string &isa_string, uint32_t start_pc,
7378
uint32_t start_mtvec, const std::string &trace_log_path,
74-
bool secure_ibex, bool icache_en);
79+
bool secure_ibex, bool icache_en, uint32_t pmp_num_regions,
80+
uint32_t pmp_granularity);
7581

7682
// simif_t implementation
7783
virtual char *addr_to_mem(reg_t addr) override;

pythondata_cpu_ibex/system_verilog/dv/cs_registers/model/register_model.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ RegisterModel::RegisterModel(SimCtrl *sc, CSRParams *params) : simctrl_(sc) {
3333
}
3434
}
3535
// mcountinhibit
36-
// - MSBs are always 1: unused counters cannot be enabled
36+
// - MSBs are always 0: unused counters cannot be inhibited
3737
// - Bit 1 is always 0: time cannot be disabled
3838
uint32_t mcountinhibit_mask =
3939
(~((0x1 << params->MHPMCounterNum) - 1) << 3) | 0x2;
40-
uint32_t mcountinhibit_resval = ~((0x1 << params->MHPMCounterNum) - 1) << 3;
40+
uint32_t mcountinhibit_resval = 0;
4141
register_map_.push_back(std::make_unique<WARLRegister>(
4242
0x320, &register_map_, mcountinhibit_mask, mcountinhibit_resval));
4343
// Performance counter setup
4444
for (unsigned int i = 3; i < 32; i++) {
4545
uint32_t reg_addr = 0x320 + i;
4646
if (i < (params->MHPMCounterNum + 3)) {
4747
register_map_.push_back(std::make_unique<WARLRegister>(
48-
reg_addr, &register_map_, 0xFFFFFFFF, 0x1 << i));
48+
reg_addr, &register_map_, 0xFFFFFFFF, 0x1 << (i - 3)));
4949
} else {
5050
register_map_.push_back(
5151
std::make_unique<NonImpRegister>(reg_addr, &register_map_));

pythondata_cpu_ibex/system_verilog/dv/uvm/common_project_cfg.hjson

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
project: ibex
66

77
// These keys are expected by dvsim.py, so we have to set them to something.
8-
doc_server: bogus.doc.server
9-
results_server: bogus.results.server
8+
doc_server: bogus.doc.server
9+
results_server: bogus.results.server
10+
results_html_name: report.html
1011

1112
// Default directory structure for the output
1213
scratch_base_path: "{scratch_root}/{dut}.{flow}.{tool}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This is generated by VCS when running DV simulations with WAVE=1.
2+
ucli.key
3+
4+
# This is generated by UVM when running simulations and doesn't seem
5+
# to be something you can disable.
6+
tr_db.log
7+
8+
# This is the default output directory in dv/uvm/core_ibex and
9+
# contains auto-generated files from building and running tests.
10+
out
11+
12+
# This is generated by the Makefile based on the ibex configuration
13+
riscv_dv_extension/riscv_core_setting.sv
14+
15+
# This is generated by Xcelium when running DV simulations, even with WAVE=0
16+
waves.shm
17+
18+
# Log files generated by Cadence tools when running DV simulations
19+
xrun.history
20+
xrun.log
21+
xmsc.log
22+
23+
# Generated by coverage
24+
imc.key
25+
mdv.log

0 commit comments

Comments
 (0)