From nobody Thu Nov 7 16:12:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1656839921; cv=none; d=zohomail.com; s=zohoarc; b=EGMY4VqxEiI4/iXHuccdC+LHLgp6khNt5NuPrIuZ+JY4/6cliFQw67jCp6qC1INvZ3Dl/2Sq71ZEdpzqH/BKh2Lwotsu02/DmP2KvwpxjQrk9XVlS17DCqiNKlkmWXxCEZQu1zl8fmW/nzutSJxZynM3umJrbtL/LTOdY+saYxI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656839921; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gyVKsSKTcz352Hx+z69WvjGNpCZ8RyuObOwnIrxXdDc=; b=Ll/6y9zlj1k89D5+9CX5Z6ToT9O+KDjGHqwHCbd45yww8fqzcdxxVq12gKJmst6KkDybD35LRAR3hBzLdbUYADNAY2D+7IvM744dQ3y9fqtjLR1XB3nXO+cLjIJPYrITvbcC+EHvMmBQ+AVI96FXypIwbzWgy03wpqqeggnwE3o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656839921130417.17214187635784; Sun, 3 Jul 2022 02:18:41 -0700 (PDT) Received: from localhost ([::1]:47566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7vkW-0003vf-3F for importer@patchew.org; Sun, 03 Jul 2022 05:18:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58660) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7vS6-0004fv-RE for qemu-devel@nongnu.org; Sun, 03 Jul 2022 04:59:38 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]:43525) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o7vS5-00049z-6o for qemu-devel@nongnu.org; Sun, 03 Jul 2022 04:59:38 -0400 Received: by mail-pg1-x531.google.com with SMTP id 68so6271452pgb.10 for ; Sun, 03 Jul 2022 01:59:36 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id cq16-20020a056a00331000b00518764d09cdsm18777593pfb.164.2022.07.03.01.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Jul 2022 01:59:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gyVKsSKTcz352Hx+z69WvjGNpCZ8RyuObOwnIrxXdDc=; b=j8L9pm/ipgXEuhr5np1WSKHtkDsB/RQ8h2eW1nEFNA5+iJTfOXxe7muKzJqlQaFukF lavf2sP4Xw5fsqSHVcAWy1dQJeGYb3nk0LvqPlbprKy9eru5loRKRLkfUK71p9CoAJF/ R3LLaZ/G3UisIzigshPQ54Qdwlr+jwOXlqfJ+ZY5saayvnO5cChrs08HqrTdvuplA128 E1bStZ2HXwc/pfSSqjiqilJgJOCJ8Ve2HXi66q9YMcXutjBBE0IFSFizC6ABfKyb06i2 AMNjA5/3y0KWqD33xzQQHE+A+TQL5Q1tdYEJkKhl/Mjrpzq+31SiMttYHaIb6WliXqq2 MFrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gyVKsSKTcz352Hx+z69WvjGNpCZ8RyuObOwnIrxXdDc=; b=Dk1Z1louV+XRXAH4F6QTxFoEM52PxERtgUrTVxhF1FpJm457ilQ5s0WV/Vg7yIJE7T UEWQwzNmvQAzfiks2RWJVH/9Tv4dBW6SRewL5QyiXUp7dPubD6MV3+tfY0o+ri89J7vl UFZkiq/6IxJcITdxhYAUjRDO4FQLlykC3H//+lCdXvpCmhyN+aGtfmcEGgEe+UUU6Z27 jMwMW/L4nRT8RNaFgrhcgZXoQJ37nyWqQPWkoO7d24ZNC+ofZJNB/vE6qDyz6jLDH8cL 3lG6TUNb7Y+XkRQjSMtFUIdagE6htcTP+BuVWNCdXmlzOZavAXCp7yPlk3w1RpogNmBK CJgw== X-Gm-Message-State: AJIora9AGWuc8T482bAjwljF3olK2plO8jBrvzTrFex9eROke1SduRID IofIeyO0Y1Go+K4mNEpM/iwKesb+1lRNszaq X-Google-Smtp-Source: AGRyM1tJgjeIUmO3ZmoLl+BCMM59dm07rXrXvYkr4VAw4y0xQmom3ORpejhjq92vclMUqaqJus1ZdQ== X-Received: by 2002:a63:2319:0:b0:411:8cff:9a98 with SMTP id j25-20020a632319000000b004118cff9a98mr18077319pgj.422.1656838775872; Sun, 03 Jul 2022 01:59:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, Song Gao , Xiaojuan Yang Subject: [PATCH v21 05/13] linux-user: Add LoongArch cpu_loop support Date: Sun, 3 Jul 2022 14:29:05 +0530 Message-Id: <20220703085913.772936-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220703085913.772936-1-richard.henderson@linaro.org> References: <20220703085913.772936-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x531.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1656839923122100001 Content-Type: text/plain; charset="utf-8" From: Song Gao Signed-off-by: Song Gao Signed-off-by: Xiaojuan Yang Reviewed-by: Richard Henderson Message-Id: <20220624031049.1716097-6-gaosong@loongson.cn> Signed-off-by: Richard Henderson --- linux-user/loongarch64/target_cpu.h | 34 ++++++++++ linux-user/loongarch64/cpu_loop.c | 96 +++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 linux-user/loongarch64/target_cpu.h create mode 100644 linux-user/loongarch64/cpu_loop.c diff --git a/linux-user/loongarch64/target_cpu.h b/linux-user/loongarch64/t= arget_cpu.h new file mode 100644 index 0000000000..a29af66156 --- /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] =3D newsp; + } + env->gpr[4] =3D 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] =3D newtls; +} + +static inline abi_ulong get_sp_from_cpustate(CPULoongArchState *state) +{ + return state->gpr[3]; +} +#endif diff --git a/linux-user/loongarch64/cpu_loop.c b/linux-user/loongarch64/cpu= _loop.c new file mode 100644 index 0000000000..894fdd111a --- /dev/null +++ b/linux-user/loongarch64/cpu_loop.c @@ -0,0 +1,96 @@ +/* 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 "user-internals.h" +#include "cpu_loop-common.h" +#include "signal-common.h" + +void cpu_loop(CPULoongArchState *env) +{ + CPUState *cs =3D env_cpu(env); + int trapnr, si_code; + abi_long ret; + + for (;;) { + cpu_exec_start(cs); + trapnr =3D 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 EXCCODE_SYS: + env->pc +=3D 4; + ret =3D 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 =3D=3D -QEMU_ERESTARTSYS) { + env->pc -=3D 4; + break; + } + if (ret =3D=3D -QEMU_ESIGRETURN) { + /* + * Returning from a successful sigreturn syscall. + * Avoid clobbering register state. + */ + break; + } + env->gpr[4] =3D ret; + break; + case EXCCODE_INE: + force_sig_fault(TARGET_SIGILL, 0, env->pc); + break; + case EXCCODE_FPE: + si_code =3D TARGET_FPE_FLTUNK; + if (GET_FP_CAUSE(env->fcsr0) & FP_INVALID) { + si_code =3D TARGET_FPE_FLTINV; + } else if (GET_FP_CAUSE(env->fcsr0) & FP_DIV0) { + si_code =3D TARGET_FPE_FLTDIV; + } else if (GET_FP_CAUSE(env->fcsr0) & FP_OVERFLOW) { + si_code =3D TARGET_FPE_FLTOVF; + } else if (GET_FP_CAUSE(env->fcsr0) & FP_UNDERFLOW) { + si_code =3D TARGET_FPE_FLTUND; + } else if (GET_FP_CAUSE(env->fcsr0) & FP_INEXACT) { + si_code =3D TARGET_FPE_FLTRES; + } + force_sig_fault(TARGET_SIGFPE, si_code, env->pc); + break; + case EXCP_DEBUG: + case EXCCODE_BRK: + force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc); + break; + case EXCCODE_BCE: + force_sig_fault(TARGET_SIGSYS, TARGET_SI_KERNEL, 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 =3D 0; i < 32; i++) { + env->gpr[i] =3D regs->regs[i]; + } + env->pc =3D regs->csr.era; + +} --=20 2.34.1