Hi Li and Zhao,
On 9/10/23 11:01, xianglai li wrote:
From: Tianrui Zhao <zhaotian...@loongson.cn>
Implement kvm_arch_get/set_registers interfaces, many regs
can be get/set in the function, such as core regs, csr regs,
fpu regs, mp state, etc.
Cc: "Michael S. Tsirkin" <m...@redhat.com>
Cc: Cornelia Huck <coh...@redhat.com>
Cc: Paolo Bonzini <pbonz...@redhat.com>
Cc: "Marc-André Lureau" <marcandre.lur...@redhat.com>
Cc: "Daniel P. Berrangé" <berra...@redhat.com>
Cc: Thomas Huth <th...@redhat.com>
Cc: "Philippe Mathieu-Daudé" <phi...@linaro.org>
Cc: Richard Henderson <richard.hender...@linaro.org>
Cc: Peter Maydell <peter.mayd...@linaro.org>
Cc: Bibo Mao <maob...@loongson.cn>
Cc: Song Gao <gaos...@loongson.cn>
Cc: Xiaojuan Yang <yangxiaoj...@loongson.cn>
Cc: Tianrui Zhao <zhaotian...@loongson.cn>
Signed-off-by: Tianrui Zhao <zhaotian...@loongson.cn>
Signed-off-by: xianglai li <lixiang...@loongson.cn>
---
meson.build | 1 +
target/loongarch/cpu.c | 3 +
target/loongarch/cpu.h | 2 +
target/loongarch/kvm.c | 406 +++++++++++++++++++++++++++++++++-
target/loongarch/trace-events | 13 ++
target/loongarch/trace.h | 1 +
6 files changed, 424 insertions(+), 2 deletions(-)
create mode 100644 target/loongarch/trace-events
create mode 100644 target/loongarch/trace.h
+static int kvm_larch_getq(CPUState *cs, uint64_t reg_id,
+ uint64_t *addr)
+{
+ struct kvm_one_reg csrreg = {
+ .id = reg_id,
+ .addr = (uintptr_t)addr
+ };
+
+ return kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &csrreg);
+}
This is kvm_get_one_reg().
+static int kvm_larch_putq(CPUState *cs, uint64_t reg_id,
+ uint64_t *addr)
+{
+ struct kvm_one_reg csrreg = {
+ .id = reg_id,
+ .addr = (uintptr_t)addr
+ };
+
+ return kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &csrreg);
+}
This is kvm_set_one_reg().
+
+#define KVM_GET_ONE_UREG64(cs, ret, regidx, addr) \
+ ({ \
+ err = kvm_larch_getq(cs, KVM_IOC_CSRID(regidx), addr); \
+ if (err < 0) { \
+ ret = err; \
+ trace_kvm_failed_get_csr(regidx, strerror(errno)); \
+ } \
+ })
+
+#define KVM_PUT_ONE_UREG64(cs, ret, regidx, addr) \
+ ({ \
+ err = kvm_larch_putq(cs, KVM_IOC_CSRID(regidx), addr); \
+ if (err < 0) { \
+ ret = err; \
+ trace_kvm_failed_put_csr(regidx, strerror(errno)); \
+ } \
+ })