vax-pinsn.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /* Print vax instructions for GDB, the GNU debugger.
  2. Copyright (C) 1986 Free Software Foundation, Inc.
  3. GDB is distributed in the hope that it will be useful, but WITHOUT ANY
  4. WARRANTY. No author or distributor accepts responsibility to anyone
  5. for the consequences of using it or for whether it serves any
  6. particular purpose or works at all, unless he says so in writing.
  7. Refer to the GDB General Public License for full details.
  8. Everyone is granted permission to copy, modify and redistribute GDB,
  9. but only under the conditions described in the GDB General Public
  10. License. A copy of this license is supposed to have been given to you
  11. along with GDB so you can know your rights and responsibilities. It
  12. should be in a file named COPYING. Among other things, the copyright
  13. notice and this notice must be preserved on all copies.
  14. In other words, go ahead and share GDB, but don't try to stop
  15. anyone else from sharing it farther. Help stamp out software hoarding!
  16. */
  17. #include <stdio.h>
  18. #include "defs.h"
  19. #include "param.h"
  20. #include "symtab.h"
  21. #include "vax-opcode.h"
  22. /* Vax instructions are never longer than this. */
  23. #define MAXLEN 62
  24. /* Number of elements in the opcode table. */
  25. #define NOPCODES (sizeof votstrs / sizeof votstrs[0])
  26. extern char *reg_names[];
  27. static unsigned char *print_insn_arg ();
  28. /* Print the vax instruction at address MEMADDR in debugged memory,
  29. on STREAM. Returns length of the instruction, in bytes. */
  30. int
  31. print_insn (memaddr, stream)
  32. CORE_ADDR memaddr;
  33. FILE *stream;
  34. {
  35. unsigned char buffer[MAXLEN];
  36. register int i;
  37. register unsigned char *p;
  38. register char *d;
  39. read_memory (memaddr, buffer, MAXLEN);
  40. for (i = 0; i < NOPCODES; i++)
  41. if (votstrs[i].detail.code == buffer[0]
  42. || votstrs[i].detail.code == *(unsigned short *)buffer)
  43. break;
  44. /* Handle undefined instructions. */
  45. if (i == NOPCODES)
  46. {
  47. fprintf (stream, "0%o", buffer[0]);
  48. return 1;
  49. }
  50. fprintf (stream, "%s", votstrs[i].name);
  51. /* Point at first byte of argument data,
  52. and at descriptor for first argument. */
  53. p = buffer + 1 + (votstrs[i].detail.code >= 0x100);
  54. d = votstrs[i].detail.args;
  55. if (*d)
  56. fputc (' ', stream);
  57. while (*d)
  58. {
  59. p = print_insn_arg (d, p, memaddr + (p - buffer), stream);
  60. d += 2;
  61. if (*d)
  62. fprintf (stream, ",");
  63. }
  64. return p - buffer;
  65. }
  66. static unsigned char *
  67. print_insn_arg (d, p, addr, stream)
  68. char *d;
  69. register char *p;
  70. CORE_ADDR addr;
  71. FILE *stream;
  72. {
  73. register int regnum = *p & 0xf;
  74. float floatlitbuf;
  75. if (*d == 'b')
  76. {
  77. if (d[1] == 'b')
  78. fprintf (stream, "0x%x", addr + *p++ + 1);
  79. else
  80. {
  81. fprintf (stream, "0x%x", addr + *(short *)p + 2);
  82. p += 2;
  83. }
  84. }
  85. else
  86. switch ((*p++ >> 4) & 0xf)
  87. {
  88. case 0:
  89. case 1:
  90. case 2:
  91. case 3: /* Literal mode */
  92. if (d[1] == 'd' || d[1] == 'f' || d[1] == 'g' || d[1] == 'h')
  93. {
  94. *(int *)&floatlitbuf = 0x4000 + ((p[-1] & 0x3f) << 4);
  95. fprintf (stream, "$%f", floatlitbuf);
  96. }
  97. else
  98. fprintf (stream, "$%d", p[-1] & 0x3f);
  99. break;
  100. case 4: /* Indexed */
  101. p = (char *) print_insn_arg (d, p, addr + 1, stream);
  102. fprintf (stream, "[%s]", reg_names[regnum]);
  103. break;
  104. case 5: /* Register */
  105. fprintf (stream, reg_names[regnum]);
  106. break;
  107. case 7: /* Autodecrement */
  108. fputc ('-', stream);
  109. case 6: /* Register deferred */
  110. fprintf (stream, "(%s)", reg_names[regnum]);
  111. break;
  112. case 9: /* Autoincrement deferred */
  113. fputc ('@', stream);
  114. if (regnum == PC_REGNUM)
  115. {
  116. fputc ('#', stream);
  117. print_address (*(long *)p, stream);
  118. p += 4;
  119. break;
  120. }
  121. case 8: /* Autoincrement */
  122. if (regnum == PC_REGNUM)
  123. {
  124. fputc ('#', stream);
  125. switch (d[1])
  126. {
  127. case 'b':
  128. fprintf (stream, "%d", *p++);
  129. break;
  130. case 'w':
  131. fprintf (stream, "%d", *(short *)p);
  132. p += 2;
  133. break;
  134. case 'l':
  135. fprintf (stream, "%d", *(long *)p);
  136. p += 4;
  137. break;
  138. case 'q':
  139. fprintf (stream, "0x%x%08x", ((long *)p)[1], ((long *)p)[0]);
  140. p += 8;
  141. break;
  142. case 'o':
  143. fprintf (stream, "0x%x%08x%08x%08x",
  144. ((long *)p)[3], ((long *)p)[2],
  145. ((long *)p)[1], ((long *)p)[0]);
  146. p += 16;
  147. break;
  148. case 'f':
  149. if (INVALID_FLOAT (p))
  150. fprintf (stream, "<<invalid float 0x%x>>", *(int *) p);
  151. else
  152. fprintf (stream, "%f", *(float *) p);
  153. p += 4;
  154. break;
  155. case 'd':
  156. if (INVALID_FLOAT (p))
  157. fprintf (stream, "<<invalid float 0x%x%08x>>",
  158. ((long *)p)[1], ((long *)p)[0]);
  159. else
  160. fprintf (stream, "%f", *(double *) p);
  161. p += 8;
  162. break;
  163. case 'g':
  164. fprintf (stream, "g-float");
  165. p += 8;
  166. break;
  167. case 'h':
  168. fprintf (stream, "h-float");
  169. p += 16;
  170. break;
  171. }
  172. }
  173. else
  174. fprintf (stream, "(%s)+", reg_names[regnum]);
  175. break;
  176. case 11: /* Byte displacement deferred */
  177. fputc ('@', stream);
  178. case 10: /* Byte displacement */
  179. if (regnum == PC_REGNUM)
  180. print_address (addr + *p + 2, stream);
  181. else
  182. fprintf (stream, "%d(%s)", *p, reg_names[regnum]);
  183. p += 1;
  184. break;
  185. case 13: /* Word displacement deferred */
  186. fputc ('@', stream);
  187. case 12: /* Word displacement */
  188. if (regnum == PC_REGNUM)
  189. print_address (addr + *(short *)p + 3, stream);
  190. else
  191. fprintf (stream, "%d(%s)", *(short *)p, reg_names[regnum]);
  192. p += 2;
  193. break;
  194. case 15: /* Long displacement deferred */
  195. fputc ('@', stream);
  196. case 14: /* Long displacement */
  197. if (regnum == PC_REGNUM)
  198. print_address (addr + *(long *)p + 5, stream);
  199. else
  200. fprintf (stream, "%d(%s)", *(long *)p, reg_names[regnum]);
  201. p += 4;
  202. }
  203. return (unsigned char *) p;
  204. }