OSDN Git Service

target/riscv: add zicntr extension flag for TCG
authorDaniel Henrique Barboza <dbarboza@ventanamicro.com>
Mon, 23 Oct 2023 15:39:24 +0000 (12:39 -0300)
committerAlistair Francis <alistair.francis@wdc.com>
Tue, 7 Nov 2023 01:06:02 +0000 (11:06 +1000)
commitc004099330c2bb9c94984ac917815572fcd55bd0
tree04d1c072f377de83e5bc3ecf7f04d3e4731ddd95
parentac66f2f0d12d7ebb69bb45d5eb7f73fb0542bae5
target/riscv: add zicntr extension flag for TCG

zicntr is the Base Counters and Timers extension described in chapter 12
of the unprivileged spec. It describes support for RDCYCLE, RDTIME and
RDINSTRET.

QEMU already implements it in TCG way before it was a discrete
extension.  zicntr is part of the RVA22 profile, so let's add it to QEMU
to make the future profile implementation flag complete. Given than it
represents an already existing feature, default it to 'true' for all
CPUs.

For TCG, we need a way to disable zicntr if the user wants to. This is
done by restricting access to the CYCLE, TIME, and INSTRET counters via
the 'ctr()' predicate when we're about to access them.

Disabling zicntr happens via the command line or if its dependency,
zicsr, happens to be disabled. We'll check for zicsr during realize()
and, in case it's absent, disable zicntr. However, if the user was
explicit about having zicntr support, error out instead of disabling it.

Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20231023153927.435083-2-dbarboza@ventanamicro.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
target/riscv/cpu.c
target/riscv/cpu_cfg.h
target/riscv/csr.c
target/riscv/tcg/tcg-cpu.c