Back to index

cell-binutils  2.17cvs20070401
w65-dis.c
Go to the documentation of this file.
00001 /* Disassemble WDC 65816 instructions.
00002    Copyright 1995, 1998, 2000, 2001, 2002, 2005
00003    Free Software Foundation, Inc.
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 2 of the License, or
00008    (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
00018    MA 02110-1301, USA.  */
00019 
00020 #include <stdio.h>
00021 #include "sysdep.h"
00022 #define STATIC_TABLE
00023 #define DEFINE_TABLE
00024 
00025 #include "w65-opc.h"
00026 #include "dis-asm.h"
00027 
00028 static fprintf_ftype fpr;
00029 static void *stream;
00030 static struct disassemble_info *local_info;
00031 
00032 static void
00033 print_operand (int lookup, char *format, int *args)
00034 {
00035   int val;
00036   int c;
00037 
00038   while (*format)
00039     {
00040       switch (c = *format++)
00041        {
00042        case '$':
00043          val = args[(*format++) - '0'];
00044          if (lookup)
00045            local_info->print_address_func (val, local_info);
00046          else
00047            fpr (stream, "0x%x", val);
00048 
00049          break;
00050        default:
00051          fpr (stream, "%c", c);
00052          break;
00053        }
00054     }
00055 }
00056 
00057 int
00058 print_insn_w65 (bfd_vma memaddr, struct disassemble_info *info)
00059 {
00060   int status = 0;
00061   unsigned char insn[4];
00062   const struct opinfo *op;
00063   int i;
00064   int X = 0;
00065   int M = 0;
00066   int args[2];
00067 
00068   stream = info->stream;
00069   fpr = info->fprintf_func;
00070   local_info = info;
00071 
00072   for (i = 0; i < 4 && status == 0; i++)
00073     status = info->read_memory_func (memaddr + i, insn + i, 1, info);
00074 
00075   for (op = optable; op->val != insn[0]; op++)
00076     ;
00077 
00078   fpr (stream, "%s", op->name);
00079 
00080   /* Prepare all the posible operand values.  */
00081   {
00082     int size = 1;
00083     int asR_W65_ABS8 = insn[1];
00084     int asR_W65_ABS16 = (insn[2] << 8) + asR_W65_ABS8;
00085     int asR_W65_ABS24 = (insn[3] << 16) + asR_W65_ABS16;
00086     int asR_W65_PCR8 = ((char) (asR_W65_ABS8)) + memaddr + 2;
00087     int asR_W65_PCR16 = ((short) (asR_W65_ABS16)) + memaddr + 3;
00088 
00089     switch (op->amode)
00090       {
00091        DISASM ();
00092       }
00093 
00094     return size;
00095   }
00096 }