[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/5] target/loongarch: Add common header file for CSR register
From: |
Bibo Mao |
Subject: |
[PATCH 3/5] target/loongarch: Add common header file for CSR register |
Date: |
Mon, 13 Jan 2025 16:25:55 +0800 |
Common header file csr.h is added here, it can be used by both
TCG mode and kvm mode.
Macro CONFIG_TCG is used for TCG specific CSR function because
of function parameter such as TCGv and TCGv_ptr.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
target/loongarch/csr.h | 35 +++++++++++++++++++
.../tcg/insn_trans/trans_privileged.c.inc | 18 +---------
2 files changed, 36 insertions(+), 17 deletions(-)
create mode 100644 target/loongarch/csr.h
diff --git a/target/loongarch/csr.h b/target/loongarch/csr.h
new file mode 100644
index 0000000000..b0e51d51cd
--- /dev/null
+++ b/target/loongarch/csr.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2025 Loongson Technology Corporation Limited
+ */
+
+#ifndef TARGET_LOONGARCH_CSR_H
+#define TARGET_LOONGARCH_CSR_H
+
+#include "cpu-csr.h"
+#ifdef CONFIG_TCG
+#include "tcg/tcg-op.h"
+#endif
+
+#ifdef CONFIG_TCG
+typedef void (*GenCSRRead)(TCGv dest, TCGv_ptr env);
+typedef void (*GenCSRWrite)(TCGv dest, TCGv_ptr env, TCGv src);
+#else
+typedef void (*GenCSRRead)(void);
+typedef void (*GenCSRWrite)(void);
+#endif
+
+enum {
+ CSRFL_READONLY = (1 << 0),
+ CSRFL_EXITTB = (1 << 1),
+ CSRFL_IO = (1 << 2),
+};
+
+typedef struct {
+ int offset;
+ int flags;
+ GenCSRRead readfn;
+ GenCSRWrite writefn;
+} CSRInfo;
+
+#endif /* TARGET_LOONGARCH_TCG_LOONGARCH_H */
diff --git a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc
b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc
index 2dfba3af76..34a7ca39fd 100644
--- a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc
+++ b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc
@@ -5,7 +5,7 @@
* LoongArch translation routines for the privileged instructions.
*/
-#include "cpu-csr.h"
+#include "csr.h"
#ifdef CONFIG_USER_ONLY
@@ -42,22 +42,6 @@ GEN_FALSE_TRANS(idle)
#else
-typedef void (*GenCSRRead)(TCGv dest, TCGv_ptr env);
-typedef void (*GenCSRWrite)(TCGv dest, TCGv_ptr env, TCGv src);
-
-typedef struct {
- int offset;
- int flags;
- GenCSRRead readfn;
- GenCSRWrite writefn;
-} CSRInfo;
-
-enum {
- CSRFL_READONLY = (1 << 0),
- CSRFL_EXITTB = (1 << 1),
- CSRFL_IO = (1 << 2),
-};
-
#define CSR_OFF_FUNCS(NAME, FL, RD, WR) \
[LOONGARCH_CSR_##NAME] = { \
.offset = offsetof(CPULoongArchState, CSR_##NAME), \
--
2.39.3