Hi Li and Zhao,

On 9/10/23 11:01, xianglai li wrote:
From: Tianrui Zhao <[email protected]>

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" <[email protected]>
Cc: Cornelia Huck <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: "Marc-André Lureau" <[email protected]>
Cc: "Daniel P. Berrangé" <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: "Philippe Mathieu-Daudé" <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Peter Maydell <[email protected]>
Cc: Bibo Mao <[email protected]>
Cc: Song Gao <[email protected]>
Cc: Xiaojuan Yang <[email protected]>
Cc: Tianrui Zhao <[email protected]>

Signed-off-by: Tianrui Zhao <[email protected]>
Signed-off-by: xianglai li <[email protected]>
---
  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));    \
+        }                                                         \
+    })


Reply via email to