home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / gdb-4.12.tar.gz / gdb-4.12.tar / gdb-4.12 / opcodes / i960-dis.c < prev    next >
C/C++ Source or Header  |  1994-02-03  |  21KB  |  862 lines

  1. /* Disassemble i80960 instructions.
  2.    Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; see the file COPYING.  If not, write to
  16. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #include "dis-asm.h"
  19.  
  20. static char *reg_names[] = {
  21. /*  0 */    "pfp", "sp",  "rip", "r3",  "r4",  "r5",  "r6",  "r7", 
  22. /*  8 */    "r8",  "r9",  "r10", "r11", "r12", "r13", "r14", "r15",
  23. /* 16 */    "g0",  "g1",  "g2",  "g3",  "g4",  "g5",  "g6",  "g7", 
  24. /* 24 */    "g8",  "g9",  "g10", "g11", "g12", "g13", "g14", "fp", 
  25. /* 32 */    "pc",  "ac",  "ip",  "tc",  "fp0", "fp1", "fp2", "fp3" 
  26. };
  27.  
  28.  
  29. static FILE *stream;        /* Output goes here */
  30. static struct disassemble_info *info;
  31. static void print_addr();
  32. static void ctrl();
  33. static void cobr();
  34. static void reg();
  35. static int mem();
  36. static void ea();
  37. static void dstop();
  38. static void regop();
  39. static void invalid();
  40. static int pinsn();
  41. static void put_abs();
  42.  
  43.  
  44. /* Print the i960 instruction at address 'memaddr' in debugged memory,
  45.    on INFO->STREAM.  Returns length of the instruction, in bytes.  */
  46.  
  47. int
  48. print_insn_i960 (memaddr, info_arg)
  49.     bfd_vma memaddr;
  50.     struct disassemble_info *info_arg;
  51. {
  52.   unsigned int word1, word2 = 0xdeadbeef;
  53.   char buffer[8];
  54.   int status;
  55.  
  56.   info = info_arg;
  57.   stream = info->stream;
  58.  
  59.   /* Read word1.  Only read word2 if the instruction
  60.      needs it, to prevent reading past the end of a section.  */
  61.  
  62.   status = (*info->read_memory_func) (memaddr, (bfd_byte *) buffer, 4, info);
  63.   if (status != 0)
  64.     {
  65.       (*info->memory_error_func) (status, memaddr, info);
  66.       return -1;
  67.     }
  68.  
  69.   word1 = buffer [0] |( buffer[1]<< 8) | (buffer[2] << 16) | ( buffer[3] <<24);
  70.  
  71.   /* Divide instruction set into classes based on high 4 bits of opcode.  */
  72.   switch ( (word1 >> 28) & 0xf )
  73.     {
  74.     default:
  75.       break;
  76.     case 0x0:
  77.     case 0x1:
  78.     case 0x2:
  79.     case 0x3:
  80.     case 0x8:
  81.     case 0x9:
  82.     case 0xa:
  83.     case 0xb:
  84.     case 0xc:
  85.       /* Read word2.  */
  86.       status = (*info->read_memory_func)
  87.     (memaddr + 4, (bfd_byte *) (buffer + 4), 4, info);
  88.       if (status != 0)
  89.     {
  90.       (*info->memory_error_func) (status, memaddr, info);
  91.       return -1;
  92.     }
  93.       word2 =
  94.     buffer [4] |( buffer[5]<< 8) | (buffer[6] << 16) | ( buffer[7] <<24);
  95.       break;
  96.     }
  97.  
  98.   return pinsn( memaddr, word1, word2 );
  99. }
  100.  
  101. #define IN_GDB
  102.  
  103. /*****************************************************************************
  104.  *    All code below this point should be identical with that of
  105.  *    the disassembler in gdmp960.
  106.  
  107.  A noble sentiment, but at least in cosmetic ways (info->fprintf_func), it
  108.  just ain't so. -kingdon, 31 Mar 93
  109.  *****************************************************************************/
  110.  
  111. struct tabent {
  112.     char    *name;
  113.     char    numops;
  114. };
  115.  
  116. static int
  117. pinsn( memaddr, word1, word2 )
  118.     unsigned long memaddr;
  119.     unsigned long word1, word2;
  120. {
  121.     int instr_len;
  122.  
  123.     instr_len = 4;
  124.     put_abs( word1, word2 );
  125.  
  126.     /* Divide instruction set into classes based on high 4 bits of opcode*/
  127.     switch ( (word1 >> 28) & 0xf ){
  128.     case 0x0:
  129.     case 0x1:
  130.         ctrl( memaddr, word1, word2 );
  131.         break;
  132.     case 0x2:
  133.     case 0x3:
  134.         cobr( memaddr, word1, word2 );
  135.         break;
  136.     case 0x5:
  137.     case 0x6:
  138.     case 0x7:
  139.         reg( word1 );
  140.         break;
  141.     case 0x8:
  142.     case 0x9:
  143.     case 0xa:
  144.     case 0xb:
  145.     case 0xc:
  146.         instr_len = mem( memaddr, word1, word2, 0 );
  147.         break;
  148.     default:
  149.         /* invalid instruction, print as data word */ 
  150.         invalid( word1 );
  151.         break;
  152.     }
  153.     return instr_len;
  154. }
  155.  
  156. /****************************************/
  157. /* CTRL format                */
  158. /****************************************/
  159. static void
  160. ctrl( memaddr, word1, word2 )
  161.     unsigned long memaddr;
  162.     unsigned long word1, word2;
  163. {
  164.     int i;
  165.     static struct tabent ctrl_tab[] = {
  166.         NULL,        0,    /* 0x00 */
  167.         NULL,        0,    /* 0x01 */
  168.         NULL,        0,    /* 0x02 */
  169.         NULL,        0,    /* 0x03 */
  170.         NULL,        0,    /* 0x04 */
  171.         NULL,        0,    /* 0x05 */
  172.         NULL,        0,    /* 0x06 */
  173.         NULL,        0,    /* 0x07 */
  174.         "b",        1,    /* 0x08 */
  175.         "call",        1,    /* 0x09 */
  176.         "ret",        0,    /* 0x0a */
  177.         "bal",        1,    /* 0x0b */
  178.         NULL,        0,    /* 0x0c */
  179.         NULL,        0,    /* 0x0d */
  180.         NULL,        0,    /* 0x0e */
  181.         NULL,        0,    /* 0x0f */
  182.         "bno",        1,    /* 0x10 */
  183.         "bg",        1,    /* 0x11 */
  184.         "be",        1,    /* 0x12 */
  185.         "bge",        1,    /* 0x13 */
  186.         "bl",        1,    /* 0x14 */
  187.         "bne",        1,    /* 0x15 */
  188.         "ble",        1,    /* 0x16 */
  189.         "bo",        1,    /* 0x17 */
  190.         "faultno",    0,    /* 0x18 */
  191.         "faultg",    0,    /* 0x19 */
  192.         "faulte",    0,    /* 0x1a */
  193.         "faultge",    0,    /* 0x1b */
  194.         "faultl",    0,    /* 0x1c */
  195.         "faultne",    0,    /* 0x1d */
  196.         "faultle",    0,    /* 0x1e */
  197.         "faulto",    0,    /* 0x1f */
  198.     };
  199.  
  200.     i = (word1 >> 24) & 0xff;
  201.     if ( (ctrl_tab[i].name == NULL) || ((word1 & 1) != 0) ){
  202.         invalid( word1 );
  203.         return;
  204.     }
  205.  
  206.     (*info->fprintf_func) ( stream, ctrl_tab[i].name );
  207.     if ( word1 & 2 ){        /* Predicts branch not taken */
  208.         (*info->fprintf_func) ( stream, ".f" );
  209.     }
  210.  
  211.     if ( ctrl_tab[i].numops == 1 ){
  212.         /* EXTRACT DISPLACEMENT AND CONVERT TO ADDRESS */
  213.         word1 &= 0x00ffffff;
  214.         if ( word1 & 0x00800000 ){        /* Sign bit is set */
  215.             word1 |= (-1 & ~0xffffff);    /* Sign extend */
  216.         }
  217.         (*info->fprintf_func)( stream, "\t" );
  218.         print_addr( word1 + memaddr );
  219.     }
  220. }
  221.  
  222. /****************************************/
  223. /* COBR format                */
  224. /****************************************/
  225. static void
  226. cobr( memaddr, word1, word2 )
  227.     unsigned long memaddr;
  228.     unsigned long word1, word2;
  229. {
  230.     int src1;
  231.     int src2;
  232.     int i;
  233.  
  234.     static struct tabent cobr_tab[] = {
  235.         "testno",    1,    /* 0x20 */
  236.         "testg",    1,    /* 0x21 */
  237.         "teste",    1,    /* 0x22 */
  238.         "testge",    1,    /* 0x23 */
  239.         "testl",    1,    /* 0x24 */
  240.         "testne",    1,    /* 0x25 */
  241.         "testle",    1,    /* 0x26 */
  242.         "testo",    1,    /* 0x27 */
  243.         NULL,        0,    /* 0x28 */
  244.         NULL,        0,    /* 0x29 */
  245.         NULL,        0,    /* 0x2a */
  246.         NULL,        0,    /* 0x2b */
  247.         NULL,        0,    /* 0x2c */
  248.         NULL,        0,    /* 0x2d */
  249.         NULL,        0,    /* 0x2e */
  250.         NULL,        0,    /* 0x2f */
  251.         "bbc",        3,    /* 0x30 */
  252.         "cmpobg",    3,    /* 0x31 */
  253.         "cmpobe",    3,    /* 0x32 */
  254.         "cmpobge",    3,    /* 0x33 */
  255.         "cmpobl",    3,    /* 0x34 */
  256.         "cmpobne",    3,    /* 0x35 */
  257.         "cmpoble",    3,    /* 0x36 */
  258.         "bbs",        3,    /* 0x37 */
  259.         "cmpibno",    3,    /* 0x38 */
  260.         "cmpibg",    3,    /* 0x39 */
  261.         "cmpibe",    3,    /* 0x3a */
  262.         "cmpibge",    3,    /* 0x3b */
  263.         "cmpibl",    3,    /* 0x3c */
  264.         "cmpibne",    3,    /* 0x3d */
  265.         "cmpible",    3,    /* 0x3e */
  266.         "cmpibo",    3,    /* 0x3f */
  267.     };
  268.  
  269.     i = ((word1 >> 24) & 0xff) - 0x20;
  270.     if ( cobr_tab[i].name == NULL ){
  271.         invalid( word1 );
  272.         return;
  273.     }
  274.  
  275.     (*info->fprintf_func) ( stream, cobr_tab[i].name );
  276.     if ( word1 & 2 ){        /* Predicts branch not taken */
  277.         (*info->fprintf_func) ( stream, ".f" );
  278.     }
  279.     (*info->fprintf_func)( stream, "\t" );
  280.  
  281.     src1 = (word1 >> 19) & 0x1f;
  282.     src2 = (word1 >> 14) & 0x1f;
  283.  
  284.     if ( word1 & 0x02000 ){        /* M1 is 1 */
  285.         (*info->fprintf_func)( stream, "%d", src1 );
  286.     } else {            /* M1 is 0 */
  287.         (*info->fprintf_func)( stream, reg_names[src1] );
  288.     }
  289.  
  290.     if ( cobr_tab[i].numops > 1 ){
  291.         if ( word1 & 1 ){        /* S2 is 1 */
  292.             (*info->fprintf_func)( stream, ",sf%d,", src2 );
  293.         } else {            /* S1 is 0 */
  294.             (*info->fprintf_func)( stream, ",%s,", reg_names[src2] );
  295.         }
  296.  
  297.         /* Extract displacement and convert to address
  298.          */
  299.         word1 &= 0x00001ffc;
  300.         if ( word1 & 0x00001000 ){    /* Negative displacement */
  301.             word1 |= (-1 & ~0x1fff);    /* Sign extend */
  302.         }
  303.         print_addr( memaddr + word1 );
  304.     }
  305. }
  306.  
  307. /****************************************/
  308. /* MEM format                */
  309. /****************************************/
  310. static int                /* returns instruction length: 4 or 8 */
  311. mem( memaddr, word1, word2, noprint )
  312.     unsigned long memaddr;
  313.     unsigned long word1, word2;
  314.     int noprint;        /* If TRUE, return instruction length, but
  315.                  * don't output any text.
  316.                  */
  317. {
  318.     int i, j;
  319.     int len;
  320.     int mode;
  321.     int offset;
  322.     char *reg1, *reg2, *reg3;
  323.  
  324.     /* This lookup table is too sparse to make it worth typing in, but not
  325.      * so large as to make a sparse array necessary.  We allocate the
  326.      * table at runtime, initialize all entries to empty, and copy the
  327.      * real ones in from an initialization table.
  328.      *
  329.      * NOTE: In this table, the meaning of 'numops' is:
  330.      *     1: single operand
  331.      *     2: 2 operands, load instruction
  332.      *    -2: 2 operands, store instruction
  333.      */
  334.     static struct tabent *mem_tab = NULL;
  335. /* Opcodes of 0x8X, 9X, aX, bX, and cX must be in the table.  */
  336. #define MEM_MIN    0x80
  337. #define MEM_MAX    0xcf
  338. #define MEM_SIZ    ((MEM_MAX-MEM_MIN+1) * sizeof(struct tabent))
  339.  
  340.     static struct { int opcode; char *name; char numops; } mem_init[] = {
  341.         0x80,    "ldob",     2,
  342.         0x82,    "stob",    -2,
  343.         0x84,    "bx",     1,
  344.         0x85,    "balx",     2,
  345.         0x86,    "callx", 1,
  346.         0x88,    "ldos",     2,
  347.         0x8a,    "stos",    -2,
  348.         0x8c,    "lda",     2,
  349.         0x90,    "ld",     2,
  350.         0x92,    "st",    -2,
  351.         0x98,    "ldl",     2,
  352.         0x9a,    "stl",    -2,
  353.         0xa0,    "ldt",     2,
  354.         0xa2,    "stt",    -2,
  355.         0xb0,    "ldq",     2,
  356.         0xb2,    "stq",    -2,
  357.         0xc0,    "ldib",     2,
  358.         0xc2,    "stib",    -2,
  359.         0xc8,    "ldis",     2,
  360.         0xca,    "stis",    -2,
  361.         0,    NULL,    0
  362.     };
  363.  
  364.     if ( mem_tab == NULL ){
  365.         mem_tab = (struct tabent *) xmalloc( MEM_SIZ );
  366.         memset( (void *) mem_tab, 0, MEM_SIZ );
  367.         for ( i = 0; mem_init[i].opcode != 0; i++ ){
  368.             j = mem_init[i].opcode - MEM_MIN;
  369.             mem_tab[j].name = mem_init[i].name;
  370.             mem_tab[j].numops = mem_init[i].numops;
  371.         }
  372.     }
  373.  
  374.     i = ((word1 >> 24) & 0xff) - MEM_MIN;
  375.     mode = (word1 >> 10) & 0xf;
  376.  
  377.     if ( (mem_tab[i].name != NULL)        /* Valid instruction */
  378.     &&   ((mode == 5) || (mode >=12)) ){    /* With 32-bit displacement */
  379.         len = 8;
  380.     } else {
  381.         len = 4;
  382.     }
  383.  
  384.     if ( noprint ){
  385.         return len;
  386.     }
  387.  
  388.     if ( (mem_tab[i].name == NULL) || (mode == 6) ){
  389.         invalid( word1 );
  390.         return len;
  391.     }
  392.  
  393.     (*info->fprintf_func)( stream, "%s\t", mem_tab[i].name );
  394.  
  395.     reg1 = reg_names[ (word1 >> 19) & 0x1f ];    /* MEMB only */
  396.     reg2 = reg_names[ (word1 >> 14) & 0x1f ];
  397.     reg3 = reg_names[ word1 & 0x1f ];        /* MEMB only */
  398.     offset = word1 & 0xfff;                /* MEMA only  */
  399.  
  400.     switch ( mem_tab[i].numops ){
  401.  
  402.     case 2: /* LOAD INSTRUCTION */
  403.         if ( mode & 4 ){            /* MEMB FORMAT */
  404.             ea( memaddr, mode, reg2, reg3, word1, word2 );
  405.             (*info->fprintf_func)( stream, ",%s", reg1 );
  406.         } else {                /* MEMA FORMAT */
  407.             (*info->fprintf_func)( stream, "0x%x", (unsigned) offset );
  408.             if (mode & 8) {
  409.                 (*info->fprintf_func)( stream, "(%s)", reg2 );
  410.             }
  411.             (*info->fprintf_func)( stream, ",%s", reg1 );
  412.         }
  413.         break;
  414.  
  415.     case -2: /* STORE INSTRUCTION */
  416.         if ( mode & 4 ){            /* MEMB FORMAT */
  417.             (*info->fprintf_func)( stream, "%s,", reg1 );
  418.             ea( memaddr, mode, reg2, reg3, word1, word2 );
  419.         } else {                /* MEMA FORMAT */
  420.             (*info->fprintf_func)( stream, "%s,0x%x", reg1, (unsigned) offset );
  421.             if (mode & 8) {
  422.                 (*info->fprintf_func)( stream, "(%s)", reg2 );
  423.             }
  424.         }
  425.         break;
  426.  
  427.     case 1: /* BX/CALLX INSTRUCTION */
  428.         if ( mode & 4 ){            /* MEMB FORMAT */
  429.             ea( memaddr, mode, reg2, reg3, word1, word2 );
  430.         } else {                /* MEMA FORMAT */
  431.             (*info->fprintf_func)( stream, "0x%x", (unsigned) offset );
  432.             if (mode & 8) {
  433.                 (*info->fprintf_func)( stream, "(%s)", reg2 );
  434.             }
  435.         }
  436.         break;
  437.     }
  438.  
  439.     return len;
  440. }
  441.  
  442. /****************************************/
  443. /* REG format                */
  444. /****************************************/
  445. static void
  446. reg( word1 )
  447.     unsigned long word1;
  448. {
  449.     int i, j;
  450.     int opcode;
  451.     int fp;
  452.     int m1, m2, m3;
  453.     int s1, s2;
  454.     int src, src2, dst;
  455.     char *mnemp;
  456.  
  457.     /* This lookup table is too sparse to make it worth typing in, but not
  458.      * so large as to make a sparse array necessary.  We allocate the
  459.      * table at runtime, initialize all entries to empty, and copy the
  460.      * real ones in from an initialization table.
  461.      *
  462.      * NOTE: In this table, the meaning of 'numops' is:
  463.      *     1: single operand, which is NOT a destination.
  464.      *    -1: single operand, which IS a destination.
  465.      *     2: 2 operands, the 2nd of which is NOT a destination.
  466.      *    -2: 2 operands, the 2nd of which IS a destination.
  467.      *     3: 3 operands
  468.      *
  469.      *    If an opcode mnemonic begins with "F", it is a floating-point
  470.      *    opcode (the "F" is not printed).
  471.      */
  472.  
  473.     static struct tabent *reg_tab = NULL;
  474.     static struct { int opcode; char *name; char numops; } reg_init[] = {
  475. #define REG_MIN    0x580
  476.         0x580,    "notbit",    3,
  477.         0x581,    "and",        3,
  478.         0x582,    "andnot",    3,
  479.         0x583,    "setbit",    3,
  480.         0x584,    "notand",    3,
  481.         0x586,    "xor",        3,
  482.         0x587,    "or",        3,
  483.         0x588,    "nor",        3,
  484.         0x589,    "xnor",        3,
  485.         0x58a,    "not",        -2,
  486.         0x58b,    "ornot",    3,
  487.         0x58c,    "clrbit",    3,
  488.         0x58d,    "notor",    3,
  489.         0x58e,    "nand",        3,
  490.         0x58f,    "alterbit",    3,
  491.         0x590,     "addo",        3,
  492.         0x591,     "addi",        3,
  493.         0x592,     "subo",        3,
  494.         0x593,     "subi",        3,
  495.         0x598,     "shro",        3,
  496.         0x59a,     "shrdi",    3,
  497.         0x59b,     "shri",        3,
  498.         0x59c,     "shlo",        3,
  499.         0x59d,     "rotate",    3,
  500.         0x59e,     "shli",        3,
  501.         0x5a0,     "cmpo",        2,
  502.         0x5a1,     "cmpi",        2,
  503.         0x5a2,     "concmpo",    2,
  504.         0x5a3,     "concmpi",    2,
  505.         0x5a4,     "cmpinco",    3,
  506.         0x5a5,     "cmpinci",    3,
  507.         0x5a6,     "cmpdeco",    3,
  508.         0x5a7,     "cmpdeci",    3,
  509.         0x5ac,     "scanbyte",    2,
  510.         0x5ae,     "chkbit",    2,
  511.         0x5b0,     "addc",        3,
  512.         0x5b2,     "subc",        3,
  513.         0x5cc,    "mov",        -2,
  514.         0x5d8,    "eshro",    3,
  515.         0x5dc,    "movl",        -2,
  516.         0x5ec,    "movt",        -2,
  517.         0x5fc,    "movq",        -2,
  518.         0x600,    "synmov",    2,
  519.         0x601,    "synmovl",    2,
  520.         0x602,    "synmovq",    2,
  521.         0x603,    "cmpstr",    3,
  522.         0x604,    "movqstr",    3,
  523.         0x605,    "movstr",    3,
  524.         0x610,    "atmod",    3,
  525.         0x612,    "atadd",    3,
  526.         0x613,    "inspacc",    -2,
  527.         0x614,    "ldphy",    -2,
  528.         0x615,    "synld",    -2,
  529.         0x617,    "fill",        3,
  530.         0x630,    "sdma",        3,
  531.         0x631,    "udma",        0,
  532.         0x640,    "spanbit",    -2,
  533.         0x641,    "scanbit",    -2,
  534.         0x642,    "daddc",    3,
  535.         0x643,    "dsubc",    3,
  536.         0x644,    "dmovt",    -2,
  537.         0x645,    "modac",    3,
  538.         0x646,    "condrec",    -2,
  539.         0x650,    "modify",    3,
  540.         0x651,    "extract",    3,
  541.         0x654,    "modtc",    3,
  542.         0x655,    "modpc",    3,
  543.         0x656,    "receive",    -2,
  544.         0x659,    "sysctl",    3,
  545.         0x660,    "calls",    1,
  546.         0x662,    "send",        3,
  547.         0x663,    "sendserv",    1,
  548.         0x664,    "resumprcs",    1,
  549.         0x665,    "schedprcs",    1,
  550.         0x666,    "saveprcs",    0,
  551.         0x668,    "condwait",    1,
  552.         0x669,    "wait",        1,
  553.         0x66a,    "signal",    1,
  554.         0x66b,    "mark",        0,
  555.         0x66c,    "fmark",    0,
  556.         0x66d,    "flushreg",    0,
  557.         0x66f,    "syncf",    0,
  558.         0x670,    "emul",        3,
  559.         0x671,    "ediv",        3,
  560.         0x673,     "ldtime",    -1,
  561.         0x674,    "Fcvtir",    -2,
  562.         0x675,    "Fcvtilr",    -2,
  563.         0x676,    "Fscalerl",    3,
  564.         0x677,    "Fscaler",    3,
  565.         0x680,    "Fatanr",    3,
  566.         0x681,    "Flogepr",    3,
  567.         0x682,    "Flogr",    3,
  568.         0x683,    "Fremr",    3,
  569.         0x684,    "Fcmpor",    2,
  570.         0x685,    "Fcmpr",    2,
  571.         0x688,    "Fsqrtr",    -2,
  572.         0x689,    "Fexpr",    -2,
  573.         0x68a,    "Flogbnr",    -2,
  574.         0x68b,    "Froundr",    -2,
  575.         0x68c,    "Fsinr",    -2,
  576.         0x68d,    "Fcosr",    -2,
  577.         0x68e,    "Ftanr",    -2,
  578.         0x68f,    "Fclassr",    1,
  579.         0x690,    "Fatanrl",    3,
  580.         0x691,    "Flogeprl",    3,
  581.         0x692,    "Flogrl",    3,
  582.         0x693,    "Fremrl",    3,
  583.         0x694,    "Fcmporl",    2,
  584.         0x695,    "Fcmprl",    2,
  585.         0x698,    "Fsqrtrl",    -2,
  586.         0x699,    "Fexprl",    -2,
  587.         0x69a,    "Flogbnrl",    -2,
  588.         0x69b,    "Froundrl",    -2,
  589.         0x69c,    "Fsinrl",    -2,
  590.         0x69d,    "Fcosrl",    -2,
  591.         0x69e,    "Ftanrl",    -2,
  592.         0x69f,    "Fclassrl",    1,
  593.         0x6c0,    "Fcvtri",    -2,
  594.         0x6c1,    "Fcvtril",    -2,
  595.         0x6c2,    "Fcvtzri",    -2,
  596.         0x6c3,    "Fcvtzril",    -2,
  597.         0x6c9,    "Fmovr",    -2,
  598.         0x6d9,    "Fmovrl",    -2,
  599.         0x6e1,     "Fmovre",    -2,
  600.         0x6e2,     "Fcpysre",    3,
  601.         0x6e3,     "Fcpyrsre",    3,
  602.         0x701,    "mulo",        3,
  603.         0x708,    "remo",        3,
  604.         0x70b,    "divo",        3,
  605.         0x741,    "muli",        3,
  606.         0x748,    "remi",        3,
  607.         0x749,    "modi",        3,
  608.         0x74b,    "divi",        3,
  609.         0x78b,    "Fdivr",    3,
  610.         0x78c,    "Fmulr",    3,
  611.         0x78d,    "Fsubr",    3,
  612.         0x78f,    "Faddr",    3,
  613.         0x79b,    "Fdivrl",    3,
  614.         0x79c,    "Fmulrl",    3,
  615.         0x79d,    "Fsubrl",    3,
  616.         0x79f,    "Faddrl",    3,
  617. #define REG_MAX    0x79f
  618. #define REG_SIZ    ((REG_MAX-REG_MIN+1) * sizeof(struct tabent))
  619.         0,    NULL,    0
  620.     };
  621.  
  622.     if ( reg_tab == NULL ){
  623.         reg_tab = (struct tabent *) xmalloc( REG_SIZ );
  624.         memset( (void *) reg_tab, 0, REG_SIZ );
  625.         for ( i = 0; reg_init[i].opcode != 0; i++ ){
  626.             j = reg_init[i].opcode - REG_MIN;
  627.             reg_tab[j].name = reg_init[i].name;
  628.             reg_tab[j].numops = reg_init[i].numops;
  629.         }
  630.     }
  631.  
  632.     opcode = ((word1 >> 20) & 0xff0) | ((word1 >> 7) & 0xf);
  633.     i = opcode - REG_MIN;
  634.  
  635.     if ( (opcode<REG_MIN) || (opcode>REG_MAX) || (reg_tab[i].name==NULL) ){
  636.         invalid( word1 );
  637.         return;
  638.     }
  639.  
  640.     mnemp = reg_tab[i].name;
  641.     if ( *mnemp == 'F' ){
  642.         fp = 1;
  643.         mnemp++;
  644.     } else {
  645.         fp = 0;
  646.     }
  647.  
  648.     (*info->fprintf_func)( stream, mnemp );
  649.  
  650.     s1   = (word1 >> 5)  & 1;
  651.     s2   = (word1 >> 6)  & 1;
  652.     m1   = (word1 >> 11) & 1;
  653.     m2   = (word1 >> 12) & 1;
  654.     m3   = (word1 >> 13) & 1;
  655.     src  =  word1        & 0x1f;
  656.     src2 = (word1 >> 14) & 0x1f;
  657.     dst  = (word1 >> 19) & 0x1f;
  658.  
  659.     if  ( reg_tab[i].numops != 0 ){
  660.         (*info->fprintf_func)( stream, "\t" );
  661.  
  662.         switch ( reg_tab[i].numops ){
  663.         case 1:
  664.             regop( m1, s1, src, fp );
  665.             break;
  666.         case -1:
  667.             dstop( m3, dst, fp );
  668.             break;
  669.         case 2:
  670.             regop( m1, s1, src, fp );
  671.             (*info->fprintf_func)( stream, "," );
  672.             regop( m2, s2, src2, fp );
  673.             break;
  674.         case -2:
  675.             regop( m1, s1, src, fp );
  676.             (*info->fprintf_func)( stream, "," );
  677.             dstop( m3, dst, fp );
  678.             break;
  679.         case 3:
  680.             regop( m1, s1, src, fp );
  681.             (*info->fprintf_func)( stream, "," );
  682.             regop( m2, s2, src2, fp );
  683.             (*info->fprintf_func)( stream, "," );
  684.             dstop( m3, dst, fp );
  685.             break;
  686.         }
  687.     }
  688. }
  689.  
  690.  
  691. /*
  692.  * Print out effective address for memb instructions.
  693.  */
  694. static void
  695. ea( memaddr, mode, reg2, reg3, word1, word2 )
  696.     unsigned long memaddr;
  697.     int mode;
  698.     char *reg2, *reg3;
  699. int word1;
  700.     unsigned int word2;
  701. {
  702.     int scale;
  703.     static int scale_tab[] = { 1, 2, 4, 8, 16 };
  704.  
  705.     scale = (word1 >> 7) & 0x07;
  706.     if ( (scale > 4) || ((word1 >> 5) & 0x03 != 0) ){
  707.         invalid( word1 );
  708.         return;
  709.     }
  710.     scale = scale_tab[scale];
  711.  
  712.     switch (mode) {
  713.     case 4:                         /* (reg) */
  714.         (*info->fprintf_func)( stream, "(%s)", reg2 );
  715.         break;
  716.     case 5:                        /* displ+8(ip) */
  717.         print_addr( word2+8+memaddr );
  718.         break;
  719.     case 7:                        /* (reg)[index*scale] */
  720.         if (scale == 1) {
  721.             (*info->fprintf_func)( stream, "(%s)[%s]", reg2, reg3 );
  722.         } else {
  723.             (*info->fprintf_func)( stream, "(%s)[%s*%d]",reg2,reg3,scale);
  724.         }
  725.         break;
  726.     case 12:                    /* displacement */
  727.         print_addr( word2 );
  728.         break;
  729.     case 13:                    /* displ(reg) */
  730.         print_addr( word2 );
  731.         (*info->fprintf_func)( stream, "(%s)", reg2 );
  732.         break;
  733.     case 14:                    /* displ[index*scale] */
  734.         print_addr( word2 );
  735.         if (scale == 1) {
  736.             (*info->fprintf_func)( stream, "[%s]", reg3 );
  737.         } else {
  738.             (*info->fprintf_func)( stream, "[%s*%d]", reg3, scale );
  739.         }
  740.         break;
  741.     case 15:                /* displ(reg)[index*scale] */
  742.         print_addr( word2 );
  743.         if (scale == 1) {
  744.             (*info->fprintf_func)( stream, "(%s)[%s]", reg2, reg3 );
  745.         } else {
  746.             (*info->fprintf_func)( stream, "(%s)[%s*%d]",reg2,reg3,scale );
  747.         }
  748.         break;
  749.     default:
  750.         invalid( word1 );
  751.         return;
  752.     }
  753. }
  754.  
  755.  
  756. /************************************************/
  757. /* Register Instruction Operand          */
  758. /************************************************/
  759. static void
  760. regop( mode, spec, reg, fp )
  761.     int mode, spec, reg, fp;
  762. {
  763.     if ( fp ){                /* FLOATING POINT INSTRUCTION */
  764.         if ( mode == 1 ){            /* FP operand */
  765.             switch ( reg ){
  766.             case 0:  (*info->fprintf_func)( stream, "fp0" );
  767.               break;
  768.             case 1:  (*info->fprintf_func)( stream, "fp1" );
  769.               break;
  770.             case 2:  (*info->fprintf_func)( stream, "fp2" );
  771.               break;
  772.             case 3:  (*info->fprintf_func)( stream, "fp3" );
  773.               break;
  774.             case 16: (*info->fprintf_func)( stream, "0f0.0" );
  775.               break;
  776.             case 22: (*info->fprintf_func)( stream, "0f1.0" );
  777.               break;
  778.             default: (*info->fprintf_func)( stream, "?" );
  779.               break;
  780.             }
  781.         } else {                /* Non-FP register */
  782.             (*info->fprintf_func)( stream, reg_names[reg] );
  783.         }
  784.     } else {                /* NOT FLOATING POINT */
  785.         if ( mode == 1 ){            /* Literal */
  786.             (*info->fprintf_func)( stream, "%d", reg );
  787.         } else {                /* Register */
  788.             if ( spec == 0 ){
  789.                 (*info->fprintf_func)( stream, reg_names[reg] );
  790.             } else {
  791.                 (*info->fprintf_func)( stream, "sf%d", reg );
  792.             }
  793.         }
  794.     }
  795. }
  796.  
  797. /************************************************/
  798. /* Register Instruction Destination Operand    */
  799. /************************************************/
  800. static void
  801. dstop( mode, reg, fp )
  802.     int mode, reg, fp;
  803. {
  804.     /* 'dst' operand can't be a literal. On non-FP instructions,  register
  805.      * mode is assumed and "m3" acts as if were "s3";  on FP-instructions,
  806.      * sf registers are not allowed so m3 acts normally.
  807.      */
  808.      if ( fp ){
  809.         regop( mode, 0, reg, fp );
  810.      } else {
  811.         regop( 0, mode, reg, fp );
  812.      }
  813. }
  814.  
  815.  
  816. static void
  817. invalid( word1 )
  818.     int word1;
  819. {
  820.     (*info->fprintf_func)( stream, ".word\t0x%08x", (unsigned) word1 );
  821. }    
  822.  
  823. static void
  824. print_addr(a)
  825. int a;
  826. {
  827.   (*info->print_address_func) ((bfd_vma) a, info);
  828. }
  829.  
  830. static void
  831. put_abs( word1, word2 )
  832.     unsigned long word1, word2;
  833. {
  834. #ifdef IN_GDB
  835.     return;
  836. #else
  837.     int len;
  838.  
  839.     switch ( (word1 >> 28) & 0xf ){
  840.     case 0x8:
  841.     case 0x9:
  842.     case 0xa:
  843.     case 0xb:
  844.     case 0xc:
  845.         /* MEM format instruction */
  846.         len = mem( 0, word1, word2, 1 );
  847.         break;
  848.     default:
  849.         len = 4;
  850.         break;
  851.     }
  852.  
  853.     if ( len == 8 ){
  854.         (*info->fprintf_func)( stream, "%08x %08x\t", word1, word2 );
  855.     } else {
  856.         (*info->fprintf_func)( stream, "%08x         \t", word1 );
  857.     }
  858. ;
  859.  
  860. #endif
  861. }
  862.