From patchwork Wed Jan 24 23:25:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 125732 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp736292ljf; Wed, 24 Jan 2018 15:39:28 -0800 (PST) X-Google-Smtp-Source: AH8x2256qd42CHvVZtye/A1bKaNW6LdWM/tqpXfCaGZRoUzWeOFzlQdgbNEeJLLuf3RuKp3xhuUn X-Received: by 10.129.55.209 with SMTP id e200mr6681317ywa.306.1516837168594; Wed, 24 Jan 2018 15:39:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516837168; cv=none; d=google.com; s=arc-20160816; b=ibqci36WRPUCceYBMtuPDJ3xRw6Rxdb6KlIPK9SArmZmNoq5hbNk2pfbdYdPIpBJ7M avo5lnrpb3V/X9myP+JtXDoNrdpUA/+Qyi1q11WdJUAhXCwT5q4jVUae9OEfg/NZ2WlQ ypafF4rOGFvPHDUMk1cSHN5x9w2jHYqBTT9rkEOsiVViBFk386fANNKc0bBXeKgGdFHZ 3EH/6VypVcpNh05EkPjSLhsq2r68YMzwuRgBWZKdFHGL3W4mbvOm67b41jeFeaATBtR6 poDdz+RUNqeYMoY2sFQBI99E3YIsDR421G79CAa1MIkaUGmuKmhqZ+ZLsqtTjCKt318N L3Yg== 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:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=+6dDGlU5G4pqOu3+fCXuYTnali05S0or37iI2x6SAAg=; b=g6S8ezHwUkxYTTE526sZ3dy2VsSp4CBOYT/qu3AEV6j+WhpZoAFdPhZ+QLMoLkDVsI ta6y8CbyqKCczBQtl3aMcj8S/Rm7HiGEsRsd4UDwQeVFXiNfNeAhzr70lnfzrsdELxnA f4yPQo6/KEXVc2puBY3zkYFC6NBPKErw9043Y+t0lr6SOy1iD7KdQE2dbZDS7aGREWzr X4I6D12M3bCpTgZ3HJ6twHQCzHYEE6x/09yGI6YK5/Fs/t/O8B0zA51XLXfKaDfYoVT9 D121G8wNkS6cmGiXPgdpEPVP0anhPq6/vzSamGpJSuplZkm91UcQKQrKJhxmJnAiX6NV 5oiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ATR8z3xj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q190si237963ywf.509.2018.01.24.15.39.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 24 Jan 2018 15:39:28 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ATR8z3xj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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]:54526 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eeUdc-0005yW-0Q for patch@linaro.org; Wed, 24 Jan 2018 18:39:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eeURJ-0004SU-CD for qemu-devel@nongnu.org; Wed, 24 Jan 2018 18:26:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eeURE-0001dQ-Gj for qemu-devel@nongnu.org; Wed, 24 Jan 2018 18:26:45 -0500 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:33730) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eeURE-0001d8-7x for qemu-devel@nongnu.org; Wed, 24 Jan 2018 18:26:40 -0500 Received: by mail-pf0-x243.google.com with SMTP id t5so4371297pfi.0 for ; Wed, 24 Jan 2018 15:26:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=+6dDGlU5G4pqOu3+fCXuYTnali05S0or37iI2x6SAAg=; b=ATR8z3xjwWJG4XyJQGgN0opnsiYQ62tH0HJzAdIvZ3PxtBkxVxQ5pM5EDvpAjk2EaV fkwr5ca4JzWp8Kva3EF/1Ly3jKBeq8rBhovlEVNqhvvM+83+nxBenP+PuOgl9b5lh6mY zQ8NA1Nu4J891OVvV/hEgodsbqS9g9MnN5zy0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=+6dDGlU5G4pqOu3+fCXuYTnali05S0or37iI2x6SAAg=; b=D7z3GvcXNvsZn/agSdrgHdjtTLlrfFYcwxiwTQ81uNOYSNA2ZUxv0R18F4tngPpEn1 LbJva95YloSYwpHPMD5vfyl0C84Qxt4BJT7eRi28Str0Ic4XiYr4wdPsoZRRVsYwSb+Z eSuybJwT8uyzH1AaCcJwo5kSBQHmUKa/c0Znd/6H/gblOPMHOTqUfX6jpuwmEt3lJn8t Y3O029g0A35/IbnaQbXCZnI8nBgu2yzrZ1iSebfLU6693yMcToY1POah0SLglc5dSXxT 0+iO72XOusQ929eaLBOb/HJ5oRs3SAFcWNx9J9THxMjKTXHXfGV3k5Bpr5ZgQpVRtgoK VD9Q== X-Gm-Message-State: AKwxyteBAdFY2n3EGTxbDb1WI/Ohw2WrnbRZLBYJig9hTahF5v2EHoIB nlvLM0q6nCneHuljOrCYGKPnrKUqtjI= X-Received: by 10.99.66.68 with SMTP id p65mr11418734pga.384.1516836398879; Wed, 24 Jan 2018 15:26:38 -0800 (PST) Received: from cloudburst.twiddle.net (174-21-6-47.tukw.qwest.net. [174.21.6.47]) by smtp.gmail.com with ESMTPSA id z19sm9760028pfh.185.2018.01.24.15.26.37 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Jan 2018 15:26:37 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 24 Jan 2018 15:25:47 -0800 Message-Id: <20180124232625.30105-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180124232625.30105-1-richard.henderson@linaro.org> References: <20180124232625.30105-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [PATCH v3 07/45] target/hppa: Implement the system mask instructions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" Signed-off-by: Richard Henderson --- target/hppa/helper.h | 4 +++ target/hppa/op_helper.c | 14 ++++++++ target/hppa/translate.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 113 insertions(+), 1 deletion(-) -- 2.14.3 diff --git a/target/hppa/helper.h b/target/hppa/helper.h index c720de523b..254a4da133 100644 --- a/target/hppa/helper.h +++ b/target/hppa/helper.h @@ -76,3 +76,7 @@ DEF_HELPER_FLAGS_4(fmpyfadd_s, TCG_CALL_NO_RWG, i32, env, i32, i32, i32) DEF_HELPER_FLAGS_4(fmpynfadd_s, TCG_CALL_NO_RWG, i32, env, i32, i32, i32) DEF_HELPER_FLAGS_4(fmpyfadd_d, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) DEF_HELPER_FLAGS_4(fmpynfadd_d, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) + +#ifndef CONFIG_USER_ONLY +DEF_HELPER_FLAGS_2(swap_system_mask, TCG_CALL_NO_RWG, tr, env, tr) +#endif diff --git a/target/hppa/op_helper.c b/target/hppa/op_helper.c index 479bfc0fdf..1c3e043cc0 100644 --- a/target/hppa/op_helper.c +++ b/target/hppa/op_helper.c @@ -601,3 +601,17 @@ float64 HELPER(fmpynfadd_d)(CPUHPPAState *env, float64 a, float64 b, float64 c) update_fr0_op(env, GETPC()); return ret; } + +#ifndef CONFIG_USER_ONLY +target_ureg HELPER(swap_system_mask)(CPUHPPAState *env, target_ureg nsm) +{ + target_ulong psw = env->psw; + /* ??? On second reading this condition simply seems + to be undefined rather than a diagnosed trap. */ + if (nsm & ~psw & PSW_Q) { + dynexcp(env, EXCP_ILL, GETPC()); + } + env->psw = (psw & ~PSW_SM) | (nsm & PSW_SM); + return psw & PSW_SM; +} +#endif diff --git a/target/hppa/translate.c b/target/hppa/translate.c index 33605a2d15..088031e7f3 100644 --- a/target/hppa/translate.c +++ b/target/hppa/translate.c @@ -299,6 +299,10 @@ typedef struct DisasContext { updated the iaq for the next instruction to be executed. */ #define DISAS_IAQ_N_STALE DISAS_TARGET_1 +/* Similarly, but we want to return to the main loop immediately + to recognize unmasked interrupts. */ +#define DISAS_IAQ_N_STALE_EXIT DISAS_TARGET_2 + typedef struct DisasInsn { uint32_t insn, mask; DisasJumpType (*trans)(DisasContext *ctx, uint32_t insn, @@ -697,6 +701,14 @@ static DisasJumpType gen_illegal(DisasContext *ctx) return nullify_end(ctx, gen_excp(ctx, EXCP_ILL)); } +#define CHECK_MOST_PRIVILEGED(EXCP) \ + do { \ + if (ctx->privilege != 0) { \ + nullify_over(ctx); \ + return nullify_end(ctx, gen_excp(ctx, EXCP)); \ + } \ + } while (0) + static bool use_goto_tb(DisasContext *ctx, target_ureg dest) { /* Suppress goto_tb in the case of single-steping and IO. */ @@ -1982,6 +1994,79 @@ static DisasJumpType trans_ldsid(DisasContext *ctx, uint32_t insn, return DISAS_NEXT; } +#ifndef CONFIG_USER_ONLY +/* Note that ssm/rsm instructions number PSW_W and PSW_E differently. */ +static target_ureg extract_sm_imm(uint32_t insn) +{ + target_ureg val = extract32(insn, 16, 10); + + if (val & PSW_SM_E) { + val = (val & ~PSW_SM_E) | PSW_E; + } + if (val & PSW_SM_W) { + val = (val & ~PSW_SM_W) | PSW_W; + } + return val; +} + +static DisasJumpType trans_rsm(DisasContext *ctx, uint32_t insn, + const DisasInsn *di) +{ + unsigned rt = extract32(insn, 0, 5); + target_ureg sm = extract_sm_imm(insn); + TCGv_reg tmp; + + CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); + nullify_over(ctx); + + tmp = get_temp(ctx); + tcg_gen_ld_reg(tmp, cpu_env, offsetof(CPUHPPAState, psw)); + tcg_gen_andi_reg(tmp, tmp, ~sm); + gen_helper_swap_system_mask(tmp, cpu_env, tmp); + save_gpr(ctx, rt, tmp); + + /* Exit the TB to recognize new interrupts, e.g. PSW_M. */ + return nullify_end(ctx, DISAS_IAQ_N_STALE_EXIT); +} + +static DisasJumpType trans_ssm(DisasContext *ctx, uint32_t insn, + const DisasInsn *di) +{ + unsigned rt = extract32(insn, 0, 5); + target_ureg sm = extract_sm_imm(insn); + TCGv_reg tmp; + + CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); + nullify_over(ctx); + + tmp = get_temp(ctx); + tcg_gen_ld_reg(tmp, cpu_env, offsetof(CPUHPPAState, psw)); + tcg_gen_ori_reg(tmp, tmp, sm); + gen_helper_swap_system_mask(tmp, cpu_env, tmp); + save_gpr(ctx, rt, tmp); + + /* Exit the TB to recognize new interrupts, e.g. PSW_I. */ + return nullify_end(ctx, DISAS_IAQ_N_STALE_EXIT); +} + +static DisasJumpType trans_mtsm(DisasContext *ctx, uint32_t insn, + const DisasInsn *di) +{ + unsigned rr = extract32(insn, 16, 5); + TCGv_reg tmp, reg; + + CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR); + nullify_over(ctx); + + reg = load_gpr(ctx, rr); + tmp = get_temp(ctx); + gen_helper_swap_system_mask(tmp, cpu_env, reg); + + /* Exit the TB to recognize new interrupts. */ + return nullify_end(ctx, DISAS_IAQ_N_STALE_EXIT); +} +#endif /* !CONFIG_USER_ONLY */ + static const DisasInsn table_system[] = { { 0x00000000u, 0xfc001fe0u, trans_break }, /* We don't implement space register, so MTSP is a nop. */ @@ -1993,6 +2078,11 @@ static const DisasInsn table_system[] = { { 0x000008a0u, 0xfc1fffe0u, trans_mfctl }, { 0x00000400u, 0xffffffffu, trans_sync }, { 0x000010a0u, 0xfc1f3fe0u, trans_ldsid }, +#ifndef CONFIG_USER_ONLY + { 0x00000e60u, 0xfc00ffe0u, trans_rsm }, + { 0x00000d60u, 0xfc00ffe0u, trans_ssm }, + { 0x00001860u, 0xffe0ffffu, trans_mtsm }, +#endif }; static DisasJumpType trans_base_idx_mod(DisasContext *ctx, uint32_t insn, @@ -4111,12 +4201,14 @@ static void hppa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) static void hppa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) { DisasContext *ctx = container_of(dcbase, DisasContext, base); + DisasJumpType is_jmp = ctx->base.is_jmp; - switch (ctx->base.is_jmp) { + switch (is_jmp) { case DISAS_NORETURN: break; case DISAS_TOO_MANY: case DISAS_IAQ_N_STALE: + case DISAS_IAQ_N_STALE_EXIT: copy_iaoq_entry(cpu_iaoq_f, ctx->iaoq_f, cpu_iaoq_f); copy_iaoq_entry(cpu_iaoq_b, ctx->iaoq_b, cpu_iaoq_b); nullify_save(ctx); @@ -4124,6 +4216,8 @@ static void hppa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) case DISAS_IAQ_N_UPDATED: if (ctx->base.singlestep_enabled) { gen_excp_1(EXCP_DEBUG); + } else if (is_jmp == DISAS_IAQ_N_STALE_EXIT) { + tcg_gen_exit_tb(0); } else { tcg_gen_lookup_and_goto_ptr(); }