Paul Mackerras [Fri, 15 May 2020 12:01:02 +0000 (22:01 +1000)]
dcache: Fix bug in store hit after dcbz case
This fixes a bug where a store that hits in the dcache immediately
following a dcbz has its write to the cache RAM suppressed (but not
its write to memory). If a load to the same location comes along
before the cache line gets replaced, the load will return incorrect
data.
Fixes: 4db1676ef8b3 ("dcache: Don't assert on dcbz cache hit")
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Thu, 14 May 2020 05:43:33 +0000 (15:43 +1000)]
soc: Work around compile error with ghdl 0.37-dev
The ghdl packaged in Fedora 31 doesn't like a port map of the form
"rst => rst or core_reset", so this works around the problem by
doing the OR in a separate statement.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Thu, 14 May 2020 05:41:51 +0000 (15:41 +1000)]
Merge branch 'mmu'
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Anton Blanchard [Thu, 14 May 2020 05:08:33 +0000 (15:08 +1000)]
Merge pull request #170 from antonblanchard/litedram
LiteDRAM integration
Benjamin Herrenschmidt [Sat, 9 May 2020 01:20:59 +0000 (11:20 +1000)]
litedram: Use 32-bit CSR bus
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Benjamin Herrenschmidt [Fri, 8 May 2020 15:09:26 +0000 (01:09 +1000)]
litedram: Add support for Microwatt-initialized controller
This adds support for initializing the memory controller from microwatt
rather than using a built-in RiscV processor. This might require some
fixes to LiteX and LiteDRAM (they haven't been merged as of this commit
yet).
This is enabled in the shipped generated files and can be changed via
modifying the generator script to pass False to "mw_init"
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Benjamin Herrenschmidt [Fri, 8 May 2020 00:42:01 +0000 (10:42 +1000)]
hello_world: Use new headers and frequency from syscon
This uses the new header files for register definitions and
extracts the core frequency from syscon rather than hard coding it.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Benjamin Herrenschmidt [Tue, 24 Sep 2019 06:19:29 +0000 (16:19 +1000)]
litedram: Improve sdram init boot messages
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Benjamin Herrenschmidt [Fri, 8 May 2020 00:27:33 +0000 (10:27 +1000)]
Add microwatt_soc.h and io.h include file
This contains C definitions for various Microwatt internal MMIOs
and a set of accessors.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Benjamin Herrenschmidt [Tue, 24 Sep 2019 12:24:31 +0000 (22:24 +1000)]
syscon: Add syscon registers
These provides some info about the SoC (though it's still somewhat
incomplete and needs more work, see comments).
There's also a control register for selecting DRAM vs. BRAM at 0
(and for soft-resetting the SoC but that isn't wired up yet).
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Benjamin Herrenschmidt [Wed, 11 Sep 2019 09:59:13 +0000 (10:59 +0100)]
fpga: Hookup nexys-video to litedram
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Benjamin Herrenschmidt [Tue, 10 Sep 2019 17:24:06 +0000 (18:24 +0100)]
fpga: Hookup Arty to litedram
The old toplevel.vhdl becomes top-generic.vhdl, which is to be used
by platforms that do not have a litedram option.
Arty has its own top-arty.vhdl which supports litedram and is now
hooked up
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Paul Mackerras [Fri, 24 Apr 2020 00:58:56 +0000 (10:58 +1000)]
MMU: Implement reading of the process table
This adds the PID register and repurposes SPR 720 as the PRTBL
register, which points to the base of the process table. There
doesn't seem to be any point to implementing the partition table given
that we don't have hypervisor mode.
The MMU caches entry 0 of the process table internally (in pgtbl3)
plus the entry indexed by the value in the PID register (pgtbl0).
Both caches are invalidated by a tlbie[l] with RIC=2 or by a move to
PRTBL. The pgtbl0 cache is invalidated by a move to PID. The dTLB
and iTLB are cleared by a move to either PRTBL or PID.
Which of the two page table root pointers is used (pgtbl0 or pgtbl3)
depends on the MSB of the address being translated. Since the segment
checking ensures that address(63) = address(62), this is sufficient to
map quadrants 0 and 3.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Thu, 7 May 2020 10:12:46 +0000 (20:12 +1000)]
tests/mmu: Add a test of PTE refetching on permission error
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Sun, 3 May 2020 22:57:05 +0000 (08:57 +1000)]
tests/mmu: Add a test for dcbz with translation on
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Thu, 7 May 2020 10:02:21 +0000 (20:02 +1000)]
Implement slbia as a dTLB/iTLB flush
Slbia (with IH=7) is used in the Linux kernel to flush the ERATs
(our iTLB/dTLB), so make it do that.
This moves the logic to work out whether to flush a single entry
or the whole TLB from dcache and icache into mmu. We now invalidate
all dTLB and iTLB entries when the AP (actual pagesize) field of
RB is non-zero on a tlbie[l], as well as when IS is non-zero.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Sat, 2 May 2020 04:23:14 +0000 (14:23 +1000)]
Decode tlbiel as tlbie
The Linux kernel contains tlbiel instructions, which we can treat
identically to tlbie.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Thu, 7 May 2020 02:08:43 +0000 (12:08 +1000)]
tests/privileged: Update for instruction translation
Since setting MSR[PR] = 1 forces instruction translation on, we need
to set up translations for the problem state code to use.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Tue, 28 Apr 2020 06:00:00 +0000 (16:00 +1000)]
tests: mmu: Add tests for instruction translation
This adds tests of instruction translation to the mmu test.
This also clears the BSS and improves the linker script.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Tue, 28 Apr 2020 04:54:22 +0000 (14:54 +1000)]
MMU: Do radix page table walks on iTLB misses
This hooks up the connections so that an OP_FETCH_FAILED coming down
to loadstore1 will get sent to the MMU for it to do a radix tree walk
for the instruction address. The MMU then sends the resulting PTE to
the icache module to be installed in the iTLB. If no valid PTE can
be found, the MMU sends an error signal back to loadstore1 which sends
it on to execute1 to generate an ISI.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Mon, 27 Apr 2020 07:43:19 +0000 (17:43 +1000)]
Add TLB to icache
This adds a direct-mapped TLB to the icache, with 64 entries by default.
Execute1 now sends a "virt_mode" signal from MSR[IR] to fetch1 along
with redirects to indicate whether instruction addresses should be
translated through the TLB, and fetch1 sends that on to icache.
Similarly a "priv_mode" signal is sent to indicate the privilege
mode for instruction fetches. This means that changes to MSR[IR]
or MSR[PR] don't take effect until the next redirect, meaning an
isync, rfid, branch, etc.
The icache uses a hash of the effective address (i.e. next instruction
address) to index the TLB. The hash is an XOR of three fields of the
address; with a 64-entry TLB, the fields are bits 12--17, 18--23 and
24--29 of the address. TLB invalidations simply invalidate the
indexed TLB entry without checking the contents.
If the icache detects a TLB miss with virt_mode=1, it will send a
fetch_failed indication through fetch2 to decode1, which will turn it
into a special OP_FETCH_FAILED opcode with unit=LDST. That will get
sent down to loadstore1 which will currently just raise a Instruction
Storage Interrupt (0x400) exception.
One bit in the PTE obtained from the TLB is used to check whether an
instruction access is allowed -- the privilege bit (bit 3). If bit 3
is 1 and priv_mode=0, then a fetch_failed indication is sent down to
fetch2 and to decode1, which generates an OP_FETCH_FAILED. Any PTEs
with PTE bit 0 (EAA[3]) clear or bit 8 (R) clear should not be put
into the iTLB since such PTEs would not allow execution by any
context.
Tlbie operations get sent from mmu to icache over a new connection.
Unfortunately the privileged instruction tests are broken for now.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Thu, 23 Apr 2020 05:33:36 +0000 (15:33 +1000)]
tests: Add a test for the MMU radix page table walks
This adds tests to check that the MMU and dTLB are translating
addresses and checking permissions correctly.
We use a simple 2-level radix tree. The radix tree maps 2GB of
address space and has a 1024-entry page directory pointing to
512-entry page table pages.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Thu, 7 May 2020 00:17:08 +0000 (10:17 +1000)]
MMU: Remove software-loaded dTLB mode
This removes the hack where the tlbie instruction could be used to
load entries directly into the dTLB, because we don't report the
correct DSISR values for accesses that hit software-loaded dTLB
entries and have privilege or permission errors.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Wed, 6 May 2020 10:21:01 +0000 (20:21 +1000)]
MMU: Refetch PTE on access fault
This is required by the architecture. It means that the error bits
reported in DSISR or SRR1 now come from the permission/RC check done
on the refetched PTE rather than the TLB entry. Unfortunately that
somewhat breaks the software-loaded TLB mode of operation in that
DSISR/SRR1 always report no PTE rather than permission error or
RC failure.
This also restructures the loadstore1 state machine a bit, combining
the FIRST_ACK_WAIT and LAST_ACK_WAIT states into a single state and
the MMU_LOOKUP_1ST and MMU_LOOKUP_LAST states likewise. We now have a
'dwords_done' bit to say whether the first transfer of two (for an
unaligned access) has been done.
The cache paradox error (where a non-cacheable access finds a hit in
the cache) is now the only cause of DSI from the dcache. This should
probably be a machine check rather than DSI in fact.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Thu, 23 Apr 2020 11:54:08 +0000 (21:54 +1000)]
MMU: Implement data segment interrupts
A data segment interrupt (DSegI) occurs when an address to be
translated by the MMU is outside the range of the radix tree
or the top two bits of the address (the quadrant) are 01 or 10.
This is detected in a new state of the MMU state machine, and
is sent back to loadstore1 as an error, which sends it on to
execute1 to generate an interrupt to the 0x380 vector.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Thu, 23 Apr 2020 05:28:22 +0000 (15:28 +1000)]
MMU: Implement radix page table machinery
This adds the necessary machinery to the MMU for it to do radix page
table walks. The core elements are a shifter that can shift the
address right by between 0 and 47 bits, a mask generator that can
generate a mask of between 5 and 16 bits, a final mask generator,
and new states in the state machine.
(The final mask generator is used for transferring bits of the
original address into the resulting TLB entry when the leaf PTE
corresponds to a page size larger than 4kB.)
The hardware does not implement a partition table or a process table.
Software is expected to load the appropriate process table entry
into a new SPR called PGTBL0, SPR 720. The contents should be
formatted as described in Book III section 5.7.6.2 of the Power ISA
v3.0B. PGTBL0 is set to 0 on hard reset. At present, the top two bits
of the address (the quadrant) are ignored.
There is currently no caching of any step in the translation process
or of the final result, other than the entry created in the dTLB.
That entry is a 4k page entry even if the leaf PTE found in the walk
corresponds to a larger page size.
This implementation can handle almost any page table layout and any
page size. The RTS field (in PGTBL0) can have any value between 0
and 31, corresponding to a total address space size between 2^31
and 2^62 bytes. The RPDS field of PGTBL0 can be any value between
5 and 16, except that a value of 0 is taken to disable radix page
table walking (for use when one is using software loading of TLB
entries). The NLS field of the page directory entries can have any
value between 5 and 16. The minimum page size is 4kB, meaning that
the sum of RPDS and the NLS values of the PDEs found on the path to
a leaf PTE must be less than or equal to RTS + 31 - 12.
The PGTBL0 SPR is in the mmu module; thus this adds a path for
loadstore1 to read and write SPRs in mmu. This adds code in dcache
to service doubleword read requests from the MMU, as well as requests
to write dTLB entries.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Wed, 22 Apr 2020 01:10:56 +0000 (11:10 +1000)]
Add framework for implementing an MMU
This adds a new module to implement an MMU. At the moment it doesn't
do very much. Tlbie instructions now get sent by loadstore1 to mmu,
which sends them to dcache, rather than loadstore1 sending them
directly to dcache. TLB misses from dcache now get sent by loadstore1
to mmu, which currently just returns an error. Loadstore1 then
generates a DSI in response to the error return from mmu.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Mon, 20 Apr 2020 02:43:06 +0000 (12:43 +1000)]
Implement access permission checks
This adds logic to the dcache to check the permissions encoded in
the PTE that it gets from the dTLB. The bits that are checked are:
R must be 1
C must be 1 for a store
EAA(0) - if this is 1, MSR[PR] must be 0
EAA(2) must be 1 for a store
EAA(1) | EAA(2) must be 1 for a load
In addition, ATT(0) is used to indicate a cache-inhibited access.
This now implements DSISR bits 36, 38 and 45.
(Bit numbers above correspond to the ISA, i.e. using big-endian
numbering.)
MSR[PR] is now conveyed to loadstore1 for use in permission checking.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Tue, 7 Apr 2020 06:17:37 +0000 (16:17 +1000)]
Implement data storage interrupts
This adds a path from loadstore1 back to execute1 for reporting
errors, and machinery in execute1 for generating data storage
interrupts at vector 0x300.
If dcache is given two requests in successive cycles and the
first encounters an error (e.g. a TLB miss), it will now cancel
the second request.
Loadstore1 now responds to errors reported by dcache by sending
an exception signal to execute1 and returning to the idle state.
Execute1 then writes SRR0 and SRR1 and jumps to the 0x300 Data
Storage Interrupt vector. DAR and DSISR are held in loadstore1.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Mon, 6 Apr 2020 07:54:45 +0000 (17:54 +1000)]
dcache: Implement data TLB
This adds a TLB to dcache, providing the ability to translate
addresses for loads and stores. No protection mechanism has been
implemented yet. The MSR_DR bit controls whether addresses are
translated through the TLB.
The TLB is a fixed-pagesize, set-associative cache. Currently
the page size is 4kB and the TLB is 2-way set associative with 64
entries per set.
This implements the tlbie instruction. RB bits 10 and 11 control
whether the whole TLB is invalidated (if either bit is 1) or just
a single entry corresponding to the effective page number in bits
12-63 of RB.
As an extension until we get a hardware page table walk, a tlbie
instruction with RB bits 9-11 set to 001 will load an entry into
the TLB. The TLB entry value is in RS in the format of a radix PTE.
Currently there is no proper handling of TLB misses. The load or
store will not be performed but no interrupt is generated.
In order to make timing at 100MHz on the Arty A7-100, we compare
the real address from each way of the TLB with the tag from each way
of the cache in parallel (requiring # TLB ways * # cache ways
comparators). Then the result is selected based on which way hit in
the TLB. That avoids a timing path going through the TLB EA
comparators, the multiplexer that selects the RA, and the cache tag
comparators.
The hack where addresses of the form 0xc------- are marked as
cache-inhibited is kept for now but restricted to real-mode accesses.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Wed, 22 Apr 2020 06:53:39 +0000 (16:53 +1000)]
Pass mtspr/mfspr to MMU-related SPRs down to loadstore1
This arranges for some mfspr and mtspr to get sent to loadstore1
instead of being handled in execute1. In particular, DAR and DSISR
are handled this way. They are therefore "slow" SPRs.
While we're at it, fix the spelling of HEIR and remove mention of
DAR and DSISR from the comments in execute1.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Sat, 2 May 2020 03:31:07 +0000 (13:31 +1000)]
mw_debug: Add support for reading GSPRs and writing memory
This adds a "gpr" command for reading 1 or more GPRs/fast SPRs,
and a "mw" command for writing an 8-byte value to memory. It also
adds an "icreset" command for resetting the instruction cache
and fixes the "creset" command to actually reset the core instead
of starting it. The MSR is now printed along with the NIA in the
status information.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Sat, 2 May 2020 03:26:30 +0000 (13:26 +1000)]
debug: Provide a way to examine GPRs, fast SPRs and MSR
This provides commands on the debug interface to read the value of
the MSR or any of the 64 GSPR register file entries. The GSPR values
are read using the B port of the register file in a cycle when
decode2 is not using it.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Sat, 2 May 2020 10:08:10 +0000 (20:08 +1000)]
Improve architectural compliance of mfspr and mtspr
Mfspr from an unimplemented SPR should be a no-op in privileged state,
so in this case we need to write back whatever was previously in the
destination register. For problem state, both mtspr and mfspr to
unimplemented SPRs should cause a program interrupt.
There are special cases in the architecture for SPRs 0, 4 5 and 6
which we still don't implement.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Sat, 2 May 2020 03:45:39 +0000 (13:45 +1000)]
decode1: Implement eieio as a nop
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Sat, 2 May 2020 03:28:19 +0000 (13:28 +1000)]
Implement the extswsli instruction
This mainly required the addition of an entry to the opcode 31 decode
table and a 32-bit sign-extender in the rotator.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Benjamin Herrenschmidt [Tue, 10 Sep 2019 17:05:56 +0000 (18:05 +0100)]
soc: Add DRAM address decoding
Still not attached to any board
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Benjamin Herrenschmidt [Thu, 7 May 2020 12:09:59 +0000 (22:09 +1000)]
core: Add alternate reset address
An external signal can control whether the core will start
executing at the standard or the alternate reset address.
This will be used when litedram is initialized by microwatt
itself, to route the reset to the built-in init code secondary
block RAM.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Benjamin Herrenschmidt [Tue, 10 Sep 2019 17:05:32 +0000 (18:05 +0100)]
litedram: Add basic support for LiteX LiteDRAM
This comes in two parts:
- A generator script which uses LiteX to generate litedram cores
along with their init files for various boards (currently Arty and
Nexys-video). This comes with configs for arty and nexys_video.
- A fusesoc "generator" which uses pre-generated litedram cores
The generation process is manual on purpose. This include pre-generated
cores for the two above boards.
This is done so that one doesn't have to install LiteX to build
microwatt. In addition, the generator script or wrapper vhdl tend to
break when LiteX changes significantly which happens.
This is still rather standalone and hasn't been plumbed into the SoC
or the FPGA toplevel files yet.
At this point LiteDRAM self-initializes using a built-in VexRiscv
"Minimum" core obtained from LiteX and included in this commit. There
is some plumbing to generate and cores that are initialized by Microwatt
directly but this isn't working yet and so isn't enabled yet.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Benjamin Herrenschmidt [Fri, 8 May 2020 01:36:37 +0000 (11:36 +1000)]
core: Improve core reset
The icache would still spit out an instruction which could
cause a 0x700 instead of a reset.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Benjamin Herrenschmidt [Mon, 4 May 2020 12:16:22 +0000 (22:16 +1000)]
mw_debug: Fix core reset
mw_debug creset would poke the START bit instead of the RESET bit
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Benjamin Herrenschmidt [Thu, 30 Apr 2020 07:52:11 +0000 (17:52 +1000)]
Update hello_world for 100Mhz clock
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Benjamin Herrenschmidt [Mon, 30 Sep 2019 04:07:16 +0000 (14:07 +1000)]
Change default frequency to 100Mhz
LiteDRAM at the moment pretty much enforces 100Mhz, and our software
isn't quite yet adaptable, so switch out default to 100Mhz accross
the board. Recent timing improvements should make it a non-issue.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Benjamin Herrenschmidt [Fri, 8 May 2020 01:40:39 +0000 (11:40 +1000)]
xics: Add missing fusesoc core file
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Anton Blanchard [Wed, 6 May 2020 23:59:19 +0000 (09:59 +1000)]
Merge pull request #166 from paulusmack/master
MSR fixes, implement privilege checking, implement dcbz
Paul Mackerras [Mon, 4 May 2020 05:17:04 +0000 (15:17 +1000)]
execute1: Fix interrupt delivery during slow instructions
During slow instructions such as multiply or divide, if a decrementer
(or other asynchronous) interrupt becomes pending, it disrupts the
logic that keeps stall asserted until the end of the slow
instruction, and the interrupt logic starts trying to deliver the
interrupt before the slow instruction has finished.
To fix that, make the interrupt logic wait until it sees e_in.valid
set before setting exception to 1.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Thu, 30 Apr 2020 23:00:21 +0000 (09:00 +1000)]
wishbone_debug_master: Fix address auto-increment for memory writes
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Wed, 6 May 2020 04:15:22 +0000 (14:15 +1000)]
Merge remote-tracking branch 'remotes/origin/master'
Paul Mackerras [Sun, 3 May 2020 22:31:18 +0000 (08:31 +1000)]
dcache: Don't assert on dcbz cache hit
We can hit the assert for req_op = OP_STORE_HIT and reloading in the
case of dcbz, since it looks like a store. Therefore we need to
exclude that case from the assert.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Anton Blanchard [Wed, 6 May 2020 03:27:17 +0000 (13:27 +1000)]
Merge pull request #165 from mikey/xics
Implement XICS compliant interrupt controller
Anton Blanchard [Fri, 1 May 2020 09:52:59 +0000 (19:52 +1000)]
Merge pull request #167 from tomtor/patch-1
Fix Rust README.md
Tom Vijlbrief [Fri, 1 May 2020 07:39:49 +0000 (09:39 +0200)]
Update README.md
Fix formatting of Rust README
Signed-off-by: Tom Vijlbrief <tvijlbrief@gmail.com>
Paul Mackerras [Wed, 29 Apr 2020 01:37:02 +0000 (11:37 +1000)]
Change the default cross compiler prefix to powerpc64le-linux-gnu-
That is what is used by the packaged cross-compilers on (at least)
Fedora and Ubuntu.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Wed, 29 Apr 2020 01:11:22 +0000 (11:11 +1000)]
Makefile: fix typo
Fix a typo which meant that the console tests weren't getting
executed by 'make check'.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Tue, 28 Apr 2020 23:09:23 +0000 (09:09 +1000)]
tests: Add a test for privileged instruction interrupts
This adds a test that tries to execute various privileged instructions
with MSR[PR] = 1. This also incidentally tests some of the MSR bit
manipulations.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Tue, 28 Apr 2020 08:11:52 +0000 (18:11 +1000)]
dcache: Implement the dcbz instruction
This adds logic to dcache and loadstore1 to implement dcbz. For now
it zeroes a single cache line (by default 64 bytes), not 128 bytes
like IBM Power processors do.
The dcbz operation is performed much like a load miss, except that
we are writing zeroes to memory instead of reading. As each ack
comes back, we write zeroes to the BRAM instead of data from memory.
In this way we zero the line in memory and also zero the line of
cache memory, establishing the line in the cache if it wasn't already
resident. If it was already resident then we overwrite the existing
line in the cache.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Fri, 3 Apr 2020 03:50:17 +0000 (14:50 +1100)]
Plumb insn_type through to loadstore1
In preparation for adding a TLB to the dcache, this plumbs the
insn_type from execute1 through to loadstore1, so that we can have
other operations besides loads and stores (e.g. tlbie) going to
loadstore1 and thence to the dcache. This also plumbs the unit field
of the decode ROM from decode2 through to execute1 to simplify the
logic around which ops need to go to loadstore1.
The load and store data formatting are now not conditional on the
op being OP_LOAD or OP_STORE. This eliminates the inferred latches
clocked by each of the bits of r.op that we were getting previously.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Tue, 28 Apr 2020 09:38:58 +0000 (19:38 +1000)]
execute1: Generate privileged instruction interrupts when MSR[PR] = 1
This adds logic to execute1 to check, when MSR[PR] = 1, whether each
instruction arriving to be executed is a privileged instruction.
If it is, a privileged-instruction type program interrupt is generated.
For the mtspr and mfspr instructions, we need to look at bit 20 of the
instruction (bit 4 of the SPR number) to determine if the SPR is
privileged.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Tue, 28 Apr 2020 10:28:20 +0000 (20:28 +1000)]
execute1: Improve architecture compliance of MSR and related instructions
This makes our treatment of the MSR conform better with the ISA.
- On reset, initialize the MSR to have the SF and LE bits set and
all the others reset. For good measure initialize r properly too.
- Fix the bit numbering in msr_copy (the code was using big-endian
bit numbers, not little-endian).
- Use constants like MSR_EE to index MSR bits instead of expressions
like '63 - 48', for readability.
- Set MSR[SF, LE] and clear MSR[PR, IR, DR, RI] on interrupts.
- Copy the relevant fields for rfid instead of using msr_copy, because
the partial function fields of the MSR should be left unchanged,
not zeroed. Our implementation of rfid is like the architecture
description of hrfid, because we don't implement hypervisor mode.
- Return the whole MSR for mfmsr.
- Implement the L field for mtmsrd (L=1 copies just EE and RI).
- For mtmsrd with L=0, leave out the HV, ME and LE bits as per the arch.
- For mtmsrd and rfid, if PR ends up set, then also set EE, IR and DR
as per the arch.
- A few other minor tidyups (no semantic change).
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Anton Blanchard [Thu, 23 Apr 2020 09:50:16 +0000 (19:50 +1000)]
Merge pull request #164 from mikey/tags
Add VHDL TAGS
Anton Blanchard [Thu, 23 Apr 2020 09:49:24 +0000 (19:49 +1000)]
Merge pull request #163 from paulusmack/excpath
Fix the bug causing the assert that Mikey hit
Michael Neuling [Thu, 23 Apr 2020 04:37:29 +0000 (14:37 +1000)]
XICS test case
Checks interrupt masking and priorities.
Adds to `make test_xics` which is run in `make check` also.
Signed-off-by: Michael Neuling <mikey@neuling.org>
Michael Neuling [Thu, 23 Apr 2020 04:36:05 +0000 (14:36 +1000)]
XICS interrupt controller
New unified ICP and ICS XICS compliant interrupt controller.
Configurable number of hardware sources.
Fixed hardware source number based on hardware line taken. All
hardware interrupts are a fixed priority. Level interrupts supported
only.
Hardwired to 0xc0004000 in SOC (UART is kept at 0xc0002000).
Signed-off-by: Michael Neuling <mikey@neuling.org>
Michael Neuling [Thu, 23 Apr 2020 04:28:59 +0000 (14:28 +1000)]
Wire up sim uart TX interrupt
TX is always ready, so just always sent interrupt when enabled.
No RX interrupt.
Signed-off-by: Michael Neuling <mikey@neuling.org>
Michael Neuling [Thu, 23 Apr 2020 04:28:08 +0000 (14:28 +1000)]
Add calls to dis/enable potato uart IRQ
Signed-off-by: Michael Neuling <mikey@neuling.org>
Michael Neuling [Wed, 8 Apr 2020 07:35:32 +0000 (17:35 +1000)]
Add VHDL TAGS
Adds `make TAGS`
Signed-off-by: Michael Neuling <mikey@neuling.org>
Paul Mackerras [Wed, 22 Apr 2020 03:54:38 +0000 (13:54 +1000)]
execute1: Don't execute ld/st instruction when taking interrupt
This fixes a bug in the logic where we would still send a load
or store instruction to loadstore1 even though we have decided
to take an asynchronous interrupt.
Reported-by: Michael Neuling <mikey@neuling.org>
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Anton Blanchard [Thu, 16 Apr 2020 08:42:42 +0000 (18:42 +1000)]
Merge pull request #162 from antonblanchard/bin2hex-removal
rust_lib_demo: Remove bin2hex.py
Anton Blanchard [Thu, 16 Apr 2020 08:42:13 +0000 (18:42 +1000)]
Merge pull request #161 from antonblanchard/hello-world-Makefile
hello_world: Use Makefile automatic variables
Anton Blanchard [Thu, 16 Apr 2020 07:44:17 +0000 (17:44 +1000)]
rust_lib_demo: Remove bin2hex.py
We are using scripts/bin2hex.py, so we can get rid of this copy.
Signed-off-by: Anton Blanchard <anton@linux.ibm.com>
Anton Blanchard [Thu, 16 Apr 2020 07:40:52 +0000 (17:40 +1000)]
Merge pull request #160 from antonblanchard/tomtor-rust-2
Rebase Tom's rust demo patches
Anton Blanchard [Thu, 16 Apr 2020 07:38:07 +0000 (17:38 +1000)]
hello_world: Use Makefile automatic variables
Fix a few whitespace issues while here.
Signed-off-by: Anton Blanchard <anton@linux.ibm.com>
Anton Blanchard [Thu, 16 Apr 2020 07:14:18 +0000 (17:14 +1000)]
rust_lib_demo: Use common console code
Use a symlink to share the console code in hello_world. Not ideal,
but we can improve on it later.
Signed-off-by: Anton Blanchard <anton@linux.ibm.com>
Anton Blanchard [Thu, 16 Apr 2020 07:08:15 +0000 (17:08 +1000)]
rust_lib_demo: Update package dependencies to fix a build error
I'm hitting a build error:
error[E0050]: method `alloc` has 2 parameters but the declaration in trait `core::alloc::AllocRef::alloc` has 3
Updating the version of linked_list_allocator fixes it. I updated
heapless to while I was at it.
Signed-off-by: Anton Blanchard <anton@linux.ibm.com>
Tom Vijlbrief [Fri, 3 Jan 2020 09:34:21 +0000 (10:34 +0100)]
Add Rust demo
Signed-off-by: Tom Vijlbrief <tvijlbrief@gmail.com>
Anton Blanchard [Thu, 16 Apr 2020 05:15:07 +0000 (15:15 +1000)]
Merge pull request #159 from shenki/fusesoc-ram-16k
FuseSoC needs 16kB of RAM
Joel Stanley [Wed, 15 Apr 2020 06:36:54 +0000 (16:06 +0930)]
Set default RAM to be 16K in microwatt.core
This allows it to run hello world out of the box.
Signed-off-by: Joel Stanley <joel@jms.id.au>
Joel Stanley [Wed, 15 Apr 2020 06:32:21 +0000 (16:02 +0930)]
README: hello world needs 16KB of RAM
STACK_TOP is at 0x2000 (8K) so we need something larger as a minimum.
Signed-off-by: Joel Stanley <joel@jms.id.au>
Anton Blanchard [Tue, 14 Apr 2020 02:47:00 +0000 (12:47 +1000)]
Merge pull request #158 from paulusmack/excpath
Fix exception stuff so we make timing again
Anton Blanchard [Thu, 9 Apr 2020 01:47:05 +0000 (11:47 +1000)]
Merge pull request #157 from paulusmack/master
Start using cache-inhibited loads and stores to access the UART
Paul Mackerras [Mon, 6 Apr 2020 04:07:45 +0000 (14:07 +1000)]
Decode attn in the major opcode decode table
This decodes attn using entry 0 of the major_decode_rom_array table
instead of a special case in the decode1_1 process. This means that
only the major opcode (the top 6 bits) is checked at decode time.
To make sure the instruction is attn not some random illegal pattern,
we now check bits 1-10 of the instruction at execute time and
generate an illegal instruction interrupt if those bits are not
0100000000.
This reduces LUT consumption by 42 LUTs on the Arty A7-100.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Mon, 6 Apr 2020 03:24:08 +0000 (13:24 +1000)]
Decode sc in the major opcode decode table
This decodes sc using entry 17 of the major_decode_rom_array table
instead of a special case in the decode1_1 process. This means that
only the major opcode (the top 6 bits) is checked at decode time.
To make sure that the instruction is sc not scv, we now check bit
1 of the instruction at execute time and generate an illegal
instruction interrupt if it is 0 (indicating scv). The level field
of the sc instruction is now ignored.
This reduces LUT consumption by 31 LUTs on the Arty A7-100.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Mon, 6 Apr 2020 03:07:00 +0000 (13:07 +1000)]
Remove sim_config instruction
It's not used any more, and it's not in the ISA.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Tue, 7 Apr 2020 10:07:33 +0000 (20:07 +1000)]
execute1: Implement trap instructions properly
This implements the trap instructions (tw, twi, td, tdi) using
much of the same code as is used for the cmp/cmpl instructions.
A 5-bit comparison value is generated, and for cmp/cmpl, the
appropriate 3 bits are used to update the destination CR, and for
trap instructions, the comparison value is ANDed with the TO
field, and an exception is generated if any bit of the result
is 1.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Mon, 6 Apr 2020 02:58:42 +0000 (12:58 +1000)]
Consolidate trap variants under a single OP_TRAP
This replaces OP_TD, OP_TDI, OP_TW and OP_TWI with a single OP_TRAP,
distinguishing the cases by the input_reg_b and is_32bit fields of
the decode ROM. This adds the twi and td cases to the decode tables.
For now we make all of the trap instructions unconditionally generate
a trap-type program interrupt if the TO field of the instruction is
all ones, and do nothing otherwise.
This reduces the number of values in insn_type_t from 65 to 62,
meaning that an insn_type_t can now be encoded in 6 bits rather
than 7.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Tue, 7 Apr 2020 08:38:18 +0000 (18:38 +1000)]
execute1: Simplify the interrupt logic a little
This makes some simplifications to the interrupt logic which will
help with later commits.
- When irq_valid is set, don't set exception to 1 until we have a
valid instruction. That means we can remove the if e_in.valid = '1'
test from the exception = '1' block.
- Don't assert stall_out on the first cycle of delivering an
interrupt. If we do get another instruction in the next cycle,
nothing will happen because we have ctrl.irq_state set and we
will just continue writing the interrupt registers.
- Make sure we deliver as many completions as we got instructions,
otherwise the outstanding instruction count in control.vhdl gets
out of sync.
- In writeback, make sure all of the other write enables are ignored
when e_in.exc_write_enable is set.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Mon, 6 Apr 2020 02:20:36 +0000 (12:20 +1000)]
Rename OP_MCRF to OP_CROP and trim insn_type_t
OP_MCRF covers the CR logical ops as well as mcrf since commit
c05441bf4793 ("Implement CRNOR and friends"), so this renames
OP_MCRF to OP_CROP. The OP_* values for the individual CR logical
ops (OP_CRAND, etc.) are not used, so remove them from insn_type_t.
No functional change.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Mon, 6 Apr 2020 04:09:20 +0000 (14:09 +1000)]
tests: Put an attn instruction at 0x700
This puts an attn instruction at offset 0x700 in each of the tests
so that the test will terminate if a program interrupt is taken.
This means that we can implement the tw instruction to cause a
program interrupt.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Fri, 3 Apr 2020 06:02:14 +0000 (17:02 +1100)]
Give exceptions a separate path to writeback
This adds separate fields in Execute1ToWritebackType for use in
writing SRR0/1 (and in future other SPRs) on an interrupt. With
this, we make timing once again on the Arty A7-100 -- previously
we were missing by 0.2ns, presumably due to the result mux being
wider than before.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Fri, 3 Apr 2020 02:47:20 +0000 (13:47 +1100)]
tests: Update executables
As suggested by Michael Neuling.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Fri, 3 Apr 2020 02:46:36 +0000 (13:46 +1100)]
tests: Adjust header inclusions and Makefile.test
This fixes the decrementer, illegal and sc tests to compile
successfully with cross-compilers that don't provide unistd.h
or string.h. Instead of those headers we include stddef.h.
This also fixes tests/Makefile.test to do what one expects
when CROSS_COMPILE is defined in the environment.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Wed, 1 Apr 2020 04:48:30 +0000 (15:48 +1100)]
hello_world: Use ldcix/stdcix to access UART
This is one step towards ultimately removing the address-based
cache inhibit hack from dcache.vhdl.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Paul Mackerras [Wed, 1 Apr 2020 04:46:43 +0000 (15:46 +1100)]
hello_world: Adjust header inclusions and Makefile
Currently hello_world fails to build with distro cross compiler
packages such as Debian gcc-powerpc64-linux-gnu, because it doesn't
provide string.h or unistd.h. In fact we don't need them, we just
need stddef.h. This adds #include <stddef.h> to console.h to get
size_t defined. We also add #include "console.h" to console.c.
The hello_world Makefile currently hard-codes CROSS_COMPILE on
non-PPC machines. This means that a command like:
$ CROSS_COMPILE=powerpc64le-linux-gnu- make
doesn't do what you expect; it just tries to use powerpc64le-linux-gcc
regardless. Adding a '?' makes it do what one expects.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Anton Blanchard [Thu, 2 Apr 2020 23:36:36 +0000 (10:36 +1100)]
Merge pull request #155 from mikey/exceptions
Add decrementer, illegal and system call exceptions
Michael Neuling [Tue, 31 Mar 2020 06:32:38 +0000 (17:32 +1100)]
Add test cases for new exceptions and supervisor state
This adds test cases for:
- sc, illegals and decrementer exceptions
- decrementer overflow
- rfid
- mt/mf sprg0/1 srr0/1
- mtdec
- mtmsrd
- sc
It also adds these test cases to make check/check_light
Signed-off-by: Michael Neuling <mikey@neuling.org>
Michael Neuling [Tue, 31 Mar 2020 06:32:09 +0000 (17:32 +1100)]
Add sc, illegal and decrementer exceptions and some supervisor state
This adds the following exceptions:
- 0x700 program check (for illegal instructions)
- 0x900 decrementer
- 0xc00 system call
This also adds some supervisor state:
- decremeter
- msr
(SPRG0/1 and SRR0/1 already exist as fast SPRs)
It also adds some supporting instructions:
- rfid
- mtmsrd
- mfmsr
- sc
MSR state is added but only EE is used in this patch set. Other bits
are read/written but are not used at all.
This adds a 2 stage state machine to execute1.vhdl. This state machine
allows fast SPRS SRR0/1 to be written in different cycles. This state
machine can be extended later to add DAR and DSISR SPR writing for
more complex exceptions like page faults.
Signed-off-by: Michael Neuling <mikey@neuling.org>
Michael Neuling [Tue, 24 Mar 2020 22:58:18 +0000 (09:58 +1100)]
Plumb attn instruction through to execute1
Currently we decode attn but we just mark it as an illegal.
This adds a separate case statement in execute 1 for attn to terminate
the core. Illegals also do this currently but we are soon implementing
a 0x700 execption for them.
Signed-off-by: Michael Neuling <mikey@neuling.org>
Michael Neuling [Tue, 17 Mar 2020 04:25:34 +0000 (15:25 +1100)]
Breakout the console code so it can be reused.
No functional change.
Signed-off-by: Michael Neuling <mikey@neuling.org>
Anton Blanchard [Mon, 30 Mar 2020 02:46:23 +0000 (13:46 +1100)]
Merge pull request #153 from paulusmack/master
Load/store improvements
Paul Mackerras [Mon, 30 Mar 2020 01:39:08 +0000 (12:39 +1100)]
loadstore1: Add support for cache-inhibited load and store instructions
This adds support for lbzcix, lhzcix, lwzcix, ldcix, stbcix, sthcix,
stwcix and stdcix. The temporary hack where accesses to addresses of
the form 0xc??????? are made non-cacheable is left in for now to avoid
making existing programs non-functional.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>