Back to index

cell-binutils  2.17cvs20070401
m68hc11-dis.c
Go to the documentation of this file.
00001 /* m68hc11-dis.c -- Motorola 68HC11 & 68HC12 disassembly
00002    Copyright 1999, 2000, 2001, 2002, 2003, 2006
00003    Free Software Foundation, Inc.
00004    Written by Stephane Carrez (stcarrez@nerim.fr)
00005 
00006 This program is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2 of the License, or
00009 (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with this program; if not, write to the Free Software
00018 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00019 
00020 #include <stdio.h>
00021 
00022 #include "ansidecl.h"
00023 #include "opcode/m68hc11.h"
00024 #include "dis-asm.h"
00025 
00026 #define PC_REGNUM 3
00027 
00028 static const char *const reg_name[] = {
00029   "X", "Y", "SP", "PC"
00030 };
00031 
00032 static const char *const reg_src_table[] = {
00033   "A", "B", "CCR", "TMP3", "D", "X", "Y", "SP"
00034 };
00035 
00036 static const char *const reg_dst_table[] = {
00037   "A", "B", "CCR", "TMP2", "D", "X", "Y", "SP"
00038 };
00039 
00040 #define OP_PAGE_MASK (M6811_OP_PAGE2|M6811_OP_PAGE3|M6811_OP_PAGE4)
00041 
00042 /* Prototypes for local functions.  */
00043 static int read_memory (bfd_vma, bfd_byte *, int, struct disassemble_info *);
00044 static int print_indexed_operand (bfd_vma, struct disassemble_info *,
00045                                   int*, int, int, bfd_vma);
00046 static int print_insn (bfd_vma, struct disassemble_info *, int);
00047 
00048 static int
00049 read_memory (bfd_vma memaddr, bfd_byte* buffer, int size,
00050              struct disassemble_info* info)
00051 {
00052   int status;
00053 
00054   /* Get first byte.  Only one at a time because we don't know the
00055      size of the insn.  */
00056   status = (*info->read_memory_func) (memaddr, buffer, size, info);
00057   if (status != 0)
00058     {
00059       (*info->memory_error_func) (status, memaddr, info);
00060       return -1;
00061     }
00062   return 0;
00063 }
00064 
00065 
00066 /* Read the 68HC12 indexed operand byte and print the corresponding mode.
00067    Returns the number of bytes read or -1 if failure.  */
00068 static int
00069 print_indexed_operand (bfd_vma memaddr, struct disassemble_info* info,
00070                        int* indirect, int mov_insn, int pc_offset,
00071                        bfd_vma endaddr)
00072 {
00073   bfd_byte buffer[4];
00074   int reg;
00075   int status;
00076   short sval;
00077   int pos = 1;
00078 
00079   if (indirect)
00080     *indirect = 0;
00081 
00082   status = read_memory (memaddr, &buffer[0], 1, info);
00083   if (status != 0)
00084     {
00085       return status;
00086     }
00087 
00088   /* n,r with 5-bits signed constant.  */
00089   if ((buffer[0] & 0x20) == 0)
00090     {
00091       reg = (buffer[0] >> 6) & 3;
00092       sval = (buffer[0] & 0x1f);
00093       if (sval & 0x10)
00094        sval |= 0xfff0;
00095       /* 68HC12 requires an adjustment for movb/movw pc relative modes.  */
00096       if (reg == PC_REGNUM && info->mach == bfd_mach_m6812 && mov_insn)
00097         sval += pc_offset;
00098       (*info->fprintf_func) (info->stream, "%d,%s",
00099                           (int) sval, reg_name[reg]);
00100 
00101       if (reg == PC_REGNUM)
00102         {
00103           (* info->fprintf_func) (info->stream, " {");
00104           (* info->print_address_func) (endaddr + sval, info);
00105           (* info->fprintf_func) (info->stream, "}");
00106         }
00107     }
00108 
00109   /* Auto pre/post increment/decrement.  */
00110   else if ((buffer[0] & 0xc0) != 0xc0)
00111     {
00112       const char *mode;
00113 
00114       reg = (buffer[0] >> 6) & 3;
00115       sval = (buffer[0] & 0x0f);
00116       if (sval & 0x8)
00117        {
00118          sval |= 0xfff0;
00119          sval = -sval;
00120          mode = "-";
00121        }
00122       else
00123        {
00124          sval = sval + 1;
00125          mode = "+";
00126        }
00127       (*info->fprintf_func) (info->stream, "%d,%s%s%s",
00128                           (int) sval,
00129                           (buffer[0] & 0x10 ? "" : mode),
00130                           reg_name[reg], (buffer[0] & 0x10 ? mode : ""));
00131     }
00132 
00133   /* [n,r] 16-bits offset indexed indirect.  */
00134   else if ((buffer[0] & 0x07) == 3)
00135     {
00136       if (mov_insn)
00137        {
00138          (*info->fprintf_func) (info->stream, "<invalid op: 0x%x>",
00139                              buffer[0] & 0x0ff);
00140          return 0;
00141        }
00142       reg = (buffer[0] >> 3) & 0x03;
00143       status = read_memory (memaddr + pos, &buffer[0], 2, info);
00144       if (status != 0)
00145        {
00146          return status;
00147        }
00148 
00149       pos += 2;
00150       sval = ((buffer[0] << 8) | (buffer[1] & 0x0FF));
00151       (*info->fprintf_func) (info->stream, "[%u,%s]",
00152                           sval & 0x0ffff, reg_name[reg]);
00153       if (indirect)
00154         *indirect = 1;
00155     }
00156 
00157   /* n,r with 9 and 16 bit signed constant.  */
00158   else if ((buffer[0] & 0x4) == 0)
00159     {
00160       if (mov_insn)
00161        {
00162          (*info->fprintf_func) (info->stream, "<invalid op: 0x%x>",
00163                              buffer[0] & 0x0ff);
00164          return 0;
00165        }
00166       reg = (buffer[0] >> 3) & 0x03;
00167       status = read_memory (memaddr + pos,
00168                          &buffer[1], (buffer[0] & 0x2 ? 2 : 1), info);
00169       if (status != 0)
00170        {
00171          return status;
00172        }
00173       if (buffer[0] & 2)
00174        {
00175          sval = ((buffer[1] << 8) | (buffer[2] & 0x0FF));
00176          sval &= 0x0FFFF;
00177          pos += 2;
00178           endaddr += 2;
00179        }
00180       else
00181        {
00182          sval = buffer[1] & 0x00ff;
00183          if (buffer[0] & 0x01)
00184            sval |= 0xff00;
00185          pos++;
00186           endaddr++;
00187        }
00188       (*info->fprintf_func) (info->stream, "%d,%s",
00189                           (int) sval, reg_name[reg]);
00190       if (reg == PC_REGNUM)
00191         {
00192           (* info->fprintf_func) (info->stream, " {");
00193           (* info->print_address_func) (endaddr + sval, info);
00194           (* info->fprintf_func) (info->stream, "}");
00195         }
00196     }
00197   else
00198     {
00199       reg = (buffer[0] >> 3) & 0x03;
00200       switch (buffer[0] & 3)
00201        {
00202        case 0:
00203          (*info->fprintf_func) (info->stream, "A,%s", reg_name[reg]);
00204          break;
00205        case 1:
00206          (*info->fprintf_func) (info->stream, "B,%s", reg_name[reg]);
00207          break;
00208        case 2:
00209          (*info->fprintf_func) (info->stream, "D,%s", reg_name[reg]);
00210          break;
00211        case 3:
00212        default:
00213          (*info->fprintf_func) (info->stream, "[D,%s]", reg_name[reg]);
00214           if (indirect)
00215             *indirect = 1;
00216          break;
00217        }
00218     }
00219 
00220   return pos;
00221 }
00222 
00223 /* Disassemble one instruction at address 'memaddr'.  Returns the number
00224    of bytes used by that instruction.  */
00225 static int
00226 print_insn (bfd_vma memaddr, struct disassemble_info* info, int arch)
00227 {
00228   int status;
00229   bfd_byte buffer[4];
00230   unsigned char code;
00231   long format, pos, i;
00232   short sval;
00233   const struct m68hc11_opcode *opcode;
00234 
00235   /* Get first byte.  Only one at a time because we don't know the
00236      size of the insn.  */
00237   status = read_memory (memaddr, buffer, 1, info);
00238   if (status != 0)
00239     {
00240       return status;
00241     }
00242 
00243   format = 0;
00244   code = buffer[0];
00245   pos = 0;
00246 
00247   /* Look for page2,3,4 opcodes.  */
00248   if (code == M6811_OPCODE_PAGE2)
00249     {
00250       pos++;
00251       format = M6811_OP_PAGE2;
00252     }
00253   else if (code == M6811_OPCODE_PAGE3 && arch == cpu6811)
00254     {
00255       pos++;
00256       format = M6811_OP_PAGE3;
00257     }
00258   else if (code == M6811_OPCODE_PAGE4 && arch == cpu6811)
00259     {
00260       pos++;
00261       format = M6811_OP_PAGE4;
00262     }
00263 
00264   /* We are in page2,3,4; get the real opcode.  */
00265   if (pos == 1)
00266     {
00267       status = read_memory (memaddr + pos, &buffer[1], 1, info);
00268       if (status != 0)
00269        {
00270          return status;
00271        }
00272       code = buffer[1];
00273     }
00274 
00275 
00276   /* Look first for a 68HC12 alias.  All of them are 2-bytes long and
00277      in page 1.  There is no operand to print.  We read the second byte
00278      only when we have a possible match.  */
00279   if ((arch & cpu6812) && format == 0)
00280     {
00281       int must_read = 1;
00282 
00283       /* Walk the alias table to find a code1+code2 match.  */
00284       for (i = 0; i < m68hc12_num_alias; i++)
00285        {
00286          if (m68hc12_alias[i].code1 == code)
00287            {
00288              if (must_read)
00289               {
00290                 status = read_memory (memaddr + pos + 1,
00291                                    &buffer[1], 1, info);
00292                 if (status != 0)
00293                   break;
00294 
00295                 must_read = 1;
00296               }
00297              if (m68hc12_alias[i].code2 == (unsigned char) buffer[1])
00298               {
00299                 (*info->fprintf_func) (info->stream, "%s",
00300                                     m68hc12_alias[i].name);
00301                 return 2;
00302               }
00303            }
00304        }
00305     }
00306 
00307   pos++;
00308 
00309   /* Scan the opcode table until we find the opcode
00310      with the corresponding page.  */
00311   opcode = m68hc11_opcodes;
00312   for (i = 0; i < m68hc11_num_opcodes; i++, opcode++)
00313     {
00314       int offset;
00315       int pc_src_offset;
00316       int pc_dst_offset = 0;
00317 
00318       if ((opcode->arch & arch) == 0)
00319        continue;
00320       if (opcode->opcode != code)
00321        continue;
00322       if ((opcode->format & OP_PAGE_MASK) != format)
00323        continue;
00324 
00325       if (opcode->format & M6812_OP_REG)
00326        {
00327          int j;
00328          int is_jump;
00329 
00330          if (opcode->format & M6811_OP_JUMP_REL)
00331            is_jump = 1;
00332          else
00333            is_jump = 0;
00334 
00335          status = read_memory (memaddr + pos, &buffer[0], 1, info);
00336          if (status != 0)
00337            {
00338              return status;
00339            }
00340          for (j = 0; i + j < m68hc11_num_opcodes; j++)
00341            {
00342              if ((opcode[j].arch & arch) == 0)
00343               continue;
00344              if (opcode[j].opcode != code)
00345               continue;
00346              if (is_jump)
00347               {
00348                 if (!(opcode[j].format & M6811_OP_JUMP_REL))
00349                   continue;
00350 
00351                 if ((opcode[j].format & M6812_OP_IBCC_MARKER)
00352                     && (buffer[0] & 0xc0) != 0x80)
00353                   continue;
00354                 if ((opcode[j].format & M6812_OP_TBCC_MARKER)
00355                     && (buffer[0] & 0xc0) != 0x40)
00356                   continue;
00357                 if ((opcode[j].format & M6812_OP_DBCC_MARKER)
00358                     && (buffer[0] & 0xc0) != 0)
00359                   continue;
00360                 if ((opcode[j].format & M6812_OP_EQ_MARKER)
00361                     && (buffer[0] & 0x20) == 0)
00362                   break;
00363                 if (!(opcode[j].format & M6812_OP_EQ_MARKER)
00364                     && (buffer[0] & 0x20) != 0)
00365                   break;
00366                 continue;
00367               }
00368              if (opcode[j].format & M6812_OP_EXG_MARKER && buffer[0] & 0x80)
00369               break;
00370              if ((opcode[j].format & M6812_OP_SEX_MARKER)
00371                 && (((buffer[0] & 0x07) >= 3 && (buffer[0] & 7) <= 7))
00372                 && ((buffer[0] & 0x0f0) <= 0x20))
00373               break;
00374              if (opcode[j].format & M6812_OP_TFR_MARKER
00375                 && !(buffer[0] & 0x80))
00376               break;
00377            }
00378          if (i + j < m68hc11_num_opcodes)
00379            opcode = &opcode[j];
00380        }
00381 
00382       /* We have found the opcode.  Extract the operand and print it.  */
00383       (*info->fprintf_func) (info->stream, "%s", opcode->name);
00384 
00385       format = opcode->format;
00386       if (format & (M6811_OP_MASK | M6811_OP_BITMASK
00387                   | M6811_OP_JUMP_REL | M6812_OP_JUMP_REL16))
00388        {
00389          (*info->fprintf_func) (info->stream, "\t");
00390        }
00391 
00392       /* The movb and movw must be handled in a special way...
00393          The source constant 'ii' is not always at the same place.
00394          This is the same for the destination for the post-indexed byte.
00395          The 'offset' is used to do the appropriate correction.
00396 
00397                                    offset          offset
00398                               for constant     for destination
00399          movb   18 OB ii hh ll       0          0
00400                 18 08 xb ii          1          -1
00401                 18 0C hh ll hh ll    0          0
00402                 18 09 xb hh ll       1          -1
00403                 18 0D xb hh ll       0          0
00404                 18 0A xb xb          0          0
00405 
00406          movw   18 03 jj kk hh ll    0          0
00407                 18 00 xb jj kk       1          -1
00408                 18 04 hh ll hh ll    0          0
00409                 18 01 xb hh ll       1          -1
00410                 18 05 xb hh ll       0          0
00411                 18 02 xb xb          0          0
00412 
00413          After the source operand is read, the position 'pos' is incremented
00414          this explains the negative offset for destination.
00415 
00416          movb/movw above are the only instructions with this matching
00417          format.  */
00418       offset = ((format & M6812_OP_IDX_P2)
00419                 && (format & (M6811_OP_IMM8 | M6811_OP_IMM16 |
00420                               M6811_OP_IND16)));
00421 
00422       /* Operand with one more byte: - immediate, offset,
00423          direct-low address.  */
00424       if (format &
00425          (M6811_OP_IMM8 | M6811_OP_IX | M6811_OP_IY | M6811_OP_DIRECT))
00426        {
00427          status = read_memory (memaddr + pos + offset, &buffer[0], 1, info);
00428          if (status != 0)
00429            {
00430              return status;
00431            }
00432 
00433          pos++;
00434 
00435           /* This movb/movw is special (see above).  */
00436           offset = -offset;
00437 
00438           pc_dst_offset = 2;
00439          if (format & M6811_OP_IMM8)
00440            {
00441              (*info->fprintf_func) (info->stream, "#%d", (int) buffer[0]);
00442              format &= ~M6811_OP_IMM8;
00443               /* Set PC destination offset.  */
00444               pc_dst_offset = 1;
00445            }
00446          else if (format & M6811_OP_IX)
00447            {
00448              /* Offsets are in range 0..255, print them unsigned.  */
00449              (*info->fprintf_func) (info->stream, "%u,x", buffer[0] & 0x0FF);
00450              format &= ~M6811_OP_IX;
00451            }
00452          else if (format & M6811_OP_IY)
00453            {
00454              (*info->fprintf_func) (info->stream, "%u,y", buffer[0] & 0x0FF);
00455              format &= ~M6811_OP_IY;
00456            }
00457          else if (format & M6811_OP_DIRECT)
00458            {
00459              (*info->fprintf_func) (info->stream, "*");
00460              (*info->print_address_func) (buffer[0] & 0x0FF, info);
00461              format &= ~M6811_OP_DIRECT;
00462            }
00463        }
00464 
00465 #define M6812_DST_MOVE  (M6812_OP_IND16_P2 | M6812_OP_IDX_P2)
00466 #define M6812_INDEXED_FLAGS (M6812_OP_IDX|M6812_OP_IDX_1|M6812_OP_IDX_2)
00467       /* Analyze the 68HC12 indexed byte.  */
00468       if (format & M6812_INDEXED_FLAGS)
00469        {
00470           int indirect;
00471           bfd_vma endaddr;
00472 
00473           endaddr = memaddr + pos + 1;
00474           if (format & M6811_OP_IND16)
00475             endaddr += 2;
00476           pc_src_offset = -1;
00477           pc_dst_offset = 1;
00478          status = print_indexed_operand (memaddr + pos, info, &indirect,
00479                                           (format & M6812_DST_MOVE),
00480                                           pc_src_offset, endaddr);
00481          if (status < 0)
00482            {
00483              return status;
00484            }
00485          pos += status;
00486 
00487           /* The indirect addressing mode of the call instruction does
00488              not need the page code.  */
00489           if ((format & M6812_OP_PAGE) && indirect)
00490             format &= ~M6812_OP_PAGE;
00491        }
00492 
00493       /* 68HC12 dbcc/ibcc/tbcc operands.  */
00494       if ((format & M6812_OP_REG) && (format & M6811_OP_JUMP_REL))
00495        {
00496          status = read_memory (memaddr + pos, &buffer[0], 2, info);
00497          if (status != 0)
00498            {
00499              return status;
00500            }
00501          (*info->fprintf_func) (info->stream, "%s,",
00502                              reg_src_table[buffer[0] & 0x07]);
00503          sval = buffer[1] & 0x0ff;
00504          if (buffer[0] & 0x10)
00505            sval |= 0xff00;
00506 
00507          pos += 2;
00508          (*info->print_address_func) (memaddr + pos + sval, info);
00509          format &= ~(M6812_OP_REG | M6811_OP_JUMP_REL);
00510        }
00511       else if (format & (M6812_OP_REG | M6812_OP_REG_2))
00512        {
00513          status = read_memory (memaddr + pos, &buffer[0], 1, info);
00514          if (status != 0)
00515            {
00516              return status;
00517            }
00518 
00519          pos++;
00520          (*info->fprintf_func) (info->stream, "%s,%s",
00521                              reg_src_table[(buffer[0] >> 4) & 7],
00522                              reg_dst_table[(buffer[0] & 7)]);
00523        }
00524 
00525       if (format & (M6811_OP_IMM16 | M6811_OP_IND16))
00526        {
00527          int val;
00528           bfd_vma addr;
00529           unsigned page = 0;
00530 
00531          status = read_memory (memaddr + pos + offset, &buffer[0], 2, info);
00532          if (status != 0)
00533            {
00534              return status;
00535            }
00536          if (format & M6812_OP_IDX_P2)
00537            offset = -2;
00538          else
00539            offset = 0;
00540          pos += 2;
00541 
00542          val = ((buffer[0] << 8) | (buffer[1] & 0x0FF));
00543          val &= 0x0FFFF;
00544           addr = val;
00545           pc_dst_offset = 2;
00546           if (format & M6812_OP_PAGE)
00547             {
00548               status = read_memory (memaddr + pos + offset, buffer, 1, info);
00549               if (status != 0)
00550                 return status;
00551 
00552               page = (unsigned) buffer[0];
00553               if (addr >= M68HC12_BANK_BASE && addr < 0x0c000)
00554                 addr = ((val - M68HC12_BANK_BASE)
00555                         | (page << M68HC12_BANK_SHIFT))
00556                    + M68HC12_BANK_VIRT;
00557             }
00558           else if ((arch & cpu6812)
00559                    && addr >= M68HC12_BANK_BASE && addr < 0x0c000)
00560              {
00561                 int cur_page;
00562                 bfd_vma vaddr;
00563                 
00564                 if (memaddr >= M68HC12_BANK_VIRT)
00565                    cur_page = ((memaddr - M68HC12_BANK_VIRT)
00566                                >> M68HC12_BANK_SHIFT);
00567                 else
00568                    cur_page = 0;
00569 
00570                 vaddr = ((addr - M68HC12_BANK_BASE)
00571                          + (cur_page << M68HC12_BANK_SHIFT))
00572                    + M68HC12_BANK_VIRT;
00573                 if (!info->symbol_at_address_func (addr, info)
00574                     && info->symbol_at_address_func (vaddr, info))
00575                    addr = vaddr;
00576              }
00577          if (format & M6811_OP_IMM16)
00578            {
00579              format &= ~M6811_OP_IMM16;
00580              (*info->fprintf_func) (info->stream, "#");
00581            }
00582          else
00583            format &= ~M6811_OP_IND16;
00584 
00585          (*info->print_address_func) (addr, info);
00586           if (format & M6812_OP_PAGE)
00587             {
00588               (* info->fprintf_func) (info->stream, " {");
00589               (* info->print_address_func) (val, info);
00590               (* info->fprintf_func) (info->stream, ", %d}", page);
00591               format &= ~M6812_OP_PAGE;
00592               pos += 1;
00593             }
00594        }
00595 
00596       if (format & M6812_OP_IDX_P2)
00597        {
00598          (*info->fprintf_func) (info->stream, ", ");
00599          status = print_indexed_operand (memaddr + pos + offset, info,
00600                                           0, 1, pc_dst_offset,
00601                                           memaddr + pos + offset + 1);
00602          if (status < 0)
00603            return status;
00604          pos += status;
00605        }
00606 
00607       if (format & M6812_OP_IND16_P2)
00608        {
00609          int val;
00610 
00611          (*info->fprintf_func) (info->stream, ", ");
00612 
00613          status = read_memory (memaddr + pos + offset, &buffer[0], 2, info);
00614          if (status != 0)
00615            {
00616              return status;
00617            }
00618          pos += 2;
00619 
00620          val = ((buffer[0] << 8) | (buffer[1] & 0x0FF));
00621          val &= 0x0FFFF;
00622          (*info->print_address_func) (val, info);
00623        }
00624 
00625       /* M6811_OP_BITMASK and M6811_OP_JUMP_REL must be treated separately
00626          and in that order.  The brset/brclr insn have a bitmask and then
00627          a relative branch offset.  */
00628       if (format & M6811_OP_BITMASK)
00629        {
00630          status = read_memory (memaddr + pos, &buffer[0], 1, info);
00631          if (status != 0)
00632            {
00633              return status;
00634            }
00635          pos++;
00636          (*info->fprintf_func) (info->stream, " #$%02x%s",
00637                              buffer[0] & 0x0FF,
00638                              (format & M6811_OP_JUMP_REL ? " " : ""));
00639          format &= ~M6811_OP_BITMASK;
00640        }
00641       if (format & M6811_OP_JUMP_REL)
00642        {
00643          int val;
00644 
00645          status = read_memory (memaddr + pos, &buffer[0], 1, info);
00646          if (status != 0)
00647            {
00648              return status;
00649            }
00650 
00651          pos++;
00652          val = (buffer[0] & 0x80) ? buffer[0] | 0xFFFFFF00 : buffer[0];
00653          (*info->print_address_func) (memaddr + pos + val, info);
00654          format &= ~M6811_OP_JUMP_REL;
00655        }
00656       else if (format & M6812_OP_JUMP_REL16)
00657        {
00658          int val;
00659 
00660          status = read_memory (memaddr + pos, &buffer[0], 2, info);
00661          if (status != 0)
00662            {
00663              return status;
00664            }
00665 
00666          pos += 2;
00667          val = ((buffer[0] << 8) | (buffer[1] & 0x0FF));
00668          if (val & 0x8000)
00669            val |= 0xffff0000;
00670 
00671          (*info->print_address_func) (memaddr + pos + val, info);
00672          format &= ~M6812_OP_JUMP_REL16;
00673        }
00674 
00675       if (format & M6812_OP_PAGE)
00676        {
00677          int val;
00678 
00679          status = read_memory (memaddr + pos + offset, &buffer[0], 1, info);
00680          if (status != 0)
00681            {
00682              return status;
00683            }
00684          pos += 1;
00685 
00686          val = buffer[0] & 0x0ff;
00687          (*info->fprintf_func) (info->stream, ", %d", val);
00688        }
00689       
00690 #ifdef DEBUG
00691       /* Consistency check.  'format' must be 0, so that we have handled
00692          all formats; and the computed size of the insn must match the
00693          opcode table content.  */
00694       if (format & ~(M6811_OP_PAGE4 | M6811_OP_PAGE3 | M6811_OP_PAGE2))
00695        {
00696          (*info->fprintf_func) (info->stream, "; Error, format: %lx", format);
00697        }
00698       if (pos != opcode->size)
00699        {
00700          (*info->fprintf_func) (info->stream, "; Error, size: %ld expect %d",
00701                              pos, opcode->size);
00702        }
00703 #endif
00704       return pos;
00705     }
00706 
00707   /* Opcode not recognized.  */
00708   if (format == M6811_OP_PAGE2 && arch & cpu6812
00709       && ((code >= 0x30 && code <= 0x39) || (code >= 0x40)))
00710     (*info->fprintf_func) (info->stream, "trap\t#%d", code & 0x0ff);
00711 
00712   else if (format == M6811_OP_PAGE2)
00713     (*info->fprintf_func) (info->stream, ".byte\t0x%02x, 0x%02x",
00714                         M6811_OPCODE_PAGE2, code);
00715   else if (format == M6811_OP_PAGE3)
00716     (*info->fprintf_func) (info->stream, ".byte\t0x%02x, 0x%02x",
00717                         M6811_OPCODE_PAGE3, code);
00718   else if (format == M6811_OP_PAGE4)
00719     (*info->fprintf_func) (info->stream, ".byte\t0x%02x, 0x%02x",
00720                         M6811_OPCODE_PAGE4, code);
00721   else
00722     (*info->fprintf_func) (info->stream, ".byte\t0x%02x", code);
00723 
00724   return pos;
00725 }
00726 
00727 /* Disassemble one instruction at address 'memaddr'.  Returns the number
00728    of bytes used by that instruction.  */
00729 int
00730 print_insn_m68hc11 (bfd_vma memaddr, struct disassemble_info* info)
00731 {
00732   return print_insn (memaddr, info, cpu6811);
00733 }
00734 
00735 int
00736 print_insn_m68hc12 (bfd_vma memaddr, struct disassemble_info* info)
00737 {
00738   return print_insn (memaddr, info, cpu6812);
00739 }