arm_dyncom_dec.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. /* Copyright (C)
  2. * 2012 - Michael.Kang blackfin.kang@gmail.com
  3. * This program is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU General Public License
  5. * as published by the Free Software Foundation; either version 2
  6. * of the License, or (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. *
  17. */
  18. /**
  19. * @file arm_dyncom_dec.cpp
  20. * @brief Some common utility for arm decoder
  21. * @author Michael.Kang blackfin.kang@gmail.com
  22. * @version 7849
  23. * @date 2012-03-15
  24. */
  25. #include "core/arm/skyeye_common/arm_regformat.h"
  26. #include "core/arm/skyeye_common/armdefs.h"
  27. #include "core/arm/dyncom/arm_dyncom_dec.h"
  28. const ISEITEM arm_instruction[] = {
  29. #define VFP_DECODE
  30. #include "core/arm/skyeye_common/vfp/vfpinstr.cpp"
  31. #undef VFP_DECODE
  32. {"srs" , 4 , 6 , 25, 31, 0x0000007c, 22, 22, 0x00000001, 16, 20, 0x0000000d, 8, 11, 0x00000005},
  33. {"rfe" , 4 , 6 , 25, 31, 0x0000007c, 22, 22, 0x00000000, 20, 20, 0x00000001, 8, 11, 0x0000000a},
  34. {"bkpt" , 2 , 3 , 20, 31, 0x00000e12, 4, 7, 0x00000007},
  35. {"blx" , 1 , 3 , 25, 31, 0x0000007d},
  36. {"cps" , 3 , 6 , 20, 31, 0x00000f10, 16, 16, 0x00000000, 5, 5, 0x00000000},
  37. {"pld" , 4 , 4 , 26, 31, 0x0000003d, 24, 24, 0x00000001, 20, 22, 0x00000005, 12, 15, 0x0000000f},
  38. {"setend" , 2 , 6 , 16, 31, 0x0000f101, 4, 7, 0x00000000},
  39. {"clrex" , 1 , 6 , 0, 31, 0xf57ff01f},
  40. {"rev16" , 2 , 6 , 16, 27, 0x000006bf, 4, 11, 0x000000fb},
  41. {"usad8" , 3 , 6 , 20, 27, 0x00000078, 12, 15, 0x0000000f, 4, 7, 0x00000001},
  42. {"sxtb" , 2 , 6 , 16, 27, 0x000006af, 4, 7, 0x00000007},
  43. {"uxtb" , 2 , 6 , 16, 27, 0x000006ef, 4, 7, 0x00000007},
  44. {"sxth" , 2 , 6 , 16, 27, 0x000006bf, 4, 7, 0x00000007},
  45. {"sxtb16" , 2 , 6 , 16, 27, 0x0000068f, 4, 7, 0x00000007},
  46. {"uxth" , 2 , 6 , 16, 27, 0x000006ff, 4, 7, 0x00000007},
  47. {"uxtb16" , 2 , 6 , 16, 27, 0x000006cf, 4, 7, 0x00000007},
  48. {"cpy" , 2 , 6 , 20, 27, 0x0000001a, 4, 11, 0x00000000},
  49. {"uxtab" , 2 , 6 , 20, 27, 0x0000006e, 4, 9, 0x00000007},
  50. {"ssub8" , 2 , 6 , 20, 27, 0x00000061, 4, 7, 0x0000000f},
  51. {"shsub8" , 2 , 6 , 20, 27, 0x00000063, 4, 7, 0x0000000f},
  52. {"ssubaddx" , 2 , 6 , 20, 27, 0x00000061, 4, 7, 0x00000005},
  53. {"strex" , 2 , 6 , 20, 27, 0x00000018, 4, 7, 0x00000009},
  54. {"strexb" , 2 , 7 , 20, 27, 0x0000001c, 4, 7, 0x00000009},
  55. {"swp" , 2 , 0 , 20, 27, 0x00000010, 4, 7, 0x00000009},
  56. {"swpb" , 2 , 0 , 20, 27, 0x00000014, 4, 7, 0x00000009},
  57. {"ssub16" , 2 , 6 , 20, 27, 0x00000061, 4, 7, 0x00000007},
  58. {"ssat16" , 2 , 6 , 20, 27, 0x0000006a, 4, 7, 0x00000003},
  59. {"shsubaddx" , 2 , 6 , 20, 27, 0x00000063, 4, 7, 0x00000005},
  60. {"qsubaddx" , 2 , 6 , 20, 27, 0x00000062, 4, 7, 0x00000005},
  61. {"shaddsubx" , 2 , 6 , 20, 27, 0x00000063, 4, 7, 0x00000003},
  62. {"shadd8" , 2 , 6 , 20, 27, 0x00000063, 4, 7, 0x00000009},
  63. {"shadd16" , 2 , 6 , 20, 27, 0x00000063, 4, 7, 0x00000001},
  64. {"sel" , 2 , 6 , 20, 27, 0x00000068, 4, 7, 0x0000000b},
  65. {"saddsubx" , 2 , 6 , 20, 27, 0x00000061, 4, 7, 0x00000003},
  66. {"sadd8" , 2 , 6 , 20, 27, 0x00000061, 4, 7, 0x00000009},
  67. {"sadd16" , 2 , 6 , 20, 27, 0x00000061, 4, 7, 0x00000001},
  68. {"shsub16" , 2 , 6 , 20, 27, 0x00000063, 4, 7, 0x00000007},
  69. {"umaal" , 2 , 6 , 20, 27, 0x00000004, 4, 7, 0x00000009},
  70. {"uxtab16" , 2 , 6 , 20, 27, 0x0000006c, 4, 7, 0x00000007},
  71. {"usubaddx" , 2 , 6 , 20, 27, 0x00000065, 4, 7, 0x00000005},
  72. {"usub8" , 2 , 6 , 20, 27, 0x00000065, 4, 7, 0x0000000f},
  73. {"usub16" , 2 , 6 , 20, 27, 0x00000065, 4, 7, 0x00000007},
  74. {"usat16" , 2 , 6 , 20, 27, 0x0000006e, 4, 7, 0x00000003},
  75. {"usada8" , 2 , 6 , 20, 27, 0x00000078, 4, 7, 0x00000001},
  76. {"uqsubaddx" , 2 , 6 , 20, 27, 0x00000066, 4, 7, 0x00000005},
  77. {"uqsub8" , 2 , 6 , 20, 27, 0x00000066, 4, 7, 0x0000000f},
  78. {"uqsub16" , 2 , 6 , 20, 27, 0x00000066, 4, 7, 0x00000007},
  79. {"uqaddsubx" , 2 , 6 , 20, 27, 0x00000066, 4, 7, 0x00000003},
  80. {"uqadd8" , 2 , 6 , 20, 27, 0x00000066, 4, 7, 0x00000009},
  81. {"uqadd16" , 2 , 6 , 20, 27, 0x00000066, 4, 7, 0x00000001},
  82. {"sxtab" , 2 , 6 , 20, 27, 0x0000006a, 4, 7, 0x00000007},
  83. {"uhsubaddx" , 2 , 6 , 20, 27, 0x00000067, 4, 7, 0x00000005},
  84. {"uhsub8" , 2 , 6 , 20, 27, 0x00000067, 4, 7, 0x0000000f},
  85. {"uhsub16" , 2 , 6 , 20, 27, 0x00000067, 4, 7, 0x00000007},
  86. {"uhaddsubx" , 2 , 6 , 20, 27, 0x00000067, 4, 7, 0x00000003},
  87. {"uhadd8" , 2 , 6 , 20, 27, 0x00000067, 4, 7, 0x00000009},
  88. {"uhadd16" , 2 , 6 , 20, 27, 0x00000067, 4, 7, 0x00000001},
  89. {"uaddsubx" , 2 , 6 , 20, 27, 0x00000065, 4, 7, 0x00000003},
  90. {"uadd8" , 2 , 6 , 20, 27, 0x00000065, 4, 7, 0x00000009},
  91. {"uadd16" , 2 , 6 , 20, 27, 0x00000065, 4, 7, 0x00000001},
  92. {"sxtah" , 2 , 6 , 20, 27, 0x0000006b, 4, 7, 0x00000007},
  93. {"sxtab16" , 2 , 6 , 20, 27, 0x00000068, 4, 7, 0x00000007},
  94. {"qadd8" , 2 , 6 , 20, 27, 0x00000062, 4, 7, 0x00000009},
  95. {"bxj" , 2 , 5 , 20, 27, 0x00000012, 4, 7, 0x00000002},
  96. {"clz" , 2 , 3 , 20, 27, 0x00000016, 4, 7, 0x00000001},
  97. {"uxtah" , 2 , 6 , 20, 27, 0x0000006f, 4, 7, 0x00000007},
  98. {"bx" , 2 , 2 , 20, 27, 0x00000012, 4, 7, 0x00000001},
  99. {"rev" , 2 , 6 , 20, 27, 0x0000006b, 4, 7, 0x00000003},
  100. {"blx" , 2 , 3 , 20, 27, 0x00000012, 4, 7, 0x00000003},
  101. {"revsh" , 2 , 6 , 20, 27, 0x0000006f, 4, 7, 0x0000000b},
  102. {"qadd" , 2 , 4 , 20, 27, 0x00000010, 4, 7, 0x00000005},
  103. {"qadd16" , 2 , 6 , 20, 27, 0x00000062, 4, 7, 0x00000001},
  104. {"qaddsubx" , 2 , 6 , 20, 27, 0x00000062, 4, 7, 0x00000003},
  105. {"ldrex" , 2 , 0 , 20, 27, 0x00000019, 4, 7, 0x00000009},
  106. {"qdadd" , 2 , 4 , 20, 27, 0x00000014, 4, 7, 0x00000005},
  107. {"qdsub" , 2 , 4 , 20, 27, 0x00000016, 4, 7, 0x00000005},
  108. {"qsub" , 2 , 4 , 20, 27, 0x00000012, 4, 7, 0x00000005},
  109. {"ldrexb" , 2 , 7 , 20, 27, 0x0000001d, 4, 7, 0x00000009},
  110. {"qsub8" , 2 , 6 , 20, 27, 0x00000062, 4, 7, 0x0000000f},
  111. {"qsub16" , 2 , 6 , 20, 27, 0x00000062, 4, 7, 0x00000007},
  112. {"smuad" , 4 , 6 , 20, 27, 0x00000070, 12, 15, 0x0000000f, 6, 7, 0x00000000, 4, 4, 0x00000001},
  113. {"smmul" , 4 , 6 , 20, 27, 0x00000075, 12, 15, 0x0000000f, 6, 7, 0x00000000, 4, 4, 0x00000001},
  114. {"smusd" , 4 , 6 , 20, 27, 0x00000070, 12, 15, 0x0000000f, 6, 7, 0x00000001, 4, 4, 0x00000001},
  115. {"smlsd" , 3 , 6 , 20, 27, 0x00000070, 6, 7, 0x00000001, 4, 4, 0x00000001},
  116. {"smlsld" , 3 , 6 , 20, 27, 0x00000074, 6, 7, 0x00000001, 4, 4, 0x00000001},
  117. {"smmla" , 3 , 6 , 20, 27, 0x00000075, 6, 7, 0x00000000, 4, 4, 0x00000001},
  118. {"smmls" , 3 , 6 , 20, 27, 0x00000075, 6, 7, 0x00000003, 4, 4, 0x00000001},
  119. {"smlald" , 3 , 6 , 20, 27, 0x00000074, 6, 7, 0x00000000, 4, 4, 0x00000001},
  120. {"smlad" , 3 , 6 , 20, 27, 0x00000070, 6, 7, 0x00000000, 4, 4, 0x00000001},
  121. {"smlaw" , 3 , 4 , 20, 27, 0x00000012, 7, 7, 0x00000001, 4, 5, 0x00000000},
  122. {"smulw" , 3 , 4 , 20, 27, 0x00000012, 7, 7, 0x00000001, 4, 5, 0x00000002},
  123. {"pkhtb" , 2 , 6 , 20, 27, 0x00000068, 4, 6, 0x00000005},
  124. {"pkhbt" , 2 , 6 , 20, 27, 0x00000068, 4, 6, 0x00000001},
  125. {"smul" , 3 , 4 , 20, 27, 0x00000016, 7, 7, 0x00000001, 4, 4, 0x00000000},
  126. {"smlalxy" , 3 , 4 , 20, 27, 0x00000014, 7, 7, 0x00000001, 4, 4, 0x00000000},
  127. // {"smlal" , 2 , 4 , 21, 27, 0x00000007, 4, 7, 0x00000009},
  128. {"smla" , 3 , 4 , 20, 27, 0x00000010, 7, 7, 0x00000001, 4, 4, 0x00000000},
  129. {"mcrr" , 1 , 6 , 20, 27, 0x000000c4},
  130. {"mrrc" , 1 , 6 , 20, 27, 0x000000c5},
  131. {"cmp" , 2 , 0 , 26, 27, 0x00000000, 20, 24, 0x00000015},
  132. {"tst" , 2 , 0 , 26, 27, 0x00000000, 20, 24, 0x00000011},
  133. {"teq" , 2 , 0 , 26, 27, 0x00000000, 20, 24, 0x00000013},
  134. {"cmn" , 2 , 0 , 26, 27, 0x00000000, 20, 24, 0x00000017},
  135. {"smull" , 2 , 0 , 21, 27, 0x00000006, 4, 7, 0x00000009},
  136. {"umull" , 2 , 0 , 21, 27, 0x00000004, 4, 7, 0x00000009},
  137. {"umlal" , 2 , 0 , 21, 27, 0x00000005, 4, 7, 0x00000009},
  138. {"smlal" , 2 , 0 , 21, 27, 0x00000007, 4, 7, 0x00000009},
  139. {"mul" , 2 , 0 , 21, 27, 0x00000000, 4, 7, 0x00000009},
  140. {"mla" , 2 , 0 , 21, 27, 0x00000001, 4, 7, 0x00000009},
  141. {"ssat" , 2 , 6 , 21, 27, 0x00000035, 4, 5, 0x00000001},
  142. {"usat" , 2 , 6 , 21, 27, 0x00000037, 4, 5, 0x00000001},
  143. {"mrs" , 4 , 0 , 23, 27, 0x00000002, 20, 21, 0x00000000, 16, 19, 0x0000000f, 0, 11, 0x00000000},
  144. {"msr" , 3 , 0 , 23, 27, 0x00000002, 20, 21, 0x00000002, 4, 7, 0x00000000},
  145. {"and" , 2 , 0 , 26, 27, 0x00000000, 21, 24, 0x00000000},
  146. {"bic" , 2 , 0 , 26, 27, 0x00000000, 21, 24, 0x0000000e},
  147. {"ldm" , 3 , 0 , 25, 27, 0x00000004, 20, 22, 0x00000005, 15, 15, 0x00000000},
  148. {"eor" , 2 , 0 , 26, 27, 0x00000000, 21, 24, 0x00000001},
  149. {"add" , 2 , 0 , 26, 27, 0x00000000, 21, 24, 0x00000004},
  150. {"rsb" , 2 , 0 , 26, 27, 0x00000000, 21, 24, 0x00000003},
  151. {"rsc" , 2 , 0 , 26, 27, 0x00000000, 21, 24, 0x00000007},
  152. {"sbc" , 2 , 0 , 26, 27, 0x00000000, 21, 24, 0x00000006},
  153. {"adc" , 2 , 0 , 26, 27, 0x00000000, 21, 24, 0x00000005},
  154. {"sub" , 2 , 0 , 26, 27, 0x00000000, 21, 24, 0x00000002},
  155. {"orr" , 2 , 0 , 26, 27, 0x00000000, 21, 24, 0x0000000c},
  156. {"mvn" , 2 , 0 , 26, 27, 0x00000000, 21, 24, 0x0000000f},
  157. {"mov" , 2 , 0 , 26, 27, 0x00000000, 21, 24, 0x0000000d},
  158. {"stm" , 2 , 0 , 25, 27, 0x00000004, 20, 22, 0x00000004},
  159. {"ldm" , 4 , 0 , 25, 27, 0x00000004, 22, 22, 0x00000001, 20, 20, 0x00000001, 15, 15, 0x00000001},
  160. {"ldrsh" , 3 , 2 , 25, 27, 0x00000000, 20, 20, 0x00000001, 4, 7, 0x0000000f},
  161. {"stm" , 3 , 0 , 25, 27, 0x00000004, 22, 22, 0x00000000, 20, 20, 0x00000000},
  162. {"ldm" , 3 , 0 , 25, 27, 0x00000004, 22, 22, 0x00000000, 20, 20, 0x00000001},
  163. {"ldrsb" , 3 , 2 , 25, 27, 0x00000000, 20, 20, 0x00000001, 4, 7, 0x0000000d},
  164. {"strd" , 3 , 4 , 25, 27, 0x00000000, 20, 20, 0x00000000, 4, 7, 0x0000000f},
  165. {"ldrh" , 3 , 0 , 25, 27, 0x00000000, 20, 20, 0x00000001, 4, 7, 0x0000000b},
  166. {"strh" , 3 , 0 , 25, 27, 0x00000000, 20, 20, 0x00000000, 4, 7, 0x0000000b},
  167. {"ldrd" , 3 , 4 , 25, 27, 0x00000000, 20, 20, 0x00000000, 4, 7, 0x0000000d},
  168. {"strt" , 3 , 0 , 26, 27, 0x00000001, 24, 24, 0x00000000, 20, 22, 0x00000002},
  169. {"strbt" , 3 , 0 , 26, 27, 0x00000001, 24, 24, 0x00000000, 20, 22, 0x00000006},
  170. {"ldrbt" , 3 , 0 , 26, 27, 0x00000001, 24, 24, 0x00000000, 20, 22, 0x00000007},
  171. {"ldrt" , 3 , 0 , 26, 27, 0x00000001, 24, 24, 0x00000000, 20, 22, 0x00000003},
  172. {"mrc" , 3 , 6 , 24, 27, 0x0000000e, 20, 20, 0x00000001, 4, 4, 0x00000001},
  173. {"mcr" , 3 , 0 , 24, 27, 0x0000000e, 20, 20, 0x00000000, 4, 4, 0x00000001},
  174. {"msr" , 2 , 0 , 23, 27, 0x00000006, 20, 21, 0x00000002},
  175. {"ldrb" , 3 , 0 , 26, 27, 0x00000001, 22, 22, 0x00000001, 20, 20, 0x00000001},
  176. {"strb" , 3 , 0 , 26, 27, 0x00000001, 22, 22, 0x00000001, 20, 20, 0x00000000},
  177. {"ldr" , 4 , 0 , 28, 31, 0x0000000e, 26, 27, 0x00000001, 22, 22, 0x00000000, 20, 20, 0x00000001},
  178. {"ldrcond" , 3 , 0 , 26, 27, 0x00000001, 22, 22, 0x00000000, 20, 20, 0x00000001},
  179. {"str" , 3 , 0 , 26, 27, 0x00000001, 22, 22, 0x00000000, 20, 20, 0x00000000},
  180. {"cdp" , 2 , 0 , 24, 27, 0x0000000e, 4, 4, 0x00000000},
  181. {"stc" , 2 , 0 , 25, 27, 0x00000006, 20, 20, 0x00000000},
  182. {"ldc" , 2 , 0 , 25, 27, 0x00000006, 20, 20, 0x00000001},
  183. {"swi" , 1 , 0 , 24, 27, 0x0000000f},
  184. {"bbl" , 1 , 0 , 25, 27, 0x00000005},
  185. };
  186. const ISEITEM arm_exclusion_code[] = {
  187. #define VFP_DECODE_EXCLUSION
  188. #include "core/arm/skyeye_common/vfp/vfpinstr.cpp"
  189. #undef VFP_DECODE_EXCLUSION
  190. {"srs" , 0 , 6 , 0},
  191. {"rfe" , 0 , 6 , 0},
  192. {"bkpt" , 0 , 3 , 0},
  193. {"blx" , 0 , 3 , 0},
  194. {"cps" , 0 , 6 , 0},
  195. {"pld" , 0 , 4 , 0},
  196. {"setend" , 0 , 6 , 0},
  197. {"clrex" , 0 , 6 , 0},
  198. {"rev16" , 0 , 6 , 0},
  199. {"usad8" , 0 , 6 , 0},
  200. {"sxtb" , 0 , 6 , 0},
  201. {"uxtb" , 0 , 6 , 0},
  202. {"sxth" , 0 , 6 , 0},
  203. {"sxtb16" , 0 , 6 , 0},
  204. {"uxth" , 0 , 6 , 0},
  205. {"uxtb16" , 0 , 6 , 0},
  206. {"cpy" , 0 , 6 , 0},
  207. {"uxtab" , 0 , 6 , 0},
  208. {"ssub8" , 0 , 6 , 0},
  209. {"shsub8" , 0 , 6 , 0},
  210. {"ssubaddx" , 0 , 6 , 0},
  211. {"strex" , 0 , 6 , 0},
  212. {"strexb" , 0 , 7 , 0},
  213. {"swp" , 0 , 0 , 0},
  214. {"swpb" , 0 , 0 , 0},
  215. {"ssub16" , 0 , 6 , 0},
  216. {"ssat16" , 0 , 6 , 0},
  217. {"shsubaddx" , 0 , 6 , 0},
  218. {"qsubaddx" , 0 , 6 , 0},
  219. {"shaddsubx" , 0 , 6 , 0},
  220. {"shadd8" , 0 , 6 , 0},
  221. {"shadd16" , 0 , 6 , 0},
  222. {"sel" , 0 , 6 , 0},
  223. {"saddsubx" , 0 , 6 , 0},
  224. {"sadd8" , 0 , 6 , 0},
  225. {"sadd16" , 0 , 6 , 0},
  226. {"shsub16" , 0 , 6 , 0},
  227. {"umaal" , 0 , 6 , 0},
  228. {"uxtab16" , 0 , 6 , 0},
  229. {"usubaddx" , 0 , 6 , 0},
  230. {"usub8" , 0 , 6 , 0},
  231. {"usub16" , 0 , 6 , 0},
  232. {"usat16" , 0 , 6 , 0},
  233. {"usada8" , 0 , 6 , 0},
  234. {"uqsubaddx" , 0 , 6 , 0},
  235. {"uqsub8" , 0 , 6 , 0},
  236. {"uqsub16" , 0 , 6 , 0},
  237. {"uqaddsubx" , 0 , 6 , 0},
  238. {"uqadd8" , 0 , 6 , 0},
  239. {"uqadd16" , 0 , 6 , 0},
  240. {"sxtab" , 0 , 6 , 0},
  241. {"uhsubaddx" , 0 , 6 , 0},
  242. {"uhsub8" , 0 , 6 , 0},
  243. {"uhsub16" , 0 , 6 , 0},
  244. {"uhaddsubx" , 0 , 6 , 0},
  245. {"uhadd8" , 0 , 6 , 0},
  246. {"uhadd16" , 0 , 6 , 0},
  247. {"uaddsubx" , 0 , 6 , 0},
  248. {"uadd8" , 0 , 6 , 0},
  249. {"uadd16" , 0 , 6 , 0},
  250. {"sxtah" , 0 , 6 , 0},
  251. {"sxtab16" , 0 , 6 , 0},
  252. {"qadd8" , 0 , 6 , 0},
  253. {"bxj" , 0 , 5 , 0},
  254. {"clz" , 0 , 3 , 0},
  255. {"uxtah" , 0 , 6 , 0},
  256. {"bx" , 0 , 2 , 0},
  257. {"rev" , 0 , 6 , 0},
  258. {"blx" , 0 , 3 , 0},
  259. {"revsh" , 0 , 6 , 0},
  260. {"qadd" , 0 , 4 , 0},
  261. {"qadd16" , 0 , 6 , 0},
  262. {"qaddsubx" , 0 , 6 , 0},
  263. {"ldrex" , 0 , 0 , 0},
  264. {"qdadd" , 0 , 4 , 0},
  265. {"qdsub" , 0 , 4 , 0},
  266. {"qsub" , 0 , 4 , 0},
  267. {"ldrexb" , 0 , 7 , 0},
  268. {"qsub8" , 0 , 6 , 0},
  269. {"qsub16" , 0 , 6 , 0},
  270. {"smuad" , 0 , 6 , 0},
  271. {"smmul" , 0 , 6 , 0},
  272. {"smusd" , 0 , 6 , 0},
  273. {"smlsd" , 0 , 6 , 0},
  274. {"smlsld" , 0 , 6 , 0},
  275. {"smmla" , 0 , 6 , 0},
  276. {"smmls" , 0 , 6 , 0},
  277. {"smlald" , 0 , 6 , 0},
  278. {"smlad" , 0 , 6 , 0},
  279. {"smlaw" , 0 , 4 , 0},
  280. {"smulw" , 0 , 4 , 0},
  281. {"pkhtb" , 0 , 6 , 0},
  282. {"pkhbt" , 0 , 6 , 0},
  283. {"smul" , 0 , 4 , 0},
  284. {"smlal" , 0 , 4 , 0},
  285. {"smla" , 0 , 4 , 0},
  286. {"mcrr" , 0 , 6 , 0},
  287. {"mrrc" , 0 , 6 , 0},
  288. {"cmp" , 3 , 0 , 4, 4, 0x00000001, 7, 7, 0x00000001, 25, 25, 0x00000000},
  289. {"tst" , 3 , 0 , 4, 4, 0x00000001, 7, 7, 0x00000001, 25, 25, 0x00000000},
  290. {"teq" , 3 , 0 , 4, 4, 0x00000001, 7, 7, 0x00000001, 25, 25, 0x00000000},
  291. {"cmn" , 3 , 0 , 4, 4, 0x00000001, 7, 7, 0x00000001, 25, 25, 0x00000000},
  292. {"smull" , 0 , 0 , 0},
  293. {"umull" , 0 , 0 , 0},
  294. {"umlal" , 0 , 0 , 0},
  295. {"smlal" , 0 , 0 , 0},
  296. {"mul" , 0 , 0 , 0},
  297. {"mla" , 0 , 0 , 0},
  298. {"ssat" , 0 , 6 , 0},
  299. {"usat" , 0 , 6 , 0},
  300. {"mrs" , 0 , 0 , 0},
  301. {"msr" , 0 , 0 , 0},
  302. {"and" , 3 , 0 , 4, 4, 0x00000001, 7, 7, 0x00000001, 25, 25, 0x00000000},
  303. {"bic" , 3 , 0 , 4, 4, 0x00000001, 7, 7, 0x00000001, 25, 25, 0x00000000},
  304. {"ldm" , 0 , 0 , 0},
  305. {"eor" , 3 , 0 , 4, 4, 0x00000001, 7, 7, 0x00000001, 25, 25, 0x00000000},
  306. {"add" , 3 , 0 , 4, 4, 0x00000001, 7, 7, 0x00000001, 25, 25, 0x00000000},
  307. {"rsb" , 3 , 0 , 4, 4, 0x00000001, 7, 7, 0x00000001, 25, 25, 0x00000000},
  308. {"rsc" , 3 , 0 , 4, 4, 0x00000001, 7, 7, 0x00000001, 25, 25, 0x00000000},
  309. {"sbc" , 3 , 0 , 4, 4, 0x00000001, 7, 7, 0x00000001, 25, 25, 0x00000000},
  310. {"adc" , 3 , 0 , 4, 4, 0x00000001, 7, 7, 0x00000001, 25, 25, 0x00000000},
  311. {"sub" , 3 , 0 , 4, 4, 0x00000001, 7, 7, 0x00000001, 25, 25, 0x00000000},
  312. {"orr" , 3 , 0 , 4, 4, 0x00000001, 7, 7, 0x00000001, 25, 25, 0x00000000},
  313. {"mvn" , 3 , 0 , 4, 4, 0x00000001, 7, 7, 0x00000001, 25, 25, 0x00000000},
  314. {"mov" , 3 , 0 , 4, 4, 0x00000001, 7, 7, 0x00000001, 25, 25, 0x00000000},
  315. {"stm" , 0 , 0 , 0},
  316. {"ldm" , 0 , 0 , 0},
  317. {"ldrsh" , 0 , 2 , 0},
  318. {"stm" , 0 , 0 , 0},
  319. {"ldm" , 0 , 0 , 0},
  320. {"ldrsb" , 0 , 2 , 0},
  321. {"strd" , 0 , 4 , 0},
  322. {"ldrh" , 0 , 0 , 0},
  323. {"strh" , 0 , 0 , 0},
  324. {"ldrd" , 0 , 4 , 0},
  325. {"strt" , 0 , 0 , 0},
  326. {"strbt" , 0 , 0 , 0},
  327. {"ldrbt" , 0 , 0 , 0},
  328. {"ldrt" , 0 , 0 , 0},
  329. {"mrc" , 0 , 6 , 0},
  330. {"mcr" , 0 , 0 , 0},
  331. {"msr" , 0 , 0 , 0},
  332. {"ldrb" , 0 , 0 , 0},
  333. {"strb" , 0 , 0 , 0},
  334. {"ldr" , 0 , 0 , 0},
  335. {"ldrcond" , 1 , 0 , 28, 31, 0x0000000e},
  336. {"str" , 0 , 0 , 0},
  337. {"cdp" , 0 , 0 , 0},
  338. {"stc" , 0 , 0 , 0},
  339. {"ldc" , 0 , 0 , 0},
  340. {"swi" , 0 , 0 , 0},
  341. {"bbl" , 0 , 0 , 0},
  342. {"bl_1_thumb", 0, INVALID, 0},/* should be table[-4] */
  343. {"bl_2_thumb", 0, INVALID, 0}, /* should be located at the end of the table[-3] */
  344. {"blx_1_thumb", 0, INVALID, 0}, /* should be located at table[-2] */
  345. {"invalid", 0, INVALID, 0}
  346. };
  347. int decode_arm_instr(uint32_t instr, int32_t *idx)
  348. {
  349. int n = 0;
  350. int base = 0;
  351. int ret = DECODE_FAILURE;
  352. int i = 0;
  353. int instr_slots = sizeof(arm_instruction)/sizeof(ISEITEM);
  354. for (i = 0; i < instr_slots; i++)
  355. {
  356. // ret = DECODE_SUCCESS;
  357. n = arm_instruction[i].attribute_value;
  358. base = 0;
  359. while (n) {
  360. if (arm_instruction[i].content[base + 1] == 31 && arm_instruction[i].content[base] == 0) {
  361. /* clrex */
  362. if (instr != arm_instruction[i].content[base + 2]) {
  363. break;
  364. }
  365. } else if (BITS(arm_instruction[i].content[base], arm_instruction[i].content[base + 1]) != arm_instruction[i].content[base + 2]) {
  366. break;
  367. }
  368. base += 3;
  369. n --;
  370. }
  371. //All conditions is satisfied.
  372. if (n == 0)
  373. ret = DECODE_SUCCESS;
  374. if (ret == DECODE_SUCCESS) {
  375. n = arm_exclusion_code[i].attribute_value;
  376. if (n != 0) {
  377. base = 0;
  378. while (n) {
  379. if (BITS(arm_exclusion_code[i].content[base], arm_exclusion_code[i].content[base + 1]) != arm_exclusion_code[i].content[base + 2]) {
  380. break; }
  381. base += 3;
  382. n --;
  383. }
  384. //All conditions is satisfied.
  385. if (n == 0)
  386. ret = DECODE_FAILURE;
  387. }
  388. }
  389. if (ret == DECODE_SUCCESS) {
  390. *idx = i;
  391. return ret;
  392. }
  393. }
  394. return ret;
  395. }