disassemble.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /*
  2. * Disassemble SuperH instructions.
  3. *
  4. * Copyright (C) 1999 kaz Kojima
  5. * Copyright (C) 2008 Paul Mundt
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/string.h>
  13. #include <linux/uaccess.h>
  14. /*
  15. * Format of an instruction in memory.
  16. */
  17. typedef enum {
  18. HEX_0, HEX_1, HEX_2, HEX_3, HEX_4, HEX_5, HEX_6, HEX_7,
  19. HEX_8, HEX_9, HEX_A, HEX_B, HEX_C, HEX_D, HEX_E, HEX_F,
  20. REG_N, REG_M, REG_NM, REG_B,
  21. BRANCH_12, BRANCH_8,
  22. DISP_8, DISP_4,
  23. IMM_4, IMM_4BY2, IMM_4BY4, PCRELIMM_8BY2, PCRELIMM_8BY4,
  24. IMM_8, IMM_8BY2, IMM_8BY4,
  25. } sh_nibble_type;
  26. typedef enum {
  27. A_END, A_BDISP12, A_BDISP8,
  28. A_DEC_M, A_DEC_N,
  29. A_DISP_GBR, A_DISP_PC, A_DISP_REG_M, A_DISP_REG_N,
  30. A_GBR,
  31. A_IMM,
  32. A_INC_M, A_INC_N,
  33. A_IND_M, A_IND_N, A_IND_R0_REG_M, A_IND_R0_REG_N,
  34. A_MACH, A_MACL,
  35. A_PR, A_R0, A_R0_GBR, A_REG_M, A_REG_N, A_REG_B,
  36. A_SR, A_VBR, A_SSR, A_SPC, A_SGR, A_DBR,
  37. F_REG_N, F_REG_M, D_REG_N, D_REG_M,
  38. X_REG_N, /* Only used for argument parsing */
  39. X_REG_M, /* Only used for argument parsing */
  40. DX_REG_N, DX_REG_M, V_REG_N, V_REG_M,
  41. FD_REG_N,
  42. XMTRX_M4,
  43. F_FR0,
  44. FPUL_N, FPUL_M, FPSCR_N, FPSCR_M,
  45. } sh_arg_type;
  46. static struct sh_opcode_info {
  47. char *name;
  48. sh_arg_type arg[7];
  49. sh_nibble_type nibbles[4];
  50. } sh_table[] = {
  51. {"add",{A_IMM,A_REG_N},{HEX_7,REG_N,IMM_8}},
  52. {"add",{ A_REG_M,A_REG_N},{HEX_3,REG_N,REG_M,HEX_C}},
  53. {"addc",{ A_REG_M,A_REG_N},{HEX_3,REG_N,REG_M,HEX_E}},
  54. {"addv",{ A_REG_M,A_REG_N},{HEX_3,REG_N,REG_M,HEX_F}},
  55. {"and",{A_IMM,A_R0},{HEX_C,HEX_9,IMM_8}},
  56. {"and",{ A_REG_M,A_REG_N},{HEX_2,REG_N,REG_M,HEX_9}},
  57. {"and.b",{A_IMM,A_R0_GBR},{HEX_C,HEX_D,IMM_8}},
  58. {"bra",{A_BDISP12},{HEX_A,BRANCH_12}},
  59. {"bsr",{A_BDISP12},{HEX_B,BRANCH_12}},
  60. {"bt",{A_BDISP8},{HEX_8,HEX_9,BRANCH_8}},
  61. {"bf",{A_BDISP8},{HEX_8,HEX_B,BRANCH_8}},
  62. {"bt.s",{A_BDISP8},{HEX_8,HEX_D,BRANCH_8}},
  63. {"bt/s",{A_BDISP8},{HEX_8,HEX_D,BRANCH_8}},
  64. {"bf.s",{A_BDISP8},{HEX_8,HEX_F,BRANCH_8}},
  65. {"bf/s",{A_BDISP8},{HEX_8,HEX_F,BRANCH_8}},
  66. {"clrmac",{0},{HEX_0,HEX_0,HEX_2,HEX_8}},
  67. {"clrs",{0},{HEX_0,HEX_0,HEX_4,HEX_8}},
  68. {"clrt",{0},{HEX_0,HEX_0,HEX_0,HEX_8}},
  69. {"cmp/eq",{A_IMM,A_R0},{HEX_8,HEX_8,IMM_8}},
  70. {"cmp/eq",{ A_REG_M,A_REG_N},{HEX_3,REG_N,REG_M,HEX_0}},
  71. {"cmp/ge",{ A_REG_M,A_REG_N},{HEX_3,REG_N,REG_M,HEX_3}},
  72. {"cmp/gt",{ A_REG_M,A_REG_N},{HEX_3,REG_N,REG_M,HEX_7}},
  73. {"cmp/hi",{ A_REG_M,A_REG_N},{HEX_3,REG_N,REG_M,HEX_6}},
  74. {"cmp/hs",{ A_REG_M,A_REG_N},{HEX_3,REG_N,REG_M,HEX_2}},
  75. {"cmp/pl",{A_REG_N},{HEX_4,REG_N,HEX_1,HEX_5}},
  76. {"cmp/pz",{A_REG_N},{HEX_4,REG_N,HEX_1,HEX_1}},
  77. {"cmp/str",{ A_REG_M,A_REG_N},{HEX_2,REG_N,REG_M,HEX_C}},
  78. {"div0s",{ A_REG_M,A_REG_N},{HEX_2,REG_N,REG_M,HEX_7}},
  79. {"div0u",{0},{HEX_0,HEX_0,HEX_1,HEX_9}},
  80. {"div1",{ A_REG_M,A_REG_N},{HEX_3,REG_N,REG_M,HEX_4}},
  81. {"exts.b",{ A_REG_M,A_REG_N},{HEX_6,REG_N,REG_M,HEX_E}},
  82. {"exts.w",{ A_REG_M,A_REG_N},{HEX_6,REG_N,REG_M,HEX_F}},
  83. {"extu.b",{ A_REG_M,A_REG_N},{HEX_6,REG_N,REG_M,HEX_C}},
  84. {"extu.w",{ A_REG_M,A_REG_N},{HEX_6,REG_N,REG_M,HEX_D}},
  85. {"jmp",{A_IND_N},{HEX_4,REG_N,HEX_2,HEX_B}},
  86. {"jsr",{A_IND_N},{HEX_4,REG_N,HEX_0,HEX_B}},
  87. {"ldc",{A_REG_N,A_SR},{HEX_4,REG_N,HEX_0,HEX_E}},
  88. {"ldc",{A_REG_N,A_GBR},{HEX_4,REG_N,HEX_1,HEX_E}},
  89. {"ldc",{A_REG_N,A_VBR},{HEX_4,REG_N,HEX_2,HEX_E}},
  90. {"ldc",{A_REG_N,A_SSR},{HEX_4,REG_N,HEX_3,HEX_E}},
  91. {"ldc",{A_REG_N,A_SPC},{HEX_4,REG_N,HEX_4,HEX_E}},
  92. {"ldc",{A_REG_N,A_DBR},{HEX_4,REG_N,HEX_7,HEX_E}},
  93. {"ldc",{A_REG_N,A_REG_B},{HEX_4,REG_N,REG_B,HEX_E}},
  94. {"ldc.l",{A_INC_N,A_SR},{HEX_4,REG_N,HEX_0,HEX_7}},
  95. {"ldc.l",{A_INC_N,A_GBR},{HEX_4,REG_N,HEX_1,HEX_7}},
  96. {"ldc.l",{A_INC_N,A_VBR},{HEX_4,REG_N,HEX_2,HEX_7}},
  97. {"ldc.l",{A_INC_N,A_SSR},{HEX_4,REG_N,HEX_3,HEX_7}},
  98. {"ldc.l",{A_INC_N,A_SPC},{HEX_4,REG_N,HEX_4,HEX_7}},
  99. {"ldc.l",{A_INC_N,A_DBR},{HEX_4,REG_N,HEX_7,HEX_7}},
  100. {"ldc.l",{A_INC_N,A_REG_B},{HEX_4,REG_N,REG_B,HEX_7}},
  101. {"lds",{A_REG_N,A_MACH},{HEX_4,REG_N,HEX_0,HEX_A}},
  102. {"lds",{A_REG_N,A_MACL},{HEX_4,REG_N,HEX_1,HEX_A}},
  103. {"lds",{A_REG_N,A_PR},{HEX_4,REG_N,HEX_2,HEX_A}},
  104. {"lds",{A_REG_M,FPUL_N},{HEX_4,REG_M,HEX_5,HEX_A}},
  105. {"lds",{A_REG_M,FPSCR_N},{HEX_4,REG_M,HEX_6,HEX_A}},
  106. {"lds.l",{A_INC_N,A_MACH},{HEX_4,REG_N,HEX_0,HEX_6}},
  107. {"lds.l",{A_INC_N,A_MACL},{HEX_4,REG_N,HEX_1,HEX_6}},
  108. {"lds.l",{A_INC_N,A_PR},{HEX_4,REG_N,HEX_2,HEX_6}},
  109. {"lds.l",{A_INC_M,FPUL_N},{HEX_4,REG_M,HEX_5,HEX_6}},
  110. {"lds.l",{A_INC_M,FPSCR_N},{HEX_4,REG_M,HEX_6,HEX_6}},
  111. {"ldtlb",{0},{HEX_0,HEX_0,HEX_3,HEX_8}},
  112. {"mac.w",{A_INC_M,A_INC_N},{HEX_4,REG_N,REG_M,HEX_F}},
  113. {"mov",{A_IMM,A_REG_N},{HEX_E,REG_N,IMM_8}},
  114. {"mov",{ A_REG_M,A_REG_N},{HEX_6,REG_N,REG_M,HEX_3}},
  115. {"mov.b",{ A_REG_M,A_IND_R0_REG_N},{HEX_0,REG_N,REG_M,HEX_4}},
  116. {"mov.b",{ A_REG_M,A_DEC_N},{HEX_2,REG_N,REG_M,HEX_4}},
  117. {"mov.b",{ A_REG_M,A_IND_N},{HEX_2,REG_N,REG_M,HEX_0}},
  118. {"mov.b",{A_DISP_REG_M,A_R0},{HEX_8,HEX_4,REG_M,IMM_4}},
  119. {"mov.b",{A_DISP_GBR,A_R0},{HEX_C,HEX_4,IMM_8}},
  120. {"mov.b",{A_IND_R0_REG_M,A_REG_N},{HEX_0,REG_N,REG_M,HEX_C}},
  121. {"mov.b",{A_INC_M,A_REG_N},{HEX_6,REG_N,REG_M,HEX_4}},
  122. {"mov.b",{A_IND_M,A_REG_N},{HEX_6,REG_N,REG_M,HEX_0}},
  123. {"mov.b",{A_R0,A_DISP_REG_M},{HEX_8,HEX_0,REG_M,IMM_4}},
  124. {"mov.b",{A_R0,A_DISP_GBR},{HEX_C,HEX_0,IMM_8}},
  125. {"mov.l",{ A_REG_M,A_DISP_REG_N},{HEX_1,REG_N,REG_M,IMM_4BY4}},
  126. {"mov.l",{ A_REG_M,A_IND_R0_REG_N},{HEX_0,REG_N,REG_M,HEX_6}},
  127. {"mov.l",{ A_REG_M,A_DEC_N},{HEX_2,REG_N,REG_M,HEX_6}},
  128. {"mov.l",{ A_REG_M,A_IND_N},{HEX_2,REG_N,REG_M,HEX_2}},
  129. {"mov.l",{A_DISP_REG_M,A_REG_N},{HEX_5,REG_N,REG_M,IMM_4BY4}},
  130. {"mov.l",{A_DISP_GBR,A_R0},{HEX_C,HEX_6,IMM_8BY4}},
  131. {"mov.l",{A_DISP_PC,A_REG_N},{HEX_D,REG_N,PCRELIMM_8BY4}},
  132. {"mov.l",{A_IND_R0_REG_M,A_REG_N},{HEX_0,REG_N,REG_M,HEX_E}},
  133. {"mov.l",{A_INC_M,A_REG_N},{HEX_6,REG_N,REG_M,HEX_6}},
  134. {"mov.l",{A_IND_M,A_REG_N},{HEX_6,REG_N,REG_M,HEX_2}},
  135. {"mov.l",{A_R0,A_DISP_GBR},{HEX_C,HEX_2,IMM_8BY4}},
  136. {"mov.w",{ A_REG_M,A_IND_R0_REG_N},{HEX_0,REG_N,REG_M,HEX_5}},
  137. {"mov.w",{ A_REG_M,A_DEC_N},{HEX_2,REG_N,REG_M,HEX_5}},
  138. {"mov.w",{ A_REG_M,A_IND_N},{HEX_2,REG_N,REG_M,HEX_1}},
  139. {"mov.w",{A_DISP_REG_M,A_R0},{HEX_8,HEX_5,REG_M,IMM_4BY2}},
  140. {"mov.w",{A_DISP_GBR,A_R0},{HEX_C,HEX_5,IMM_8BY2}},
  141. {"mov.w",{A_DISP_PC,A_REG_N},{HEX_9,REG_N,PCRELIMM_8BY2}},
  142. {"mov.w",{A_IND_R0_REG_M,A_REG_N},{HEX_0,REG_N,REG_M,HEX_D}},
  143. {"mov.w",{A_INC_M,A_REG_N},{HEX_6,REG_N,REG_M,HEX_5}},
  144. {"mov.w",{A_IND_M,A_REG_N},{HEX_6,REG_N,REG_M,HEX_1}},
  145. {"mov.w",{A_R0,A_DISP_REG_M},{HEX_8,HEX_1,REG_M,IMM_4BY2}},
  146. {"mov.w",{A_R0,A_DISP_GBR},{HEX_C,HEX_1,IMM_8BY2}},
  147. {"mova",{A_DISP_PC,A_R0},{HEX_C,HEX_7,PCRELIMM_8BY4}},
  148. {"movca.l",{A_R0,A_IND_N},{HEX_0,REG_N,HEX_C,HEX_3}},
  149. {"movt",{A_REG_N},{HEX_0,REG_N,HEX_2,HEX_9}},
  150. {"muls",{ A_REG_M,A_REG_N},{HEX_2,REG_N,REG_M,HEX_F}},
  151. {"mul.l",{ A_REG_M,A_REG_N},{HEX_0,REG_N,REG_M,HEX_7}},
  152. {"mulu",{ A_REG_M,A_REG_N},{HEX_2,REG_N,REG_M,HEX_E}},
  153. {"neg",{ A_REG_M,A_REG_N},{HEX_6,REG_N,REG_M,HEX_B}},
  154. {"negc",{ A_REG_M,A_REG_N},{HEX_6,REG_N,REG_M,HEX_A}},
  155. {"nop",{0},{HEX_0,HEX_0,HEX_0,HEX_9}},
  156. {"not",{ A_REG_M,A_REG_N},{HEX_6,REG_N,REG_M,HEX_7}},
  157. {"ocbi",{A_IND_N},{HEX_0,REG_N,HEX_9,HEX_3}},
  158. {"ocbp",{A_IND_N},{HEX_0,REG_N,HEX_A,HEX_3}},
  159. {"ocbwb",{A_IND_N},{HEX_0,REG_N,HEX_B,HEX_3}},
  160. {"or",{A_IMM,A_R0},{HEX_C,HEX_B,IMM_8}},
  161. {"or",{ A_REG_M,A_REG_N},{HEX_2,REG_N,REG_M,HEX_B}},
  162. {"or.b",{A_IMM,A_R0_GBR},{HEX_C,HEX_F,IMM_8}},
  163. {"pref",{A_IND_N},{HEX_0,REG_N,HEX_8,HEX_3}},
  164. {"rotcl",{A_REG_N},{HEX_4,REG_N,HEX_2,HEX_4}},
  165. {"rotcr",{A_REG_N},{HEX_4,REG_N,HEX_2,HEX_5}},
  166. {"rotl",{A_REG_N},{HEX_4,REG_N,HEX_0,HEX_4}},
  167. {"rotr",{A_REG_N},{HEX_4,REG_N,HEX_0,HEX_5}},
  168. {"rte",{0},{HEX_0,HEX_0,HEX_2,HEX_B}},
  169. {"rts",{0},{HEX_0,HEX_0,HEX_0,HEX_B}},
  170. {"sets",{0},{HEX_0,HEX_0,HEX_5,HEX_8}},
  171. {"sett",{0},{HEX_0,HEX_0,HEX_1,HEX_8}},
  172. {"shad",{ A_REG_M,A_REG_N},{HEX_4,REG_N,REG_M,HEX_C}},
  173. {"shld",{ A_REG_M,A_REG_N},{HEX_4,REG_N,REG_M,HEX_D}},
  174. {"shal",{A_REG_N},{HEX_4,REG_N,HEX_2,HEX_0}},
  175. {"shar",{A_REG_N},{HEX_4,REG_N,HEX_2,HEX_1}},
  176. {"shll",{A_REG_N},{HEX_4,REG_N,HEX_0,HEX_0}},
  177. {"shll16",{A_REG_N},{HEX_4,REG_N,HEX_2,HEX_8}},
  178. {"shll2",{A_REG_N},{HEX_4,REG_N,HEX_0,HEX_8}},
  179. {"shll8",{A_REG_N},{HEX_4,REG_N,HEX_1,HEX_8}},
  180. {"shlr",{A_REG_N},{HEX_4,REG_N,HEX_0,HEX_1}},
  181. {"shlr16",{A_REG_N},{HEX_4,REG_N,HEX_2,HEX_9}},
  182. {"shlr2",{A_REG_N},{HEX_4,REG_N,HEX_0,HEX_9}},
  183. {"shlr8",{A_REG_N},{HEX_4,REG_N,HEX_1,HEX_9}},
  184. {"sleep",{0},{HEX_0,HEX_0,HEX_1,HEX_B}},
  185. {"stc",{A_SR,A_REG_N},{HEX_0,REG_N,HEX_0,HEX_2}},
  186. {"stc",{A_GBR,A_REG_N},{HEX_0,REG_N,HEX_1,HEX_2}},
  187. {"stc",{A_VBR,A_REG_N},{HEX_0,REG_N,HEX_2,HEX_2}},
  188. {"stc",{A_SSR,A_REG_N},{HEX_0,REG_N,HEX_3,HEX_2}},
  189. {"stc",{A_SPC,A_REG_N},{HEX_0,REG_N,HEX_4,HEX_2}},
  190. {"stc",{A_SGR,A_REG_N},{HEX_0,REG_N,HEX_6,HEX_2}},
  191. {"stc",{A_DBR,A_REG_N},{HEX_0,REG_N,HEX_7,HEX_2}},
  192. {"stc",{A_REG_B,A_REG_N},{HEX_0,REG_N,REG_B,HEX_2}},
  193. {"stc.l",{A_SR,A_DEC_N},{HEX_4,REG_N,HEX_0,HEX_3}},
  194. {"stc.l",{A_GBR,A_DEC_N},{HEX_4,REG_N,HEX_1,HEX_3}},
  195. {"stc.l",{A_VBR,A_DEC_N},{HEX_4,REG_N,HEX_2,HEX_3}},
  196. {"stc.l",{A_SSR,A_DEC_N},{HEX_4,REG_N,HEX_3,HEX_3}},
  197. {"stc.l",{A_SPC,A_DEC_N},{HEX_4,REG_N,HEX_4,HEX_3}},
  198. {"stc.l",{A_SGR,A_DEC_N},{HEX_4,REG_N,HEX_6,HEX_3}},
  199. {"stc.l",{A_DBR,A_DEC_N},{HEX_4,REG_N,HEX_7,HEX_3}},
  200. {"stc.l",{A_REG_B,A_DEC_N},{HEX_4,REG_N,REG_B,HEX_3}},
  201. {"sts",{A_MACH,A_REG_N},{HEX_0,REG_N,HEX_0,HEX_A}},
  202. {"sts",{A_MACL,A_REG_N},{HEX_0,REG_N,HEX_1,HEX_A}},
  203. {"sts",{A_PR,A_REG_N},{HEX_0,REG_N,HEX_2,HEX_A}},
  204. {"sts",{FPUL_M,A_REG_N},{HEX_0,REG_N,HEX_5,HEX_A}},
  205. {"sts",{FPSCR_M,A_REG_N},{HEX_0,REG_N,HEX_6,HEX_A}},
  206. {"sts.l",{A_MACH,A_DEC_N},{HEX_4,REG_N,HEX_0,HEX_2}},
  207. {"sts.l",{A_MACL,A_DEC_N},{HEX_4,REG_N,HEX_1,HEX_2}},
  208. {"sts.l",{A_PR,A_DEC_N},{HEX_4,REG_N,HEX_2,HEX_2}},
  209. {"sts.l",{FPUL_M,A_DEC_N},{HEX_4,REG_N,HEX_5,HEX_2}},
  210. {"sts.l",{FPSCR_M,A_DEC_N},{HEX_4,REG_N,HEX_6,HEX_2}},
  211. {"sub",{ A_REG_M,A_REG_N},{HEX_3,REG_N,REG_M,HEX_8}},
  212. {"subc",{ A_REG_M,A_REG_N},{HEX_3,REG_N,REG_M,HEX_A}},
  213. {"subv",{ A_REG_M,A_REG_N},{HEX_3,REG_N,REG_M,HEX_B}},
  214. {"swap.b",{ A_REG_M,A_REG_N},{HEX_6,REG_N,REG_M,HEX_8}},
  215. {"swap.w",{ A_REG_M,A_REG_N},{HEX_6,REG_N,REG_M,HEX_9}},
  216. {"tas.b",{A_IND_N},{HEX_4,REG_N,HEX_1,HEX_B}},
  217. {"trapa",{A_IMM},{HEX_C,HEX_3,IMM_8}},
  218. {"tst",{A_IMM,A_R0},{HEX_C,HEX_8,IMM_8}},
  219. {"tst",{ A_REG_M,A_REG_N},{HEX_2,REG_N,REG_M,HEX_8}},
  220. {"tst.b",{A_IMM,A_R0_GBR},{HEX_C,HEX_C,IMM_8}},
  221. {"xor",{A_IMM,A_R0},{HEX_C,HEX_A,IMM_8}},
  222. {"xor",{ A_REG_M,A_REG_N},{HEX_2,REG_N,REG_M,HEX_A}},
  223. {"xor.b",{A_IMM,A_R0_GBR},{HEX_C,HEX_E,IMM_8}},
  224. {"xtrct",{ A_REG_M,A_REG_N},{HEX_2,REG_N,REG_M,HEX_D}},
  225. {"mul.l",{ A_REG_M,A_REG_N},{HEX_0,REG_N,REG_M,HEX_7}},
  226. {"dt",{A_REG_N},{HEX_4,REG_N,HEX_1,HEX_0}},
  227. {"dmuls.l",{ A_REG_M,A_REG_N},{HEX_3,REG_N,REG_M,HEX_D}},
  228. {"dmulu.l",{ A_REG_M,A_REG_N},{HEX_3,REG_N,REG_M,HEX_5}},
  229. {"mac.l",{A_INC_M,A_INC_N},{HEX_0,REG_N,REG_M,HEX_F}},
  230. {"braf",{A_REG_N},{HEX_0,REG_N,HEX_2,HEX_3}},
  231. {"bsrf",{A_REG_N},{HEX_0,REG_N,HEX_0,HEX_3}},
  232. {"fabs",{FD_REG_N},{HEX_F,REG_N,HEX_5,HEX_D}},
  233. {"fadd",{F_REG_M,F_REG_N},{HEX_F,REG_N,REG_M,HEX_0}},
  234. {"fadd",{D_REG_M,D_REG_N},{HEX_F,REG_N,REG_M,HEX_0}},
  235. {"fcmp/eq",{F_REG_M,F_REG_N},{HEX_F,REG_N,REG_M,HEX_4}},
  236. {"fcmp/eq",{D_REG_M,D_REG_N},{HEX_F,REG_N,REG_M,HEX_4}},
  237. {"fcmp/gt",{F_REG_M,F_REG_N},{HEX_F,REG_N,REG_M,HEX_5}},
  238. {"fcmp/gt",{D_REG_M,D_REG_N},{HEX_F,REG_N,REG_M,HEX_5}},
  239. {"fcnvds",{D_REG_N,FPUL_M},{HEX_F,REG_N,HEX_B,HEX_D}},
  240. {"fcnvsd",{FPUL_M,D_REG_N},{HEX_F,REG_N,HEX_A,HEX_D}},
  241. {"fdiv",{F_REG_M,F_REG_N},{HEX_F,REG_N,REG_M,HEX_3}},
  242. {"fdiv",{D_REG_M,D_REG_N},{HEX_F,REG_N,REG_M,HEX_3}},
  243. {"fipr",{V_REG_M,V_REG_N},{HEX_F,REG_NM,HEX_E,HEX_D}},
  244. {"fldi0",{F_REG_N},{HEX_F,REG_N,HEX_8,HEX_D}},
  245. {"fldi1",{F_REG_N},{HEX_F,REG_N,HEX_9,HEX_D}},
  246. {"flds",{F_REG_N,FPUL_M},{HEX_F,REG_N,HEX_1,HEX_D}},
  247. {"float",{FPUL_M,FD_REG_N},{HEX_F,REG_N,HEX_2,HEX_D}},
  248. {"fmac",{F_FR0,F_REG_M,F_REG_N},{HEX_F,REG_N,REG_M,HEX_E}},
  249. {"fmov",{F_REG_M,F_REG_N},{HEX_F,REG_N,REG_M,HEX_C}},
  250. {"fmov",{DX_REG_M,DX_REG_N},{HEX_F,REG_N,REG_M,HEX_C}},
  251. {"fmov",{A_IND_M,F_REG_N},{HEX_F,REG_N,REG_M,HEX_8}},
  252. {"fmov",{A_IND_M,DX_REG_N},{HEX_F,REG_N,REG_M,HEX_8}},
  253. {"fmov",{F_REG_M,A_IND_N},{HEX_F,REG_N,REG_M,HEX_A}},
  254. {"fmov",{DX_REG_M,A_IND_N},{HEX_F,REG_N,REG_M,HEX_A}},
  255. {"fmov",{A_INC_M,F_REG_N},{HEX_F,REG_N,REG_M,HEX_9}},
  256. {"fmov",{A_INC_M,DX_REG_N},{HEX_F,REG_N,REG_M,HEX_9}},
  257. {"fmov",{F_REG_M,A_DEC_N},{HEX_F,REG_N,REG_M,HEX_B}},
  258. {"fmov",{DX_REG_M,A_DEC_N},{HEX_F,REG_N,REG_M,HEX_B}},
  259. {"fmov",{A_IND_R0_REG_M,F_REG_N},{HEX_F,REG_N,REG_M,HEX_6}},
  260. {"fmov",{A_IND_R0_REG_M,DX_REG_N},{HEX_F,REG_N,REG_M,HEX_6}},
  261. {"fmov",{F_REG_M,A_IND_R0_REG_N},{HEX_F,REG_N,REG_M,HEX_7}},
  262. {"fmov",{DX_REG_M,A_IND_R0_REG_N},{HEX_F,REG_N,REG_M,HEX_7}},
  263. {"fmov.d",{A_IND_M,DX_REG_N},{HEX_F,REG_N,REG_M,HEX_8}},
  264. {"fmov.d",{DX_REG_M,A_IND_N},{HEX_F,REG_N,REG_M,HEX_A}},
  265. {"fmov.d",{A_INC_M,DX_REG_N},{HEX_F,REG_N,REG_M,HEX_9}},
  266. {"fmov.d",{DX_REG_M,A_DEC_N},{HEX_F,REG_N,REG_M,HEX_B}},
  267. {"fmov.d",{A_IND_R0_REG_M,DX_REG_N},{HEX_F,REG_N,REG_M,HEX_6}},
  268. {"fmov.d",{DX_REG_M,A_IND_R0_REG_N},{HEX_F,REG_N,REG_M,HEX_7}},
  269. {"fmov.s",{A_IND_M,F_REG_N},{HEX_F,REG_N,REG_M,HEX_8}},
  270. {"fmov.s",{F_REG_M,A_IND_N},{HEX_F,REG_N,REG_M,HEX_A}},
  271. {"fmov.s",{A_INC_M,F_REG_N},{HEX_F,REG_N,REG_M,HEX_9}},
  272. {"fmov.s",{F_REG_M,A_DEC_N},{HEX_F,REG_N,REG_M,HEX_B}},
  273. {"fmov.s",{A_IND_R0_REG_M,F_REG_N},{HEX_F,REG_N,REG_M,HEX_6}},
  274. {"fmov.s",{F_REG_M,A_IND_R0_REG_N},{HEX_F,REG_N,REG_M,HEX_7}},
  275. {"fmul",{F_REG_M,F_REG_N},{HEX_F,REG_N,REG_M,HEX_2}},
  276. {"fmul",{D_REG_M,D_REG_N},{HEX_F,REG_N,REG_M,HEX_2}},
  277. {"fneg",{FD_REG_N},{HEX_F,REG_N,HEX_4,HEX_D}},
  278. {"frchg",{0},{HEX_F,HEX_B,HEX_F,HEX_D}},
  279. {"fschg",{0},{HEX_F,HEX_3,HEX_F,HEX_D}},
  280. {"fsqrt",{FD_REG_N},{HEX_F,REG_N,HEX_6,HEX_D}},
  281. {"fsts",{FPUL_M,F_REG_N},{HEX_F,REG_N,HEX_0,HEX_D}},
  282. {"fsub",{F_REG_M,F_REG_N},{HEX_F,REG_N,REG_M,HEX_1}},
  283. {"fsub",{D_REG_M,D_REG_N},{HEX_F,REG_N,REG_M,HEX_1}},
  284. {"ftrc",{FD_REG_N,FPUL_M},{HEX_F,REG_N,HEX_3,HEX_D}},
  285. {"ftrv",{XMTRX_M4,V_REG_N},{HEX_F,REG_NM,HEX_F,HEX_D}},
  286. { 0 },
  287. };
  288. static void print_sh_insn(u32 memaddr, u16 insn)
  289. {
  290. int relmask = ~0;
  291. int nibs[4] = { (insn >> 12) & 0xf, (insn >> 8) & 0xf, (insn >> 4) & 0xf, insn & 0xf};
  292. int lastsp;
  293. struct sh_opcode_info *op = sh_table;
  294. for (; op->name; op++) {
  295. int n;
  296. int imm = 0;
  297. int rn = 0;
  298. int rm = 0;
  299. int rb = 0;
  300. int disp_pc;
  301. int disp_pc_addr = 0;
  302. for (n = 0; n < 4; n++) {
  303. int i = op->nibbles[n];
  304. if (i < 16) {
  305. if (nibs[n] == i)
  306. continue;
  307. goto fail;
  308. }
  309. switch (i) {
  310. case BRANCH_8:
  311. imm = (nibs[2] << 4) | (nibs[3]);
  312. if (imm & 0x80)
  313. imm |= ~0xff;
  314. imm = ((char)imm) * 2 + 4 ;
  315. goto ok;
  316. case BRANCH_12:
  317. imm = ((nibs[1]) << 8) | (nibs[2] << 4) | (nibs[3]);
  318. if (imm & 0x800)
  319. imm |= ~0xfff;
  320. imm = imm * 2 + 4;
  321. goto ok;
  322. case IMM_4:
  323. imm = nibs[3];
  324. goto ok;
  325. case IMM_4BY2:
  326. imm = nibs[3] <<1;
  327. goto ok;
  328. case IMM_4BY4:
  329. imm = nibs[3] <<2;
  330. goto ok;
  331. case IMM_8:
  332. imm = (nibs[2] << 4) | nibs[3];
  333. goto ok;
  334. case PCRELIMM_8BY2:
  335. imm = ((nibs[2] << 4) | nibs[3]) <<1;
  336. relmask = ~1;
  337. goto ok;
  338. case PCRELIMM_8BY4:
  339. imm = ((nibs[2] << 4) | nibs[3]) <<2;
  340. relmask = ~3;
  341. goto ok;
  342. case IMM_8BY2:
  343. imm = ((nibs[2] << 4) | nibs[3]) <<1;
  344. goto ok;
  345. case IMM_8BY4:
  346. imm = ((nibs[2] << 4) | nibs[3]) <<2;
  347. goto ok;
  348. case DISP_8:
  349. imm = (nibs[2] << 4) | (nibs[3]);
  350. goto ok;
  351. case DISP_4:
  352. imm = nibs[3];
  353. goto ok;
  354. case REG_N:
  355. rn = nibs[n];
  356. break;
  357. case REG_M:
  358. rm = nibs[n];
  359. break;
  360. case REG_NM:
  361. rn = (nibs[n] & 0xc) >> 2;
  362. rm = (nibs[n] & 0x3);
  363. break;
  364. case REG_B:
  365. rb = nibs[n] & 0x07;
  366. break;
  367. default:
  368. return;
  369. }
  370. }
  371. ok:
  372. printk("%-8s ", op->name);
  373. lastsp = (op->arg[0] == A_END);
  374. disp_pc = 0;
  375. for (n = 0; n < 6 && op->arg[n] != A_END; n++) {
  376. if (n && op->arg[1] != A_END)
  377. printk(", ");
  378. switch (op->arg[n]) {
  379. case A_IMM:
  380. printk("#%d", (char)(imm));
  381. break;
  382. case A_R0:
  383. printk("r0");
  384. break;
  385. case A_REG_N:
  386. printk("r%d", rn);
  387. break;
  388. case A_INC_N:
  389. printk("@r%d+", rn);
  390. break;
  391. case A_DEC_N:
  392. printk("@-r%d", rn);
  393. break;
  394. case A_IND_N:
  395. printk("@r%d", rn);
  396. break;
  397. case A_DISP_REG_N:
  398. printk("@(%d,r%d)", imm, rn);
  399. break;
  400. case A_REG_M:
  401. printk("r%d", rm);
  402. break;
  403. case A_INC_M:
  404. printk("@r%d+", rm);
  405. break;
  406. case A_DEC_M:
  407. printk("@-r%d", rm);
  408. break;
  409. case A_IND_M:
  410. printk("@r%d", rm);
  411. break;
  412. case A_DISP_REG_M:
  413. printk("@(%d,r%d)", imm, rm);
  414. break;
  415. case A_REG_B:
  416. printk("r%d_bank", rb);
  417. break;
  418. case A_DISP_PC:
  419. disp_pc = 1;
  420. disp_pc_addr = imm + 4 + (memaddr & relmask);
  421. printk("%08x <%pS>", disp_pc_addr,
  422. (void *)disp_pc_addr);
  423. break;
  424. case A_IND_R0_REG_N:
  425. printk("@(r0,r%d)", rn);
  426. break;
  427. case A_IND_R0_REG_M:
  428. printk("@(r0,r%d)", rm);
  429. break;
  430. case A_DISP_GBR:
  431. printk("@(%d,gbr)",imm);
  432. break;
  433. case A_R0_GBR:
  434. printk("@(r0,gbr)");
  435. break;
  436. case A_BDISP12:
  437. case A_BDISP8:
  438. printk("%08x", imm + memaddr);
  439. break;
  440. case A_SR:
  441. printk("sr");
  442. break;
  443. case A_GBR:
  444. printk("gbr");
  445. break;
  446. case A_VBR:
  447. printk("vbr");
  448. break;
  449. case A_SSR:
  450. printk("ssr");
  451. break;
  452. case A_SPC:
  453. printk("spc");
  454. break;
  455. case A_MACH:
  456. printk("mach");
  457. break;
  458. case A_MACL:
  459. printk("macl");
  460. break;
  461. case A_PR:
  462. printk("pr");
  463. break;
  464. case A_SGR:
  465. printk("sgr");
  466. break;
  467. case A_DBR:
  468. printk("dbr");
  469. break;
  470. case FD_REG_N:
  471. if (0)
  472. goto d_reg_n;
  473. case F_REG_N:
  474. printk("fr%d", rn);
  475. break;
  476. case F_REG_M:
  477. printk("fr%d", rm);
  478. break;
  479. case DX_REG_N:
  480. if (rn & 1) {
  481. printk("xd%d", rn & ~1);
  482. break;
  483. }
  484. d_reg_n:
  485. case D_REG_N:
  486. printk("dr%d", rn);
  487. break;
  488. case DX_REG_M:
  489. if (rm & 1) {
  490. printk("xd%d", rm & ~1);
  491. break;
  492. }
  493. case D_REG_M:
  494. printk("dr%d", rm);
  495. break;
  496. case FPSCR_M:
  497. case FPSCR_N:
  498. printk("fpscr");
  499. break;
  500. case FPUL_M:
  501. case FPUL_N:
  502. printk("fpul");
  503. break;
  504. case F_FR0:
  505. printk("fr0");
  506. break;
  507. case V_REG_N:
  508. printk("fv%d", rn*4);
  509. break;
  510. case V_REG_M:
  511. printk("fv%d", rm*4);
  512. break;
  513. case XMTRX_M4:
  514. printk("xmtrx");
  515. break;
  516. default:
  517. return;
  518. }
  519. }
  520. if (disp_pc && strcmp(op->name, "mova") != 0) {
  521. u32 val;
  522. if (relmask == ~1)
  523. __get_user(val, (u16 *)disp_pc_addr);
  524. else
  525. __get_user(val, (u32 *)disp_pc_addr);
  526. printk(" ! %08x <%pS>", val, (void *)val);
  527. }
  528. return;
  529. fail:
  530. ;
  531. }
  532. printk(".word 0x%x%x%x%x", nibs[0], nibs[1], nibs[2], nibs[3]);
  533. }
  534. void show_code(struct pt_regs *regs)
  535. {
  536. unsigned short *pc = (unsigned short *)regs->pc;
  537. long i;
  538. if (regs->pc & 0x1)
  539. return;
  540. printk("Code:\n");
  541. for (i = -3 ; i < 6 ; i++) {
  542. unsigned short insn;
  543. if (__get_user(insn, pc + i)) {
  544. printk(" (Bad address in pc)\n");
  545. break;
  546. }
  547. printk("%s%08lx: ", (i ? " ": "->"), (unsigned long)(pc + i));
  548. print_sh_insn((unsigned long)(pc + i), insn);
  549. printk("\n");
  550. }
  551. printk("\n");
  552. }