From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.3 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02280C43603 for ; Sun, 8 Dec 2019 19:01:26 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C9B2A205F4 for ; Sun, 8 Dec 2019 19:01:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="srWP+Pd5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C9B2A205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:60914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ie1o4-0007wb-HZ for qemu-devel@archiver.kernel.org; Sun, 08 Dec 2019 14:01:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37469) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ie1Ti-0002Cc-Sb for qemu-devel@nongnu.org; Sun, 08 Dec 2019 13:40:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ie1Tc-00038H-Nj for qemu-devel@nongnu.org; Sun, 08 Dec 2019 13:40:18 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:38431) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ie1Tc-0002z0-4s for qemu-devel@nongnu.org; Sun, 08 Dec 2019 13:40:16 -0500 Received: by mail-wr1-x442.google.com with SMTP id y17so13536364wrh.5 for ; Sun, 08 Dec 2019 10:40:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HFlHW9huHXAAq1OqeA1arZy4zj7ZChbwEh6iZzUvZtY=; b=srWP+Pd5e0iPnHsx5plk936P+yPWIzjXqMSkDr7RH0Zlwhp5vw/FU7AhVbEvJTOs+9 /cfUYAM29Z+69t6hFu4Pdo57lk09pWECWfQTO8fP6ac7R8C1aA6uGUhC9DVQouSiyX8V qNOcf1V3a+hJx2+ev5u8ieasY9v8P6+SRkeo+D05yuaWMnRBntzaE138dPemzlgvUNlL QKmjB4jUVH9lAMx3l5rxaQDSoJrWG8i0KrqqtuVqTRy6KhzJq7D/MnDDnB5LZLHMpnGG 9P5lYH9xbAZfztHlSfiDg9dP5EUe+4lfhtPqmpuvdI/lBJD0mwJHfL3hxrTV8i68m5cg ydwg== 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=HFlHW9huHXAAq1OqeA1arZy4zj7ZChbwEh6iZzUvZtY=; b=JpkyVhVB2EaIivf6PBRb0s/305pNcmCwq6u9/U/O5xa9UszDW7P0sdFjOhgFPY1Lgs BCVW++9iH0+KIAxA7D8AjV6W7LCzJvp9GqkiDj5yqeZuNZzp3N3MR3eG9P7cO7+ga4cJ J1ynNutQXEojltJVe9XiDAD9dYadAhYyR2TKJNKkAgZO/bqZWtZIALRQKvU3haSRcRW/ 1oqWvYkoPltrjvDAodseYfFSK2Wl8gnJDvyEx015pmb+d05AOBXEYqSL+bNMMN9okzsl F2mFnqysKtc9qn0sLR119t+JyBjbVjvulsyNegj9BOn4cLxq0rSej9WPuSy9fo3sd/kz FrPg== X-Gm-Message-State: APjAAAVpYju0YBpT8iBqwGywzckmXQdzn4ySN+FoCCHoeQbyW9cWcIig cZEZBc4niTlKnUvC3daKtiY7uMJ81ww9IjEj X-Google-Smtp-Source: APXvYqxY7bALJST07pIWXW8RSO/yTHIMOejKSY2IneiLv5OMgi3J0prsL89GR1g7TBP5HP27wW/xJg== X-Received: by 2002:adf:f28c:: with SMTP id k12mr26342804wro.360.1575830408834; Sun, 08 Dec 2019 10:40:08 -0800 (PST) Received: from 8c859074c0ff.ant.amazon.com.com (bzq-79-180-52-3.red.bezeqint.net. [79.180.52.3]) by smtp.gmail.com with ESMTPSA id h17sm25289717wrs.18.2019.12.08.10.40.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Dec 2019 10:40:08 -0800 (PST) From: Michael Rolnik To: qemu-devel@nongnu.org Subject: [PATCH v38 08/22] target/avr: Add instruction translation - Bit and Bit-test Instructions Date: Sun, 8 Dec 2019 20:39:08 +0200 Message-Id: <20191208183922.13757-9-mrolnik@gmail.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20191208183922.13757-1-mrolnik@gmail.com> References: <20191208183922.13757-1-mrolnik@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thuth@redhat.com, Michael Rolnik , me@xcancerberox.com.ar, richard.henderson@linaro.org, dovgaluk@ispras.ru, imammedo@redhat.com, philmd@redhat.com, aleksandar.m.mail@gmail.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This includes: - LSR, ROR - ASR - SWAP - SBI, CBI - BST, BLD - BSET, BCLR Signed-off-by: Michael Rolnik --- target/avr/translate.c | 243 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) diff --git a/target/avr/translate.c b/target/avr/translate.c index 031176c9bd..d8d8f11933 100644 --- a/target/avr/translate.c +++ b/target/avr/translate.c @@ -313,6 +313,15 @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) } +static void gen_rshift_ZNVSf(TCGv R) +{ + tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_Zf, R, 0); /* Zf = R == 0 */ + tcg_gen_shri_tl(cpu_Nf, R, 7); /* Nf = R(7) */ + tcg_gen_xor_tl(cpu_Vf, cpu_Nf, cpu_Cf); + tcg_gen_xor_tl(cpu_Sf, cpu_Nf, cpu_Vf); /* Sf = Nf ^ Vf */ +} + + /* * Adds two registers without the C Flag and places the result in the * destination register Rd. @@ -2273,3 +2282,237 @@ static bool trans_LAT(DisasContext *ctx, arg_LAT *a) return true; } + + +/* + * Shifts all bits in Rd one place to the right. Bit 7 is cleared. Bit 0 is + * loaded into the C Flag of the SREG. This operation effectively divides an + * unsigned value by two. The C Flag can be used to round the result. + */ +static bool trans_LSR(DisasContext *ctx, arg_LSR *a) +{ + TCGv Rd = cpu_r[a->rd]; + + tcg_gen_andi_tl(cpu_Cf, Rd, 1); + tcg_gen_shri_tl(Rd, Rd, 1); + tcg_gen_setcondi_tl(TCG_COND_EQ, cpu_Zf, Rd, 0); /* Zf = Rd == 0 */ + tcg_gen_movi_tl(cpu_Nf, 0); + tcg_gen_mov_tl(cpu_Vf, cpu_Cf); + tcg_gen_mov_tl(cpu_Sf, cpu_Vf); + + return true; +} + + +/* + * Shifts all bits in Rd one place to the right. The C Flag is shifted into + * bit 7 of Rd. Bit 0 is shifted into the C Flag. This operation, combined + * with ASR, effectively divides multi-byte signed values by two. Combined with + * LSR it effectively divides multi-byte unsigned values by two. The Carry Flag + * can be used to round the result. + */ +static bool trans_ROR(DisasContext *ctx, arg_ROR *a) +{ + TCGv Rd = cpu_r[a->rd]; + TCGv t0 = tcg_temp_new_i32(); + + tcg_gen_shli_tl(t0, cpu_Cf, 7); + tcg_gen_andi_tl(cpu_Cf, Rd, 1); + tcg_gen_shri_tl(Rd, Rd, 1); + tcg_gen_or_tl(Rd, Rd, t0); + gen_rshift_ZNVSf(Rd); + + tcg_temp_free_i32(t0); + + return true; +} + + +/* + * Shifts all bits in Rd one place to the right. Bit 7 is held constant. Bit 0 + * is loaded into the C Flag of the SREG. This operation effectively divides a + * signed value by two without changing its sign. The Carry Flag can be used to + * round the result. + */ +static bool trans_ASR(DisasContext *ctx, arg_ASR *a) +{ + TCGv Rd = cpu_r[a->rd]; + TCGv t0 = tcg_temp_new_i32(); + + tcg_gen_andi_tl(cpu_Cf, Rd, 1); /* Cf = Rd(0) */ + tcg_gen_andi_tl(t0, Rd, 0x80); /* Rd = (Rd & 0x80) | (Rd >> 1) */ + tcg_gen_shri_tl(Rd, Rd, 1); + tcg_gen_or_tl(Rd, Rd, t0); + + gen_rshift_ZNVSf(Rd); + + tcg_temp_free_i32(t0); + + return true; +} + + +/* + * Swaps high and low nibbles in a register. + */ +static bool trans_SWAP(DisasContext *ctx, arg_SWAP *a) +{ + TCGv Rd = cpu_r[a->rd]; + TCGv t0 = tcg_temp_new_i32(); + TCGv t1 = tcg_temp_new_i32(); + + tcg_gen_andi_tl(t0, Rd, 0x0f); + tcg_gen_shli_tl(t0, t0, 4); + tcg_gen_andi_tl(t1, Rd, 0xf0); + tcg_gen_shri_tl(t1, t1, 4); + tcg_gen_or_tl(Rd, t0, t1); + + tcg_temp_free_i32(t1); + tcg_temp_free_i32(t0); + + return true; +} + + +/* + * Sets a specified bit in an I/O Register. This instruction operates on + * the lower 32 I/O Registers -- addresses 0-31. + */ +static bool trans_SBI(DisasContext *ctx, arg_SBI *a) +{ + TCGv data = tcg_temp_new_i32(); + TCGv port = tcg_const_i32(a->reg); + + gen_helper_inb(data, cpu_env, port); + tcg_gen_ori_tl(data, data, 1 << a->bit); + gen_helper_outb(cpu_env, port, data); + + tcg_temp_free_i32(port); + tcg_temp_free_i32(data); + + return true; +} + + +/* + * Clears a specified bit in an I/O Register. This instruction operates on + * the lower 32 I/O Registers -- addresses 0-31. + */ +static bool trans_CBI(DisasContext *ctx, arg_CBI *a) +{ + TCGv data = tcg_temp_new_i32(); + TCGv port = tcg_const_i32(a->reg); + + gen_helper_inb(data, cpu_env, port); + tcg_gen_andi_tl(data, data, ~(1 << a->bit)); + gen_helper_outb(cpu_env, port, data); + + tcg_temp_free_i32(data); + tcg_temp_free_i32(port); + + return true; +} + + +/* + * Stores bit b from Rd to the T Flag in SREG (Status Register). + */ +static bool trans_BST(DisasContext *ctx, arg_BST *a) +{ + TCGv Rd = cpu_r[a->rd]; + + tcg_gen_andi_tl(cpu_Tf, Rd, 1 << a->bit); + tcg_gen_shri_tl(cpu_Tf, cpu_Tf, a->bit); + + return true; +} + + +/* + * Copies the T Flag in the SREG (Status Register) to bit b in register Rd. + */ +static bool trans_BLD(DisasContext *ctx, arg_BLD *a) +{ + TCGv Rd = cpu_r[a->rd]; + TCGv t1 = tcg_temp_new_i32(); + + tcg_gen_andi_tl(Rd, Rd, ~(1u << a->bit)); /* clear bit */ + tcg_gen_shli_tl(t1, cpu_Tf, a->bit); /* create mask */ + tcg_gen_or_tl(Rd, Rd, t1); + + tcg_temp_free_i32(t1); + + return true; +} + + +/* + * Sets a single Flag or bit in SREG. + */ +static bool trans_BSET(DisasContext *ctx, arg_BSET *a) +{ + switch (a->bit) { + case 0x00: + tcg_gen_movi_tl(cpu_Cf, 0x01); + break; + case 0x01: + tcg_gen_movi_tl(cpu_Zf, 0x01); + break; + case 0x02: + tcg_gen_movi_tl(cpu_Nf, 0x01); + break; + case 0x03: + tcg_gen_movi_tl(cpu_Vf, 0x01); + break; + case 0x04: + tcg_gen_movi_tl(cpu_Sf, 0x01); + break; + case 0x05: + tcg_gen_movi_tl(cpu_Hf, 0x01); + break; + case 0x06: + tcg_gen_movi_tl(cpu_Tf, 0x01); + break; + case 0x07: + tcg_gen_movi_tl(cpu_If, 0x01); + break; + } + + return true; +} + + +/* + * Clears a single Flag in SREG. + */ +static bool trans_BCLR(DisasContext *ctx, arg_BCLR *a) +{ + switch (a->bit) { + case 0x00: + tcg_gen_movi_tl(cpu_Cf, 0x00); + break; + case 0x01: + tcg_gen_movi_tl(cpu_Zf, 0x00); + break; + case 0x02: + tcg_gen_movi_tl(cpu_Nf, 0x00); + break; + case 0x03: + tcg_gen_movi_tl(cpu_Vf, 0x00); + break; + case 0x04: + tcg_gen_movi_tl(cpu_Sf, 0x00); + break; + case 0x05: + tcg_gen_movi_tl(cpu_Hf, 0x00); + break; + case 0x06: + tcg_gen_movi_tl(cpu_Tf, 0x00); + break; + case 0x07: + tcg_gen_movi_tl(cpu_If, 0x00); + break; + } + + return true; +} -- 2.17.2 (Apple Git-113)