crabstone 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (302) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.md +61 -0
  3. data/LICENSE +25 -0
  4. data/MANIFEST +312 -0
  5. data/README.md +103 -0
  6. data/Rakefile +27 -0
  7. data/bin/genconst +66 -0
  8. data/bin/genreg +99 -0
  9. data/crabstone.gemspec +27 -0
  10. data/examples/hello_world.rb +43 -0
  11. data/lib/arch/arm.rb +128 -0
  12. data/lib/arch/arm64.rb +167 -0
  13. data/lib/arch/arm64_const.rb +1055 -0
  14. data/lib/arch/arm64_registers.rb +295 -0
  15. data/lib/arch/arm_const.rb +777 -0
  16. data/lib/arch/arm_registers.rb +149 -0
  17. data/lib/arch/mips.rb +78 -0
  18. data/lib/arch/mips_const.rb +850 -0
  19. data/lib/arch/mips_registers.rb +208 -0
  20. data/lib/arch/ppc.rb +90 -0
  21. data/lib/arch/ppc_const.rb +1181 -0
  22. data/lib/arch/ppc_registers.rb +209 -0
  23. data/lib/arch/sparc.rb +79 -0
  24. data/lib/arch/sparc_const.rb +461 -0
  25. data/lib/arch/sparc_registers.rb +121 -0
  26. data/lib/arch/systemz.rb +79 -0
  27. data/lib/arch/sysz_const.rb +779 -0
  28. data/lib/arch/sysz_registers.rb +66 -0
  29. data/lib/arch/x86.rb +107 -0
  30. data/lib/arch/x86_const.rb +1698 -0
  31. data/lib/arch/x86_registers.rb +265 -0
  32. data/lib/arch/xcore.rb +78 -0
  33. data/lib/arch/xcore_const.rb +185 -0
  34. data/lib/arch/xcore_registers.rb +57 -0
  35. data/lib/crabstone.rb +564 -0
  36. data/test/MC/AArch64/basic-a64-instructions.s.cs +2014 -0
  37. data/test/MC/AArch64/gicv3-regs.s.cs +111 -0
  38. data/test/MC/AArch64/neon-2velem.s.cs +113 -0
  39. data/test/MC/AArch64/neon-3vdiff.s.cs +143 -0
  40. data/test/MC/AArch64/neon-aba-abd.s.cs +28 -0
  41. data/test/MC/AArch64/neon-across.s.cs +40 -0
  42. data/test/MC/AArch64/neon-add-pairwise.s.cs +11 -0
  43. data/test/MC/AArch64/neon-add-sub-instructions.s.cs +21 -0
  44. data/test/MC/AArch64/neon-bitwise-instructions.s.cs +17 -0
  45. data/test/MC/AArch64/neon-compare-instructions.s.cs +136 -0
  46. data/test/MC/AArch64/neon-crypto.s.cs +15 -0
  47. data/test/MC/AArch64/neon-extract.s.cs +3 -0
  48. data/test/MC/AArch64/neon-facge-facgt.s.cs +13 -0
  49. data/test/MC/AArch64/neon-frsqrt-frecp.s.cs +7 -0
  50. data/test/MC/AArch64/neon-halving-add-sub.s.cs +25 -0
  51. data/test/MC/AArch64/neon-max-min-pairwise.s.cs +37 -0
  52. data/test/MC/AArch64/neon-max-min.s.cs +37 -0
  53. data/test/MC/AArch64/neon-mla-mls-instructions.s.cs +19 -0
  54. data/test/MC/AArch64/neon-mov.s.cs +74 -0
  55. data/test/MC/AArch64/neon-mul-div-instructions.s.cs +24 -0
  56. data/test/MC/AArch64/neon-perm.s.cs +43 -0
  57. data/test/MC/AArch64/neon-rounding-halving-add.s.cs +13 -0
  58. data/test/MC/AArch64/neon-rounding-shift.s.cs +15 -0
  59. data/test/MC/AArch64/neon-saturating-add-sub.s.cs +29 -0
  60. data/test/MC/AArch64/neon-saturating-rounding-shift.s.cs +15 -0
  61. data/test/MC/AArch64/neon-saturating-shift.s.cs +15 -0
  62. data/test/MC/AArch64/neon-scalar-abs.s.cs +8 -0
  63. data/test/MC/AArch64/neon-scalar-add-sub.s.cs +3 -0
  64. data/test/MC/AArch64/neon-scalar-by-elem-mla.s.cs +13 -0
  65. data/test/MC/AArch64/neon-scalar-by-elem-mul.s.cs +13 -0
  66. data/test/MC/AArch64/neon-scalar-by-elem-saturating-mla.s.cs +15 -0
  67. data/test/MC/AArch64/neon-scalar-by-elem-saturating-mul.s.cs +18 -0
  68. data/test/MC/AArch64/neon-scalar-compare.s.cs +12 -0
  69. data/test/MC/AArch64/neon-scalar-cvt.s.cs +34 -0
  70. data/test/MC/AArch64/neon-scalar-dup.s.cs +23 -0
  71. data/test/MC/AArch64/neon-scalar-extract-narrow.s.cs +10 -0
  72. data/test/MC/AArch64/neon-scalar-fp-compare.s.cs +21 -0
  73. data/test/MC/AArch64/neon-scalar-mul.s.cs +13 -0
  74. data/test/MC/AArch64/neon-scalar-neg.s.cs +6 -0
  75. data/test/MC/AArch64/neon-scalar-recip.s.cs +11 -0
  76. data/test/MC/AArch64/neon-scalar-reduce-pairwise.s.cs +3 -0
  77. data/test/MC/AArch64/neon-scalar-rounding-shift.s.cs +3 -0
  78. data/test/MC/AArch64/neon-scalar-saturating-add-sub.s.cs +25 -0
  79. data/test/MC/AArch64/neon-scalar-saturating-rounding-shift.s.cs +9 -0
  80. data/test/MC/AArch64/neon-scalar-saturating-shift.s.cs +9 -0
  81. data/test/MC/AArch64/neon-scalar-shift-imm.s.cs +42 -0
  82. data/test/MC/AArch64/neon-scalar-shift.s.cs +3 -0
  83. data/test/MC/AArch64/neon-shift-left-long.s.cs +13 -0
  84. data/test/MC/AArch64/neon-shift.s.cs +22 -0
  85. data/test/MC/AArch64/neon-simd-copy.s.cs +42 -0
  86. data/test/MC/AArch64/neon-simd-ldst-multi-elem.s.cs +197 -0
  87. data/test/MC/AArch64/neon-simd-ldst-one-elem.s.cs +129 -0
  88. data/test/MC/AArch64/neon-simd-misc.s.cs +213 -0
  89. data/test/MC/AArch64/neon-simd-post-ldst-multi-elem.s.cs +107 -0
  90. data/test/MC/AArch64/neon-simd-shift.s.cs +151 -0
  91. data/test/MC/AArch64/neon-tbl.s.cs +21 -0
  92. data/test/MC/AArch64/trace-regs.s.cs +383 -0
  93. data/test/MC/ARM/arm-aliases.s.cs +7 -0
  94. data/test/MC/ARM/arm-arithmetic-aliases.s.cs +50 -0
  95. data/test/MC/ARM/arm-it-block.s.cs +2 -0
  96. data/test/MC/ARM/arm-memory-instructions.s.cs +138 -0
  97. data/test/MC/ARM/arm-shift-encoding.s.cs +50 -0
  98. data/test/MC/ARM/arm-thumb-trustzone.s.cs +3 -0
  99. data/test/MC/ARM/arm-trustzone.s.cs +3 -0
  100. data/test/MC/ARM/arm_addrmode2.s.cs +15 -0
  101. data/test/MC/ARM/arm_addrmode3.s.cs +9 -0
  102. data/test/MC/ARM/arm_instructions.s.cs +25 -0
  103. data/test/MC/ARM/basic-arm-instructions-v8.s.cs +10 -0
  104. data/test/MC/ARM/basic-arm-instructions.s.cs +997 -0
  105. data/test/MC/ARM/basic-thumb-instructions.s.cs +130 -0
  106. data/test/MC/ARM/basic-thumb2-instructions-v8.s.cs +1 -0
  107. data/test/MC/ARM/basic-thumb2-instructions.s.cs +1242 -0
  108. data/test/MC/ARM/crc32-thumb.s.cs +7 -0
  109. data/test/MC/ARM/crc32.s.cs +7 -0
  110. data/test/MC/ARM/dot-req.s.cs +3 -0
  111. data/test/MC/ARM/fp-armv8.s.cs +52 -0
  112. data/test/MC/ARM/idiv-thumb.s.cs +3 -0
  113. data/test/MC/ARM/idiv.s.cs +3 -0
  114. data/test/MC/ARM/load-store-acquire-release-v8-thumb.s.cs +15 -0
  115. data/test/MC/ARM/load-store-acquire-release-v8.s.cs +15 -0
  116. data/test/MC/ARM/mode-switch.s.cs +7 -0
  117. data/test/MC/ARM/neon-abs-encoding.s.cs +15 -0
  118. data/test/MC/ARM/neon-absdiff-encoding.s.cs +39 -0
  119. data/test/MC/ARM/neon-add-encoding.s.cs +119 -0
  120. data/test/MC/ARM/neon-bitcount-encoding.s.cs +15 -0
  121. data/test/MC/ARM/neon-bitwise-encoding.s.cs +126 -0
  122. data/test/MC/ARM/neon-cmp-encoding.s.cs +88 -0
  123. data/test/MC/ARM/neon-convert-encoding.s.cs +27 -0
  124. data/test/MC/ARM/neon-crypto.s.cs +16 -0
  125. data/test/MC/ARM/neon-dup-encoding.s.cs +13 -0
  126. data/test/MC/ARM/neon-minmax-encoding.s.cs +57 -0
  127. data/test/MC/ARM/neon-mov-encoding.s.cs +76 -0
  128. data/test/MC/ARM/neon-mul-accum-encoding.s.cs +39 -0
  129. data/test/MC/ARM/neon-mul-encoding.s.cs +72 -0
  130. data/test/MC/ARM/neon-neg-encoding.s.cs +15 -0
  131. data/test/MC/ARM/neon-pairwise-encoding.s.cs +47 -0
  132. data/test/MC/ARM/neon-reciprocal-encoding.s.cs +13 -0
  133. data/test/MC/ARM/neon-reverse-encoding.s.cs +13 -0
  134. data/test/MC/ARM/neon-satshift-encoding.s.cs +75 -0
  135. data/test/MC/ARM/neon-shift-encoding.s.cs +238 -0
  136. data/test/MC/ARM/neon-shiftaccum-encoding.s.cs +97 -0
  137. data/test/MC/ARM/neon-shuffle-encoding.s.cs +59 -0
  138. data/test/MC/ARM/neon-sub-encoding.s.cs +82 -0
  139. data/test/MC/ARM/neon-table-encoding.s.cs +9 -0
  140. data/test/MC/ARM/neon-v8.s.cs +38 -0
  141. data/test/MC/ARM/neon-vld-encoding.s.cs +213 -0
  142. data/test/MC/ARM/neon-vst-encoding.s.cs +120 -0
  143. data/test/MC/ARM/neon-vswp.s.cs +3 -0
  144. data/test/MC/ARM/neont2-abs-encoding.s.cs +15 -0
  145. data/test/MC/ARM/neont2-absdiff-encoding.s.cs +39 -0
  146. data/test/MC/ARM/neont2-add-encoding.s.cs +65 -0
  147. data/test/MC/ARM/neont2-bitcount-encoding.s.cs +15 -0
  148. data/test/MC/ARM/neont2-bitwise-encoding.s.cs +15 -0
  149. data/test/MC/ARM/neont2-cmp-encoding.s.cs +17 -0
  150. data/test/MC/ARM/neont2-convert-encoding.s.cs +19 -0
  151. data/test/MC/ARM/neont2-dup-encoding.s.cs +19 -0
  152. data/test/MC/ARM/neont2-minmax-encoding.s.cs +57 -0
  153. data/test/MC/ARM/neont2-mov-encoding.s.cs +58 -0
  154. data/test/MC/ARM/neont2-mul-accum-encoding.s.cs +41 -0
  155. data/test/MC/ARM/neont2-mul-encoding.s.cs +31 -0
  156. data/test/MC/ARM/neont2-neg-encoding.s.cs +15 -0
  157. data/test/MC/ARM/neont2-pairwise-encoding.s.cs +43 -0
  158. data/test/MC/ARM/neont2-reciprocal-encoding.s.cs +13 -0
  159. data/test/MC/ARM/neont2-reverse-encoding.s.cs +13 -0
  160. data/test/MC/ARM/neont2-satshift-encoding.s.cs +75 -0
  161. data/test/MC/ARM/neont2-shift-encoding.s.cs +80 -0
  162. data/test/MC/ARM/neont2-shiftaccum-encoding.s.cs +97 -0
  163. data/test/MC/ARM/neont2-shuffle-encoding.s.cs +23 -0
  164. data/test/MC/ARM/neont2-sub-encoding.s.cs +23 -0
  165. data/test/MC/ARM/neont2-table-encoding.s.cs +9 -0
  166. data/test/MC/ARM/neont2-vld-encoding.s.cs +51 -0
  167. data/test/MC/ARM/neont2-vst-encoding.s.cs +48 -0
  168. data/test/MC/ARM/simple-fp-encoding.s.cs +157 -0
  169. data/test/MC/ARM/thumb-fp-armv8.s.cs +51 -0
  170. data/test/MC/ARM/thumb-hints.s.cs +12 -0
  171. data/test/MC/ARM/thumb-neon-crypto.s.cs +16 -0
  172. data/test/MC/ARM/thumb-neon-v8.s.cs +38 -0
  173. data/test/MC/ARM/thumb-shift-encoding.s.cs +19 -0
  174. data/test/MC/ARM/thumb.s.cs +19 -0
  175. data/test/MC/ARM/thumb2-b.w-encodingT4.s.cs +2 -0
  176. data/test/MC/ARM/thumb2-branches.s.cs +85 -0
  177. data/test/MC/ARM/thumb2-mclass.s.cs +41 -0
  178. data/test/MC/ARM/thumb2-narrow-dp.ll.cs +379 -0
  179. data/test/MC/ARM/thumb2-pldw.s.cs +2 -0
  180. data/test/MC/ARM/vfp4-thumb.s.cs +13 -0
  181. data/test/MC/ARM/vfp4.s.cs +13 -0
  182. data/test/MC/ARM/vpush-vpop-thumb.s.cs +9 -0
  183. data/test/MC/ARM/vpush-vpop.s.cs +9 -0
  184. data/test/MC/Mips/hilo-addressing.s.cs +4 -0
  185. data/test/MC/Mips/micromips-alu-instructions-EB.s.cs +33 -0
  186. data/test/MC/Mips/micromips-alu-instructions.s.cs +33 -0
  187. data/test/MC/Mips/micromips-branch-instructions-EB.s.cs +11 -0
  188. data/test/MC/Mips/micromips-branch-instructions.s.cs +11 -0
  189. data/test/MC/Mips/micromips-expansions.s.cs +20 -0
  190. data/test/MC/Mips/micromips-jump-instructions-EB.s.cs +5 -0
  191. data/test/MC/Mips/micromips-jump-instructions.s.cs +6 -0
  192. data/test/MC/Mips/micromips-loadstore-instructions-EB.s.cs +9 -0
  193. data/test/MC/Mips/micromips-loadstore-instructions.s.cs +9 -0
  194. data/test/MC/Mips/micromips-loadstore-unaligned-EB.s.cs +5 -0
  195. data/test/MC/Mips/micromips-loadstore-unaligned.s.cs +5 -0
  196. data/test/MC/Mips/micromips-movcond-instructions-EB.s.cs +5 -0
  197. data/test/MC/Mips/micromips-movcond-instructions.s.cs +5 -0
  198. data/test/MC/Mips/micromips-multiply-instructions-EB.s.cs +5 -0
  199. data/test/MC/Mips/micromips-multiply-instructions.s.cs +5 -0
  200. data/test/MC/Mips/micromips-shift-instructions-EB.s.cs +9 -0
  201. data/test/MC/Mips/micromips-shift-instructions.s.cs +9 -0
  202. data/test/MC/Mips/micromips-trap-instructions-EB.s.cs +13 -0
  203. data/test/MC/Mips/micromips-trap-instructions.s.cs +13 -0
  204. data/test/MC/Mips/mips-alu-instructions.s.cs +53 -0
  205. data/test/MC/Mips/mips-control-instructions-64.s.cs +33 -0
  206. data/test/MC/Mips/mips-control-instructions.s.cs +33 -0
  207. data/test/MC/Mips/mips-coprocessor-encodings.s.cs +17 -0
  208. data/test/MC/Mips/mips-dsp-instructions.s.cs +43 -0
  209. data/test/MC/Mips/mips-expansions.s.cs +20 -0
  210. data/test/MC/Mips/mips-fpu-instructions.s.cs +93 -0
  211. data/test/MC/Mips/mips-jump-instructions.s.cs +1 -0
  212. data/test/MC/Mips/mips-memory-instructions.s.cs +17 -0
  213. data/test/MC/Mips/mips-register-names.s.cs +33 -0
  214. data/test/MC/Mips/mips64-alu-instructions.s.cs +47 -0
  215. data/test/MC/Mips/mips64-instructions.s.cs +3 -0
  216. data/test/MC/Mips/mips64-register-names.s.cs +33 -0
  217. data/test/MC/Mips/mips_directives.s.cs +12 -0
  218. data/test/MC/Mips/nabi-regs.s.cs +12 -0
  219. data/test/MC/Mips/set-at-directive.s.cs +6 -0
  220. data/test/MC/Mips/test_2r.s.cs +16 -0
  221. data/test/MC/Mips/test_2rf.s.cs +33 -0
  222. data/test/MC/Mips/test_3r.s.cs +243 -0
  223. data/test/MC/Mips/test_3rf.s.cs +83 -0
  224. data/test/MC/Mips/test_bit.s.cs +49 -0
  225. data/test/MC/Mips/test_cbranch.s.cs +11 -0
  226. data/test/MC/Mips/test_ctrlregs.s.cs +33 -0
  227. data/test/MC/Mips/test_elm.s.cs +16 -0
  228. data/test/MC/Mips/test_elm_insert.s.cs +4 -0
  229. data/test/MC/Mips/test_elm_insve.s.cs +5 -0
  230. data/test/MC/Mips/test_i10.s.cs +5 -0
  231. data/test/MC/Mips/test_i5.s.cs +45 -0
  232. data/test/MC/Mips/test_i8.s.cs +11 -0
  233. data/test/MC/Mips/test_lsa.s.cs +5 -0
  234. data/test/MC/Mips/test_mi10.s.cs +24 -0
  235. data/test/MC/Mips/test_vec.s.cs +8 -0
  236. data/test/MC/PowerPC/ppc64-encoding-bookII.s.cs +25 -0
  237. data/test/MC/PowerPC/ppc64-encoding-bookIII.s.cs +35 -0
  238. data/test/MC/PowerPC/ppc64-encoding-ext.s.cs +535 -0
  239. data/test/MC/PowerPC/ppc64-encoding-fp.s.cs +110 -0
  240. data/test/MC/PowerPC/ppc64-encoding-vmx.s.cs +170 -0
  241. data/test/MC/PowerPC/ppc64-encoding.s.cs +202 -0
  242. data/test/MC/PowerPC/ppc64-operands.s.cs +32 -0
  243. data/test/MC/README +6 -0
  244. data/test/MC/Sparc/sparc-alu-instructions.s.cs +47 -0
  245. data/test/MC/Sparc/sparc-atomic-instructions.s.cs +7 -0
  246. data/test/MC/Sparc/sparc-ctrl-instructions.s.cs +11 -0
  247. data/test/MC/Sparc/sparc-fp-instructions.s.cs +59 -0
  248. data/test/MC/Sparc/sparc-mem-instructions.s.cs +25 -0
  249. data/test/MC/Sparc/sparc-vis.s.cs +2 -0
  250. data/test/MC/Sparc/sparc64-alu-instructions.s.cs +13 -0
  251. data/test/MC/Sparc/sparc64-ctrl-instructions.s.cs +102 -0
  252. data/test/MC/Sparc/sparcv8-instructions.s.cs +7 -0
  253. data/test/MC/Sparc/sparcv9-instructions.s.cs +1 -0
  254. data/test/MC/SystemZ/insn-good-z196.s.cs +589 -0
  255. data/test/MC/SystemZ/insn-good.s.cs +2265 -0
  256. data/test/MC/SystemZ/regs-good.s.cs +45 -0
  257. data/test/MC/X86/3DNow.s.cs +29 -0
  258. data/test/MC/X86/address-size.s.cs +5 -0
  259. data/test/MC/X86/avx512-encodings.s.cs +12 -0
  260. data/test/MC/X86/intel-syntax-encoding.s.cs +30 -0
  261. data/test/MC/X86/x86-32-avx.s.cs +833 -0
  262. data/test/MC/X86/x86-32-fma3.s.cs +169 -0
  263. data/test/MC/X86/x86-32-ms-inline-asm.s.cs +27 -0
  264. data/test/MC/X86/x86_64-avx-clmul-encoding.s.cs +11 -0
  265. data/test/MC/X86/x86_64-avx-encoding.s.cs +1058 -0
  266. data/test/MC/X86/x86_64-bmi-encoding.s.cs +51 -0
  267. data/test/MC/X86/x86_64-encoding.s.cs +59 -0
  268. data/test/MC/X86/x86_64-fma3-encoding.s.cs +169 -0
  269. data/test/MC/X86/x86_64-fma4-encoding.s.cs +98 -0
  270. data/test/MC/X86/x86_64-hle-encoding.s.cs +3 -0
  271. data/test/MC/X86/x86_64-imm-widths.s.cs +27 -0
  272. data/test/MC/X86/x86_64-rand-encoding.s.cs +13 -0
  273. data/test/MC/X86/x86_64-rtm-encoding.s.cs +4 -0
  274. data/test/MC/X86/x86_64-sse4a.s.cs +1 -0
  275. data/test/MC/X86/x86_64-tbm-encoding.s.cs +40 -0
  276. data/test/MC/X86/x86_64-xop-encoding.s.cs +152 -0
  277. data/test/README +6 -0
  278. data/test/test.rb +205 -0
  279. data/test/test.rb.SPEC +235 -0
  280. data/test/test_arm.rb +202 -0
  281. data/test/test_arm.rb.SPEC +275 -0
  282. data/test/test_arm64.rb +150 -0
  283. data/test/test_arm64.rb.SPEC +116 -0
  284. data/test/test_detail.rb +228 -0
  285. data/test/test_detail.rb.SPEC +322 -0
  286. data/test/test_exhaustive.rb +80 -0
  287. data/test/test_mips.rb +118 -0
  288. data/test/test_mips.rb.SPEC +91 -0
  289. data/test/test_ppc.rb +137 -0
  290. data/test/test_ppc.rb.SPEC +84 -0
  291. data/test/test_sanity.rb +83 -0
  292. data/test/test_skipdata.rb +111 -0
  293. data/test/test_skipdata.rb.SPEC +58 -0
  294. data/test/test_sparc.rb +113 -0
  295. data/test/test_sparc.rb.SPEC +116 -0
  296. data/test/test_sysz.rb +111 -0
  297. data/test/test_sysz.rb.SPEC +61 -0
  298. data/test/test_x86.rb +189 -0
  299. data/test/test_x86.rb.SPEC +579 -0
  300. data/test/test_xcore.rb +100 -0
  301. data/test/test_xcore.rb.SPEC +75 -0
  302. metadata +393 -0
@@ -0,0 +1,150 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ # Library by Nguyen Anh Quynh
4
+ # Original binding by Nguyen Anh Quynh and Tan Sheng Di
5
+ # Additional binding work by Ben Nagy
6
+ # (c) 2013 COSEINC. All Rights Reserved.
7
+
8
+ require 'crabstone'
9
+ require 'stringio'
10
+
11
+ module TestARM64
12
+
13
+ include Crabstone
14
+ include Crabstone::ARM64
15
+
16
+ ARM64_CODE = "\x09\x00\x38\xd5\xbf\x40\x00\xd5\x0c\x05\x13\xd5\x20\x50\x02\x0e\x20\xe4\x3d\x0f\x00\x18\xa0\x5f\xa2\x00\xae\x9e\x9f\x37\x03\xd5\xbf\x33\x03\xd5\xdf\x3f\x03\xd5\x21\x7c\x02\x9b\x21\x7c\x00\x53\x00\x40\x21\x4b\xe1\x0b\x40\xb9\x20\x04\x81\xda\x20\x08\x02\x8b\x10\x5b\xe8\x3c"
17
+
18
+ @platforms = [
19
+ Hash[
20
+ 'arch' => ARCH_ARM64,
21
+ 'mode' => MODE_ARM,
22
+ 'code' => ARM64_CODE,
23
+ 'comment' => "ARM-64"
24
+ ],
25
+ ]
26
+
27
+ def self.uint32 i
28
+ Integer(i) & 0xffffffff
29
+ end
30
+
31
+ def self.uint64 i
32
+ Integer(i) & ((1<<64)-1)
33
+ end
34
+
35
+ def self.print_detail(cs, i, sio)
36
+
37
+ # Sanity checks for register equivalency (string, const or numeric literal)
38
+ if i.reads_reg?( 'sp' ) || i.reads_reg?( 12 ) || i.reads_reg?( REG_SP )
39
+ unless i.reads_reg?( 'sp' ) && i.reads_reg?( 12 ) && i.reads_reg?( REG_SP )
40
+ fail "Error in reg read decomposition"
41
+ end
42
+ end
43
+ if i.writes_reg?( 'lr' ) || i.writes_reg?( 10 ) || i.writes_reg?( REG_LR )
44
+ unless i.writes_reg?( 'lr' ) && i.writes_reg?( 10 ) && i.writes_reg?( REG_LR )
45
+ fail "Error in reg write decomposition"
46
+ end
47
+ end
48
+
49
+ if i.op_count > 0 then
50
+ sio.puts "\top_count: #{i.op_count}"
51
+ i.operands.each.with_index do |op,idx|
52
+
53
+ case op[:type]
54
+ when OP_REG
55
+ sio.puts "\t\toperands[#{idx}].type: REG = #{cs.reg_name(op[:value][:reg])}"
56
+ when OP_IMM
57
+ sio.puts "\t\toperands[#{idx}].type: IMM = 0x#{self.uint64(op.value).to_s(16)}"
58
+ when OP_FP
59
+ sio.puts "\t\toperands[#{idx}].type: FP = 0x#{self.uint32(op[:value][:fp])}"
60
+ when OP_CIMM
61
+ sio.puts "\t\toperands[#{idx}].type: C-IMM = #{self.uint32(op[:value][:imm])}"
62
+ when OP_MEM
63
+ sio.puts "\t\toperands[#{idx}].type: MEM"
64
+ if op[:value][:mem][:base].nonzero?
65
+ sio.puts "\t\t\toperands[#{idx}].mem.base: REG = %s" % cs.reg_name(op.value[:base])
66
+ end
67
+ if op[:value][:mem][:index].nonzero?
68
+ sio.puts "\t\t\toperands[#{idx}].mem.index: REG = %s" % cs.reg_name(op.value[:index])
69
+ end
70
+ if op[:value][:mem][:disp].nonzero?
71
+ sio.puts "\t\t\toperands[#{idx}].mem.disp: 0x#{self.uint32(op.value[:disp]).to_s(16)}"
72
+ end
73
+ when OP_REG_MRS
74
+ sio.puts "\t\toperands[#{idx}].type: REG_MRS = 0x#{op.value.to_s(16)}\n"
75
+ when OP_REG_MSR
76
+ sio.puts "\t\toperands[#{idx}].type: REG_MSR = 0x#{op[:value][:reg].to_s(16)}\n"
77
+ when OP_PSTATE
78
+ sio.puts "\t\toperands[#{idx}].type: PSTATE = 0x#{uint32(op.value)}\n"
79
+ when OP_SYS
80
+ sio.puts "\t\toperands[#{idx}].type: SYS = 0x#{uint32(op.value)}\n"
81
+ when OP_PREFETCH
82
+ sio.puts "\t\toperands[#{idx}].type: PREFETCH = 0x#{uint32(op.value)}\n"
83
+ when OP_BARRIER
84
+ sio.puts "\t\toperands[#{idx}].type: BARRIER = 0x#{uint32(op.value)}\n"
85
+ else
86
+ # unknown type - test will fail anyway
87
+ end
88
+
89
+ sio.puts "\t\t\tShift: type = #{op.shift_type}, value = #{op.shift_value}\n" if op.shift?
90
+ sio.puts "\t\t\tVector Arrangement Specifier: 0x#{uint32(op[:vas])}\n" if op[:vas].nonzero?
91
+ sio.puts "\t\t\tVector Element Size Specifier: #{op[:vess]}\n" if op[:vess].nonzero?
92
+ sio.puts"\t\t\tVector Index: #{op[:vector_index]}\n" if op[:vector_index] != -1
93
+ sio.puts "\t\t\tExt: #{op[:ext]}\n" if op[:ext].nonzero?
94
+ end
95
+ end
96
+
97
+ sio.puts "\tUpdate-flags: True" if i.update_flags
98
+ sio.puts "\tWrite-back: True" if i.writeback
99
+ if not [CC_AL, CC_INVALID].include? i.cc
100
+ sio.puts "\tCode-condition: #{i.cc}"
101
+ end
102
+
103
+ sio.puts
104
+
105
+ end
106
+
107
+ ours = StringIO.new
108
+
109
+ begin
110
+ cs = Disassembler.new(0,0)
111
+ print "ARM64 Test: Capstone v #{cs.version.join('.')} - "
112
+ ensure
113
+ cs.close
114
+ end
115
+
116
+ #Test through all modes and architectures
117
+ @platforms.each do |p|
118
+ ours.puts "****************"
119
+ ours.puts "Platform: #{p['comment']}"
120
+ ours.puts "Code: #{p['code'].bytes.map {|b| "0x%.2x" % b}.join(' ')} "
121
+ ours.puts "Disasm:"
122
+ cs = Disassembler.new(p['arch'], p['mode'])
123
+
124
+ if p['syntax']
125
+ cs.syntax = p['syntax']
126
+ end
127
+
128
+ cs.decomposer = true
129
+ cache = nil
130
+ cs.disasm(p['code'], 0x2c).each {|insn|
131
+ ours.puts "0x#{insn.address.to_s(16)}:\t#{insn.mnemonic}\t#{insn.op_str}"
132
+ self.print_detail(cs, insn, ours)
133
+ cache = insn.address + insn.size
134
+ }
135
+ ours.printf("0x%x:\n", cache)
136
+ ours.puts
137
+
138
+ cs.close
139
+ end
140
+
141
+ ours.rewind
142
+ theirs = File.binread(__FILE__ + ".SPEC")
143
+ if ours.read == theirs
144
+ puts "#{__FILE__}: PASS"
145
+ else
146
+ ours.rewind
147
+ puts ours.read
148
+ puts "#{__FILE__}: FAIL"
149
+ end
150
+ end
@@ -0,0 +1,116 @@
1
+ ****************
2
+ Platform: ARM-64
3
+ Code: 0x09 0x00 0x38 0xd5 0xbf 0x40 0x00 0xd5 0x0c 0x05 0x13 0xd5 0x20 0x50 0x02 0x0e 0x20 0xe4 0x3d 0x0f 0x00 0x18 0xa0 0x5f 0xa2 0x00 0xae 0x9e 0x9f 0x37 0x03 0xd5 0xbf 0x33 0x03 0xd5 0xdf 0x3f 0x03 0xd5 0x21 0x7c 0x02 0x9b 0x21 0x7c 0x00 0x53 0x00 0x40 0x21 0x4b 0xe1 0x0b 0x40 0xb9 0x20 0x04 0x81 0xda 0x20 0x08 0x02 0x8b 0x10 0x5b 0xe8 0x3c
4
+ Disasm:
5
+ 0x2c: mrs x9, midr_el1
6
+ op_count: 2
7
+ operands[0].type: REG = x9
8
+ operands[1].type: REG_MRS = 0xc000
9
+
10
+ 0x30: msr spsel, #0
11
+ op_count: 2
12
+ operands[0].type: PSTATE = 0x5
13
+ operands[1].type: IMM = 0x0
14
+ Update-flags: True
15
+
16
+ 0x34: msr dbgdtrtx_el0, x12
17
+ op_count: 2
18
+ operands[0].type: REG_MSR = 0x9828
19
+ operands[1].type: REG = x12
20
+
21
+ 0x38: tbx v0.8b, {v1.16b, v2.16b, v3.16b}, v2.8b
22
+ op_count: 5
23
+ operands[0].type: REG = v0
24
+ Vector Arrangement Specifier: 0x1
25
+ operands[1].type: REG = v1
26
+ Vector Arrangement Specifier: 0x2
27
+ operands[2].type: REG = v2
28
+ Vector Arrangement Specifier: 0x2
29
+ operands[3].type: REG = v3
30
+ Vector Arrangement Specifier: 0x2
31
+ operands[4].type: REG = v2
32
+ Vector Arrangement Specifier: 0x1
33
+
34
+ 0x3c: scvtf v0.2s, v1.2s, #3
35
+ op_count: 3
36
+ operands[0].type: REG = v0
37
+ Vector Arrangement Specifier: 0x5
38
+ operands[1].type: REG = v1
39
+ Vector Arrangement Specifier: 0x5
40
+ operands[2].type: IMM = 0x3
41
+
42
+ 0x40: fmla s0, s0, v0.s[3]
43
+ op_count: 3
44
+ operands[0].type: REG = s0
45
+ operands[1].type: REG = s0
46
+ operands[2].type: REG = v0
47
+ Vector Element Size Specifier: 3
48
+ Vector Index: 3
49
+
50
+ 0x44: fmov x2, v5.d[1]
51
+ op_count: 2
52
+ operands[0].type: REG = x2
53
+ operands[1].type: REG = v5
54
+ Vector Element Size Specifier: 4
55
+ Vector Index: 1
56
+
57
+ 0x48: dsb nsh
58
+ op_count: 1
59
+ operands[0].type: BARRIER = 0x7
60
+
61
+ 0x4c: dmb osh
62
+ op_count: 1
63
+ operands[0].type: BARRIER = 0x3
64
+
65
+ 0x50: isb
66
+
67
+ 0x54: mul x1, x1, x2
68
+ op_count: 3
69
+ operands[0].type: REG = x1
70
+ operands[1].type: REG = x1
71
+ operands[2].type: REG = x2
72
+
73
+ 0x58: lsr w1, w1, #0
74
+ op_count: 3
75
+ operands[0].type: REG = w1
76
+ operands[1].type: REG = w1
77
+ operands[2].type: IMM = 0x0
78
+
79
+ 0x5c: sub w0, w0, w1, uxtw
80
+ op_count: 3
81
+ operands[0].type: REG = w0
82
+ operands[1].type: REG = w0
83
+ operands[2].type: REG = w1
84
+ Ext: 3
85
+
86
+ 0x60: ldr w1, [sp, #8]
87
+ op_count: 2
88
+ operands[0].type: REG = w1
89
+ operands[1].type: MEM
90
+ operands[1].mem.base: REG = sp
91
+ operands[1].mem.disp: 0x8
92
+
93
+ 0x64: cneg x0, x1, ne
94
+ op_count: 2
95
+ operands[0].type: REG = x0
96
+ operands[1].type: REG = x1
97
+ Code-condition: 2
98
+
99
+ 0x68: add x0, x1, x2, lsl #2
100
+ op_count: 3
101
+ operands[0].type: REG = x0
102
+ operands[1].type: REG = x1
103
+ operands[2].type: REG = x2
104
+ Shift: type = 1, value = 2
105
+
106
+ 0x6c: ldr q16, [x24, w8, uxtw #4]
107
+ op_count: 2
108
+ operands[0].type: REG = q16
109
+ operands[1].type: MEM
110
+ operands[1].mem.base: REG = x24
111
+ operands[1].mem.index: REG = w8
112
+ Shift: type = 1, value = 4
113
+ Ext: 3
114
+
115
+ 0x70:
116
+
@@ -0,0 +1,228 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Library by Nguyen Anh Quynh
4
+ # Original binding by Nguyen Anh Quynh and Tan Sheng Di
5
+ # Additional binding work by Ben Nagy
6
+ # (c) 2013 COSEINC. All Rights Reserved.
7
+
8
+ require 'crabstone'
9
+ require 'stringio'
10
+
11
+ module TestDetail
12
+
13
+ X86_CODE16 = "\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00"
14
+ X86_CODE32 = "\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00"
15
+ X86_CODE64 = "\x55\x48\x8b\x05\xb8\x13\x00\x00"
16
+ ARM_CODE = "\xED\xFF\xFF\xEB\x04\xe0\x2d\xe5\x00\x00\x00\x00\xe0\x83\x22\xe5\xf1\x02\x03\x0e\x00\x00\xa0\xe3\x02\x30\xc1\xe7\x00\x00\x53\xe3"
17
+ ARM_CODE2 = "\x10\xf1\x10\xe7\x11\xf2\x31\xe7\xdc\xa1\x2e\xf3\xe8\x4e\x62\xf3"
18
+ THUMB_CODE = "\x70\x47\xeb\x46\x83\xb0\xc9\x68"
19
+ THUMB_CODE2 = "\x4f\xf0\x00\x01\xbd\xe8\x00\x88\xd1\xe8\x00\xf0"
20
+ THUMB_MCLASS = "\xef\xf3\x02\x80"
21
+ ARMV8 = "\xe0\x3b\xb2\xee\x42\x00\x01\xe1\x51\xf0\x7f\xf5"
22
+ MIPS_CODE = "\x0C\x10\x00\x97\x00\x00\x00\x00\x24\x02\x00\x0c\x8f\xa2\x00\x00\x34\x21\x34\x56\x00\x80\x04\x08"
23
+ MIPS_CODE2 = "\x56\x34\x21\x34\xc2\x17\x01\x00"
24
+ MIPS_32R6M = "\x00\x07\x00\x07\x00\x11\x93\x7c\x01\x8c\x8b\x7c\x00\xc7\x48\xd0"
25
+ MIPS_32R6 = "\xec\x80\x00\x19\x7c\x43\x22\xa0"
26
+ ARM64_CODE = "\x09\x00\x38\xd5\xbf\x40\x00\xd5\x0c\x05\x13\xd5\x20\x50\x02\x0e\x20\xe4\x3d\x0f\x00\x18\xa0\x5f\xa2\x00\xae\x9e\x9f\x37\x03\xd5\xbf\x33\x03\xd5\xdf\x3f\x03\xd5\x21\x7c\x02\x9b\x21\x7c\x00\x53\x00\x40\x21\x4b\xe1\x0b\x40\xb9\x20\x04\x81\xda\x20\x08\x02\x8b\x10\x5b\xe8\x3c"
27
+ PPC_CODE = "\x80\x20\x00\x00\x80\x3f\x00\x00\x10\x43\x23\x0e\xd0\x44\x00\x80\x4c\x43\x22\x02\x2d\x03\x00\x80\x7c\x43\x20\x14\x7c\x43\x20\x93\x4f\x20\x00\x21\x4c\xc8\x00\x21\x40\x82\x00\x14"
28
+ SPARC_CODE = "\x80\xa0\x40\x02\x85\xc2\x60\x08\x85\xe8\x20\x01\x81\xe8\x00\x00\x90\x10\x20\x01\xd5\xf6\x10\x16\x21\x00\x00\x0a\x86\x00\x40\x02\x01\x00\x00\x00\x12\xbf\xff\xff\x10\xbf\xff\xff\xa0\x02\x00\x09\x0d\xbf\xff\xff\xd4\x20\x60\x00\xd4\x4e\x00\x16\x2a\xc2\x80\x03"
29
+ SPARCV9_CODE = "\x81\xa8\x0a\x24\x89\xa0\x10\x20\x89\xa0\x1a\x60\x89\xa0\x00\xe0"
30
+ SYSZ_CODE = "\xed\x00\x00\x00\x00\x1a\x5a\x0f\x1f\xff\xc2\x09\x80\x00\x00\x00\x07\xf7\xeb\x2a\xff\xff\x7f\x57\xe3\x01\xff\xff\x7f\x57\xeb\x00\xf0\x00\x00\x24\xb2\x4f\x00\x78"
31
+ XCORE_CODE = "\xfe\x0f\xfe\x17\x13\x17\xc6\xfe\xec\x17\x97\xf8\xec\x4f\x1f\xfd\xec\x37\x07\xf2\x45\x5b\xf9\xfa\x02\x06\x1b\x10"
32
+
33
+ include Crabstone
34
+
35
+ @platforms = [
36
+ Hash[
37
+ 'arch' => ARCH_X86,
38
+ 'mode' => MODE_16,
39
+ 'code' => X86_CODE16,
40
+ 'comment' => "X86 16bit (Intel syntax)"
41
+ ],
42
+ Hash[
43
+ 'arch' => ARCH_X86,
44
+ 'mode' => MODE_32,
45
+ 'code' => X86_CODE32,
46
+ 'syntax' => :att,
47
+ 'comment' => "X86 32bit (ATT syntax)"
48
+ ],
49
+ Hash[
50
+ 'arch' => ARCH_X86,
51
+ 'mode' => MODE_32,
52
+ 'code' => X86_CODE32,
53
+ 'comment' => "X86 32 (Intel syntax)"
54
+ ],
55
+ Hash[
56
+ 'arch' => ARCH_X86,
57
+ 'mode' => MODE_64,
58
+ 'code' => X86_CODE64,
59
+ 'comment' => "X86 64 (Intel syntax)"
60
+ ],
61
+ Hash[
62
+ 'arch' => ARCH_ARM,
63
+ 'mode' => MODE_ARM,
64
+ 'code' => ARM_CODE,
65
+ 'comment' => "ARM"
66
+ ],
67
+ Hash[
68
+ 'arch' => ARCH_ARM,
69
+ 'mode' => MODE_THUMB,
70
+ 'code' => THUMB_CODE2,
71
+ 'comment' => "THUMB-2"
72
+ ],
73
+ Hash[
74
+ 'arch' => ARCH_ARM,
75
+ 'mode' => MODE_ARM,
76
+ 'code' => ARM_CODE2,
77
+ 'comment' => "ARM: Cortex-A15 + NEON"
78
+ ],
79
+ Hash[
80
+ 'arch' => ARCH_ARM,
81
+ 'mode' => MODE_THUMB,
82
+ 'code' => THUMB_CODE,
83
+ 'comment' => "THUMB"
84
+ ],
85
+ Hash[
86
+ 'arch' => ARCH_ARM,
87
+ 'mode' => MODE_THUMB + MODE_MCLASS,
88
+ 'code' => THUMB_MCLASS,
89
+ 'comment' => "Thumb-MClass"
90
+ ],
91
+ Hash[
92
+ 'arch' => ARCH_ARM,
93
+ 'mode' => MODE_ARM + MODE_V8,
94
+ 'code' => ARMV8,
95
+ 'comment' => "Arm-V8"
96
+ ],
97
+ Hash[
98
+ 'arch' => ARCH_MIPS,
99
+ 'mode' => MODE_32 + MODE_BIG_ENDIAN,
100
+ 'code' => MIPS_CODE,
101
+ 'comment' => "MIPS-32 (Big-endian)"
102
+ ],
103
+ Hash[
104
+ 'arch' => ARCH_MIPS,
105
+ 'mode' => MODE_64 + MODE_LITTLE_ENDIAN,
106
+ 'code' => MIPS_CODE2,
107
+ 'comment' => "MIPS-64-EL (Little-endian)"
108
+ ],
109
+ Hash[
110
+ 'arch' => ARCH_MIPS,
111
+ 'mode' => MODE_MIPS32R6 + MODE_MICRO + MODE_BIG_ENDIAN,
112
+ 'code' => MIPS_32R6M,
113
+ 'comment' => "MIPS-32R6 | Micro (Big-endian)"
114
+ ],
115
+ Hash[
116
+ 'arch' => ARCH_MIPS,
117
+ 'mode' => MODE_MIPS32R6 + MODE_BIG_ENDIAN,
118
+ 'code' => MIPS_32R6,
119
+ 'comment' => "MIPS-32R6 (Big-endian)"
120
+ ],
121
+ Hash[
122
+ 'arch' => ARCH_ARM64,
123
+ 'mode' => 0,
124
+ 'code' => ARM64_CODE,
125
+ 'comment' => "ARM-64"
126
+ ],
127
+ Hash[
128
+ 'arch' => ARCH_PPC,
129
+ 'mode' => MODE_BIG_ENDIAN,
130
+ 'code' => PPC_CODE,
131
+ 'comment' => "PPC-64"
132
+ ],
133
+ Hash[
134
+ 'arch' => ARCH_SPARC,
135
+ 'mode' => MODE_BIG_ENDIAN,
136
+ 'code' => SPARC_CODE,
137
+ 'comment' => "Sparc"
138
+ ],
139
+ Hash[
140
+ 'arch' => ARCH_SPARC,
141
+ 'mode' => MODE_BIG_ENDIAN + MODE_V9,
142
+ 'code' => SPARCV9_CODE,
143
+ 'comment' => "SparcV9"
144
+ ],
145
+ Hash[
146
+ 'arch' => ARCH_SYSZ,
147
+ 'mode' => MODE_BIG_ENDIAN,
148
+ 'code' => SYSZ_CODE,
149
+ 'comment' => "SystemZ"
150
+ ],
151
+ Hash[
152
+ 'arch' => ARCH_XCORE,
153
+ 'mode' => MODE_BIG_ENDIAN,
154
+ 'code' => XCORE_CODE,
155
+ 'comment' => "XCore"
156
+ ]
157
+ ]
158
+
159
+ def self.print_detail cs, insn, sio
160
+ if insn.regs_read.any?
161
+ read = insn.regs_read.map {|r| cs.reg_name r}.join(' ')
162
+ sio.puts "\tImplicit registers read: #{read} "
163
+ end
164
+
165
+ if insn.regs_write.any?
166
+ written = insn.regs_write.map {|r| cs.reg_name r}.join(' ')
167
+ sio.puts "\tImplicit registers modified: #{written} "
168
+ end
169
+
170
+ if insn.groups.any?
171
+ groups = insn.groups.map {|gid| insn.group_name gid}
172
+ sio.puts "\tThis instruction belongs to groups: #{groups.join(' ')} "
173
+ end
174
+ end
175
+
176
+ ours = StringIO.new
177
+
178
+ begin
179
+ cs = Disassembler.new(0,0)
180
+ print "Detailed Test: Capstone v #{cs.version.join('.')} - "
181
+ ensure
182
+ cs.close
183
+ end
184
+
185
+ #Test through all modes and architectures
186
+ @platforms.each do |p|
187
+ ours.puts "****************"
188
+ ours.puts "Platform: #{p['comment']}"
189
+ ours.puts "Code: #{p['code'].bytes.map {|b| "0x%.2x" % b}.join(' ')} "
190
+ ours.puts "Disasm:"
191
+ cs = Disassembler.new(p['arch'], p['mode'])
192
+ cs.decomposer = true
193
+ if p['syntax']
194
+ cs.syntax = p['syntax']
195
+ end
196
+ cache = nil
197
+ cs.disasm(p['code'], 0x1000).each {|insn|
198
+ ours.printf(
199
+ "0x%x:\t%s\t\t%s ",
200
+ insn.address,
201
+ insn.mnemonic,
202
+ insn.op_str
203
+ )
204
+ if insn.id.nonzero? then
205
+ ours.printf(
206
+ "// insn-ID: %u, insn-mnem: %s\n",
207
+ insn.id,
208
+ insn.name
209
+ )
210
+ end
211
+ self.print_detail cs, insn, ours
212
+ cache = insn.address + insn.size
213
+ }
214
+ ours.printf("0x%x:\n", cache)
215
+ ours.puts
216
+ cs.close
217
+ end
218
+
219
+ ours.rewind
220
+ theirs = File.binread(__FILE__ + ".SPEC")
221
+ if ours.read == theirs
222
+ puts "#{__FILE__}: PASS"
223
+ else
224
+ ours.rewind
225
+ puts ours.read
226
+ puts "#{__FILE__}: FAIL"
227
+ end
228
+ end