Skip to content

Commit 6d73375

Browse files
committed
Bump pythondata_cpu_minerva/sources subtree to d393a7b
Updated using 0.0.post155 from https://github.com/litex-hub/litex-data-auto
2 parents 4c93234 + d393a7b commit 6d73375

Some content is hidden

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

45 files changed

+2540
-2992
lines changed

pythondata_cpu_minerva/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
data_git_describe = "v0.0-139-gd393a7b"
2525
data_git_msg = """\
2626
commit d393a7b4367d2d2c1c5d26be03039cdee45010c0
27-
Author: Jean-François Nguyen <jf@jfng.fr>
27+
Author: Jean-François Nguyen <jf@jfng.fr>
2828
Date: Wed Feb 19 19:28:12 2025 +0100
2929
3030
gpr: remove unused d_{rp1,rp2}_en ports.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
AMARANTH_USE_YOSYS=builtin
2+
YOSYS=yowasp-yosys

pythondata_cpu_minerva/sources/.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
# Python
22
__pycache__/
3+
__pypackages__/
4+
dist/
35
/*.egg-info
46
/.eggs
57

8+
# pdm
9+
/.pdm-plugins
10+
/.pdm-python
11+
/.venv
12+
/pdm.lock
13+
614
# tests
7-
**/test/spec_*/
15+
tests/spec_*/
816
*.vcd
917
*.gtkw
1018

pythondata_cpu_minerva/sources/README.md

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,15 @@
22

33
## A 32-bit RISC-V soft processor
44

5-
Minerva is a CPU core that currently implements the [RISC-V][1] RV32IM instruction set. Its microarchitecture is described in plain Python code using the [Amaranth][2] toolbox.
5+
Minerva is a CPU core that implements the [RISC-V][1] `RV32IMZicsr` instruction set. Its microarchitecture is described in plain Python code using [Amaranth HDL][2].
66

77
### Quick start
88

9-
Minerva requires Python 3.7+ and [Amaranth][2]. Installation instructions for Amaranth can be found [here](https://amaranth-lang.org/docs/amaranth/latest/install.html).
9+
pipx install pdm
10+
pdm install
11+
pdm run python cli.py generate minerva.v
1012

11-
python setup.py install
12-
python cli.py generate > minerva.v
13-
14-
To use Minerva in its minimal configuration, you need to wire the following ports to `minerva_cpu`:
15-
16-
* `clk`
17-
* `rst`
18-
* `ibus__*`
19-
* `dbus__*`
20-
* `external_interrupt`
21-
* `timer_interrupt`
22-
* `software_interrupt`
13+
See `pdm run python cli.py -h` for more options.
2314

2415
### Features
2516

@@ -53,43 +44,27 @@ The following parameters can be used to configure the Minerva core.
5344
| `reset_address` | `0x00000000` | Reset vector address |
5445
| `with_icache` | `False` | Enable the instruction cache |
5546
| `icache_nways` | `1` | Number of ways in the instruction cache |
56-
| `icache_nlines` | `128` | Number of lines in the instruction cache |
47+
| `icache_nlines` | `32` | Number of lines in the instruction cache |
5748
| `icache_nwords` | `4` | Number of words in a line of the instruction cache |
5849
| `icache_base` | `0x00000000` | Base of the instruction cache address space |
5950
| `icache_limit` | `0x80000000` | Limit of the instruction cache address space |
6051
| `with_dcache` | `False` | Enable the data cache |
6152
| `dcache_nways` | `1` | Number of ways in the data cache |
62-
| `dcache_nlines` | `128` | Number of lines in the data cache |
53+
| `dcache_nlines` | `32` | Number of lines in the data cache |
6354
| `dcache_nwords` | `4` | Number of words in a line of the data cache |
6455
| `dcache_base` | `0x00000000` | Base of the data cache address space |
6556
| `dcache_limit` | `0x80000000` | Limit of the data cache address space |
57+
| `wrbuf_depth` | `8` | Depth of the write buffer FIFO |
6658
| `with_muldiv` | `False` | Enable RV32M support |
67-
| `with_debug` | `False` | Enable the Debug Module |
68-
| `with_trigger` | `False` | Enable the Trigger Module |
69-
| `nb_triggers` | `8` | Number of triggers |
7059
| `with_rvfi` | `False` | Enable the riscv-formal interface |
7160

72-
### Testing
73-
74-
A riscv-formal testbench for Minerva is available [here](https://github.com/jfng/riscv-formal/tree/minerva/cores/minerva).
75-
76-
### Possible improvements
77-
78-
In no particular order:
79-
80-
* RV64I
81-
* Floating Point Unit
82-
* Stateful branch prediction
83-
* MMU
84-
* ...
85-
86-
If you are interested in sponsoring new features or improvements, get in touch at contact [at] lambdaconcept.com .
61+
A riscv-formal testbench for Minerva is available [here](https://github.com/minerva-cpu/riscv-formal/tree/minerva/cores/minerva).
8762

8863
### License
8964

9065
Minerva is released under the permissive two-clause BSD license.
9166
See LICENSE file for full copyright and license information.
9267

9368
[1]: https://riscv.org/specifications/
94-
[2]: https://github.com/amaranth-lang/amaranth/
69+
[2]: https://amaranth-lang.org/
9570
[3]: https://github.com/m-labs/lm32/

pythondata_cpu_minerva/sources/cli.py

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,58 @@
11
import argparse
2-
import warnings
32
from amaranth import cli
3+
from amaranth.back import rtlil, cxxrtl, verilog
44

55
from minerva.core import Minerva
66

77

8+
__all__ = ["main"]
9+
10+
11+
def main_parser(parser=None):
12+
if parser is None:
13+
parser = argparse.ArgumentParser()
14+
15+
p_action = parser.add_subparsers(dest="action")
16+
17+
p_generate = p_action.add_parser("generate",
18+
help="generate RTLIL, Verilog or CXXRTL from the design")
19+
p_generate.add_argument("-t", "--type",
20+
dest="generate_type", metavar="LANGUAGE", choices=["il", "cc", "v"],
21+
help="generate LANGUAGE (il for RTLIL, v for Verilog, cc for CXXRTL; "
22+
"default: file extension of FILE, if given)")
23+
p_generate.add_argument("--no-src",
24+
dest="emit_src", default=True, action="store_false",
25+
help="suppress generation of source location attributes")
26+
p_generate.add_argument("generate_file",
27+
metavar="FILE", type=argparse.FileType("w"), nargs="?",
28+
help="write generated code to FILE")
29+
30+
return parser
31+
32+
33+
def main_runner(parser, args, design, name="top"):
34+
if args.action == "generate":
35+
generate_type = args.generate_type
36+
if generate_type is None and args.generate_file:
37+
if args.generate_file.name.endswith(".il"):
38+
generate_type = "il"
39+
if args.generate_file.name.endswith(".cc"):
40+
generate_type = "cc"
41+
if args.generate_file.name.endswith(".v"):
42+
generate_type = "v"
43+
if generate_type is None:
44+
parser.error("Unable to auto-detect language, specify explicitly with -t/--type")
45+
if generate_type == "il":
46+
output = rtlil.convert(design, name=name, emit_src=args.emit_src)
47+
if generate_type == "cc":
48+
output = cxxrtl.convert(design, name=name, emit_src=args.emit_src)
49+
if generate_type == "v":
50+
output = verilog.convert(design, name=name, emit_src=args.emit_src)
51+
if args.generate_file:
52+
args.generate_file.write(output)
53+
else:
54+
print(output)
55+
856
def main():
957
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
1058

@@ -21,12 +69,6 @@ def main():
2169
parser.add_argument("--with-muldiv",
2270
default=False, action="store_true",
2371
help="enable RV32M support")
24-
parser.add_argument("--with-debug",
25-
default=False, action="store_true",
26-
help="enable the Debug Module")
27-
parser.add_argument("--with-trigger",
28-
default=False, action="store_true",
29-
help="enable the Trigger Module")
3072
parser.add_argument("--with-rvfi",
3173
default=False, action="store_true",
3274
help="enable the riscv-formal interface")
@@ -68,50 +110,20 @@ def main():
68110
type=int, default=8,
69111
help="write buffer depth")
70112

71-
trigger_group = parser.add_argument_group("trigger options")
72-
trigger_group.add_argument("--nb-triggers",
73-
type=int, default=8,
74-
help="number of triggers")
75-
76-
cli.main_parser(parser)
113+
main_parser(parser)
77114

78115
args = parser.parse_args()
79116

80-
if args.with_debug and not args.with_trigger:
81-
warnings.warn("Support for hardware breakpoints requires --with-trigger")
82-
83117
cpu = Minerva(args.reset_addr,
84118
args.with_icache, args.icache_nways, args.icache_nlines, args.icache_nwords,
85119
args.icache_base, args.icache_limit,
86120
args.with_dcache, args.dcache_nways, args.dcache_nlines, args.dcache_nwords,
87121
args.dcache_base, args.dcache_limit,
88122
args.wrbuf_depth,
89123
args.with_muldiv,
90-
args.with_debug,
91-
args.with_trigger, args.nb_triggers,
92124
args.with_rvfi)
93125

94-
ports = [
95-
cpu.external_interrupt, cpu.timer_interrupt, cpu.software_interrupt,
96-
cpu.ibus.ack, cpu.ibus.adr, cpu.ibus.bte, cpu.ibus.cti, cpu.ibus.cyc, cpu.ibus.dat_r,
97-
cpu.ibus.dat_w, cpu.ibus.sel, cpu.ibus.stb, cpu.ibus.we, cpu.ibus.err,
98-
cpu.dbus.ack, cpu.dbus.adr, cpu.dbus.bte, cpu.dbus.cti, cpu.dbus.cyc, cpu.dbus.dat_r,
99-
cpu.dbus.dat_w, cpu.dbus.sel, cpu.dbus.stb, cpu.dbus.we, cpu.dbus.err
100-
]
101-
102-
if args.with_debug:
103-
ports += [cpu.jtag.tck, cpu.jtag.tdi, cpu.jtag.tdo, cpu.jtag.tms]
104-
105-
if args.with_rvfi:
106-
ports += [
107-
cpu.rvfi.valid, cpu.rvfi.order, cpu.rvfi.insn, cpu.rvfi.trap, cpu.rvfi.halt,
108-
cpu.rvfi.intr, cpu.rvfi.mode, cpu.rvfi.ixl, cpu.rvfi.rs1_addr, cpu.rvfi.rs2_addr,
109-
cpu.rvfi.rs1_rdata, cpu.rvfi.rs2_rdata, cpu.rvfi.rd_addr, cpu.rvfi.rd_wdata,
110-
cpu.rvfi.pc_rdata, cpu.rvfi.pc_wdata, cpu.rvfi.mem_addr, cpu.rvfi.mem_rmask,
111-
cpu.rvfi.mem_wmask, cpu.rvfi.mem_rdata, cpu.rvfi.mem_wdata
112-
]
113-
114-
cli.main_runner(parser, args, cpu, name="minerva_cpu", ports=ports)
126+
main_runner(parser, args, cpu, name="minerva_cpu")
115127

116128

117129
if __name__ == "__main__":
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from amaranth import *
2+
from amaranth.lib import wiring
3+
from amaranth.lib.wiring import In, Out
4+
5+
from amaranth_soc import wishbone
6+
7+
8+
__all__ = ["WishboneArbiter"]
9+
10+
11+
class WishboneArbiter(wiring.Component):
12+
bus: Out(wishbone.Signature(addr_width=30, data_width=32, granularity=8,
13+
features=("err", "cti", "bte")))
14+
15+
def __init__(self):
16+
self._port_map = dict()
17+
super().__init__()
18+
19+
def port(self, priority):
20+
if not isinstance(priority, int) or priority < 0:
21+
raise TypeError("Priority must be a non-negative integer, not '{!r}'"
22+
.format(priority))
23+
if priority in self._port_map:
24+
raise ValueError("Conflicting priority: '{!r}'".format(priority))
25+
port = wishbone.Interface(addr_width=30, data_width=32, granularity=8,
26+
features=("err", "cti", "bte"))
27+
self._port_map[priority] = port
28+
return port
29+
30+
def elaborate(self, platform):
31+
m = Module()
32+
33+
ports = [port for priority, port in sorted(self._port_map.items())]
34+
35+
req = Signal(len(ports))
36+
gnt = Signal.like(req)
37+
38+
with m.If(~self.bus.cyc):
39+
for i, port in enumerate(ports):
40+
m.d.sync += req[i].eq(port.cyc)
41+
42+
m.d.comb += gnt.eq(req & (-req)) # isolate rightmost 1-bit
43+
44+
bus_adr_mux = 0
45+
bus_dat_w_mux = 0
46+
bus_sel_mux = 0
47+
bus_cyc_mux = 0
48+
bus_stb_mux = 0
49+
bus_we_mux = 0
50+
bus_cti_mux = 0
51+
bus_bte_mux = 0
52+
53+
for i, port in enumerate(ports):
54+
bus_adr_mux |= Mux(gnt[i], port.adr, 0)
55+
bus_dat_w_mux |= Mux(gnt[i], port.dat_w, 0)
56+
bus_sel_mux |= Mux(gnt[i], port.sel, 0)
57+
bus_cyc_mux |= Mux(gnt[i], port.cyc, 0)
58+
bus_stb_mux |= Mux(gnt[i], port.stb, 0)
59+
bus_we_mux |= Mux(gnt[i], port.we, 0)
60+
bus_cti_mux |= Mux(gnt[i], port.cti, 0)
61+
bus_bte_mux |= Mux(gnt[i], port.bte, 0)
62+
63+
m.d.comb += [
64+
port.dat_r.eq(self.bus.dat_r),
65+
port.ack .eq(self.bus.ack & gnt[i]),
66+
port.err .eq(self.bus.err & gnt[i]),
67+
]
68+
69+
m.d.comb += [
70+
self.bus.adr .eq(bus_adr_mux),
71+
self.bus.dat_w.eq(bus_dat_w_mux),
72+
self.bus.sel .eq(bus_sel_mux),
73+
self.bus.cyc .eq(bus_cyc_mux),
74+
self.bus.stb .eq(bus_stb_mux),
75+
self.bus.we .eq(bus_we_mux),
76+
self.bus.cti .eq(bus_cti_mux),
77+
self.bus.bte .eq(bus_bte_mux),
78+
]
79+
80+
return m

0 commit comments

Comments
 (0)