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