From patchwork Wed Apr 24 22:51:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 791534 Delivered-To: patch@linaro.org Received: by 2002:a5d:4884:0:b0:346:15ad:a2a with SMTP id g4csp1091713wrq; Wed, 24 Apr 2024 15:52:26 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWmBc5XpgCn8s6wrq6olagVNGnfPO26oU+nEKO4dugMZMboXeEn4UqmLrfR2Axl2ZmYqTydLKXjnW/Bg+QH/4dc X-Google-Smtp-Source: AGHT+IFq5UmB3dKvAOpnOxo07vgD6svOVHHWvCrsEBzPsZOKs7NzPXzyQhy4kaU4Nixca5xSDpDE X-Received: by 2002:a05:620a:28c5:b0:78d:53a1:299a with SMTP id l5-20020a05620a28c500b0078d53a1299amr2135095qkp.12.1713999146438; Wed, 24 Apr 2024 15:52:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713999146; cv=none; d=google.com; s=arc-20160816; b=ILU1IZM+bJjT8hiLGUqFvMLnRrw/EjlQXuvJDQbNv3FeJbe/8D/DBNl5iAIgQs392S 63oAgsR0io1Zp3MjS2IhKSv5Jw4RNfTYCFD9PCEeS9o/zs55q072nswrUjFQJYWQqHM1 eMOUyjRBswyp6WUYTBNxdUBkgZceqwMWtdTXqQEScAADjGSOiUbmRzofJOV3HlaAlDZt uLv2G/oqWnTw7CaTsnT32RHkVEJlrNPnIoMpuuIZab/N/zYm0PgdaWQIXlic+YWdtbtF M1/FM2mEflqFUpZlPv6clL7CVoAlTagPFIY8AqrKR1ik7WFnAnXmqK9VUtWGEWm4h+8R 03vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=N1Fb/iLBacLjG+JYW3VIwBtHrdP9tAIF5ogLnK/WoGA=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=00L46RJRTAdRNfV72L7NWt/qOUfa9HVIzQzVHxUqsEsLY2wgjJHuW3OVq2EH8PedCG IZMxewWu4vYEtrPHY0g8FXOAnyGdUV2yxtYkmPESnTkOJ1JzDAqNyVA5E/qr3rKMvHr5 yrtrStknSa+0T4ZwDIffTK5Fin2IppOWJYchD3AUFcKyBViYdupjnUSvifHAgk4Dsol/ C+4bjcZF7Kk0Xh4BNDJz/1GuUIEspZNntA6qjNk33Rc4LH35izw5X+ZAS0yc9jKq2Zhb GqHPcEF3jknktXZviTrRO7G1j77NV7qc7VxRrqQxNxwbjv4R96fl3KjsivgvtndZ9Sji WGOA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gXL7aYad; 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 v24-20020ae9e318000000b007906d1b6826si8874187qkf.157.2024.04.24.15.52.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2024 15:52:26 -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=gXL7aYad; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rzlSk-00070t-4m; Wed, 24 Apr 2024 18:51:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rzlSi-0006yM-E4 for qemu-devel@nongnu.org; Wed, 24 Apr 2024 18:51:36 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rzlSg-0006h3-K5 for qemu-devel@nongnu.org; Wed, 24 Apr 2024 18:51:36 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6ee0642f718so1140591b3a.0 for ; Wed, 24 Apr 2024 15:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713999093; x=1714603893; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=N1Fb/iLBacLjG+JYW3VIwBtHrdP9tAIF5ogLnK/WoGA=; b=gXL7aYadEgiP2R7/QB5RSLbcPfaEMqT0uSwshd+3qtx3EVwMGft3oW0Qc6GSZpRtor 4XAH8PS/1o69MvDZH2xVP8Zil1lcoAE26fxhNQi384GW1mOU7U8W6wm6G8REQy9FX+E/ 5IcbwEtjKgY3Z0qrloB7FczCj2CTB02Y5EGsDt3IosB+OWRhkZfWtAt7HebEiuBaD+XI 0VY0jwhjt4i2/qWgbDusqm9RcySHfw322k/CMqJQLLKauEHZ4ww6cyzDvKWENtfhxxG1 kOCTK32P9iQlf/GV15MS1otRwvQFGSS1sIUytVoJw4HfXMG/3OC1TqvYS6LQF/6LUiLG ckYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713999093; x=1714603893; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N1Fb/iLBacLjG+JYW3VIwBtHrdP9tAIF5ogLnK/WoGA=; b=nYqZ0vqakZmv8m5PePkiaB3RanK0U7VcN6pkXVBJkGcW0V+4ltWOEKTAg+c8k7ldsC 2Md2eZ1jNaKqME8QAk6f7WQ1PbIEMNV85yhrorj39PyeUG1etQotWeJGRwwEmveU0rtv A2eLIzoZEAvl6W7OfrtV2vcsoyaKcYkRjylUM7R7kGTmEtBi1WXZ5f4v9ughi7O4+PHh hjIwUokk385Bs4Uc+FYodvXBUF4IMGM7b8Z4cfblEYZAJHw7hKUJOmFKWTetVF9LSsLV nR9jL2f6ymY8I+DTKxo67V00fzBRzGj0Ql87aSphoHKWoiMvdPYfr2diNYy4QNw8V6VN 318w== X-Gm-Message-State: AOJu0YxvPI6ZnguqeMGCy3YWMEfOaa6BQRfZBOTJQQIMuVcby1yzYHxb 5SvJBwZybC9QTjATyyWKRx//+eQc+Mw3tbP+A9Q+z9inDymT0feecCixv+Bo7EWUDSvr6ln+7Nf 1 X-Received: by 2002:a05:6a20:9190:b0:1a9:9839:f142 with SMTP id v16-20020a056a20919000b001a99839f142mr1675127pzd.10.1713999093218; Wed, 24 Apr 2024 15:51:33 -0700 (PDT) Received: from stoup.. ([156.19.246.23]) by smtp.gmail.com with ESMTPSA id it12-20020a056a00458c00b006ead792b6f2sm11960864pfb.1.2024.04.24.15.51.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 15:51:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 8/9] target/m68k: Perform the semihosting test during translate Date: Wed, 24 Apr 2024 15:51:22 -0700 Message-Id: <20240424225123.929152-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240424225123.929152-1-richard.henderson@linaro.org> References: <20240424225123.929152-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Replace EXCP_HALT_INSN by EXCP_SEMIHOSTING. Perform the pre- and post-insn tests during translate, leaving only the actual semihosting operation for the exception. Signed-off-by: Richard Henderson --- target/m68k/cpu.h | 2 +- target/m68k/op_helper.c | 14 ++----------- target/m68k/translate.c | 45 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h index e184239a81..b5bbeedb7a 100644 --- a/target/m68k/cpu.h +++ b/target/m68k/cpu.h @@ -66,7 +66,7 @@ #define EXCP_MMU_ACCESS 58 /* MMU Access Level Violation Error */ #define EXCP_RTE 0x100 -#define EXCP_HALT_INSN 0x101 +#define EXCP_SEMIHOSTING 0x101 #define M68K_DTTR0 0 #define M68K_DTTR1 1 diff --git a/target/m68k/op_helper.c b/target/m68k/op_helper.c index 125f6c1b08..15bad5dd46 100644 --- a/target/m68k/op_helper.c +++ b/target/m68k/op_helper.c @@ -202,18 +202,8 @@ static void cf_interrupt_all(CPUM68KState *env, int is_hw) /* Return from an exception. */ cf_rte(env); return; - case EXCP_HALT_INSN: - if (semihosting_enabled((env->sr & SR_S) == 0) - && (env->pc & 3) == 0 - && cpu_lduw_code(env, env->pc - 4) == 0x4e71 - && cpu_ldl_code(env, env->pc) == 0x4e7bf000) { - env->pc += 4; - do_m68k_semihosting(env, env->dregs[0]); - return; - } - cs->halted = 1; - cs->exception_index = EXCP_HLT; - cpu_loop_exit(cs); + case EXCP_SEMIHOSTING: + do_m68k_semihosting(env, env->dregs[0]); return; } } diff --git a/target/m68k/translate.c b/target/m68k/translate.c index 8a194f2f21..647bd9d9be 100644 --- a/target/m68k/translate.c +++ b/target/m68k/translate.c @@ -26,12 +26,11 @@ #include "qemu/log.h" #include "qemu/qemu-print.h" #include "exec/translator.h" - #include "exec/helper-proto.h" #include "exec/helper-gen.h" - #include "exec/log.h" #include "fpu/softfloat.h" +#include "semihosting/semihost.h" #define HELPER_H "helper.h" #include "exec/helper-info.c.inc" @@ -1401,6 +1400,40 @@ static void gen_jmp_tb(DisasContext *s, int n, target_ulong dest, s->base.is_jmp = DISAS_NORETURN; } +#ifndef CONFIG_USER_ONLY +static bool semihosting_test(DisasContext *s) +{ + uint32_t test; + + if (!semihosting_enabled(IS_USER(s))) { + return false; + } + + /* + * "The semihosting instruction is immediately preceded by a + * nop aligned to a 4-byte boundary..." + * The preceding 2-byte (aligned) nop plus the 2-byte halt/bkpt + * means that we have advanced 4 bytes from the required nop. + */ + if (s->pc % 4 != 0) { + return false; + } + test = translator_lduw(s->env, &s->base, s->pc - 4); + if (test != 0x4e71) { + return false; + } + /* "... and followed by an invalid sentinel instruction movec %sp,0." */ + test = translator_ldl(s->env, &s->base, s->pc); + if (test != 0x4e7bf000) { + return false; + } + + /* Consume the sentinel. */ + s->pc += 4; + return true; +} +#endif /* !CONFIG_USER_ONLY */ + DISAS_INSN(scc) { DisasCompare c; @@ -4465,8 +4498,12 @@ DISAS_INSN(halt) gen_exception(s, s->base.pc_next, EXCP_PRIVILEGE); return; } - - gen_exception(s, s->pc, EXCP_HALT_INSN); + if (semihosting_test(s)) { + gen_exception(s, s->pc, EXCP_SEMIHOSTING); + return; + } + tcg_gen_movi_i32(cpu_halted, 1); + gen_exception(s, s->pc, EXCP_HLT); } DISAS_INSN(stop)