Commit graph

7309 commits

Author SHA1 Message Date
Mark Cave-Ayland 0be85bf91a target/m68k: don't set SSW ATC bit for physical bus errors
If a NuBus slot doesn't contain a card, the Quadra hardware generates a physical
bus error if the CPU attempts to access the slot address space. Both Linux and
MacOS use a separate bus error handler during NuBus accesses in order to detect
and recover when addressing empty slots.

According to the MC68040 users manual the ATC bit of the SSW is used to
distinguish between ATC faults and physical bus errors. MacOS specifically checks
the stack frame generated by a NuBus error and panics if the SSW ATC bit is set.

Update m68k_cpu_transaction_failed() so that the SSW ATC bit is not set if the
memory API returns MEMTX_DECODE_ERROR which will be used to indicate that an
access to an empty NuBus slot occurred.

Backports d6cbd8f7a19e6f0fd22a598aad992c4913f481f2
2021-03-12 14:29:37 -05:00
Laurent Vivier 945dd6fba9 target/m68k: implement rtr instruction
This is needed to boot MacOS ROM.

Pull the condition code and the program counter from the stack.

Operation:

(SP) -> CCR
SP + 2 -> SP
(SP) -> PC
SP + 4 -> SP

This operation is not privileged.

Backports 6abcec36741e589c855084e59195fc3454bf4be6
2021-03-12 14:28:33 -05:00
Alex Bennée c1ca2ae0ba include/exec: lightly re-arrange TranslationBlock
Lets make sure all the flags we compare when looking up blocks are
together in the same place.

Backports 872ebd884dd68ecef4c6f9f86c5da519f18bd31e
2021-03-09 13:25:04 -05:00
Richard Henderson d83b1ea283 tcg: Split out tcg_raise_tb_overflow
Allow other places in tcg to restart with a smaller tb.

Backports db6b7d0c6936cd209e3e8d95aea61ad29ceef5e6
2021-03-09 13:23:02 -05:00
Richard Henderson 6ef897bbad tcg/aarch64: Fix generation of scalar vector operations
For some vector operations, "1D" is not a valid type, and there
are separate instructions for the 64-bit scalar operation.

Backports d81bad24dfea6ec0331599de1f31d822aba9dae1
2021-03-09 13:22:06 -05:00
Richard Henderson b01d5a9fdf tcg/aarch64: Fix I3617_CMLE0
Fix a typo in the encodeing of the cmle (zero) instruction.

Fixes: 14e4c1e2355 ("tcg/aarch64: Add vector operations")

Backports 6c2c7772f69bcd7e7a88308fd6aaf19debb7ada4
2021-03-09 13:17:15 -05:00
Richard Henderson 043d65862a tcg/aarch64: Fix constant subtraction in tcg_out_addsub2
An hppa guest executing

0x000000000000e05c: ldil L%10000,r4
0x000000000000e060: ldo 0(r4),r4
0x000000000000e064: sub r3,r4,sp

produces

---- 000000000000e064 000000000000e068
sub2_i32 tmp0,tmp4,r3,$0x1,$0x10000,$0x0

after folding and constant propagation. Then we hit

tcg-target.c.inc:640: tcg_out_insn_3401: Assertion `aimm <= 0xfff' failed.

because aimm is in fact -16, but unsigned.

The ((bl < 0) ^ sub) condition which negates bl is incorrect and will
always lead to this abort. If the constant is positive, sub will make
it negative; if the constant is negative, sub will keep it negative.

Backports 707b45a2475e25709f0dee00f8fdf39d346ed21e
2021-03-09 13:16:41 -05:00
Atish Patra e54d0916ef target/riscv/pmp: Raise exception if no PMP entry is configured
As per the privilege specification, any access from S/U mode should fail
if no pmp region is configured.

Backports d102f19a2085ac931cb998e6153b73248cca49f1
2021-03-08 15:39:55 -05:00
Alistair Francis 037b9e3bd1 target/riscv: csr: Remove compile time XLEN checks
Backports 8987cdc48120c268568cdf87ba38591809d3efd1
2021-03-08 15:34:30 -05:00
Alistair Francis 90abfa7c11 target/riscv: cpu_helper: Remove compile time XLEN checks
Backports f08c7ff3dc552d423439284a725f384b85b99062
2021-03-08 15:29:13 -05:00
Alistair Francis ea716ff2db target/riscv: Add a riscv_cpu_is_32bit() helper function
Backports 51ae0cabc67c418264d5ae28214603aabc88b9b6
2021-03-08 15:26:57 -05:00
Alistair Francis 5973588ac0 target/riscv: fpu_helper: Match function defs in HELPER macros
Update the function definitions generated in helper.h to match the
actual function implementations.

Also remove all compile time XLEN checks when building.

Backports 5b6c291b8db8effff625db321be232e0c4dcdb6c
2021-03-08 15:25:30 -05:00
Alistair Francis b23e786779 riscv: spike: Remove target macro conditionals
Backports dc4d4aaee31cd3ac4020d3b15729f0a104ce8862
2021-03-08 15:20:41 -05:00
Alistair Francis 19c937f2cc target/riscv: Add a TYPE_RISCV_CPU_BASE CPU
Backports c0a635f3973d974befb954463287786fd988bb64
2021-03-08 15:18:00 -05:00
Alex Richardson 8e4e0a6993 target/riscv: Fix definition of MSTATUS_TW and MSTATUS_TSR
The TW and TSR fields should be bits 21 and 22 and not 30/29.
This was found while comparing QEMU behaviour against the sail formal
model (https://github.com/rems-project/sail-riscv/).

Backports 529577457cbba9e429af629c46204f63e50fa832
2021-03-08 15:16:50 -05:00
Yifei Jiang c50f8c9d93 target/riscv: Fix the bug of HLVX/HLV/HSV
We found that the hypervisor virtual-machine load and store instructions,
included HLVX/HLV/HSV, couldn't access guest userspace memory.

In the riscv-privileged spec, HLVX/HLV/HSV is defined as follow:
"As usual when V=1, two-stage address translation is applied, and
the HS-level sstatus.SUM is ignored."

But get_physical_address() doesn't ignore sstatus.SUM, when HLVX/HLV/HSV
accesses guest userspace memory. So this patch fixes it.

Backports c63ca4ff7f81116c26984973052991ff0bd7caec
2021-03-08 15:16:06 -05:00
Alistair Francis 416b2a0077 target/riscv: Split the Hypervisor execute load helpers
Split the hypervisor execute load functions into two seperate functions.
This avoids us having to pass the memop to the C helper functions.

Backports 7687537ab0c16e0b1e69e7707456573a64b8e13b
2021-03-08 15:14:47 -05:00
Alistair Francis 4762dcda3c target/riscv: Remove the hyp load and store functions
Remove the special Virtulisation load and store functions and just use
the standard tcg tcg_gen_qemu_ld_tl() and tcg_gen_qemu_st_tl() functions
instead.

As part of this change we ensure we still run an access check to make
sure we can perform the operations.

Backports 743077b35b1ed88ed243daefafe9403d88a958f6
2021-03-08 15:11:11 -05:00
Alistair Francis bd81c057ed target/riscv: Remove the HS_TWO_STAGE flag
The HS_TWO_STAGE flag is no longer required as the MMU index contains
the information if we are performing a two stage access.

Backports 1c1c060aa866986ef8b7eb334abbb8c104a46e5c
2021-03-08 15:03:15 -05:00
Alistair Francis e5a9b8fc17 target/riscv: Set the virtualised MMU mode when doing hyp accesses
When performing the hypervisor load/store operations set the MMU mode to
indicate that we are virtualised.

Backports 3e5979046f3f5f65828d3950d0c3ec9846d63715
2021-03-08 14:57:58 -05:00
Alistair Francis a998c18ad8 target/riscv: Add a virtualised MMU Mode
Add a new MMU mode that includes the current virt mode.

Backports c445593d30037d0c82241e8ec23eb845bca476e9
2021-03-08 14:56:14 -05:00
Xinhao Zhang 757608b77c target/riscv/csr.c : add space before the open parenthesis '('
Fix code style. Space required before the open parenthesis '('.

Backports 422819776101520cb56658ee5facf926526cf870
2021-03-08 14:54:03 -05:00
Yifei Jiang 9d47840784 target/riscv: Merge m/vsstatus and m/vsstatush into one uint64_t unit
mstatus/mstatush and vsstatus/vsstatush are two halved for RISCV32.
This patch expands mstatus and vsstatus to uint64_t instead of
target_ulong so that it can be saved as one unit and reduce some
ifdefs in the code.

Backports 284d697c74ef3f4210cbccc5cd6b4894740e4ab3
2021-03-08 14:52:44 -05:00
Yifei Jiang 281d851303 target/riscv: raise exception to HS-mode at get_physical_address
VS-stage translation at get_physical_address needs to translate pte
address by G-stage translation. But the G-stage translation error
can not be distinguished from VS-stage translation error in
riscv_cpu_tlb_fill. On migration, destination needs to rebuild pte,
and this G-stage translation error must be handled by HS-mode. So
introduce TRANSLATE_STAGE2_FAIL so that riscv_cpu_tlb_fill could
distinguish and raise it to HS-mode.

Backports 33a9a57d2c31ec9ed68858911dc490b5de15f342
2021-03-08 14:43:00 -05:00
Georg Kotheimer d2cea344f0 target/riscv: Fix implementation of HLVX.WU instruction
The HLVX.WU instruction is supposed to read a machine word,
but prior to this change it read a byte instead.

Fixes: 8c5362acb57 ("target/riscv: Allow generating hlv/hlvx/hsv instructions")

Backports 1da46012eaaeb2feb3aa6a5a8fc0a03200b673aa
2021-03-08 14:40:28 -05:00
Georg Kotheimer 7351f09919 target/riscv: Fix update of hstatus.GVA in riscv_cpu_do_interrupt
The hstatus.GVA bit was not set if the faulting guest virtual address
was zero.

Backports 4aeb9e26c219a85f465eb2cc7ef6939a3c71944f
2021-03-08 14:39:31 -05:00
Georg Kotheimer 640a26bf58 target/riscv: Fix update of hstatus.SPVP
When trapping from virt into HS mode, hstatus.SPVP was set to
the value of sstatus.SPP, as according to the specification both
flags should be set to the same value.
However, the assignment of SPVP takes place before SPP itself is
updated, which results in SPVP having an outdated value.

Backports ace544532c4064e995ef69ec9dc93aad62e19988
2021-03-08 14:38:23 -05:00
Alistair Francis 4805f204d8 riscv: Convert interrupt logs to use qemu_log_mask()
Currently we log interrupts and exceptions using the trace backend in
riscv_cpu_do_interrupt(). We also log exceptions using the interrupt log
mask (-d int) in riscv_raise_exception().

This patch converts riscv_cpu_do_interrupt() to log both interrupts and
exceptions with the interrupt log mask, so that both are printed when a
user runs QEMU with -d int.

Backports 69430111ab2fe3f32548a0e70437655d0d937a6a
2021-03-08 14:37:08 -05:00
Stefan Hajnoczi 320b59ddb9 qemu/atomic.h: rename atomic_ to qatomic_
clang's C11 atomic_fetch_*() functions only take a C11 atomic type
pointer argument. QEMU uses direct types (int, etc) and this causes a
compiler error when a QEMU code calls these functions in a source file
that also included <stdatomic.h> via a system header file:

$ CC=clang CXX=clang++ ./configure ... && make
../util/async.c:79:17: error: address argument to atomic operation must be a pointer to _Atomic type ('unsigned int *' invalid)

Avoid using atomic_*() names in QEMU's atomic.h since that namespace is
used by <stdatomic.h>. Prefix QEMU's APIs with 'q' so that atomic.h
and <stdatomic.h> can co-exist. I checked /usr/include on my machine and
searched GitHub for existing "qatomic_" users but there seem to be none.

This patch was generated using:

$ git grep -h -o '\<atomic\(64\)\?_[a-z0-9_]\+' include/qemu/atomic.h | \
sort -u >/tmp/changed_identifiers
$ for identifier in $(</tmp/changed_identifiers); do
sed -i "s%\<$identifier\>%q$identifier%g" \
$(git grep -I -l "\<$identifier\>")
done

I manually fixed line-wrap issues and misaligned rST tables.

Backports d73415a315471ac0b127ed3fad45c8ec5d711de1
2021-03-08 14:34:35 -05:00
Bin Meng 1341de97f0 hw/riscv: clint: Avoid using hard-coded timebase frequency
At present the CLINT timestamp is using a hard-coded timebase
frequency value SIFIVE_CLINT_TIMEBASE_FREQ. This might not be
true for all boards.

Add a new 'timebase-freq' property to the CLINT device, and
update various functions to accept this as a parameter.

Backports a47ef6e93ab2ca1db8d5ecb61fda3c41f926a26b
2021-03-08 14:01:58 -05:00
Bin Meng d508a74a74 target/riscv: cpu: Add a new 'resetvec' property
Currently the reset vector address is hard-coded in a RISC-V CPU's
instance_init() routine. In a real world we can have 2 exact same
CPUs except for the reset vector address, which is pretty common in
the RISC-V core IP licensing business.

Normally reset vector address is a configurable parameter. Let's
create a 64-bit property to store the reset vector address which
covers both 32-bit and 64-bit CPUs.

Backports 9b4c9b2b2a50fe4eb90d0ac2d8723b46ecb42511
2021-03-08 13:57:57 -05:00
Alistair Francis 0e14547c7d target/riscv: Support the Virtual Instruction fault
Backports e39a8320b088dd5efc9ebaafe387e52b3d962665
2021-03-08 13:55:02 -05:00
Alistair Francis c3d9e15f02 target/riscv: Return the exception from invalid CSR accesses
When performing a CSR access let's return a negative exception value on
an error instead of -1. This will allow us to specify the exception in
future patches.

Backports 57cb2083e638bb28616c059cbf067d99552a04bb
2021-03-08 13:49:09 -05:00
Alistair Francis dd9f854edb target/riscv: Support the v0.6 Hypervisor extension CRSs
Backports 83028098f45a08da209799aeea4801c362d0afeb
2021-03-08 13:40:30 -05:00
Alistair Francis 8e3d241d2c target/riscv: Only support little endian guests
Backports 30f663b16f81d862256c7c71bc909d4588924d8c
2021-03-08 13:34:22 -05:00
Alistair Francis 12d33edea5 target/riscv: Only support a single VSXL length
Backports f8dc878efc45691be7e6c2019a19c271fb9aebbb
2021-03-08 13:33:38 -05:00
Alistair Francis 1551a961ba target/riscv: Update the CSRs to the v0.6 Hyp extension
Backports 543ba53157f9003eaa9b802d44c577c5814e232c
2021-03-08 13:33:03 -05:00
Alistair Francis bf52a9b17e target/riscv: Update the Hypervisor trap return/entry
Backports f2d5850f71f3e41b240f328c2bc844a4e44e66c9
2021-03-08 13:31:03 -05:00
Alistair Francis db749a279d target/riscv: Fix the interrupt cause code
Backports 84b1c04bbaf48798a535b38410a0bf839f4a1943
2021-03-08 13:28:11 -05:00
Alistair Francis a5311a267d target/riscv: Convert MSTATUS MTL to GVA
Backports 9034e90ad9959b89da32978e3b6d71b7069050a5
2021-03-08 13:26:31 -05:00
Alistair Francis 7ceb984b60 target/riscv: Don't allow guest to write to htinst
Backports e2eb5ca8f66c239f6194afda88cad455e42725ef
2021-03-08 13:22:51 -05:00
Alistair Francis 4972437f93 target/riscv: Allow generating hlv/hlvx/hsv instructions
Backports 8c5362acb573b8b1913238a5ddefdeef12f513a8
2021-03-08 13:13:32 -05:00
Alistair Francis a8bce9af7a target/riscv: Allow setting a two-stage lookup in the virt status
Backports 5a894dd7709f3b6a9f3e861dec71f78098bb3373
2021-03-08 12:49:16 -05:00
Zong Li 9792907bcf target/riscv: Change the TLB page size depends on PMP entries.
The minimum granularity of PMP is 4 bytes, it is small than 4KB page
size, therefore, the pmp checking would be ignored if its range doesn't
start from the alignment of one page. This patch detects the pmp entries
and sets the small page size to TLB if there is a PMP entry which cover
the page size.

Backports af3fc195e3c8e98b62eca3e4ee927f1965381dc3
2021-03-08 12:46:27 -05:00
Zong Li 2edba8fcfe target/riscv: Fix the translation of physical address
The real physical address should add the 12 bits page offset. It also
causes the PMP wrong checking due to the minimum granularity of PMP is
4 byte, but we always get the physical address which is 4KB alignment,
that means, we always use the start address of the page to check PMP for
all addresses which in the same page.

Backports 9ef82119b10d996cef63af679af5c1a7a85e6c19
2021-03-08 12:43:43 -05:00
Hou Weiying 55be7adad9 riscv: Fix bug in setting pmpcfg CSR for RISCV64
First, sizeof(target_ulong) equals to 4 on riscv32, so this change
does not change the function on riscv32. Second, sizeof(target_ulong)
equals to 8 on riscv64, and 'reg_index * 8 + i' is not a legal
pmp_index (we will explain later), which should be 'reg_index * 4 + i'.

If the parameter reg_index equals to 2 (means that we will change the
value of pmpcfg2, or the second pmpcfg on riscv64), then
pmpcfg_csr_write(env, 2, val) will map write tasks to
pmp_write_cfg(env, 2 * 8 + [0...7], val). However, no cfg csr is indexed
by value 16 or 23 on riscv64, so we consider it as a bug.

We are looking for constant (e.g., define a new constant named
RISCV_WORD_SIZE) in QEMU to help others understand code better,
but none was found. A possible good explanation of this literal is it is
the minimum word length on riscv is 4 bytes (32 bit).

Backports fdd33b86b20d153b131fc6259aea7a0084ab14b8
2021-03-08 12:42:12 -05:00
LIU Zhiwei cde007ccb6 target/riscv: check before allocating TCG temps
Backports ec80f8745931f0c8f8f2251e16bcc69170cf6f27
2021-03-08 12:41:19 -05:00
LIU Zhiwei 8fe29be764 target/riscv: Clean up fmv.w.x
Use tcg_gen_extu_tl_i64 to avoid the ifdef.

Backports 6e0229e63868b8b5bfcc54959cea227ed19f7bd3
2021-03-08 12:39:38 -05:00
Richard Henderson 3af34d3df4 target/riscv: Check nanboxed inputs in trans_rvf.inc.c
If a 32-bit input is not properly nanboxed, then the input is replaced
with the default qnan. The only inline expansion is for the sign-changing
set of instructions: FSGNJ.S, FSGNJX.S, FSGNJN.S.

Backports ffe70e4dfc9cf2a6934e674b81b69c847b403c4b
2021-03-08 12:38:15 -05:00
Richard Henderson ce54dfb4f7 target/riscv: Check nanboxed inputs to fp helpers
If a 32-bit input is not properly nanboxed, then the input is
replaced with the default qnan.

Backports 00e925c56074f8c4923a087e2eecea8a3315ea40
2021-03-08 12:31:18 -05:00