From patchwork Wed Jun 22 09:51:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Rolnik X-Patchwork-Id: 9192317 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 0DBC460756 for ; Wed, 22 Jun 2016 09:58:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDA4328161 for ; Wed, 22 Jun 2016 09:58:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E19FB283DF; Wed, 22 Jun 2016 09:58:39 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 DBD1628161 for ; Wed, 22 Jun 2016 09:58:38 +0000 (UTC) Received: from localhost ([::1]:56870 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFeve-0001NZ-2J for patchwork-qemu-devel@patchwork.kernel.org; Wed, 22 Jun 2016 05:58:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40725) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFepk-0002Vt-R7 for qemu-devel@nongnu.org; Wed, 22 Jun 2016 05:52:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFepf-0006J5-D3 for qemu-devel@nongnu.org; Wed, 22 Jun 2016 05:52:32 -0400 Received: from mail-lb0-x243.google.com ([2a00:1450:4010:c04::243]:34765) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFepe-0006Ir-QV for qemu-devel@nongnu.org; Wed, 22 Jun 2016 05:52:27 -0400 Received: by mail-lb0-x243.google.com with SMTP id w10so3831780lbo.1 for ; Wed, 22 Jun 2016 02:52:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qLZm2FDG4JMmVX9G5erQixAa7qsx2sEKtGRwegqn71s=; b=ngBBznPVbcl684rRMf7krqlc/YucHPxce8u0P/jSXCVQYLZ62vH+h0SXDzcVrS2wlG J/g/KbKFFANFYTFXn9WAvoi0+66GUl3nP7c9C8y+bHMmhri23mEsxHPEZg5XEb5V1SdU y5Fg4gNE1zmywcEaBFbYJi78ouKqYZuS2dajSafcFiwujQwaTOtNUMlbtNv0ixh3LvLx jxw0gSwGWBddr4w50sP2tFb9WqwL5qEisufU/gFlNU7z53U5Kw3JaJpLdEgiMk5r4IZ3 Hx9zt1JV3GmQS7je/kTlN1JE+NugNXUQfyy40Dvgi91vbN3CbBWzR2dp2mP2dVeSbaZq qdYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qLZm2FDG4JMmVX9G5erQixAa7qsx2sEKtGRwegqn71s=; b=HhltZYPkh74I64sStwUgRHK+Ol1SIxVkKTx031M/RDFVD2mW4/7f2fV4S1Uo/Spg0q Po4JSb9hVVnwfDt7S8PBGZbM3OBC4+iYezlTEsDnJiW3HWeLllYz9ACYeMZHXo3iJ4Kf V1rgA7DgAaehm60+3wKfwGVgtu2XUvqTnGmtUiIaDk9YAoCVRGi1GmYyzDM3DDw5KfsF vx8KRFkZWaDSDn40vo+uITYchsjRw8BSyg39bxNlSuEHUoW0gI4tumV0s/Nr1Ku1Zijb yKWGKnnsy6kItxTP+7MUJkbx3p6smK1v+eRuparcK9H3pwFRSBe1uh8H1hdDXQMe5fFE 3OJw== X-Gm-Message-State: ALyK8tJkt1DAObR2MNEx77JC778tYI6oJbozXMBaQT3mcorwBaJzOv8/BPtCDQ1CAp4J9A== X-Received: by 10.194.234.103 with SMTP id ud7mr23739111wjc.39.1466589145889; Wed, 22 Jun 2016 02:52:25 -0700 (PDT) Received: from a0999b0126e1.ant.amazon.com ([5.102.195.79]) by smtp.gmail.com with ESMTPSA id b187sm7215976wmg.15.2016.06.22.02.52.24 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 Jun 2016 02:52:24 -0700 (PDT) From: Michael Rolnik To: qemu-devel@nongnu.org Date: Wed, 22 Jun 2016 12:51:52 +0300 Message-Id: <1466589115-57738-8-git-send-email-mrolnik@gmail.com> X-Mailer: git-send-email 2.4.9 (Apple Git-60) In-Reply-To: <1466589115-57738-1-git-send-email-mrolnik@gmail.com> References: <1466589115-57738-1-git-send-email-mrolnik@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c04::243 Subject: [Qemu-devel] [PATCH v9 07/10] target-avr: adding instruction decoder 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, Michael Rolnik , rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Michael Rolnik --- target-avr/decode.c | 693 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 693 insertions(+) create mode 100644 target-avr/decode.c diff --git a/target-avr/decode.c b/target-avr/decode.c new file mode 100644 index 0000000..44a5815 --- /dev/null +++ b/target-avr/decode.c @@ -0,0 +1,693 @@ +/* + * QEMU AVR CPU + * + * Copyright (c) 2016 Michael Rolnik + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + * + */ + + +#include +#include "translate.h" + +void avr_decode(uint32_t pc, uint32_t *l, uint32_t c, translate_function_t *t) +{ + uint32_t opc = extract32(c, 0, 16); + switch (opc & 0x0000d000) { + case 0x00000000: { + switch (opc & 0x00002c00) { + case 0x00000000: { + switch (opc & 0x00000300) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_NOP; + break; + } + case 0x00000100: { + *l = 16; + *t = &avr_translate_MOVW; + break; + } + case 0x00000200: { + *l = 16; + *t = &avr_translate_MULS; + break; + } + case 0x00000300: { + switch (opc & 0x00000088) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_MULSU; + break; + } + case 0x00000008: { + *l = 16; + *t = &avr_translate_FMUL; + break; + } + case 0x00000080: { + *l = 16; + *t = &avr_translate_FMULS; + break; + } + case 0x00000088: { + *l = 16; + *t = &avr_translate_FMULSU; + break; + } + } + break; + } + } + break; + } + case 0x00000400: { + *l = 16; + *t = &avr_translate_CPC; + break; + } + case 0x00000800: { + *l = 16; + *t = &avr_translate_SBC; + break; + } + case 0x00000c00: { + *l = 16; + *t = &avr_translate_ADD; + break; + } + case 0x00002000: { + *l = 16; + *t = &avr_translate_AND; + break; + } + case 0x00002400: { + *l = 16; + *t = &avr_translate_EOR; + break; + } + case 0x00002800: { + *l = 16; + *t = &avr_translate_OR; + break; + } + case 0x00002c00: { + *l = 16; + *t = &avr_translate_MOV; + break; + } + } + break; + } + case 0x00001000: { + switch (opc & 0x00002000) { + case 0x00000000: { + switch (opc & 0x00000c00) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_CPSE; + break; + } + case 0x00000400: { + *l = 16; + *t = &avr_translate_CP; + break; + } + case 0x00000800: { + *l = 16; + *t = &avr_translate_SUB; + break; + } + case 0x00000c00: { + *l = 16; + *t = &avr_translate_ADC; + break; + } + } + break; + } + case 0x00002000: { + *l = 16; + *t = &avr_translate_CPI; + break; + } + } + break; + } + case 0x00004000: { + switch (opc & 0x00002000) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_SBCI; + break; + } + case 0x00002000: { + *l = 16; + *t = &avr_translate_ORI; + break; + } + } + break; + } + case 0x00005000: { + switch (opc & 0x00002000) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_SUBI; + break; + } + case 0x00002000: { + *l = 16; + *t = &avr_translate_ANDI; + break; + } + } + break; + } + case 0x00008000: { + switch (opc & 0x00000208) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_LDDZ; + break; + } + case 0x00000008: { + *l = 16; + *t = &avr_translate_LDDY; + break; + } + case 0x00000200: { + *l = 16; + *t = &avr_translate_STDZ; + break; + } + case 0x00000208: { + *l = 16; + *t = &avr_translate_STDY; + break; + } + } + break; + } + case 0x00009000: { + switch (opc & 0x00002800) { + case 0x00000000: { + switch (opc & 0x00000600) { + case 0x00000000: { + switch (opc & 0x0000000f) { + case 0x00000000: { + *l = 32; + *t = &avr_translate_LDS; + break; + } + case 0x00000001: { + *l = 16; + *t = &avr_translate_LDZ2; + break; + } + case 0x00000002: { + *l = 16; + *t = &avr_translate_LDZ3; + break; + } + case 0x00000003: { + break; + } + case 0x00000004: { + *l = 16; + *t = &avr_translate_LPM2; + break; + } + case 0x00000005: { + *l = 16; + *t = &avr_translate_LPMX; + break; + } + case 0x00000006: { + *l = 16; + *t = &avr_translate_ELPM2; + break; + } + case 0x00000007: { + *l = 16; + *t = &avr_translate_ELPMX; + break; + } + case 0x00000008: { + break; + } + case 0x00000009: { + *l = 16; + *t = &avr_translate_LDY2; + break; + } + case 0x0000000a: { + *l = 16; + *t = &avr_translate_LDY3; + break; + } + case 0x0000000b: { + break; + } + case 0x0000000c: { + *l = 16; + *t = &avr_translate_LDX1; + break; + } + case 0x0000000d: { + *l = 16; + *t = &avr_translate_LDX2; + break; + } + case 0x0000000e: { + *l = 16; + *t = &avr_translate_LDX3; + break; + } + case 0x0000000f: { + *l = 16; + *t = &avr_translate_POP; + break; + } + } + break; + } + case 0x00000200: { + switch (opc & 0x0000000f) { + case 0x00000000: { + *l = 32; + *t = &avr_translate_STS; + break; + } + case 0x00000001: { + *l = 16; + *t = &avr_translate_STZ2; + break; + } + case 0x00000002: { + *l = 16; + *t = &avr_translate_STZ3; + break; + } + case 0x00000003: { + break; + } + case 0x00000004: { + *l = 16; + *t = &avr_translate_XCH; + break; + } + case 0x00000005: { + *l = 16; + *t = &avr_translate_LAS; + break; + } + case 0x00000006: { + *l = 16; + *t = &avr_translate_LAC; + break; + } + case 0x00000007: { + *l = 16; + *t = &avr_translate_LAT; + break; + } + case 0x00000008: { + break; + } + case 0x00000009: { + *l = 16; + *t = &avr_translate_STY2; + break; + } + case 0x0000000a: { + *l = 16; + *t = &avr_translate_STY3; + break; + } + case 0x0000000b: { + break; + } + case 0x0000000c: { + *l = 16; + *t = &avr_translate_STX1; + break; + } + case 0x0000000d: { + *l = 16; + *t = &avr_translate_STX2; + break; + } + case 0x0000000e: { + *l = 16; + *t = &avr_translate_STX3; + break; + } + case 0x0000000f: { + *l = 16; + *t = &avr_translate_PUSH; + break; + } + } + break; + } + case 0x00000400: { + switch (opc & 0x0000000e) { + case 0x00000000: { + switch (opc & 0x00000001) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_COM; + break; + } + case 0x00000001: { + *l = 16; + *t = &avr_translate_NEG; + break; + } + } + break; + } + case 0x00000002: { + switch (opc & 0x00000001) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_SWAP; + break; + } + case 0x00000001: { + *l = 16; + *t = &avr_translate_INC; + break; + } + } + break; + } + case 0x00000004: { + *l = 16; + *t = &avr_translate_ASR; + break; + } + case 0x00000006: { + switch (opc & 0x00000001) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_LSR; + break; + } + case 0x00000001: { + *l = 16; + *t = &avr_translate_ROR; + break; + } + } + break; + } + case 0x00000008: { + switch (opc & 0x00000181) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_BSET; + break; + } + case 0x00000001: { + switch (opc & 0x00000010) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_IJMP; + break; + } + case 0x00000010: { + *l = 16; + *t = &avr_translate_EIJMP; + break; + } + } + break; + } + case 0x00000080: { + *l = 16; + *t = &avr_translate_BCLR; + break; + } + case 0x00000081: { + break; + } + case 0x00000100: { + switch (opc & 0x00000010) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_RET; + break; + } + case 0x00000010: { + *l = 16; + *t = &avr_translate_RETI; + break; + } + } + break; + } + case 0x00000101: { + switch (opc & 0x00000010) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_ICALL; + break; + } + case 0x00000010: { + *l = 16; + *t = &avr_translate_EICALL; + break; + } + } + break; + } + case 0x00000180: { + switch (opc & 0x00000070) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_SLEEP; + break; + } + case 0x00000010: { + *l = 16; + *t = &avr_translate_BREAK; + break; + } + case 0x00000020: { + *l = 16; + *t = &avr_translate_WDR; + break; + } + case 0x00000030: { + break; + } + case 0x00000040: { + *l = 16; + *t = &avr_translate_LPM1; + break; + } + case 0x00000050: { + *l = 16; + *t = &avr_translate_ELPM1; + break; + } + case 0x00000060: { + *l = 16; + *t = &avr_translate_SPM; + break; + } + case 0x00000070: { + *l = 16; + *t = &avr_translate_SPMX; + break; + } + } + break; + } + case 0x00000181: { + break; + } + } + break; + } + case 0x0000000a: { + switch (opc & 0x00000001) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_DEC; + break; + } + case 0x00000001: { + *l = 16; + *t = &avr_translate_DES; + break; + } + } + break; + } + case 0x0000000c: { + *l = 32; + *t = &avr_translate_JMP; + break; + } + case 0x0000000e: { + *l = 32; + *t = &avr_translate_CALL; + break; + } + } + break; + } + case 0x00000600: { + switch (opc & 0x00000100) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_ADIW; + break; + } + case 0x00000100: { + *l = 16; + *t = &avr_translate_SBIW; + break; + } + } + break; + } + } + break; + } + case 0x00000800: { + switch (opc & 0x00000400) { + case 0x00000000: { + switch (opc & 0x00000300) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_CBI; + break; + } + case 0x00000100: { + *l = 16; + *t = &avr_translate_SBIC; + break; + } + case 0x00000200: { + *l = 16; + *t = &avr_translate_SBI; + break; + } + case 0x00000300: { + *l = 16; + *t = &avr_translate_SBIS; + break; + } + } + break; + } + case 0x00000400: { + *l = 16; + *t = &avr_translate_MUL; + break; + } + } + break; + } + case 0x00002000: { + *l = 16; + *t = &avr_translate_IN; + break; + } + case 0x00002800: { + *l = 16; + *t = &avr_translate_OUT; + break; + } + } + break; + } + case 0x0000c000: { + switch (opc & 0x00002000) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_RJMP; + break; + } + case 0x00002000: { + *l = 16; + *t = &avr_translate_LDI; + break; + } + } + break; + } + case 0x0000d000: { + switch (opc & 0x00002000) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_RCALL; + break; + } + case 0x00002000: { + switch (opc & 0x00000c00) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_BRBS; + break; + } + case 0x00000400: { + *l = 16; + *t = &avr_translate_BRBC; + break; + } + case 0x00000800: { + switch (opc & 0x00000200) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_BLD; + break; + } + case 0x00000200: { + *l = 16; + *t = &avr_translate_BST; + break; + } + } + break; + } + case 0x00000c00: { + switch (opc & 0x00000200) { + case 0x00000000: { + *l = 16; + *t = &avr_translate_SBRC; + break; + } + case 0x00000200: { + *l = 16; + *t = &avr_translate_SBRS; + break; + } + } + break; + } + } + break; + } + } + break; + } + } + +}