microwatt.git
7 months agoignore /abc.history voxels_game
Jacob Lifshay [Thu, 5 Oct 2023 23:42:25 +0000 (16:42 -0700)]
ignore /abc.history

7 months agooptimize for speed
Jacob Lifshay [Thu, 5 Oct 2023 23:38:16 +0000 (16:38 -0700)]
optimize for speed

7 months agoswitch to world with libre-soc logo
Jacob Lifshay [Thu, 5 Oct 2023 03:59:18 +0000 (20:59 -0700)]
switch to world with libre-soc logo

7 months agoadd 3D voxels game
Jacob Lifshay [Sun, 1 Oct 2023 09:26:51 +0000 (02:26 -0700)]
add 3D voxels game

7 months agoMerge pull request #423 from nickg/fix-vunit
Michael Neuling [Sat, 30 Sep 2023 22:12:19 +0000 (09:12 +1100)]
Merge pull request #423 from nickg/fix-vunit

Fix compatibility with VUnit 5

7 months agoFix compatibility with latest VUnit release
Nick Gasson [Tue, 25 Apr 2023 20:27:42 +0000 (21:27 +0100)]
Fix compatibility with latest VUnit release

Signed-off-by: Nick Gasson <nick@nickg.me.uk>
7 months agoMerge pull request #420 from paulusmack/master
Paul Mackerras [Tue, 19 Sep 2023 06:22:07 +0000 (16:22 +1000)]
Merge pull request #420 from paulusmack/master

Various minor improvements

7 months agoMerge pull request #421 from paulusmack/fixes
Paul Mackerras [Tue, 19 Sep 2023 06:21:34 +0000 (16:21 +1000)]
Merge pull request #421 from paulusmack/fixes

Fix instruction logging

8 months agoicache: Fix instruction sent to log
Paul Mackerras [Sat, 16 Sep 2023 12:12:02 +0000 (22:12 +1000)]
icache: Fix instruction sent to log

Log the instruction read from the icache, not the instruction (if any)
being written to the icache.

Fixes: 6db626d24547 ("icache: Log 36 bits of instruction rather than 32")
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
8 months agoscripts/fmt_log: Update for recent changes
Paul Mackerras [Sat, 16 Sep 2023 10:44:53 +0000 (20:44 +1000)]
scripts/fmt_log: Update for recent changes

This updates fmt_log.c to account for the recent changes to
insn_type_t and to unit_t.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
8 months agoMerge pull request #419 from paulusmack/prefix
Paul Mackerras [Fri, 15 Sep 2023 05:01:46 +0000 (15:01 +1000)]
Merge pull request #419 from paulusmack/prefix

Add support for prefixed instructions

8 months agocore_debug: Add support for detecting writes to a memory address
Paul Mackerras [Mon, 28 Aug 2023 02:22:31 +0000 (12:22 +1000)]
core_debug: Add support for detecting writes to a memory address

This adds a new type of stop trigger for the log buffer which triggers
when any byte(s) of a specified doubleword of memory are written.
The trigger logic snoops the wishbone for writes to the address
specified and stops the log 256 cycles later (same as for the
instruction fetch address trigger).  The trigger address is a real
address and sees DMA writes from devices as well as stores done by the
CPU.

The mw_debug command has a new 'mtrig' subcommand to set the trigger
and query its state.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
8 months agoMakefile: Remove long micropython test from check_light
Paul Mackerras [Wed, 26 Jul 2023 06:31:05 +0000 (16:31 +1000)]
Makefile: Remove long micropython test from check_light

It takes a very long time, so remove it from the "light" check.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
8 months agodcache: Make reading of DTLB independent of d_in.valid
Paul Mackerras [Wed, 26 Jul 2023 05:49:12 +0000 (15:49 +1000)]
dcache: Make reading of DTLB independent of d_in.valid

This improves timing.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
8 months agodcache: Make r1.acks_pending independent of r1.state
Paul Mackerras [Wed, 19 Jan 2022 21:36:10 +0000 (08:36 +1100)]
dcache: Make r1.acks_pending independent of r1.state

With this, the logic that maintains r1.acks_pending operates in every
state based on r1.wb and wishbone_in, rather than only operating in
STORE_WAIT_ACK state.  This makes things a bit clearer and improves
timing slightly.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
8 months agoarty: Change shield I/O pin bus into individual signals
Paul Mackerras [Thu, 22 Apr 2021 05:37:09 +0000 (15:37 +1000)]
arty: Change shield I/O pin bus into individual signals

Make the shield I/O pins be individual signals rather than a bus in
order to avoid warnings on pins which don't have both a driver and a
receiver.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
8 months agoMerge pull request #404 from CodeConstruct:dev/gpio-interrupt
Paul Mackerras [Thu, 14 Sep 2023 23:29:51 +0000 (09:29 +1000)]
Merge pull request #404 from CodeConstruct:dev/gpio-interrupt

Interrupts for GPIO

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
8 months agoImplement byte reversal instructions
Paul Mackerras [Sat, 9 Sep 2023 12:14:03 +0000 (22:14 +1000)]
Implement byte reversal instructions

This implements the byte-reverse halfword, word and doubleword
instructions: brh, brw, and brd.  These instructions were added to the
ISA in version 3.1.  They use a new OP_BREV insn_type value.  The
logic for these instructions is implemented in logical.vhdl.

In order to avoid going over 64 insn_type values, OP_AND and OP_OR
were combined into OP_LOGIC, which is like OP_AND except that the RS
input can be inverted as well as the RB input.  The various forms of
OR instruction are then implemented using the identity

    a OR b = NOT (NOT a AND NOT b)

The 'is_signed' field of the instruction decode table is used to
indicate that RS should be inverted.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
8 months agoImplement set[n]bc[r] instructions
Paul Mackerras [Thu, 27 Jul 2023 04:58:09 +0000 (14:58 +1000)]
Implement set[n]bc[r] instructions

This implements the setbc, setnbc, setbcr and setnbcr instructions.
Because the insn_type_t type already has 64 elements, this uses the
existing OP_SETB for the new instructions, and has execute1 compute
different results depending on bits 6-9 of the instruction.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
10 months agotests: Add a test for prefixed instructions
Paul Mackerras [Wed, 5 Jul 2023 09:25:28 +0000 (19:25 +1000)]
tests: Add a test for prefixed instructions

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
10 months agoImplement interrupts for prefixed instructions
Paul Mackerras [Mon, 3 Jul 2023 08:19:38 +0000 (18:19 +1000)]
Implement interrupts for prefixed instructions

This arranges to generate an illegal instruction type program
interrupt for illegal prefixed instructions, that is, those where the
suffix is not a legal value given the prefix, or the prefix has a
reserved value in the subtype field.  This implementation doesn't
generate an interrupt for the invalid 8LS:D and MLS:D instruction
forms where R = 1 and RA != 0.  (In those cases it uses (RA) as the
addend, i.e. it ignores the R bit.)

This detects the case where the address of an instruction prefix is
equal mod 64 to 60, and generates an alignment interrupt in that case.

This also arranges to set bit 34 of SRR1 when an interrupt occurs due
to a prefixed instruction, for those interrupts where that is required
(i.e. trace, alignment, floating-point unavailable, data storage, data
segment, and most cases of program interrupt).

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
10 months agoDecode prefixed instructions
Paul Mackerras [Mon, 3 Jul 2023 02:32:43 +0000 (12:32 +1000)]
Decode prefixed instructions

This adds logic to do basic decoding of the prefixed instructions
defined in PowerISA v3.1B which are in the SFFS (Scalar Fixed plus
Floating-Point Subset) compliancy subset.  In PowerISA v3.1B SFFS,
there are 14 prefixed load/store instructions plus the prefixed no-op
instruction (pnop).  The prefixed load/store instructions all use an
extended version of D-form, which has an extra 18 bits of displacement
in the prefix, plus an 'R' bit which enables PC-relative addressing.

When decode1 sees an instruction word where the insn_code is
INSN_prefix (i.e. the primary opcode was 1), it stores the prefix word
and sends nothing down to decode2 in that cycle.  When the next valid
instruction word arrives, it is interpreted as a suffix, meaning that
its insn_code gets modified before being used to look up the decode
table.

The insn_code values are rearranged so that the values for
instructions which are the suffix of a valid prefixed instruction are
all at even indexes, and the corresponding prefixed instructions
follow immediately, so that an insn_code value can be converted to the
corresponding prefixed value by setting the LSB of the insn_code
value.  There are two prefixed instructions, pld and pstd, for which
the suffix is not a valid SFFS instruction by itself, so these have
been given dummy insn_code values which decode as illegal (INSN_op57
and INSN_op61).

For a prefixed instruction, decode1 examines the type and subtype
fields of the prefix and checks that the suffix is valid for the type
and subtype.  This check doesn't affect which entry of the decode
table is used; the result is passed down to decode2, and will in
future be acted upon in execute1.

The instruction address passed down to decode2 is the address of the
prefix.  To enable this, part of the instruction address is saved when
the prefix is seen, and then the instruction address received from
icache is partly overlaid by the saved prefix address.  Because
prefixed instructions are not permitted to cross 64-byte boundaries,
we only need to save bits 5:2 of the instruction to do this.  If the
alignment restriction ever gets relaxed, we will then need to save
more bits of the address.

Decode2 has been extended to handle the R bit of the prefix (in 8LS
and MLS forms) and to be able to generate the 34-bit immediate value
from the prefix and suffix.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
10 months agoMove insn_codes for mcrfs, mtfsb0/1 and mtfsfi
Paul Mackerras [Mon, 3 Jul 2023 11:09:33 +0000 (21:09 +1000)]
Move insn_codes for mcrfs, mtfsb0/1 and mtfsfi

This moves the insn_code values for mcrfs, mtfsb0/1 and mtfsfi into
the region used for floating-point instructions.  This means that in
no-FPU implementations, they will get turned into illegal instructions
in predecode.  We then don't need the code in execute1 that makes FP
instructions illegal in no-FPU implementations.

We also remove the NONE value for unit_t, since it was only ever used
with insn_type = OP_ILLEGAL, and the check for unit = NONE was
redundant with the check for insn_type = OP_ILLEGAL.  Thus the check
for unit = NONE is no longer needed and is removed here.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
10 months agofetch1: Change the way predictions from the BTC are sent downstream
Paul Mackerras [Sat, 20 Aug 2022 08:06:06 +0000 (18:06 +1000)]
fetch1: Change the way predictions from the BTC are sent downstream

Instead of sending down the predicted taken/not-taken bits with the
target of the branch, we now send them down with the branch itself.
Previously icache adjusted for this by sending the prediction bits to
decode1 without a 1-clock delay while everything else had a 1-clock
delay.  Now icache keeps the prediction bits with the rest of the
attributes for the request.

Also fix a buglet in fetch1 where the first address sent out after
reset didn't have .req set.  Currently this doesn't cause a problem
because icache doesn't really look at .req.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
14 months agoMerge pull request #417 from kraigher/master
Anton Blanchard [Mon, 20 Feb 2023 06:18:35 +0000 (17:18 +1100)]
Merge pull request #417 from kraigher/master

Add VHDL-LS language server configuration

15 months agoAdd vhdl_ls.toml dump to run.py
Olof Kraigher [Sun, 12 Feb 2023 17:50:10 +0000 (18:50 +0100)]
Add vhdl_ls.toml dump to run.py

Signed-off-by: Olof Kraigher <olof.kraigher@gmail.com>
17 months agoMerge pull request #409 from CodeConstruct/dev/soc-reset
Michael Neuling [Mon, 5 Dec 2022 06:33:11 +0000 (17:33 +1100)]
Merge pull request #409 from CodeConstruct/dev/soc-reset

Make syscon SOC reset work

18 months agoarty: Add software reset from syscon
Matt Johnston [Thu, 27 Oct 2022 03:50:12 +0000 (11:50 +0800)]
arty: Add software reset from syscon

Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
18 months agosoc: Expose sw_soc_reset for syscon reset
Matt Johnston [Thu, 29 Sep 2022 04:20:40 +0000 (12:20 +0800)]
soc: Expose sw_soc_reset for syscon reset

The soc itself will be reset when a syscon soc reset is triggered.

Separately, top- board files can use the sw_soc_rst signal
if they need to reset other peripherals

Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
18 months agoRegenerate litedram with updated sdram init
Matt Johnston [Thu, 27 Oct 2022 05:02:05 +0000 (13:02 +0800)]
Regenerate litedram with updated sdram init

Using

litedram c770dd62edc281c370f9e2c694fe4ac1525a0b4a
litex e570b612b2a9d8f8d2002d79497bda0dc35b936a

Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
18 months agolitedram: only run sdram init at first boot
Matt Johnston [Thu, 27 Oct 2022 03:20:27 +0000 (11:20 +0800)]
litedram: only run sdram init at first boot

Subsequent boots can skip the dram configuration, it will already
be in a usable state.

Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
18 months agoMove alt_reset to syscon
Matt Johnston [Thu, 27 Oct 2022 03:23:30 +0000 (11:23 +0800)]
Move alt_reset to syscon

Instead of connecting core_alt_reset to litedram init_done, it moves to
a syscon register bit. This simplifies top- files and future soc_reset
handling. sdram main.c can unset the alt_reset bit after sdram init.

Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
18 months agobin2hex: handle any file length, not just 8 or 4
Matt Johnston [Thu, 27 Oct 2022 06:16:49 +0000 (14:16 +0800)]
bin2hex: handle any file length, not just 8 or 4

Treat the input as if it was padded with zeroes to a multiple
of 8. This is needed if the .data in a binary changes size, it
won't be a nice multiple of 4 or 8. At present the microwatt
binaries all are multiples of 8, but making code alterations could make
bin2hex fail unexpectedly.

Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
18 months agoMerge pull request #415 from ozbenh/uart16550-core
Michael Neuling [Mon, 24 Oct 2022 23:52:34 +0000 (10:52 +1100)]
Merge pull request #415 from ozbenh/uart16550-core

Bundle the uart16550 core file

18 months agoMerge pull request #414 from ozbenh/misc
Michael Neuling [Mon, 24 Oct 2022 22:02:08 +0000 (09:02 +1100)]
Merge pull request #414 from ozbenh/misc

Fixup plru_tb to use the new plrufn, take out the old plru and vunit test misc changes

18 months agoBundle the uart16550 core file
Benjamin Herrenschmidt [Mon, 24 Oct 2022 04:25:39 +0000 (15:25 +1100)]
Bundle the uart16550 core file

We already carry the UART verilog source, so we may as well use it
instead of requiring fusesoc to import it from its library

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
18 months agoFix plru_tb to use the new plrufn and take out the old plru.vhdl
Benjamin Herrenschmidt [Sun, 23 Oct 2022 04:24:11 +0000 (15:24 +1100)]
Fix plru_tb to use the new plrufn and take out the old plru.vhdl

This reworks (and simplifies) plru_tb to use the new plrufn module
instead of the old (and now unused) plru module.

The latter is now removed completely.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
18 months agoMerge pull request #413 from ozbenh/fix-io-bridge-qw-store
Michael Neuling [Mon, 24 Oct 2022 04:02:33 +0000 (15:02 +1100)]
Merge pull request #413 from ozbenh/fix-io-bridge-qw-store

soc: Fix issues with 64-bit stores to IO bridge

18 months agoClean vunit_out on make clean
Benjamin Herrenschmidt [Sun, 23 Oct 2022 04:45:48 +0000 (15:45 +1100)]
Clean vunit_out on make clean

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
18 months agoAdd shebang to run.py
Benjamin Herrenschmidt [Sun, 23 Oct 2022 04:24:16 +0000 (15:24 +1100)]
Add shebang to run.py

It's useful to run the vunit tests by hand, this makes it easier

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
18 months agosoc: Fix issues with 64-bit stores to IO bridge
Benjamin Herrenschmidt [Sun, 23 Oct 2022 02:42:56 +0000 (13:42 +1100)]
soc: Fix issues with 64-bit stores to IO bridge

The IO bridge would latch the top half of write data and selection signals
when issuing the second downstream store. Unfortunately at this point the
bridge has already "accepted" the upstream store from the core (due to
stall being 0 on the cycle when stb/cyc are 1), so the values on the
wishbone signals aren't stable and might already reflect a subsequent
wishbone command.

This causes occasional data corruption of 64-bit stores through the IO
bridge.

While at it, take out a bunch of useless conditions on the data latch
path. It doesn't matter whether we is 0 or 1, we can just always latch
the data, the destination will decide whether to use the content or not,
which should save a bit of hardware.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
18 months agogpio: Add interrupts and trigger registers
Matt Johnston [Thu, 8 Sep 2022 05:26:00 +0000 (13:26 +0800)]
gpio: Add interrupts and trigger registers

Allows to trigger on rising/falling/both edge, as well
as high/low level.

Registers are compatible with Linux ftgpio010 driver.

Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
19 months agoMerge pull request #411 from ozbenh/dcache-plru-update-fix
Paul Mackerras [Fri, 7 Oct 2022 07:27:13 +0000 (18:27 +1100)]
Merge pull request #411 from ozbenh/dcache-plru-update-fix

Dcache PLRU update fix

19 months agodcache: Update PLRU on misses as well as hits
Benjamin Herrenschmidt [Sun, 2 Oct 2022 06:43:58 +0000 (17:43 +1100)]
dcache: Update PLRU on misses as well as hits

The current dcache will not update the PLRU on a cache miss which is later
satisfied during the reload process. Thus subsequent misses will potentially
evict the same cache line. The same issue happens with dcbz which are
treated more/less as load misses.

This fixes it by triggering a PLRU update when r1.choose_victim, which is
set on a miss for one cycle to snapshot the PLRU output. This means we will
update the PLRU on the same cycle as we capture its output, which is fine
(the new value will be visible on the next cycle).

That way, a "miss" will result in a PLRU update to reflect that the entry
being refilled is actually used (and will be used to serve subsequent
load operations from the same cache line while being refilled).

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
19 months agoFix dcache_tb (and add dump of victim way to dcache)
Benjamin Herrenschmidt [Fri, 30 Sep 2022 02:04:26 +0000 (12:04 +1000)]
Fix dcache_tb (and add dump of victim way to dcache)

It bitrotted... more signals need to be initialized. This also adds
a lot more accesses with different timing conditions allowing to
test cases of hit during reloads, hit with reload formward, hit on idle
cache etc...

It also exposes a bug where the cache miss caused by the read of 0x140
uses the same victim way as previous cache miss of 0x40 (same index).

This bug will need to be fixed separately, but at least this exposes it.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
19 months agoAdd more interrupt numbers to microwatt_soc.h
Matt Johnston [Thu, 8 Sep 2022 06:38:39 +0000 (14:38 +0800)]
Add more interrupt numbers to microwatt_soc.h

Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
19 months agoarty: Add switches and buttons as gpio 10-17
Matt Johnston [Thu, 18 Aug 2022 06:54:12 +0000 (14:54 +0800)]
arty: Add switches and buttons as gpio 10-17

Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
19 months agoarty: Add other RGB LEDs, attach to gpio 0-8
Matt Johnston [Thu, 18 Aug 2022 06:53:32 +0000 (14:53 +0800)]
arty: Add other RGB LEDs, attach to gpio 0-8

Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
19 months agoarty: Add switches and buttons to xdc file
Matt Johnston [Thu, 18 Aug 2022 06:14:20 +0000 (14:14 +0800)]
arty: Add switches and buttons to xdc file

Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
19 months agoMerge pull request #408 from paulusmack/plru-improvement
Michael Neuling [Thu, 29 Sep 2022 01:49:08 +0000 (11:49 +1000)]
Merge pull request #408 from paulusmack/plru-improvement

PLRU improvements

19 months agoMerge pull request #406 from shingarov/spi-kintex
Michael Neuling [Mon, 26 Sep 2022 06:49:11 +0000 (16:49 +1000)]
Merge pull request #406 from shingarov/spi-kintex

Add support for flashing the s25fl256s onboard Genesys2

19 months agoMerge pull request #407 from shingarov/openocd-012
Michael Neuling [Mon, 26 Sep 2022 06:47:15 +0000 (16:47 +1000)]
Merge pull request #407 from shingarov/openocd-012

Recognize version string "0.12" in recent OpenOCD master

19 months agoRecognize version string "0.12" in recent OpenOCD master
Boris Shingarov [Sat, 24 Sep 2022 11:08:42 +0000 (07:08 -0400)]
Recognize version string "0.12" in recent OpenOCD master

Starting from 5e7612eb4, OpenOCD identifies itself as 0.12.
This causes Microwatt's flash-arty script to fail.  Because neither
the cfg nor the proxy bitstream are affected, we can keep treating
everything as indistinguishable from 0.11.  This patch simply tests
for "0.12" as an alias; it would probably be better to replace this
confusing terminology with something like "single-tap/multi-tap".

Signed-off-by: Boris Shingarov <shingarov@labware.com>
19 months agoAdd support for flashing the s25fl256s onboard Genesys2
Boris Shingarov [Fri, 23 Sep 2022 20:10:04 +0000 (16:10 -0400)]
Add support for flashing the s25fl256s onboard Genesys2

This includes the cable configuration, additions to the Python script,
and the jtagspi proxy bitstream. The single-tap version is not included
because 0.10 supported only 3-byte addresses which is unusable on the
s25fl256s anyway.

Signed-off-by: Boris Shingarov <shingarov@labware.com>
19 months agolitedram: Split L2 PLRU into storage and logic
Paul Mackerras [Mon, 19 Sep 2022 08:05:30 +0000 (18:05 +1000)]
litedram: Split L2 PLRU into storage and logic

As has been done for the L1 dcache and icache, this puts the L2 cache
PLRU state into a little RAM and has a single copy of the logic to
calculate the pseudo-LRU way and update the PLRU state.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
20 months agodcache: Split PLRU into storage and logic
Paul Mackerras [Wed, 7 Sep 2022 10:21:42 +0000 (20:21 +1000)]
dcache: Split PLRU into storage and logic

Rather than having update and decode logic for each individual PLRU
as well as a register to store the current PLRU state, we now put the
PLRU state in a little RAM, which will typically use LUT RAM on FPGAs,
and have just a single copy of the logic to calculate the pseudo-LRU
way and to update the PLRU state.

The PLRU RAM that apples to the data storage (as opposed to the TLB)
is read asynchronously in the cycle after the cache tag matching is
done.  At the end of that cycle the PLRU RAM entry is updated if the
access was a cache hit, or a victim way is calculated and stored if
the access was a cache miss.  It is possible that a cache miss doesn't
start being handled until later, in which case the stored victim way
is used later when the miss gets handled.

Similarly for the TLB PLRU, the RAM is read asynchronously in the
cycle after a TLB lookup is done, and either updated at the end of
that cycle (for a hit), or a victim is chosen and stored for when the
TLB miss is satisfied.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
20 months agoicache: Split PLRU into storage and logic
Paul Mackerras [Wed, 7 Sep 2022 10:18:18 +0000 (20:18 +1000)]
icache: Split PLRU into storage and logic

Rather than having update and decode logic for each individual PLRU
as well as a register to store the current PLRU state, we now put the
PLRU state in a little RAM, which will typically use LUT RAM on FPGAs,
and have just a single copy of the logic to calculate the pseudo-LRU
way and to update the PLRU state.  This logic is in the plrufn module
and is just combinatorial logic.  A new module was created for this as
other parts of the system are still using plru.vhdl.

The PLRU RAM in the icache is read asynchronously in the cycle
after the cache tag matching is done.  At the end of that cycle the
PLRU RAM entry is updated if the access was a cache hit, or a victim
way is calculated and stored if the access was a cache miss and
miss handling is starting in this cycle.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
20 months agoMerge pull request #403 from mikey/litedram-warnings
Anton Blanchard [Wed, 7 Sep 2022 08:00:11 +0000 (18:00 +1000)]
Merge pull request #403 from mikey/litedram-warnings

Fix litedram wrapper build warnings and metavalues

20 months agodcache: Fix compilation with NUM_WAYS and/or TLB_NUM_WAYS = 1
Paul Mackerras [Wed, 7 Sep 2022 06:02:06 +0000 (16:02 +1000)]
dcache: Fix compilation with NUM_WAYS and/or TLB_NUM_WAYS = 1

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
20 months agoicache: Fix compilation with NUM_WAYS = 1
Paul Mackerras [Wed, 7 Sep 2022 05:32:46 +0000 (15:32 +1000)]
icache: Fix compilation with NUM_WAYS = 1

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
20 months agoFix litedram wrapper build warnings and metavalues
Michael Neuling [Mon, 5 Sep 2022 04:57:49 +0000 (14:57 +1000)]
Fix litedram wrapper build warnings and metavalues

This fixes a couple of build warnings in litedram-wrapper-l2.vhdl

litedram/extras/litedram-wrapper-l2.vhdl:552:17:warning: declaration of "i" hides constant "i" [-Whide]
            for i in 0 to ROW_SIZE-1 loop
                ^
litedram/extras/litedram-wrapper-l2.vhdl:1129:9:warning: declaration of "litedram_trace" hides generic "litedram_trace" [-Whide]
        litedram_trace: litedram_trace_stub;
        ^

It also cleans up the runtime metavalue warnings

Signed-off-by: Michael Neuling <mikey@neuling.org>
20 months agoMerge pull request #402 from ozbenh/misc
Michael Neuling [Mon, 5 Sep 2022 04:51:29 +0000 (14:51 +1000)]
Merge pull request #402 from ozbenh/misc

Fix core_dram_tb and dram_tb

20 months agoFix build of core_dram_tb and dram_tb and fix tracing
Benjamin Herrenschmidt [Sun, 4 Sep 2022 14:21:47 +0000 (00:21 +1000)]
Fix build of core_dram_tb and dram_tb and fix tracing

We disabled --trace by default, so we need to stop linking verilated_vcd_c.o
as it doesn't exist in that case.

While at it, make a Makefile variable to enable/disable verilator tracing
and add a couple of generics to those test benches to control tracing
in the L2 and in litedram.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
20 months agoIgnore vunit_out in git
Benjamin Herrenschmidt [Sun, 4 Sep 2022 14:22:19 +0000 (00:22 +1000)]
Ignore vunit_out in git

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
20 months agoMerge pull request #401 from shenki/dcscm
Michael Neuling [Thu, 1 Sep 2022 01:08:59 +0000 (11:08 +1000)]
Merge pull request #401 from shenki/dcscm

Add Antmicro Artix DC-SCM support

20 months agoopenocd: Add Artix DC-SCM cable type
Joel Stanley [Tue, 16 Aug 2022 05:14:44 +0000 (15:14 +1000)]
openocd: Add Artix DC-SCM cable type

The Antmicro Artix DC-SCM uses the following FTDI part:

 0403:6011 Future Technology Devices International, Ltd FT4232H Quad HS USB-UART/FIFO IC

To use:

 $ openocd/flash-arty -c antmicro-artix-dc-scm -f a100 -t bin -a 0x300000 ~/u-boot

Signed-off-by: Joel Stanley <joel@jms.id.au>
20 months agoantmicro-artix-dc-scm: Add liteeth
Joel Stanley [Thu, 25 Aug 2022 09:51:07 +0000 (19:51 +1000)]
antmicro-artix-dc-scm: Add liteeth

As with the DRAM configuration, the DC-SCM board uses the same PHY as
the Nexys Video and works with it's generated VHDL.

Signed-off-by: Joel Stanley <joel@jms.id.au>
20 months agoantmicro-artix-dc-scm: Add Ethernet pins
Joel Stanley [Thu, 25 Aug 2022 09:50:47 +0000 (19:50 +1000)]
antmicro-artix-dc-scm: Add Ethernet pins

Signed-off-by: Joel Stanley <joel@jms.id.au>
20 months agoantmicro-artix-dc-scm: Enable SPI flash
Joel Stanley [Thu, 25 Aug 2022 08:27:19 +0000 (18:27 +1000)]
antmicro-artix-dc-scm: Enable SPI flash

Load from 3MB as the flash is only 4MB on this board.

Signed-off-by: Joel Stanley <joel@jms.id.au>
20 months agoantmicro-artix-dc-scm: Formatting to match top-arty
Joel Stanley [Thu, 25 Aug 2022 08:26:53 +0000 (18:26 +1000)]
antmicro-artix-dc-scm: Formatting to match top-arty

Make it easier to follow what needs to be updated.

Signed-off-by: Joel Stanley <joel@jms.id.au>
20 months agoantmicro-artix-dc-scm: Add SPI flash pins
Joel Stanley [Thu, 25 Aug 2022 08:26:02 +0000 (18:26 +1000)]
antmicro-artix-dc-scm: Add SPI flash pins

Signed-off-by: Joel Stanley <joel@jms.id.au>
20 months agoantmicro-artix-dc-scm: Update DRAM properties
Joel Stanley [Thu, 25 Aug 2022 09:51:55 +0000 (19:51 +1000)]
antmicro-artix-dc-scm: Update DRAM properties

Most pins are set to SSTL15, but litex generates SSTL135.

This should silence a vivado warning.

Signed-off-by: Joel Stanley <joel@jms.id.au>
20 months agoantmicro-artix-dc-scm: Add DRAM support
Paul Mackerras [Wed, 27 Oct 2021 03:58:34 +0000 (14:58 +1100)]
antmicro-artix-dc-scm: Add DRAM support

This uses the exact same gateware as the nexys video, since the DRAM
connection is identical to the nexys video down to the pin assignments
on the FPGA.  The only minor difference is that the DRAM chip on the
dc-scm is a MT41K256M16TW vs. a ...HA part on the nexys video.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
[joel: rebase and tweaks]
Signed-off-by: Joel Stanley <joel@jms.id.au>
20 months agoAdd Antmicro Artix DC SCM hello world support
Michael Neuling [Wed, 20 Oct 2021 23:50:46 +0000 (10:50 +1100)]
Add Antmicro Artix DC SCM hello world support

works with:
 fusesoc build --target=antmicro-artix-dc-scm microwatt --ram_init_file=../hello_world/hello_world.hex

Signed-off-by: Michael Neuling <mikey@neuling.org>
[joel: Fixes and updates]
Signed-off-by: Joel Stanley <joel@jms.id.au>
20 months agoMerge pull request #400 from mikey/githash
Anton Blanchard [Tue, 30 Aug 2022 01:49:40 +0000 (11:49 +1000)]
Merge pull request #400 from mikey/githash

syscon: Implement a register for storing git hash info

20 months agoMerge pull request #399 from ozbenh/misc
Michael Neuling [Mon, 29 Aug 2022 05:20:24 +0000 (15:20 +1000)]
Merge pull request #399 from ozbenh/misc

Fix PLRU

20 months agohello_world: Debug print the gitinfo syscon register
Dan Horák [Tue, 1 Sep 2020 20:43:50 +0000 (22:43 +0200)]
hello_world: Debug print the gitinfo syscon register

   .oOOo.
 ."      ".
 ;  .mw.  ;   Microwatt, it works.
  . '  ' .
   \ || /     HDL Git SHA1: 211d23c4ad4fb5-dirty
    ;..;
    ;..;
    `ww'

Signed-off-by: Dan Horák <dan@danny.cz>
Signed-off-by: Michael Neuling <mikey@neuling.org>
20 months agosyscon: Implement a register for storing git hash info
Dan Horák [Fri, 28 Aug 2020 12:24:07 +0000 (14:24 +0200)]
syscon: Implement a register for storing git hash info

It also stores the dirty status so that's known.

This does some Makefile tricks so that we only rebuild when the git
hash changes. This avoids rebuilding the world every time we run
make.

Also adds fusesoc generator, so that should continue to work as
before.

Signed-off-by: Dan Horák <dan@danny.cz>
Signed-off-by: Michael Neuling <mikey@neuling.org>
20 months agoFix PLRU
Benjamin Herrenschmidt [Thu, 25 Aug 2022 03:14:20 +0000 (13:14 +1000)]
Fix PLRU

Jacob Lifshay found a couple of issues with the PLRU implementation:

 - The tree array is one bit too long. This is harmless as this bit is never
accessed and thus should be optimized out

 - The PLRU read is using the wrong nodes when going down the tree, which leads
to incorrect results.

This fixes it and improves the test bench a bit. I have verified the expected
output using a hand-written tree states, observed the mismatch with the
current implementation and verified the fix.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
21 months agoMerge pull request #397 from mikey/metavalue-counts
Anton Blanchard [Sun, 14 Aug 2022 23:32:54 +0000 (09:32 +1000)]
Merge pull request #397 from mikey/metavalue-counts

tests: Update metavalues test count

21 months agotests: Update metavalues test count
Michael Neuling [Sat, 13 Aug 2022 05:52:04 +0000 (15:52 +1000)]
tests: Update metavalues test count

With Paulus changes in PR #396 merged in 5c6d57de30, we can now reduce
the metavalue test counts.

Signed-off-by: Michael Neuling <mikey@neuling.org>
21 months agoMerge pull request #396 from paulusmack/reduce-meta
Michael Neuling [Sat, 13 Aug 2022 05:45:57 +0000 (15:45 +1000)]
Merge pull request #396 from paulusmack/reduce-meta

Reduce metavalue warnings

21 months agoexecute1: Reduce metavalue warnings
Paul Mackerras [Fri, 12 Aug 2022 12:19:37 +0000 (22:19 +1000)]
execute1: Reduce metavalue warnings

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
21 months agoloadstore1: Reduce metavalue warnings
Paul Mackerras [Fri, 12 Aug 2022 09:47:45 +0000 (19:47 +1000)]
loadstore1: Reduce metavalue warnings

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
21 months agodecode2: Reduce metavalue warnings
Paul Mackerras [Fri, 12 Aug 2022 09:46:45 +0000 (19:46 +1000)]
decode2: Reduce metavalue warnings

Explicitly check for undefined values and propagate them.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
21 months agocore_debug: Reduce metavalue warnings
Paul Mackerras [Fri, 12 Aug 2022 09:46:09 +0000 (19:46 +1000)]
core_debug: Reduce metavalue warnings

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
21 months agoicache: Reduce metavalue warnings
Paul Mackerras [Fri, 12 Aug 2022 09:42:35 +0000 (19:42 +1000)]
icache: Reduce metavalue warnings

As in dcache, this changes most signals declared with integer type to
be unsigned bit vectors instead.  Some code has been rearranged to do
to_integer() or equality comparisons only when the relevant signals
should be well defined.  Non-fatal asserts have been sprinkled
throughout to assist with determining the cause of warnings from
library functions (primarily NUMERIC_STD.TO_INTEGER and
NUMERIC_STD."=").

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
21 months agodcache: Reduce metavalue warnings
Paul Mackerras [Fri, 12 Aug 2022 09:38:16 +0000 (19:38 +1000)]
dcache: Reduce metavalue warnings

Among other changes, this makes the things that were previously
declared as signals of integer base type to be unsigned, since
unsigned can carry metavalues, and hence we can get the checking for
metavalues closer to the uses and therefore restrict the checking to
the situations where the signal really ought to be well defined.
We now have a couple more signals that indicate request validity to
help with that.

Non-fatal asserts have been sprinkled throughout to assist with
determining the cause of warnings from library functions (primarily
NUMERIC_STD.TO_INTEGER and NUMERIC_STD."=").

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
21 months agoMerge pull request #382 from paulusmack/master
Michael Neuling [Wed, 10 Aug 2022 05:33:15 +0000 (15:33 +1000)]
Merge pull request #382 from paulusmack/master

Decode in block RAM and other improvements

21 months agoMerge pull request #392 from paulusmack/fix-branch-alias
Michael Neuling [Wed, 10 Aug 2022 02:43:29 +0000 (12:43 +1000)]
Merge pull request #392 from paulusmack/fix-branch-alias

fetch1: Fix bug where BTC entries don't match on MSR[IR]

21 months agomultiply_tb: Fix multiply_tb.vhdl for the new multiplier interface
Paul Mackerras [Wed, 10 Aug 2022 02:03:36 +0000 (12:03 +1000)]
multiply_tb: Fix multiply_tb.vhdl for the new multiplier interface

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
21 months agoexecute1: Make it clear that divide logic is not included when HAS_FPU=true
Paul Mackerras [Wed, 10 Aug 2022 01:33:10 +0000 (11:33 +1000)]
execute1: Make it clear that divide logic is not included when HAS_FPU=true

This adds a "not HAS_FPU" condition in a few places to make it obvious
that logic to interface to the divide unit is not included when we
have an FPU.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
21 months agoRemove option for "short" 16x16 bit multiplier
Paul Mackerras [Tue, 19 Jul 2022 02:29:47 +0000 (12:29 +1000)]
Remove option for "short" 16x16 bit multiplier

Now that we have a 33 bit x 33 bit signed multiplier in execute1,
there is really no need for the 16 bit multiplier.  The coremark
results are just as good without it as with it.  This removes the
option for the sake of simplicity.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
21 months agoMerge branch 'fix-branch-alias' into branch-alias
Michael Neuling [Wed, 10 Aug 2022 00:29:59 +0000 (10:29 +1000)]
Merge branch 'fix-branch-alias' into branch-alias

Merging Anton's test case for this.

Signed-off-by: Michael Neuling <mikey@neuling.org>
21 months agoMerge pull request #388 from antonblanchard/trace-test
Michael Neuling [Wed, 10 Aug 2022 00:25:59 +0000 (10:25 +1000)]
Merge pull request #388 from antonblanchard/trace-test

tests/trace: Test trace vs system call interrupt

21 months agofetch1: Fix bug where BTC entries don't match on MSR[IR]
Paul Mackerras [Wed, 10 Aug 2022 00:13:50 +0000 (10:13 +1000)]
fetch1: Fix bug where BTC entries don't match on MSR[IR]

This fixes a bug in the BTC where entries created for a given address
when MSR[IR] = 0 are used when MSR[IR] = 1 and vice-versa.  The fix is
to include r.virt_mode (which mirrors MSR[IR]) in the tag portion of
the BTC.

Fixes: 0fb207be6069 ("fetch1: Implement a simple branch target cache", 2020-12-19)
Reported-by: Anton Blanchard <anton@linux.ibm.com>
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
21 months agoChange the multiplier interface to support signed multipliers
Paul Mackerras [Mon, 8 Aug 2022 12:26:39 +0000 (22:26 +1000)]
Change the multiplier interface to support signed multipliers

This adds an 'is_signed' signal to MultiplyInputType to indicate
whether the data1 and data2 fields are to be interpreted as signed or
unsigned numbers.

The 'not_result' field is replaced by a 'subtract' field which
provides a more intuitive interface for requesting that the product be
subtracted from the addend rather than added, i.e. subtract = 1 gives
C - A * B, vs. subtract = 0 giving C + A * B.  (Previously the users
of the multipliers got the same effect by complementing the addend and
setting not_result = 1.)

The is_32bit field is removed because it is no longer used now that we
have a separate 32-bit multiplier.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
21 months agoAdd branch alias test
Anton Blanchard [Tue, 9 Aug 2022 10:32:52 +0000 (20:32 +1000)]
Add branch alias test

Signed-off-by: Anton Blanchard <anton@linux.ibm.com>
21 months agoxilinx_mult: Prepare for doing signed multiplication
Paul Mackerras [Mon, 8 Aug 2022 07:06:46 +0000 (17:06 +1000)]
xilinx_mult: Prepare for doing signed multiplication

This rearranges the way that partial products are generated and summed
so that the partial products that could be negative in a signed
multiplier are now sign-extended.  The inputs are still zero-extended,
however.

The overflow detection logic now only detects 64-bit overflow, since
32-bit multiplications are handled in a separate multiplier.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
21 months agoexecute1: Add a pipelined 33-bit signed multiplier
Paul Mackerras [Sat, 16 Jul 2022 01:49:28 +0000 (11:49 +1000)]
execute1: Add a pipelined 33-bit signed multiplier

This adds a pipelined 33-bit by 33-bit signed multiplier with one
cycle latency to the execute pipeline, and uses it for the mullw,
mulhw and mulhwu instructions.  Because it has one cycle of latency we
can assume that its result is available in the second execute stage
without needing to add busy logic to the second stage.

This adds both a generic version of the multiplier and a
Xilinx-specific version using four DSP slices of the Artix-7.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>