From patchwork Fri Apr 22 16:52:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 564878 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp687178map; Fri, 22 Apr 2022 10:33:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwso7cSPD1To1Kut4zjmw4+mJxOsBNNVaWUS2ysx1G7TZ2KwTY2TCIZ1GwwyUmA8ZHTE8aT X-Received: by 2002:a05:6902:84:b0:63d:4a3d:eb5 with SMTP id h4-20020a056902008400b0063d4a3d0eb5mr5841315ybs.145.1650648800440; Fri, 22 Apr 2022 10:33:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650648800; cv=none; d=google.com; s=arc-20160816; b=bM8pzDtOWZfJAPNlEHybrql56JnyXuXnYo6iHuHOOVEO4h5FZKvIB8bfSXd9K7ATY5 JsmQ9RTL5ybniAWOpvgO/Qvay6c5gZneotGcQPZECi8zAOFWCMhuAZMV2Q6Dz4eghRX7 4vwDqiRgnLqcqzHIEonCS9SDgyf7B2m+eZTUoVrd25w5EW3lP4kePGCkJ+BLwZ4Y7Jjs GftJ9MTdy7ghcEAayxjnc7Lwqr2VAD75Jq9FARPbyV371dYVkOtz4qkwGQCgosgu2cA3 SN5C4yA7qJE1pdxYAJpOzMMTy4opBlWfPgBrnqdtVJ7dHjPh4FHMsY8HMjQnpd/aLjG8 2bWg== 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=JGG1SeKnuAT2QHCjae7Ts/IpHjmxbOVPlNo/xG2utBk=; b=e/2shtJLFOO0gWuWrQATOuN9FC6IJwGo9FMvt3eIQwat17Q2dnfayvDQ2xzMFPYx3X gWY6sABMnuGT9L0mSy0n5iH97AfTGBF3AD8oOd6H4wZCUDLv7S0eLcFQquLrzc6fKSHR GVrU9zFOchbfebX0fdgNNpdXBDW9ypGTvuljftLSTnW6QgAbTsQPgUqB2620IjRBg3cX F5B9DSXJMrVb6qX+HFyQe8oj0GBfcZVSxBc/JTNT1wtXi4jQrlZLUpK4cVgLchnE6DX0 RJpj2nRFc+Wr+Y+cj7W6jIKHNLc/p/mL0eO9UGKa1XiRmSTjJ5sjgMwSZe2A4CwNPDew 6Jfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qUL4PHVK; 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=pass (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 195-20020a8115cc000000b002f7b5e458fcsi1529106ywv.456.2022.04.22.10.33.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Apr 2022 10:33:20 -0700 (PDT) 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=pass header.i=@linaro.org header.s=google header.b=qUL4PHVK; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhx9j-00033I-SN for patch@linaro.org; Fri, 22 Apr 2022 13:33:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhwXK-0001oc-OY for qemu-devel@nongnu.org; Fri, 22 Apr 2022 12:53:38 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:35423) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhwXJ-0007LX-0N for qemu-devel@nongnu.org; Fri, 22 Apr 2022 12:53:38 -0400 Received: by mail-pf1-x42d.google.com with SMTP id w16so2092062pfj.2 for ; Fri, 22 Apr 2022 09:53:36 -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=JGG1SeKnuAT2QHCjae7Ts/IpHjmxbOVPlNo/xG2utBk=; b=qUL4PHVKlqreIu+XbMad15hxLNnu9c8guTSdIyU6GEOg2pc/hMBzrKTkmJ3YYvVHLi uXqeiXMhX9iZuSrMhc/NztiZzyKKEAL1QQifoPVpd17WQ25SL6leFar6OdGhfIA2sIZq 67fDBHZsfMv2V5SqoCS5/RFYAxzoofFuTBRF3XRNN5IlNe114O/A0X8bABUMYsHQpE6o YBbVmbHUN+miDaqkJuP0esl0Ui45XQRZUI6a7Rl1SwnD8wkuEsK5RexczhSjwa81X02z K8tSNS8moAva4EbNg50RrvpIAvKK+ZosUu3skwm6i92JS1PmLJPIE4BV2/arQyulWe4a vIDA== 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=JGG1SeKnuAT2QHCjae7Ts/IpHjmxbOVPlNo/xG2utBk=; b=ti9Ebrbo/3fvLu2T/FEOQU/YunldPC7FuA2U6SzPhh7H0pHWislgnCIiU/USC/HSod ZL5XyhO6J2I8gw2jjwfrB2SL0VOvCRVQ+uSPQPdaxGYtg/PaXkDdxjZRFc4ibcexSGto atNpbdRnoBI2MIcKYQMo/veU3K2jjMhJxuMSdqseiFaiB1E1L4OS7LbleOq4Y7227AK+ xpK1I+bftIQsrBMKZXYuqC9m5I8Mr4Lf6zuG2RCtIdGPUkm1AqTPwhnfVdpgToVb79MI U68599I51LUqnDot/fAvRC1bZ4r1tEKsVtVqk5zYykDA9favJ5gSxSA1oM5NrE2XjkYF 3zvw== X-Gm-Message-State: AOAM531XQ4YTZ4VGGKc8j8TmzaYMIO/eT6NyjICadoOo+LVUVl/rActy UrdepHePPrm97/AB9i8XNdlUrd5LuXuKkzr8 X-Received: by 2002:a05:6a00:1895:b0:50a:6a91:e833 with SMTP id x21-20020a056a00189500b0050a6a91e833mr5956810pfh.26.1650646415694; Fri, 22 Apr 2022 09:53:35 -0700 (PDT) Received: from stoup.. ([2607:fb90:27d0:b0f2:934d:3e2:9f8c:dd1]) by smtp.gmail.com with ESMTPSA id 6-20020a17090a030600b001cd4989ff5fsm6835904pje.38.2022.04.22.09.53.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 09:53:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v8 31/68] target/nios2: Create EXCP_SEMIHOST for semi-hosting Date: Fri, 22 Apr 2022 09:52:01 -0700 Message-Id: <20220422165238.1971496-32-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220422165238.1971496-1-richard.henderson@linaro.org> References: <20220422165238.1971496-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.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: , Cc: Peter Maydell 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 Message-Id: <20220421151735.31996-32-richard.henderson@linaro.org> --- 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 65bcc5fc0e..01cead5502 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 a56aaaea18..1d17c0379f 100644 --- a/target/nios2/helper.c +++ b/target/nios2/helper.c @@ -152,14 +152,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]; @@ -176,6 +168,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 4191db1342..97e531529f 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(),