From patchwork Thu Jun 2 20:06:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Rolnik X-Patchwork-Id: 9151161 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 811BA60221 for ; Thu, 2 Jun 2016 20:23:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7130B2656B for ; Thu, 2 Jun 2016 20:23:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6610928328; Thu, 2 Jun 2016 20:23:13 +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 430652656B for ; Thu, 2 Jun 2016 20:23:12 +0000 (UTC) Received: from localhost ([::1]:50181 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Z95-0003qy-Ek for patchwork-qemu-devel@patchwork.kernel.org; Thu, 02 Jun 2016 16:23:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55306) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Ytv-0006NY-9b for qemu-devel@nongnu.org; Thu, 02 Jun 2016 16:07:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8Ytn-0003nD-Fj for qemu-devel@nongnu.org; Thu, 02 Jun 2016 16:07:31 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33558) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Ytm-0003mx-Mn for qemu-devel@nongnu.org; Thu, 02 Jun 2016 16:07:23 -0400 Received: by mail-wm0-x242.google.com with SMTP id a136so18656899wme.0 for ; Thu, 02 Jun 2016 13:07:22 -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=VkNuQyxqzq1B/xY/hWx9SdATKdrfCYs38vAs1uA/tnM=; b=ONNw1TfPWsNY/ViqqoRZ8jjWITJQF9kTWrMCUzlu2x9IuuZTIAJBT3bYmjicZkNeOH DrIM1642vMj37Tz52f9xRVAT1Wpv8U6wVZnbXawMRRVHsE+qlcP9PvPZ+x0uL0LRGrU/ Vr8KGAEQMBLJeRb3loB5a3yDGcFq6iOdyQnogokWSMNCAjH+Hp+YTfhdCkJq7EwBUPL1 HZXserN1pnz9ESaV+NP3p0LSijDlEyISAaNvrb/MkNpWPOwBPXU+6NWDvMcnfs3FODyj RNhDuH6LUalrCWC03s0Y6BDPq89Xxnt4LkwawNm9+H5olrM6h4cQ0MrdlhVurXrsv5dp OZww== 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=VkNuQyxqzq1B/xY/hWx9SdATKdrfCYs38vAs1uA/tnM=; b=efYAgmjSuuCgzS8InFcYZGy0Dx83Urcc7COQ7I/8UpDcVpOCDYDI6otPLnckoPTc8O e2KIE04IWywYVosLgo8ZDlV90PIuHS4tz/UZYe37yN0W4ERMLdsAnSTZupt2VTJqk/uX +f+8SFV2EO6quv/XNp80OL0JZD5+747bBS1T4o9DamUnJEQ1RAHilaggAYQXSNkNRu7P pgmuF7apxHqNO+7+J/uYhpfRUuIezHALEH891ugLjgh6/PiAC73nx/I1TaIDV1ZfWvUn qZD8lwMK8J3R2RJ/ZBiL5E6IV32e9FUy2njoI17JLYuEg8Zzuigsm/aKAReIIfJDvfaJ wUNg== X-Gm-Message-State: ALyK8tLVBD9r4LPvvD0tqJa9ajdJr0lMT7H7oqRsFcsIBpsoJXLvtNK7szL/0EZ7Zj2rjg== X-Received: by 10.194.105.4 with SMTP id gi4mr10625540wjb.87.1464898041948; Thu, 02 Jun 2016 13:07:21 -0700 (PDT) Received: from a0999b0126e1.ant.amazon.com ([94.230.86.227]) by smtp.gmail.com with ESMTPSA id i4sm2127090wjj.49.2016.06.02.13.07.20 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 02 Jun 2016 13:07:21 -0700 (PDT) From: Michael Rolnik X-Google-Original-From: Michael Rolnik To: qemu-devel@nongnu.org Date: Thu, 2 Jun 2016 23:06:59 +0300 Message-Id: <1464898022-97990-7-git-send-email-rolnik@amazon.com> X-Mailer: git-send-email 2.4.9 (Apple Git-60) In-Reply-To: <1464898022-97990-1-git-send-email-rolnik@amazon.com> References: <1464898022-97990-1-git-send-email-rolnik@amazon.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PATCH 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: Michael Rolnik , Michael Rolnik 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 | 724 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 724 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..22e2d36 --- /dev/null +++ b/target-avr/decode.c @@ -0,0 +1,724 @@ +/* + * 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" + + +uint32_t avr_decode(uint32_t pc, uint32_t *length, uint32_t code, translate_function_t *translate) +{ + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x0000d000) { + case 0x00000000: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00002c00) { + case 0x00000000: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000300) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_NOP; + break; + } + case 0x00000100: { + *length = 16; + *translate = (translate_function_t)&avr_translate_MOVW; + break; + } + case 0x00000200: { + *length = 16; + *translate = (translate_function_t)&avr_translate_MULS; + break; + } + case 0x00000300: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000088) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_MULSU; + break; + } + case 0x00000008: { + *length = 16; + *translate = (translate_function_t)&avr_translate_FMUL; + break; + } + case 0x00000080: { + *length = 16; + *translate = (translate_function_t)&avr_translate_FMULS; + break; + } + case 0x00000088: { + *length = 16; + *translate = (translate_function_t)&avr_translate_FMULSU; + break; + } + } + break; + } + } + break; + } + case 0x00000400: { + *length = 16; + *translate = (translate_function_t)&avr_translate_CPC; + break; + } + case 0x00000800: { + *length = 16; + *translate = (translate_function_t)&avr_translate_SBC; + break; + } + case 0x00000c00: { + *length = 16; + *translate = (translate_function_t)&avr_translate_ADD; + break; + } + case 0x00002000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_AND; + break; + } + case 0x00002400: { + *length = 16; + *translate = (translate_function_t)&avr_translate_EOR; + break; + } + case 0x00002800: { + *length = 16; + *translate = (translate_function_t)&avr_translate_OR; + break; + } + case 0x00002c00: { + *length = 16; + *translate = (translate_function_t)&avr_translate_MOV; + break; + } + } + break; + } + case 0x00001000: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00002000) { + case 0x00000000: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000c00) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_CPSE; + break; + } + case 0x00000400: { + *length = 16; + *translate = (translate_function_t)&avr_translate_CP; + break; + } + case 0x00000800: { + *length = 16; + *translate = (translate_function_t)&avr_translate_SUB; + break; + } + case 0x00000c00: { + *length = 16; + *translate = (translate_function_t)&avr_translate_ADC; + break; + } + } + break; + } + case 0x00002000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_CPI; + break; + } + } + break; + } + case 0x00004000: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00002000) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_SBCI; + break; + } + case 0x00002000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_ORI; + break; + } + } + break; + } + case 0x00005000: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00002000) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_SUBI; + break; + } + case 0x00002000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_ANDI; + break; + } + } + break; + } + case 0x00008000: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000208) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LDDZ; + break; + } + case 0x00000008: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LDDY; + break; + } + case 0x00000200: { + *length = 16; + *translate = (translate_function_t)&avr_translate_STDZ; + break; + } + case 0x00000208: { + *length = 16; + *translate = (translate_function_t)&avr_translate_STDY; + break; + } + } + break; + } + case 0x00009000: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00002800) { + case 0x00000000: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000600) { + case 0x00000000: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x0000000f) { + case 0x00000000: { + *length = 32; + *translate = (translate_function_t)&avr_translate_LDS; + break; + } + case 0x00000001: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LDZ2; + break; + } + case 0x00000002: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LDZ3; + break; + } + case 0x00000003: { + break; + } + case 0x00000004: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LPM2; + break; + } + case 0x00000005: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LPMX; + break; + } + case 0x00000006: { + *length = 16; + *translate = (translate_function_t)&avr_translate_ELPM2; + break; + } + case 0x00000007: { + *length = 16; + *translate = (translate_function_t)&avr_translate_ELPMX; + break; + } + case 0x00000008: { + break; + } + case 0x00000009: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LDY2; + break; + } + case 0x0000000a: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LDY3; + break; + } + case 0x0000000b: { + break; + } + case 0x0000000c: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LDX1; + break; + } + case 0x0000000d: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LDX2; + break; + } + case 0x0000000e: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LDX3; + break; + } + case 0x0000000f: { + *length = 16; + *translate = (translate_function_t)&avr_translate_POP; + break; + } + } + break; + } + case 0x00000200: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x0000000f) { + case 0x00000000: { + *length = 32; + *translate = (translate_function_t)&avr_translate_STS; + break; + } + case 0x00000001: { + *length = 16; + *translate = (translate_function_t)&avr_translate_STZ2; + break; + } + case 0x00000002: { + *length = 16; + *translate = (translate_function_t)&avr_translate_STZ3; + break; + } + case 0x00000003: { + break; + } + case 0x00000004: { + *length = 16; + *translate = (translate_function_t)&avr_translate_XCH; + break; + } + case 0x00000005: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LAS; + break; + } + case 0x00000006: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LAC; + break; + } + case 0x00000007: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LAT; + break; + } + case 0x00000008: { + break; + } + case 0x00000009: { + *length = 16; + *translate = (translate_function_t)&avr_translate_STY2; + break; + } + case 0x0000000a: { + *length = 16; + *translate = (translate_function_t)&avr_translate_STY3; + break; + } + case 0x0000000b: { + break; + } + case 0x0000000c: { + *length = 16; + *translate = (translate_function_t)&avr_translate_STX1; + break; + } + case 0x0000000d: { + *length = 16; + *translate = (translate_function_t)&avr_translate_STX2; + break; + } + case 0x0000000e: { + *length = 16; + *translate = (translate_function_t)&avr_translate_STX3; + break; + } + case 0x0000000f: { + *length = 16; + *translate = (translate_function_t)&avr_translate_PUSH; + break; + } + } + break; + } + case 0x00000400: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x0000000e) { + case 0x00000000: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000001) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_COM; + break; + } + case 0x00000001: { + *length = 16; + *translate = (translate_function_t)&avr_translate_NEG; + break; + } + } + break; + } + case 0x00000002: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000001) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_SWAP; + break; + } + case 0x00000001: { + *length = 16; + *translate = (translate_function_t)&avr_translate_INC; + break; + } + } + break; + } + case 0x00000004: { + *length = 16; + *translate = (translate_function_t)&avr_translate_ASR; + break; + } + case 0x00000006: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000001) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LSR; + break; + } + case 0x00000001: { + *length = 16; + *translate = (translate_function_t)&avr_translate_ROR; + break; + } + } + break; + } + case 0x00000008: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000181) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_BSET; + break; + } + case 0x00000001: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000010) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_IJMP; + break; + } + case 0x00000010: { + *length = 16; + *translate = (translate_function_t)&avr_translate_EIJMP; + break; + } + } + break; + } + case 0x00000080: { + *length = 16; + *translate = (translate_function_t)&avr_translate_BCLR; + break; + } + case 0x00000081: { + break; + } + case 0x00000100: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000010) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_RET; + break; + } + case 0x00000010: { + *length = 16; + *translate = (translate_function_t)&avr_translate_RETI; + break; + } + } + break; + } + case 0x00000101: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000010) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_ICALL; + break; + } + case 0x00000010: { + *length = 16; + *translate = (translate_function_t)&avr_translate_EICALL; + break; + } + } + break; + } + case 0x00000180: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000070) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_SLEEP; + break; + } + case 0x00000010: { + *length = 16; + *translate = (translate_function_t)&avr_translate_BREAK; + break; + } + case 0x00000020: { + *length = 16; + *translate = (translate_function_t)&avr_translate_WDR; + break; + } + case 0x00000030: { + break; + } + case 0x00000040: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LPM1; + break; + } + case 0x00000050: { + *length = 16; + *translate = (translate_function_t)&avr_translate_ELPM1; + break; + } + case 0x00000060: { + *length = 16; + *translate = (translate_function_t)&avr_translate_SPM; + break; + } + case 0x00000070: { + *length = 16; + *translate = (translate_function_t)&avr_translate_SPMX; + break; + } + } + break; + } + case 0x00000181: { + break; + } + } + break; + } + case 0x0000000a: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000001) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_DEC; + break; + } + case 0x00000001: { + *length = 16; + *translate = (translate_function_t)&avr_translate_DES; + break; + } + } + break; + } + case 0x0000000c: { + *length = 32; + *translate = (translate_function_t)&avr_translate_JMP; + break; + } + case 0x0000000e: { + *length = 32; + *translate = (translate_function_t)&avr_translate_CALL; + break; + } + } + break; + } + case 0x00000600: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000100) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_ADIW; + break; + } + case 0x00000100: { + *length = 16; + *translate = (translate_function_t)&avr_translate_SBIW; + break; + } + } + break; + } + } + break; + } + case 0x00000800: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000400) { + case 0x00000000: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000300) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_CBI; + break; + } + case 0x00000100: { + *length = 16; + *translate = (translate_function_t)&avr_translate_SBIC; + break; + } + case 0x00000200: { + *length = 16; + *translate = (translate_function_t)&avr_translate_SBI; + break; + } + case 0x00000300: { + *length = 16; + *translate = (translate_function_t)&avr_translate_SBIS; + break; + } + } + break; + } + case 0x00000400: { + *length = 16; + *translate = (translate_function_t)&avr_translate_MUL; + break; + } + } + break; + } + case 0x00002000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_IN; + break; + } + case 0x00002800: { + *length = 16; + *translate = (translate_function_t)&avr_translate_OUT; + break; + } + } + break; + } + case 0x0000c000: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00002000) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_RJMP; + break; + } + case 0x00002000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_LDI; + break; + } + } + break; + } + case 0x0000d000: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00002000) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_RCALL; + break; + } + case 0x00002000: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000c00) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_BRBS; + break; + } + case 0x00000400: { + *length = 16; + *translate = (translate_function_t)&avr_translate_BRBC; + break; + } + case 0x00000800: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000200) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_BLD; + break; + } + case 0x00000200: { + *length = 16; + *translate = (translate_function_t)&avr_translate_BST; + break; + } + } + break; + } + case 0x00000c00: { + uint32_t opcode = extract32(code, 0, 16); + switch (opcode & 0x00000200) { + case 0x00000000: { + *length = 16; + *translate = (translate_function_t)&avr_translate_SBRC; + break; + } + case 0x00000200: { + *length = 16; + *translate = (translate_function_t)&avr_translate_SBRS; + break; + } + } + break; + } + } + break; + } + } + break; + } + } + return 0; +}