From patchwork Fri Dec 29 06:31:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 122890 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4323642qgn; Thu, 28 Dec 2017 22:35:30 -0800 (PST) X-Google-Smtp-Source: ACJfBot61c6+lIEv7dda5QsfomeAz7Y+x0W8avj9qoUPaipQIImq02HEiLC9s9fUAZ8A2+8+dMGM X-Received: by 10.37.160.212 with SMTP id i20mr11737715ybm.369.1514529330181; Thu, 28 Dec 2017 22:35:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514529330; cv=none; d=google.com; s=arc-20160816; b=0vZ+alRWz9mlVIXqC82PqR1xxTN2wPWM5a8KTRoTBPgrB9msWUMR5CjfjBzt5c2mad XYmbL+fbofLdxts2xCDFBq2ZVCO0cxdJJ1qHjS6Hz2RV3xacVB63nqQB0ApePOzjtzZF KHMlkKOt15L5MXmK2YSbclQGAQuIPxJh101oo5ITi4kCpJFUv4JukAJ+3CZVtNlRIaJI jm33NyutYlWZGsi0dkkOZAtcARSZVY+xS8ZAGpmPh79DYkF8VgxuUD4cjkhhBKcCaV5S ggda1sjR0OQ0oUy/Rqx0akLyK7hxzBppTd1gMTXpGWsB1lsWyH1Hz8ps0y52S/J1g094 TJkg== 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:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=3gzYIDYwrLqXhp8LKDm2IWxOsRsW6YU5/5H4qfQ1pGw=; b=aKZWHc8eB4pG9piVDV8VSrT2eCYLlgT3B8XdqXnptcB2M5o3kbMb69qL4cOnv0bEoi nDMLbCLCoNSjzN7ITH/xNRdyC32KKdp6PxCZ9cJDqVx3Zsbzr6S8NsbC8DVQDbFgQBZ5 2LbDUaLZ4ZeHnzSvG7sQcDYWMeRK3h2tRvxCrGu2HmsA0VwQWwNKO+j7H1bP1l0AvsiL K+XbebHLQ/FvPHpf/IyDuPmU3syNM5PFwPkhdCZ5ZzpowJBAO+wV1YMg+wB+BTKvIgHf fkNRmRWEVT9e5WdWMLHOMnGLQUaXD8w9b8GYF18amuPIJEcsQj+dBpknB6rIS/y2SS/Z aWkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Wa7cLxvY; 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 g125si6847839ywf.633.2017.12.28.22.35.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Dec 2017 22:35:30 -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=Wa7cLxvY; 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]:56941 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUoGP-0005MI-Jx for patch@linaro.org; Fri, 29 Dec 2017 01:35:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50613) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUoD3-0002rn-7s for qemu-devel@nongnu.org; Fri, 29 Dec 2017 01:32:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eUoD1-0004YQ-BK for qemu-devel@nongnu.org; Fri, 29 Dec 2017 01:32:01 -0500 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:37316) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eUoD1-0004Y8-36 for qemu-devel@nongnu.org; Fri, 29 Dec 2017 01:31:59 -0500 Received: by mail-pg0-x244.google.com with SMTP id o13so9956209pgp.4 for ; Thu, 28 Dec 2017 22:31:58 -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; bh=3gzYIDYwrLqXhp8LKDm2IWxOsRsW6YU5/5H4qfQ1pGw=; b=Wa7cLxvYAQbo/HjraA8A/rt3G0D/+0A+0dv+WFNbDkjXfYyYvEtkmSnAj2ZdgVpnV1 v4Bg3bF72K8irhNQ19ynzV77Bix66myYhNMRKq4gJqi/qptGuSNyKVtBHBvt8QfWcWE+ qzuiSZQq+nFDC23oJS1hTdjf59r3AZTS+X7OY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3gzYIDYwrLqXhp8LKDm2IWxOsRsW6YU5/5H4qfQ1pGw=; b=TW7346mkYsg3qgvCDMOtOq0VOdayinzO3atFmyo+N0a2gLV9Pbz+HG7lvw+gCn11u3 XIV0deVJ4OmiNnu2deOsFtQGIpY8WWNIwA9tQh7X91ea9HKvDmxv1UG2xQKMmheXnoD/ aet/awtfeet30xdOQpezUNhJPdThVexe3w/ejmJtB6wZtOBHKwU3P8QeLRMRDBTCcTFt GY2fa3IQsbtXTzu4wMV4ZbMj4epDq2Wmluk+vc/yuS58VuPSAEEmt1wq3WsLjiknZSMk AJaisXnUn6qUary+sJrz2sTEoZbvV3aoMwiiTkQzIfv6Mxo7Mc567AS+klqbMoT/7wGQ Maxw== X-Gm-Message-State: AKGB3mIIReIVJYqDAFy8WUwS68eIyk9W3i4eUFtXK5z1Au1VwrsOvQ1e jfWYkOeNp1qC6SUEhhux2umhm7Xs2pM= X-Received: by 10.99.122.17 with SMTP id v17mr28195174pgc.60.1514529117830; Thu, 28 Dec 2017 22:31:57 -0800 (PST) Received: from cloudburst.twiddle.net (97-113-183-164.tukw.qwest.net. [97.113.183.164]) by smtp.gmail.com with ESMTPSA id c28sm76539063pfe.69.2017.12.28.22.31.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Dec 2017 22:31:56 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 28 Dec 2017 22:31:14 -0800 Message-Id: <20171229063145.29167-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171229063145.29167-1-richard.henderson@linaro.org> References: <20171229063145.29167-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:c05::244 Subject: [Qemu-devel] [PATCH 07/38] 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: , Cc: deller@gmx.de 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 | 101 +++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 117 insertions(+), 2 deletions(-) -- 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 7afd91b69d..6f165fdd3d 100644 --- a/target/hppa/translate.c +++ b/target/hppa/translate.c @@ -295,6 +295,11 @@ 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_UPDATED_EXIT DISAS_TARGET_2 +#define DISAS_IAQ_N_STALE_EXIT DISAS_TARGET_3 + typedef struct DisasInsn { uint32_t insn, mask; DisasJumpType (*trans)(DisasContext *ctx, uint32_t insn, @@ -693,6 +698,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. */ @@ -1971,6 +1984,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. */ @@ -1982,6 +2068,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, @@ -4107,21 +4198,27 @@ 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); /* FALLTHRU */ case DISAS_IAQ_N_UPDATED: + case DISAS_IAQ_N_UPDATED_EXIT: if (ctx->base.singlestep_enabled) { gen_excp_1(EXCP_DEBUG); - } else { + } else if (is_jmp != DISAS_IAQ_N_UPDATED_EXIT + && is_jmp != DISAS_IAQ_N_STALE_EXIT) { tcg_gen_lookup_and_goto_ptr(); + } else { + tcg_gen_exit_tb(0); } break; default: