From patchwork Thu Mar 10 11:26:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 550110 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp919304mag; Thu, 10 Mar 2022 03:57:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJzq3xDg794vnTXQQ0xhvxg5ZkTTVRO7Mq3ZYvpTUBBf5tCZFP4rgQWLbI2shUHnewZqKrCq X-Received: by 2002:a81:a055:0:b0:2dc:5771:1c4e with SMTP id x82-20020a81a055000000b002dc57711c4emr3448738ywg.351.1646913452691; Thu, 10 Mar 2022 03:57:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646913452; cv=none; d=google.com; s=arc-20160816; b=vv9ROlFk3DeBhlTOZadXytt+hNtwKzeIR7Q/9iuccX51IftjKDG3kR/FqtwtsoS7te KB8XfSvriRjpIuxY52MYLsujoItwtiiIRBA6F0K4So8JXeMdIpWd9nq4TmUqokv093YN hrFg5Zu3rlnryXJ0PuIOHXLp7HNICxz4/EBDgIjQoeJgFXB45Nr5Nm7wcCg317aPv8uU M7LzokK4JfMpTlfYJzrZiaQ9difOKgHrNaTMVizcpgsLCJNmTHJLc1La3M+Cl5h3Q3YY vY5cBchItmNQ+3ndhlZD28DquUg2KheSrkkYqtiol4u/Zq5LHcGk7HNvbHpTJ5ztJs22 APkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=62d8othJIfgAKm86Avncs/clZTnNTHcuD30Oj5z4NnM=; b=My6DFbWkB4IGLgUW7wSuqXR3Uo26gT3tUQSX64L3Rj0DhZVK/UPInF1KSHKmdpgUOk bTWSkslVt9aRrOFhxlhEJScJ+yr/CsvIyqnSKYoHiSf5H9zQFGGILoAYvQkVz99Bpb// Ik4nNqcpbUgi+mnqZavrnvNMRU/ulc+UvLkM7+qrdIDOQCAO6WOm2LY1ICusJWyqfGX3 RIF6Qc0BxK03w3ii/tnx60XdL0EdacTKiU6F1ns79EdKNfNzGF1Yybb+6cWfTQUxL4nb spgOi2JvcWXddlCMZMcN3ThXcqc5XGroKPEJ2DCIRdqudE/sMK/F4pv+odfO+1EvKV5N h5Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Js6I3+tl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 188-20020a8117c5000000b002dc08d98021si2628560ywx.28.2022.03.10.03.57.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Mar 2022 03:57:32 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Js6I3+tl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSHQC-0000U4-72 for patch@linaro.org; Thu, 10 Mar 2022 06:57:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSGxT-0005fI-Jb for qemu-devel@nongnu.org; Thu, 10 Mar 2022 06:27:51 -0500 Received: from [2607:f8b0:4864:20::102f] (port=34508 helo=mail-pj1-x102f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSGxR-0007yn-UL for qemu-devel@nongnu.org; Thu, 10 Mar 2022 06:27:51 -0500 Received: by mail-pj1-x102f.google.com with SMTP id k5-20020a17090a3cc500b001befa0d3102so6092114pjd.1 for ; Thu, 10 Mar 2022 03:27:49 -0800 (PST) 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=62d8othJIfgAKm86Avncs/clZTnNTHcuD30Oj5z4NnM=; b=Js6I3+tl4MgfPZk/1FQAe90hI3aIBtY49Q94ebm322DRaLmAJ9Ksyvtr7dURWTgy1P ARrvEyba6AnWjQYuBuvyUzJISjkldJE+69zTgZxCX7bbmlGTwo+XVGhEtL89OJ2stAU2 7fp6u5vcAzDSBG0Uv6aBjSlamlT0BqBxWJGH2vImsMfbqKzVOp6s/2Js7u5OBzk4wlBO tf9Nqqs3wkCK75/xHbfK9sr8ec7+ZJBUwVXfBVmMDM9ZQS2/Kcb7UJIZaQ4+an0j1DYD wTjPl3pUeyBS8bWTalptZPBFtF2Attf2deUY28E8Wrp9g5zId1C0TcEaerCnd9R9hrVj +z0g== 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=62d8othJIfgAKm86Avncs/clZTnNTHcuD30Oj5z4NnM=; b=0t5SB9rqR+9n8DeFJc8ODFm11ZcPeekge2UXgPcLeV4kMLfcvwuWEVShRmtrodQRen mUzfepf1fWUNY0msKxaO/Hjk185E0UslC7vPODt/PhHrkCA/DMhjNdh53bxZyLNjXacE sQ7W6QY66fspZHohqFx/d4+ATFoPcK5nh+9Zr5hNRDIu8NmbEGz91GZbzmSCaISPiJS5 BQU3q8FFueNUtBEbAK63TBtGIXAHzEcE+VHobFyJTSwit3entJOflC+mvXLJE0dR/kcL nYWHw9BOzwdcTg6p9FN98XhzlgG0Dje1lmc64A8mlNj4hUnUvBmTYvscu8j0gzTpZ6sb DDpw== X-Gm-Message-State: AOAM531uuOBK4KNelF9A6EZsBcRFVFIk8ZaUU6aZeD6awhIvDcd6XWA6 9kW/WlStRI+DifkAl4rihadz2hYq/37o7g== X-Received: by 2002:a17:902:c40a:b0:151:a792:71f2 with SMTP id k10-20020a170902c40a00b00151a79271f2mr4631360plk.36.1646911668699; Thu, 10 Mar 2022 03:27:48 -0800 (PST) Received: from localhost.localdomain (174-21-142-130.tukw.qwest.net. [174.21.142.130]) by smtp.gmail.com with ESMTPSA id js15-20020a17090b148f00b001bfc8614b93sm3114977pjb.1.2022.03.10.03.27.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 03:27:48 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v5 20/48] target/nios2: Create EXCP_SEMIHOST for semi-hosting Date: Thu, 10 Mar 2022 03:26:57 -0800 Message-Id: <20220310112725.570053-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220310112725.570053-1-richard.henderson@linaro.org> References: <20220310112725.570053-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::102f (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: marex@denx.de, peter.maydell@linaro.org, amir.gonnen@neuroblade.ai Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Decode 'break 1' during translation, rather than doing it again during exception processing. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/nios2/cpu.h | 1 + target/nios2/helper.c | 14 ++++++-------- target/nios2/translate.c | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h index 555972fe6b..d003af5afc 100644 --- a/target/nios2/cpu.h +++ b/target/nios2/cpu.h @@ -156,6 +156,7 @@ FIELD(CR_TLBMISC, EE, 24, 1) /* Exceptions */ #define EXCP_BREAK 0x1000 +#define EXCP_SEMIHOST 0x1001 #define EXCP_RESET 0 #define EXCP_PRESET 1 #define EXCP_IRQ 2 diff --git a/target/nios2/helper.c b/target/nios2/helper.c index 52a49f7ead..eeff032379 100644 --- a/target/nios2/helper.c +++ b/target/nios2/helper.c @@ -172,14 +172,6 @@ void nios2_cpu_do_interrupt(CPUState *cs) case EXCP_BREAK: qemu_log_mask(CPU_LOG_INT, "BREAK exception at pc=%x\n", env->pc); - /* The semihosting instruction is "break 1". */ - if (semihosting_enabled() && - cpu_ldl_code(env, env->pc) == 0x003da07a) { - qemu_log_mask(CPU_LOG_INT, "Entering semihosting\n"); - env->pc += 4; - do_nios2_semihosting(env); - break; - } if ((env->ctrl[CR_STATUS] & CR_STATUS_EH) == 0) { env->ctrl[CR_BSTATUS] = env->ctrl[CR_STATUS]; @@ -196,6 +188,12 @@ void nios2_cpu_do_interrupt(CPUState *cs) env->pc = cpu->exception_addr; break; + case EXCP_SEMIHOST: + qemu_log_mask(CPU_LOG_INT, "BREAK semihosting at pc=%x\n", env->pc); + env->pc += 4; + do_nios2_semihosting(env); + break; + default: cpu_abort(cs, "unhandled exception type=%d\n", cs->exception_index); diff --git a/target/nios2/translate.c b/target/nios2/translate.c index 459e30b338..cfad110186 100644 --- a/target/nios2/translate.c +++ b/target/nios2/translate.c @@ -33,6 +33,7 @@ #include "exec/translator.h" #include "qemu/qemu-print.h" #include "exec/gen-icount.h" +#include "semihosting/semihost.h" /* is_jmp field values */ #define DISAS_JUMP DISAS_TARGET_0 /* only pc was modified dynamically */ @@ -686,6 +687,20 @@ static void trap(DisasContext *dc, uint32_t code, uint32_t flags) t_gen_helper_raise_exception(dc, EXCP_TRAP); } +static void gen_break(DisasContext *dc, uint32_t code, uint32_t flags) +{ +#ifndef CONFIG_USER_ONLY + /* The semihosting instruction is "break 1". */ + R_TYPE(instr, code); + if (semihosting_enabled() && instr.imm5 == 1) { + t_gen_helper_raise_exception(dc, EXCP_SEMIHOST); + return; + } +#endif + + t_gen_helper_raise_exception(dc, EXCP_BREAK); +} + static const Nios2Instruction r_type_instructions[] = { INSTRUCTION_ILLEGAL(), INSTRUCTION(eret), /* eret */ @@ -739,7 +754,7 @@ static const Nios2Instruction r_type_instructions[] = { INSTRUCTION(add), /* add */ INSTRUCTION_ILLEGAL(), INSTRUCTION_ILLEGAL(), - INSTRUCTION_FLG(gen_excp, EXCP_BREAK), /* break */ + INSTRUCTION(gen_break), /* break */ INSTRUCTION_ILLEGAL(), INSTRUCTION(nop), /* nop */ INSTRUCTION_ILLEGAL(),