From patchwork Thu Jun 2 20:04:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Rolnik X-Patchwork-Id: 9151141 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 4614A60467 for ; Thu, 2 Jun 2016 20:10:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33B6728326 for ; Thu, 2 Jun 2016 20:10:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2802928328; Thu, 2 Jun 2016 20:10:08 +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 E4A4528326 for ; Thu, 2 Jun 2016 20:10:06 +0000 (UTC) Received: from localhost ([::1]:50098 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8YwO-0008SE-J0 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 02 Jun 2016 16:10:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54470) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Yr1-0003Pq-5K for qemu-devel@nongnu.org; Thu, 02 Jun 2016 16:04:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8Yqx-0003Bs-TR for qemu-devel@nongnu.org; Thu, 02 Jun 2016 16:04:30 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:36575) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Yqx-0003Bi-8w for qemu-devel@nongnu.org; Thu, 02 Jun 2016 16:04:27 -0400 Received: by mail-wm0-x243.google.com with SMTP id a20so7023859wma.3 for ; Thu, 02 Jun 2016 13:04:27 -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=SDuIa0sTgLxIAvhI3pVyjJMSgto/hkLaaSrq0qAb2ZyMZ4Hc6OiyjxV8Oz92RCdTc5 ASKZ+m5ROl5LVBh0HEngDB/WsgZG2tvtkXmep26ElPwLTPsIZpVK0egvwS9Dcumwn1x+ Hg7YWLYOHwPx9jAnoYJAS8SbzFfzw6/tCLb8hcSYvqTzQk/Pye+BV2X4NTRIqi9Pxxb3 vaugNgfxzrMtLigSS24H8HGqSMxsNv+t2PFb4T1p8p7JkujBEJ56kpNfFHt/N+Qk1Nxe XX4FEnn+66vNSTJgit3fvHqubHt7XgG1Z6jlJC7IDPNvenA4OgDFm3mhawqPoE9ixAqR cjKQ== 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=Hu9HpEogZ0vgUYjSJUQoWo3oVVYhSje9hiKfSBlK3nvWDZLEmRz7q5n5uXUbv3hyXB JpviIKdnN79EkyKrEJs3KV9vfIzwWExdr4RH6VT6243KrUK03F2MW0pGDC6SMsVpR9FC dbZeL4wDrztvWufTtepcjjBUl2qrtjBNb6he8JbGyKTDHn0BghjFIwcp74nrKPIAw7vs mbGvztrAUe2pZc/yZpdAUZ8/scUxQZ86QxeUv7OvETbfF7+5rfNFIvwlRNQdTfoXbxIg 8zHBv8P2QbrVDiU/69d1pzr9hIt3604q4shYRAaJ66lCLZfXmFmdJJg0TLvdftG2Ig9g 40qw== X-Gm-Message-State: ALyK8tLCQBx4FK3MElsziFrb1YnDGj/N4cCNoIFDHkfdr1xQ4H+htlkcGvezsZ/7Vrxa6Q== X-Received: by 10.28.85.3 with SMTP id j3mr30457966wmb.0.1464897866459; Thu, 02 Jun 2016 13:04:26 -0700 (PDT) Received: from a0999b0126e1.ant.amazon.com ([94.230.86.227]) by smtp.gmail.com with ESMTPSA id lf9sm2114488wjc.44.2016.06.02.13.04.25 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 02 Jun 2016 13:04:25 -0700 (PDT) From: Michael Rolnik X-Google-Original-From: Michael Rolnik To: qemu-devel@nongnu.org Date: Thu, 2 Jun 2016 23:04:03 +0300 Message-Id: <1464897846-97364-7-git-send-email-rolnik@amazon.com> X-Mailer: git-send-email 2.4.9 (Apple Git-60) In-Reply-To: <1464897846-97364-1-git-send-email-rolnik@amazon.com> References: <1464897846-97364-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::243 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; +}