From patchwork Thu Oct 20 21:11:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Weil X-Patchwork-Id: 120910 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3A5241007D1 for ; Fri, 21 Oct 2011 08:35:38 +1100 (EST) Received: from localhost ([::1]:39189 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGzw3-0005LV-Cy for incoming@patchwork.ozlabs.org; Thu, 20 Oct 2011 17:13:55 -0400 Received: from eggs.gnu.org ([140.186.70.92]:59995) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGzvM-0003Qw-9f for qemu-devel@nongnu.org; Thu, 20 Oct 2011 17:13:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RGzvB-00038C-1z for qemu-devel@nongnu.org; Thu, 20 Oct 2011 17:13:02 -0400 Received: from v220110690675601.yourvserver.net ([78.47.199.172]:35200) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGzvA-000386-Bz for qemu-devel@nongnu.org; Thu, 20 Oct 2011 17:13:00 -0400 Received: from localhost (v220110690675601.yourvserver.net.local [127.0.0.1]) by v220110690675601.yourvserver.net (Postfix) with ESMTP id DD5537283495; Thu, 20 Oct 2011 23:12:49 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at weilnetz.de Received: from v220110690675601.yourvserver.net ([127.0.0.1]) by localhost (v220110690675601.yourvserver.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ovmol64h96Ag; Thu, 20 Oct 2011 23:12:29 +0200 (CEST) Received: by v220110690675601.yourvserver.net (Postfix, from userid 1000) id C0D607283499; Thu, 20 Oct 2011 23:11:41 +0200 (CEST) From: Stefan Weil To: qemu-devel@nongnu.org Date: Thu, 20 Oct 2011 23:11:24 +0200 Message-Id: <1319145085-10561-6-git-send-email-sw@weilnetz.de> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1319145085-10561-1-git-send-email-sw@weilnetz.de> References: <1319145085-10561-1-git-send-email-sw@weilnetz.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 78.47.199.172 Cc: Stefan Weil Subject: [Qemu-devel] [PATCH v2 5/6] tcg: Add tci disassembler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Stefan Weil --- dis-asm.h | 1 + disas.c | 4 +++- tci-dis.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletions(-) create mode 100644 tci-dis.c diff --git a/dis-asm.h b/dis-asm.h index 5b07d7f..4f15fad 100644 --- a/dis-asm.h +++ b/dis-asm.h @@ -365,6 +365,7 @@ typedef struct disassemble_info { target address. Return number of bytes processed. */ typedef int (*disassembler_ftype) (bfd_vma, disassemble_info *); +int print_insn_tci(bfd_vma, disassemble_info*); int print_insn_big_mips (bfd_vma, disassemble_info*); int print_insn_little_mips (bfd_vma, disassemble_info*); int print_insn_i386 (bfd_vma, disassemble_info*); diff --git a/disas.c b/disas.c index 611b30b..3b1fd97 100644 --- a/disas.c +++ b/disas.c @@ -273,7 +273,9 @@ void disas(FILE *out, void *code, unsigned long size) #else disasm_info.endian = BFD_ENDIAN_LITTLE; #endif -#if defined(__i386__) +#if defined(CONFIG_TCG_INTERPRETER) + print_insn = print_insn_tci; +#elif defined(__i386__) disasm_info.mach = bfd_mach_i386_i386; print_insn = print_insn_i386; #elif defined(__x86_64__) diff --git a/tci-dis.c b/tci-dis.c new file mode 100644 index 0000000..10c411b --- /dev/null +++ b/tci-dis.c @@ -0,0 +1,59 @@ +/* + * Tiny Code Interpreter for QEMU - disassembler + * + * Copyright (c) 2011 Stefan Weil + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "dis-asm.h" +#include "tcg/tcg.h" + +/* Disassemble TCI bytecode. */ +int print_insn_tci(bfd_vma addr, disassemble_info *info) +{ + int length; + uint8_t byte; + int status; + TCGOpcode op; + + status = info->read_memory_func(addr, &byte, 1, info); + if (status != 0) { + info->memory_error_func(status, addr, info); + return -1; + } + op = byte; + + addr++; + status = info->read_memory_func(addr, &byte, 1, info); + if (status != 0) { + info->memory_error_func(status, addr, info); + return -1; + } + length = byte; + + if (op >= tcg_op_defs_max) { + info->fprintf_func(info->stream, "illegal opcode %d", op); + } else { + const TCGOpDef *def = &tcg_op_defs[op]; + int nb_oargs = def->nb_oargs; + int nb_iargs = def->nb_iargs; + int nb_cargs = def->nb_cargs; + /* TODO: Improve disassembler output. */ + info->fprintf_func(info->stream, "%s\to=%d i=%d c=%d", + def->name, nb_oargs, nb_iargs, nb_cargs); + } + + return length; +}