From patchwork Wed Jun 7 00:31:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 9770399 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0DDD560353 for ; Wed, 7 Jun 2017 01:00:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E19692852D for ; Wed, 7 Jun 2017 01:00:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D29CD2853F; Wed, 7 Jun 2017 01:00:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2A52027E63 for ; Wed, 7 Jun 2017 01:00:44 +0000 (UTC) Received: from localhost ([::1]:40674 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIPL0-000403-PJ for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Jun 2017 21:00:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIOtz-0003g8-8W for qemu-devel@nongnu.org; Tue, 06 Jun 2017 20:32:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIOty-0002M3-66 for qemu-devel@nongnu.org; Tue, 06 Jun 2017 20:32:47 -0400 Received: from mail-qk0-x241.google.com ([2607:f8b0:400d:c09::241]:32793) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dIOty-0002LX-1a for qemu-devel@nongnu.org; Tue, 06 Jun 2017 20:32:46 -0400 Received: by mail-qk0-x241.google.com with SMTP id c206so15446437qkb.0 for ; Tue, 06 Jun 2017 17:32:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=aoyqz1cwRAFdpDJJjV+m2IJRXkAKTrq9TGbDFKXB7yE=; b=qKVoDnzF2gL5MzDgnxB47JPeSo9GPDG178ucCBVBkWl3/gBcm78/BXLsSpRn+Jpv+T nRA/pOa0EIHyVdGD+eiSq9ts09M48Hdp5+e40FkE2vDg45utXZzbUbSDylQ8LXkuZKeX u7YUP5odhAU9OOzqzC+W+njKCFJMkG8WkQXxrijgrtFg58KjFPZd8bfv1RDcaw4fXMxC hS1gY8Zny/e/qdSwwNX5wl64R0CXtZpg42opeLwo26SLujO8sNgAcO6J/Rh8oHeHr7uq hvyY+pdg1GI8wS27gavHJcPx1wq6piNTSTeZC3YnihAx3GK06pECI5ZeuY/WyFhapJMH 29sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=aoyqz1cwRAFdpDJJjV+m2IJRXkAKTrq9TGbDFKXB7yE=; b=BK4n3jD9qsZFFUkwE/xqsJ7BlP6Xk6eAYi4XQOwh+kCgzMVaTfYl3wI+JzLDfjDpRU ckk7VXwRRfc3OzBJ/n85/FloJCM1w3Gj7SXZuYQphFhuXua5xx9QjLJOHLAnq2L0lekd p9uJ07rzSwp9jX1cY/IwFyajvCD8dpBsDpoFFBLVECP5fpRMmttX4aS2LrtJ3yV6tdHI +YQA84zmYU2fbM8+WmwKIC1cea+cs6zWOl53Iv+PYBQTAYbD/KpU/pwKpX4pGRXhuU5e 3u1Ih04P00Hretp/6yzF4MTCdKR9s3EX+w9medUFQVjSsrM46IVfXvsCslaDL+sRwl2x D93Q== X-Gm-Message-State: AODbwcACi8BShn+htXfoTdOqfyco1R441OYYgC1t4geCNG0iGgbbU91U 6Qn4NXePVbxn/SE7YkE= X-Received: by 10.55.4.135 with SMTP id 129mr31323414qke.10.1496795565338; Tue, 06 Jun 2017 17:32:45 -0700 (PDT) Received: from bigtime.twiddle.net.com (71-217-91-69.tukw.qwest.net. [71.217.91.69]) by smtp.gmail.com with ESMTPSA id m47sm29286qtc.36.2017.06.06.17.32.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Jun 2017 17:32:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 6 Jun 2017 17:31:11 -0700 Message-Id: <20170607003119.14778-63-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607003119.14778-1-rth@twiddle.net> References: <20170607003119.14778-1-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::241 Subject: [Qemu-devel] [PULL v2 62/70] target/s390x: implement UNPACK ASCII 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: peter.maydell@linaro.org, aurelien@aurel32.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Aurelien Jarno Reviewed-by: Richard Henderson Signed-off-by: Aurelien Jarno Message-Id: <20170531220129.27724-26-aurelien@aurel32.net> Signed-off-by: Richard Henderson --- target/s390x/helper.h | 1 + target/s390x/insn-data.def | 2 ++ target/s390x/mem_helper.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ target/s390x/translate.c | 17 ++++++++++++++++ 4 files changed, 71 insertions(+) diff --git a/target/s390x/helper.h b/target/s390x/helper.h index cda7f7f..c21be50 100644 --- a/target/s390x/helper.h +++ b/target/s390x/helper.h @@ -89,6 +89,7 @@ DEF_HELPER_FLAGS_4(pack, TCG_CALL_NO_WG, void, env, i32, i64, i64) DEF_HELPER_FLAGS_4(pka, TCG_CALL_NO_WG, void, env, i64, i64, i32) DEF_HELPER_FLAGS_4(pku, TCG_CALL_NO_WG, void, env, i64, i64, i32) DEF_HELPER_FLAGS_4(unpk, TCG_CALL_NO_WG, void, env, i32, i64, i64) +DEF_HELPER_FLAGS_4(unpka, TCG_CALL_NO_WG, i32, env, i64, i32, i64) DEF_HELPER_FLAGS_4(tr, TCG_CALL_NO_WG, void, env, i32, i64, i64) DEF_HELPER_4(tre, i64, env, i64, i64, i64) DEF_HELPER_4(trt, i32, env, i32, i64, i64) diff --git a/target/s390x/insn-data.def b/target/s390x/insn-data.def index 1b487c3..1782e2f 100644 --- a/target/s390x/insn-data.def +++ b/target/s390x/insn-data.def @@ -871,6 +871,8 @@ /* Really format SS_b, but we pack both lengths into one argument for the helper call, so we might as well leave one 8-bit field. */ C(0xf300, UNPK, SS_a, Z, la1, a2, 0, 0, unpk, 0) +/* UNPACK ASCII */ + C(0xea00, UNPKA, SS_a, E2, la1, a2, 0, 0, unpka, 0) #ifndef CONFIG_USER_ONLY /* COMPARE AND SWAP AND PURGE */ diff --git a/target/s390x/mem_helper.c b/target/s390x/mem_helper.c index 218f1ab..b87e417 100644 --- a/target/s390x/mem_helper.c +++ b/target/s390x/mem_helper.c @@ -1008,6 +1008,57 @@ void HELPER(unpk)(CPUS390XState *env, uint32_t len, uint64_t dest, } } +uint32_t HELPER(unpka)(CPUS390XState *env, uint64_t dest, uint32_t destlen, + uint64_t src) +{ + uintptr_t ra = GETPC(); + int i; + uint32_t cc; + uint8_t b; + /* The source operand is always 16 bytes long. */ + const int srclen = 16; + + /* The operands are processed from right to left. */ + src += srclen - 1; + dest += destlen - 1; + + /* Check for the sign. */ + b = cpu_ldub_data_ra(env, src, ra); + src--; + switch (b & 0xf) { + case 0xa: + case 0xc: + case 0xe ... 0xf: + cc = 0; /* plus */ + break; + case 0xb: + case 0xd: + cc = 1; /* minus */ + break; + default: + case 0x0 ... 0x9: + cc = 3; /* invalid */ + break; + } + + /* Now pad every nibble with 0x30, advancing one nibble at a time. */ + for (i = 0; i < destlen; i++) { + if (i == 31) { + /* If length is 32 bytes, the leftmost byte is 0. */ + b = 0; + } else if (i % 2) { + b = cpu_ldub_data_ra(env, src, ra); + src--; + } else { + b >>= 4; + } + cpu_stb_data_ra(env, dest, 0x30 + (b & 0xf), ra); + dest--; + } + + return cc; +} + static uint32_t do_helper_tr(CPUS390XState *env, uint32_t len, uint64_t array, uint64_t trans, uintptr_t ra) { diff --git a/target/s390x/translate.c b/target/s390x/translate.c index 7e01c40..cd5cbd1 100644 --- a/target/s390x/translate.c +++ b/target/s390x/translate.c @@ -4349,6 +4349,23 @@ static ExitStatus op_unpk(DisasContext *s, DisasOps *o) return NO_EXIT; } +static ExitStatus op_unpka(DisasContext *s, DisasOps *o) +{ + int l1 = get_field(s->fields, l1) + 1; + TCGv_i32 l; + + /* The length must not exceed 32 bytes. */ + if (l1 > 32) { + gen_program_exception(s, PGM_SPECIFICATION); + return EXIT_NORETURN; + } + l = tcg_const_i32(l1); + gen_helper_unpka(cc_op, cpu_env, o->addr1, l, o->in2); + tcg_temp_free_i32(l); + set_cc_static(s); + return NO_EXIT; +} + static ExitStatus op_xc(DisasContext *s, DisasOps *o) { int d1 = get_field(s->fields, d1);