All of lore.kernel.org
 help / color / mirror / Atom feed
From: Song Gao <gaosong@loongson.cn>
To: qemu-devel@nongnu.org
Cc: Xiaojuan Yang <yangxiaojuan@loongson.cn>,
	richard.henderson@linaro.org, laurent@vivier.eu
Subject: [PATCH v12 22/26] linux-user: Add LoongArch cpu_loop support
Date: Wed,  1 Dec 2021 16:16:21 +0800	[thread overview]
Message-ID: <1638346585-3436-23-git-send-email-gaosong@loongson.cn> (raw)
In-Reply-To: <1638346585-3436-1-git-send-email-gaosong@loongson.cn>

Signed-off-by: Song Gao <gaosong@loongson.cn>
Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 configure                           |  5 ++
 linux-user/loongarch64/cpu_loop.c   | 94 +++++++++++++++++++++++++++++++++++++
 linux-user/loongarch64/target_cpu.h | 34 ++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 linux-user/loongarch64/cpu_loop.c
 create mode 100644 linux-user/loongarch64/target_cpu.h

diff --git a/configure b/configure
index 48c2177..9df99f6 100755
--- a/configure
+++ b/configure
@@ -581,6 +581,8 @@ elif check_define __arm__ ; then
   cpu="arm"
 elif check_define __aarch64__ ; then
   cpu="aarch64"
+elif check_define __loongarch64__ ; then
+  cpu="loongarch64"
 else
   cpu=$(uname -m)
 fi
@@ -612,6 +614,9 @@ case "$cpu" in
   sparc|sun4[cdmuv])
     cpu="sparc"
   ;;
+  loongarch)
+    cpu="loongarch"
+  ;;
   *)
     # This will result in either an error or falling back to TCI later
     ARCH=unknown
diff --git a/linux-user/loongarch64/cpu_loop.c b/linux-user/loongarch64/cpu_loop.c
new file mode 100644
index 0000000..2895472
--- /dev/null
+++ b/linux-user/loongarch64/cpu_loop.c
@@ -0,0 +1,94 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * QEMU LoongArch user cpu_loop.
+ *
+ * Copyright (c) 2021 Loongson Technology Corporation Limited
+ */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "qemu-common.h"
+#include "user-internals.h"
+#include "cpu_loop-common.h"
+#include "signal-common.h"
+
+void cpu_loop(CPULoongArchState *env)
+{
+    CPUState *cs = env_cpu(env);
+    int trapnr, si_code;
+    abi_long ret;
+
+    for (;;) {
+        cpu_exec_start(cs);
+        trapnr = cpu_exec(cs);
+        cpu_exec_end(cs);
+        process_queued_cpu_work(cs);
+
+        switch (trapnr) {
+        case EXCP_INTERRUPT:
+            /* just indicate that signals should be handled asap */
+            break;
+        case EXCP_SYSCALL:
+            env->pc += 4;
+            ret = do_syscall(env, env->gpr[11],
+                             env->gpr[4], env->gpr[5],
+                             env->gpr[6], env->gpr[7],
+                             env->gpr[8], env->gpr[9],
+                             -1, -1);
+            if (ret == -TARGET_ERESTARTSYS) {
+                env->pc -= 4;
+                break;
+            }
+            if (ret == -TARGET_QEMU_ESIGRETURN) {
+                /*
+                 * Returning from a successful sigreturn syscall.
+                 * Avoid clobbering register state.
+                 */
+                break;
+            }
+            env->gpr[4] = ret;
+            break;
+        case EXCP_INE:
+            force_sig_fault(TARGET_SIGILL, 0, env->pc);
+            break;
+        case EXCP_FPE:
+            si_code = TARGET_FPE_FLTUNK;
+            if (GET_FP_CAUSE(env->fcsr0) & FP_INVALID) {
+                si_code = TARGET_FPE_FLTINV;
+            } else if (GET_FP_CAUSE(env->fcsr0) & FP_DIV0) {
+                si_code = TARGET_FPE_FLTDIV;
+            } else if (GET_FP_CAUSE(env->fcsr0) & FP_OVERFLOW) {
+                si_code = TARGET_FPE_FLTOVF;
+            } else if (GET_FP_CAUSE(env->fcsr0) & FP_UNDERFLOW) {
+                si_code = TARGET_FPE_FLTUND;
+            } else if (GET_FP_CAUSE(env->fcsr0) & FP_INEXACT) {
+                si_code = TARGET_FPE_FLTRES;
+            }
+            force_sig_fault(TARGET_SIGFPE, si_code, env->pc);
+            break;
+        case EXCP_DEBUG:
+        case EXCP_BREAK:
+            force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc);
+            break;
+        case EXCP_ATOMIC:
+            cpu_exec_step_atomic(cs);
+            break;
+        default:
+            EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\n",
+                      trapnr);
+            exit(EXIT_FAILURE);
+        }
+        process_pending_signals(env);
+    }
+}
+
+void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
+{
+    int i;
+
+    for (i = 0; i < 32; i++) {
+        env->gpr[i] = regs->regs[i];
+    }
+    env->pc = regs->csr_era;
+
+}
diff --git a/linux-user/loongarch64/target_cpu.h b/linux-user/loongarch64/target_cpu.h
new file mode 100644
index 0000000..a29af66
--- /dev/null
+++ b/linux-user/loongarch64/target_cpu.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * LoongArch specific CPU ABI and functions for linux-user
+ *
+ * Copyright (c) 2021 Loongson Technology Corporation Limited
+ */
+
+#ifndef LOONGARCH_TARGET_CPU_H
+#define LOONGARCH_TARGET_CPU_H
+
+static inline void cpu_clone_regs_child(CPULoongArchState *env,
+                                        target_ulong newsp, unsigned flags)
+{
+    if (newsp) {
+        env->gpr[3] = newsp;
+    }
+    env->gpr[4] = 0;
+}
+
+static inline void cpu_clone_regs_parent(CPULoongArchState *env,
+                                         unsigned flags)
+{
+}
+
+static inline void cpu_set_tls(CPULoongArchState *env, target_ulong newtls)
+{
+    env->gpr[2] = newtls;
+}
+
+static inline abi_ulong get_sp_from_cpustate(CPULoongArchState *state)
+{
+    return state->gpr[3];
+}
+#endif
-- 
1.8.3.1



  parent reply	other threads:[~2021-12-01  8:32 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-01  8:15 [PATCH v12 00/26] Add LoongArch linux-user emulation support Song Gao
2021-12-01  8:16 ` [PATCH v12 01/26] target/loongarch: Add README Song Gao
2021-12-01  8:16 ` [PATCH v12 02/26] target/loongarch: Add core definition Song Gao
2021-12-01  8:16 ` [PATCH v12 03/26] target/loongarch: Add main translation routines Song Gao
2021-12-01  8:16 ` [PATCH v12 04/26] target/loongarch: Add fixed point arithmetic instruction translation Song Gao
2021-12-01  8:16 ` [PATCH v12 05/26] target/loongarch: Add fixed point shift " Song Gao
2021-12-01  8:16 ` [PATCH v12 06/26] target/loongarch: Add fixed point bit " Song Gao
2021-12-01  8:16 ` [PATCH v12 07/26] target/loongarch: Add fixed point load/store " Song Gao
2021-12-01  8:16 ` [PATCH v12 08/26] target/loongarch: Add fixed point atomic " Song Gao
2021-12-01 21:22   ` Richard Henderson
2021-12-01  8:16 ` [PATCH v12 09/26] target/loongarch: Add fixed point extra " Song Gao
2021-12-01  8:16 ` [PATCH v12 10/26] target/loongarch: Add floating point arithmetic " Song Gao
2021-12-01  8:16 ` [PATCH v12 11/26] target/loongarch: Add floating point comparison " Song Gao
2021-12-01  8:16 ` [PATCH v12 12/26] target/loongarch: Add floating point conversion " Song Gao
2021-12-01  8:16 ` [PATCH v12 13/26] target/loongarch: Add floating point move " Song Gao
2021-12-01  8:16 ` [PATCH v12 14/26] target/loongarch: Add floating point load/store " Song Gao
2021-12-01  8:16 ` [PATCH v12 15/26] target/loongarch: Add branch " Song Gao
2021-12-01  8:16 ` [PATCH v12 16/26] target/loongarch: Add disassembler Song Gao
2021-12-01 21:28   ` Richard Henderson
2021-12-01  8:16 ` [PATCH v12 17/26] linux-user: Add LoongArch generic header files Song Gao
2021-12-01  8:16 ` [PATCH v12 18/26] linux-user: Add LoongArch specific structures Song Gao
2021-12-01  8:16 ` [PATCH v12 19/26] linux-user: Add LoongArch signal support Song Gao
2021-12-01  8:16 ` [PATCH v12 20/26] linux-user: Add LoongArch elf support Song Gao
2021-12-01  8:16 ` [PATCH v12 21/26] linux-user: Add LoongArch syscall support Song Gao
2021-12-01  8:16 ` Song Gao [this message]
2021-12-01  8:16 ` [PATCH v12 23/26] default-configs: Add loongarch linux-user support Song Gao
2021-12-01  8:16 ` [PATCH v12 24/26] target/loongarch: Add target build suport Song Gao
2021-12-01  8:16 ` [PATCH v12 25/26] target/loongarch: 'make check-tcg' support Song Gao
2021-12-01  8:16 ` [PATCH v12 26/26] scripts: add loongarch64 binfmt config Song Gao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1638346585-3436-23-git-send-email-gaosong@loongson.cn \
    --to=gaosong@loongson.cn \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=yangxiaojuan@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.