xref: /openbsd-src/gnu/usr.bin/binutils-2.17/opcodes/w65-dis.c (revision 3d8817e467ea46cf4772788d6804dd293abfb01a)
1*3d8817e4Smiod /* Disassemble WDC 65816 instructions.
2*3d8817e4Smiod    Copyright 1995, 1998, 2000, 2001, 2002, 2005
3*3d8817e4Smiod    Free Software Foundation, Inc.
4*3d8817e4Smiod 
5*3d8817e4Smiod    This program is free software; you can redistribute it and/or modify
6*3d8817e4Smiod    it under the terms of the GNU General Public License as published by
7*3d8817e4Smiod    the Free Software Foundation; either version 2 of the License, or
8*3d8817e4Smiod    (at your option) any later version.
9*3d8817e4Smiod 
10*3d8817e4Smiod    This program is distributed in the hope that it will be useful,
11*3d8817e4Smiod    but WITHOUT ANY WARRANTY; without even the implied warranty of
12*3d8817e4Smiod    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*3d8817e4Smiod    GNU General Public License for more details.
14*3d8817e4Smiod 
15*3d8817e4Smiod    You should have received a copy of the GNU General Public License
16*3d8817e4Smiod    along with this program; if not, write to the Free Software
17*3d8817e4Smiod    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
18*3d8817e4Smiod    MA 02110-1301, USA.  */
19*3d8817e4Smiod 
20*3d8817e4Smiod #include <stdio.h>
21*3d8817e4Smiod #include "sysdep.h"
22*3d8817e4Smiod #define STATIC_TABLE
23*3d8817e4Smiod #define DEFINE_TABLE
24*3d8817e4Smiod 
25*3d8817e4Smiod #include "w65-opc.h"
26*3d8817e4Smiod #include "dis-asm.h"
27*3d8817e4Smiod 
28*3d8817e4Smiod static fprintf_ftype fpr;
29*3d8817e4Smiod static void *stream;
30*3d8817e4Smiod static struct disassemble_info *local_info;
31*3d8817e4Smiod 
32*3d8817e4Smiod static void
print_operand(int lookup,char * format,int * args)33*3d8817e4Smiod print_operand (int lookup, char *format, int *args)
34*3d8817e4Smiod {
35*3d8817e4Smiod   int val;
36*3d8817e4Smiod   int c;
37*3d8817e4Smiod 
38*3d8817e4Smiod   while (*format)
39*3d8817e4Smiod     {
40*3d8817e4Smiod       switch (c = *format++)
41*3d8817e4Smiod 	{
42*3d8817e4Smiod 	case '$':
43*3d8817e4Smiod 	  val = args[(*format++) - '0'];
44*3d8817e4Smiod 	  if (lookup)
45*3d8817e4Smiod 	    local_info->print_address_func (val, local_info);
46*3d8817e4Smiod 	  else
47*3d8817e4Smiod 	    fpr (stream, "0x%x", val);
48*3d8817e4Smiod 
49*3d8817e4Smiod 	  break;
50*3d8817e4Smiod 	default:
51*3d8817e4Smiod 	  fpr (stream, "%c", c);
52*3d8817e4Smiod 	  break;
53*3d8817e4Smiod 	}
54*3d8817e4Smiod     }
55*3d8817e4Smiod }
56*3d8817e4Smiod 
57*3d8817e4Smiod int
print_insn_w65(bfd_vma memaddr,struct disassemble_info * info)58*3d8817e4Smiod print_insn_w65 (bfd_vma memaddr, struct disassemble_info *info)
59*3d8817e4Smiod {
60*3d8817e4Smiod   int status = 0;
61*3d8817e4Smiod   unsigned char insn[4];
62*3d8817e4Smiod   const struct opinfo *op;
63*3d8817e4Smiod   int i;
64*3d8817e4Smiod   int X = 0;
65*3d8817e4Smiod   int M = 0;
66*3d8817e4Smiod   int args[2];
67*3d8817e4Smiod 
68*3d8817e4Smiod   stream = info->stream;
69*3d8817e4Smiod   fpr = info->fprintf_func;
70*3d8817e4Smiod   local_info = info;
71*3d8817e4Smiod 
72*3d8817e4Smiod   for (i = 0; i < 4 && status == 0; i++)
73*3d8817e4Smiod     status = info->read_memory_func (memaddr + i, insn + i, 1, info);
74*3d8817e4Smiod 
75*3d8817e4Smiod   for (op = optable; op->val != insn[0]; op++)
76*3d8817e4Smiod     ;
77*3d8817e4Smiod 
78*3d8817e4Smiod   fpr (stream, "%s", op->name);
79*3d8817e4Smiod 
80*3d8817e4Smiod   /* Prepare all the posible operand values.  */
81*3d8817e4Smiod   {
82*3d8817e4Smiod     int size = 1;
83*3d8817e4Smiod     int asR_W65_ABS8 = insn[1];
84*3d8817e4Smiod     int asR_W65_ABS16 = (insn[2] << 8) + asR_W65_ABS8;
85*3d8817e4Smiod     int asR_W65_ABS24 = (insn[3] << 16) + asR_W65_ABS16;
86*3d8817e4Smiod     int asR_W65_PCR8 = ((char) (asR_W65_ABS8)) + memaddr + 2;
87*3d8817e4Smiod     int asR_W65_PCR16 = ((short) (asR_W65_ABS16)) + memaddr + 3;
88*3d8817e4Smiod 
89*3d8817e4Smiod     switch (op->amode)
90*3d8817e4Smiod       {
91*3d8817e4Smiod 	DISASM ();
92*3d8817e4Smiod       }
93*3d8817e4Smiod 
94*3d8817e4Smiod     return size;
95*3d8817e4Smiod   }
96*3d8817e4Smiod }
97