From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29599 invoked by alias); 16 May 2013 22:33:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 29567 invoked by uid 89); 16 May 2013 22:33:03 -0000 X-Spam-SWARE-Status: No, score=-7.4 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 16 May 2013 22:33:02 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r4GMX0X8019654 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 16 May 2013 18:33:00 -0400 Received: from mesquite.lan (ovpn-113-81.phx2.redhat.com [10.3.113.81]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r4GMWx2F007242 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 16 May 2013 18:33:00 -0400 Date: Thu, 16 May 2013 22:33:00 -0000 From: Kevin Buettner To: binutils@sourceware.org Cc: gdb-patches@sourceware.org Subject: Re: [RFC] msp430 instruction decoder Message-ID: <20130516153258.4f2282c1@mesquite.lan> In-Reply-To: <20130516150246.2463f977@mesquite.lan> References: <20130516150246.2463f977@mesquite.lan> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SW-Source: 2013-05/txt/msg00657.txt.bz2 On Thu, 16 May 2013 15:02:46 -0700 Kevin Buettner wrote: > The work, below, was written by DJ Delorie. He's on vacation at the > moment and asked me to submit this work on his behalf. > > It implements instruction decoding support for msp430 and msp430x. This > support is used by both gdb and the simulator. > > Okay? > > * msp430-decode.opc: New. > * msp430-decode.c: New. > * Makefile.am: Add it. > * Makefile.in: Likewise. > * configure.in: Likewise. > * configure: Likewise. (In case it's not obvious, the above entries will go in opcodes/Changelog.) I forgot to post the piece in include/. Here it is: include/opcode/ChangeLog: * msp430-decode.h: New. Index: opcode/msp430-decode.h =================================================================== RCS file: opcode/msp430-decode.h diff -N opcode/msp430-decode.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ opcode/msp430-decode.h 16 May 2013 22:29:23 -0000 @@ -0,0 +1,126 @@ +/* Opcode decoder for the TI MSP430 + Copyright 2012-2013 + Free Software Foundation, Inc. + Written by DJ Delorie + + This file is part of GDB, the GNU Debugger. + + 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 3 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, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA + 02110-1301, USA. */ + +typedef enum { + MSO_unknown, + /* double-operand instructions - all repeat .REPEATS times. */ + MSO_mov, /* dest = src */ + MSO_add, /* dest += src */ + MSO_addc, /* dest += src + carry */ + MSO_subc, /* dest -= (src-1) + carry */ + MSO_sub, /* dest -= src */ + MSO_cmp, /* dest - src -> status */ + MSO_dadd, /* dest += src (as BCD) */ + MSO_bit, /* dest & src -> status */ + MSO_bic, /* dest &= ~src (bit clear) */ + MSO_bis, /* dest |= src (bit set, OR) */ + MSO_xor, /* dest ^= src */ + MSO_and, /* dest &= src */ + + /* single-operand instructions */ + MSO_rrc, /* rotate through carry, dest >>= .REPEATS */ + MSO_swpb, /* swap lower bytes of operand */ + MSO_rra, /* signed shift dest >>= .REPEATS */ + MSO_sxt, /* sign extend lower byte */ + MSO_push, /* push .REPEATS registers (or other op) starting at SRC going towards R0 */ + MSO_pop, /* pop .REPEATS registers starting at DEST going towards R15 */ + MSO_call, + MSO_reti, + + /* jumps */ + MSO_jmp, /* pc = SRC if .COND true. */ + + /* Extended single-operand instructions */ + MSO_rru, /* unsigned shift right, dest >>= .REPEATS */ + +} MSP430_Opcode_ID; + +typedef enum { + MSP430_Operand_None, + MSP430_Operand_Immediate, + MSP430_Operand_Register, + MSP430_Operand_Indirect, + MSP430_Operand_Indirect_Postinc +} MSP430_Operand_Type; + +typedef enum { + MSR_0 = 0, + MSR_PC = 0, + MSR_SP = 1, + MSR_SR = 2, + MSR_CG = 3, + MSR_None = 16, +} MSP430_Register; + +typedef struct { + MSP430_Operand_Type type; + int addend; + MSP430_Register reg : 8; + MSP430_Register reg2 : 8; + unsigned char bit_number : 4; + unsigned char condition : 3; +} MSP430_Opcode_Operand; + +typedef enum +{ + MSP430_Byte = 0, + MSP430_Word, + MSP430_Addr +} MSP430_Size; + +/* These numerically match the bit encoding */ +typedef enum { + MSC_nz = 0, + MSC_z, + MSC_nc, + MSC_c, + MSC_n, + MSC_ge, + MSC_l, + MSC_true, +} MSP430_Condition; + +#define MSP430_FLAG_C 0x01 +#define MSP430_FLAG_Z 0x02 +#define MSP430_FLAG_N 0x04 +#define MSP430_FLAG_V 0x80 + +typedef struct +{ + int lineno; + MSP430_Opcode_ID id; + unsigned flags_1:8; /* These flags are set to '1' by the insn. */ + unsigned flags_0:8; /* These flags are set to '0' by the insn. */ + unsigned flags_set:8; /* These flags are set appropriately by the insn. */ + unsigned zc:1; /* if set, pretend the carry bit is zero */ + unsigned repeat_reg:1; /* if set, count is in REG[repeats] */ + unsigned ofs_430x:1; /* if set, the offset in any operand is 430x (else use 430 compatibility mode) */ + unsigned repeats:5; /* contains COUNT-1, or register number. */ + int n_bytes; /* opcode size in BYTES */ + char * syntax; + MSP430_Size size; /* operand size in BITS */ + MSP430_Condition cond; + /* By convention, these are [0]destination, [1]source. */ + MSP430_Opcode_Operand op[2]; +} MSP430_Opcode_Decoded; + +int msp430_decode_opcode (unsigned long, MSP430_Opcode_Decoded *, int (*)(void *), void *);