From patchwork Fri Dec 29 06:31:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 122904 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4330765qgn; Thu, 28 Dec 2017 22:45:04 -0800 (PST) X-Google-Smtp-Source: ACJfBoshXpVXla1JummldpEhP/z2M4ce/bAGFcltD5p0CuAlPWdMvVVpEPNafBneA3pwsPM2/16k X-Received: by 10.129.122.194 with SMTP id v185mr25047244ywc.204.1514529904456; Thu, 28 Dec 2017 22:45:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514529904; cv=none; d=google.com; s=arc-20160816; b=gnh0LJOczByQCa3kvfunZsWOU1618PBoprXjYKD9Lrw7hI8DRvpXYgG7+QoxMuNSUt qvnTF5xuXHSrAsuSxIg6oFUOkdGuuzx7OR1zQSVPZCdRkfAnuTyRHkIMdUf3DrfZxg4B NMZ4IhHP2evTFPVMaRCS6vqlO1am4Ty7VNQmFTehqWGUT1D8y195FTlwSxB4cTYx+4NQ 26DZHgzk2CiCM7HKJm3US4qjanR9oTaroIE+kLyJ3YeKs9DYGMzWEz5P7PinkZ+yFDLD IWcG/aix/iljOrm4j/wlJa9IPGHb8SgByIE2AQPWMeC2EKm9N6W17ShyZSr/FJcs5N0G 616A== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=xpwPr2R8AeA3LQsy3N3pgJFgWGewNiSzGP1V343MF+U=; b=MdO+7czgfD/TuGVUIvxpfAnI+8mFcBkD87AHO0dI6XOvFJ/qbmZhAViI3Usjl02d3n EXSZN3tSnlMZ+Pa0RPvMKDfMuchLf3QCDMWncZ0shqYGyq5vcRdXdYGLEzIgBuGeHnd2 +XDJtb5HOHZYfRz/C08Xi139GY76k/6JsdYr/CjKhfzkTTI2jcBkRvA3q4Iuplbp0/4F XndMq7Lgcaz/zzOvIrrQEW+NE1XbYiBtVDXxT7ab5kH230nD9tORcOdHmDJqpU7kJKTT /YcLGXDXiZF+eg3kREaCPCuVvAzOtHncWkpsAkNlHcW++cS0saCz2DD1xfagM2TZjYo1 Ye9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MZV28FXJ; 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 j4si6968851ywm.360.2017.12.28.22.45.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Dec 2017 22:45:04 -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=MZV28FXJ; 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]:57002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUoPf-0005JO-Te for patch@linaro.org; Fri, 29 Dec 2017 01:45:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUoDE-00031W-3E for qemu-devel@nongnu.org; Fri, 29 Dec 2017 01:32:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eUoDD-0004gL-1n for qemu-devel@nongnu.org; Fri, 29 Dec 2017 01:32:12 -0500 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]:36837) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eUoDC-0004g2-Ru for qemu-devel@nongnu.org; Fri, 29 Dec 2017 01:32:10 -0500 Received: by mail-pl0-x244.google.com with SMTP id b12so22519302plm.3 for ; Thu, 28 Dec 2017 22:32:10 -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=xpwPr2R8AeA3LQsy3N3pgJFgWGewNiSzGP1V343MF+U=; b=MZV28FXJffFdGeYOOeNzyaIVHSySlrp3j/1a+XHB9t00qE1XnGwaLxmKAm41I0sdn5 o7pdxtH3O8YZRXED87bGDDxbM5uOyjcx/1ueQaIdhuk6DJvFfySijxqvRkyxDFp3qcFp zOma+2UEAdtBm37hksnPkfO4VdIpCNkt0R4KU= 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:mime-version:content-transfer-encoding; bh=xpwPr2R8AeA3LQsy3N3pgJFgWGewNiSzGP1V343MF+U=; b=exUsbc38GjZoad/mycXfgzvOjJche0qqnFb6AOsKWLgVJpTqbnjPiTUFtyA14HpPP3 OPy+wmwrrdGUFwDl95F5wGULgAarAkvqdmpQqBBPC9/bsVMpswIu4KXfDoDr0tTpraiv ansc3Rt/rBmpnBS6gv283xkGpyeemc+8sI0TXh88cxlklKCAZfGjz8kCJ9rEPe4Ck7VD PAM+BC02ymIMzksH9rYhcPrcMUmn4IzMpx4iVoUjnhPIL44XNitJqN6NOB9XFqqpQB/M 2I3jbjLqdPjWsDofhDtyNcspF5gk6XJHaGeRl4D5deAlEp7Pz7OiG+eqL8AQ2Mqe8wpC AT9w== X-Gm-Message-State: AKGB3mLNcMhZ3AtLzdn8uMdgxeI98OjtBg7mqL2xDNXPIXeJ/3OSCmYQ sbPVST2afkOJuq8C7tSyUATZssKILfY= X-Received: by 10.159.253.75 with SMTP id b11mr34563070plx.316.1514529129523; Thu, 28 Dec 2017 22:32:09 -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.32.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Dec 2017 22:32:08 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 28 Dec 2017 22:31:23 -0800 Message-Id: <20171229063145.29167-17-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> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::244 Subject: [Qemu-devel] [PATCH 16/38] target/hppa: Avoid privilege level decrease during branches 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" These instructions force the destination privilege level of the branch destination to be no higher than current. Signed-off-by: Richard Henderson --- target/hppa/translate.c | 52 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) -- 2.14.3 diff --git a/target/hppa/translate.c b/target/hppa/translate.c index 4d5974c94d..918b444895 100644 --- a/target/hppa/translate.c +++ b/target/hppa/translate.c @@ -1859,6 +1859,40 @@ static DisasJumpType do_ibranch(DisasContext *ctx, TCGv_reg dest, return DISAS_NEXT; } +/* Implement + * if (IAOQ_Front{30..31} < GR[b]{30..31}) + * IAOQ_Next{30..31} ← GR[b]{30..31}; + * else + * IAOQ_Next{30..31} ← IAOQ_Front{30..31}; + * which keeps the privilege level from being increased. + */ +static TCGv_reg do_ibranch_priv(DisasContext *ctx, TCGv_reg offset) +{ +#ifdef CONFIG_USER_ONLY + return offset; +#else + TCGv_reg dest; + switch (ctx->privilege) { + case 0: + /* Privilege 0 is maximum and is allowed to decrease. */ + return offset; + case 3: + /* Privilege 3 is minimum and is never allowed increase. */ + dest = get_temp(ctx); + tcg_gen_ori_reg(dest, offset, 3); + break; + default: + dest = tcg_temp_new(); + tcg_gen_andi_reg(dest, offset, -4); + tcg_gen_ori_reg(dest, dest, ctx->privilege); + tcg_gen_movcond_reg(TCG_COND_GTU, dest, dest, offset, dest, offset); + tcg_temp_free(dest); + break; + } + return dest; +#endif +} + #ifdef CONFIG_USER_ONLY /* On Linux, page zero is normally marked execute only + gateway. Therefore normal read or write is supposed to fail, but specific @@ -3438,6 +3472,7 @@ static DisasJumpType trans_be(DisasContext *ctx, uint32_t insn, bool is_l) unsigned n = extract32(insn, 1, 1); unsigned b = extract32(insn, 21, 5); target_sreg disp = assemble_17(insn); + TCGv_reg tmp; /* unsigned s = low_uextract(insn, 13, 3); */ /* ??? It seems like there should be a good way of using @@ -3446,16 +3481,19 @@ static DisasJumpType trans_be(DisasContext *ctx, uint32_t insn, bool is_l) manage along side branch delay slots. Therefore we handle entry into the gateway page via absolute address. */ +#ifdef CONFIG_USER_ONLY /* Since we don't implement spaces, just branch. Do notice the special case of "be disp(*,r0)" using a direct branch to disp, so that we can goto_tb to the TB containing the syscall. */ if (b == 0) { return do_dbranch(ctx, disp, is_l ? 31 : 0, n); - } else { - TCGv_reg tmp = get_temp(ctx); - tcg_gen_addi_reg(tmp, load_gpr(ctx, b), disp); - return do_ibranch(ctx, tmp, is_l ? 31 : 0, n); } +#endif + + tmp = get_temp(ctx); + tcg_gen_addi_reg(tmp, load_gpr(ctx, b), disp); + tmp = do_ibranch_priv(ctx, tmp); + return do_ibranch(ctx, tmp, is_l ? 31 : 0, n); } static DisasJumpType trans_bl(DisasContext *ctx, uint32_t insn, @@ -3487,6 +3525,7 @@ static DisasJumpType trans_blr(DisasContext *ctx, uint32_t insn, tcg_gen_shli_reg(tmp, load_gpr(ctx, rx), 3); tcg_gen_addi_reg(tmp, tmp, ctx->iaoq_f + 8); + /* The computation here never changes privilege level. */ return do_ibranch(ctx, tmp, link, n); } @@ -3505,6 +3544,7 @@ static DisasJumpType trans_bv(DisasContext *ctx, uint32_t insn, tcg_gen_shli_reg(dest, load_gpr(ctx, rx), 3); tcg_gen_add_reg(dest, dest, load_gpr(ctx, rb)); } + dest = do_ibranch_priv(ctx, dest); return do_ibranch(ctx, dest, 0, n); } @@ -3514,8 +3554,10 @@ static DisasJumpType trans_bve(DisasContext *ctx, uint32_t insn, unsigned n = extract32(insn, 1, 1); unsigned rb = extract32(insn, 21, 5); unsigned link = extract32(insn, 13, 1) ? 2 : 0; + TCGv_reg dest; - return do_ibranch(ctx, load_gpr(ctx, rb), link, n); + dest = do_ibranch_priv(ctx, load_gpr(ctx, rb)); + return do_ibranch(ctx, dest, link, n); } static const DisasInsn table_branch[] = {