immunio 0.15.4 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (454) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +0 -27
  3. data/ext/immunio/Rakefile +9 -0
  4. data/lib/immunio/plugins/active_record.rb +1 -1
  5. data/lib/immunio/plugins/active_record_relation.rb +1 -1
  6. data/lib/immunio/plugins/environment_reporter.rb +20 -0
  7. data/lib/immunio/rufus_lua_ext/ref.rb +1 -3
  8. data/lib/immunio/version.rb +1 -1
  9. data/lib/immunio/vm.rb +1 -2
  10. data/lua-hooks/Makefile +97 -0
  11. data/lua-hooks/ext/all.c +41 -52
  12. data/lua-hooks/ext/all.o +0 -0
  13. data/lua-hooks/ext/libinjection/libinjection_html5.o +0 -0
  14. data/lua-hooks/ext/libinjection/libinjection_sqli.o +0 -0
  15. data/lua-hooks/ext/libinjection/libinjection_xss.o +0 -0
  16. data/lua-hooks/ext/libinjection/lualib.c +2 -2
  17. data/lua-hooks/ext/lpeg/lpcap.c +2 -2
  18. data/lua-hooks/ext/lpeg/lpcap.o +0 -0
  19. data/lua-hooks/ext/lpeg/lpcode.c +2 -2
  20. data/lua-hooks/ext/lpeg/lpcode.h +1 -1
  21. data/lua-hooks/ext/lpeg/lpcode.o +0 -0
  22. data/lua-hooks/ext/lpeg/lpprint.o +0 -0
  23. data/lua-hooks/ext/lpeg/lptree.c +2 -2
  24. data/lua-hooks/ext/lpeg/lptypes.h +1 -1
  25. data/lua-hooks/ext/lpeg/lpvm.c +2 -2
  26. data/lua-hooks/ext/lpeg/lpvm.o +0 -0
  27. data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +16 -3
  28. data/lua-hooks/ext/lua-snapshot/snapshot.c +14 -7
  29. data/lua-hooks/ext/luajit/COPYRIGHT +56 -0
  30. data/lua-hooks/ext/luajit/Makefile +159 -0
  31. data/lua-hooks/ext/luajit/README +16 -0
  32. data/lua-hooks/ext/luajit/doc/bluequad-print.css +166 -0
  33. data/lua-hooks/ext/luajit/doc/bluequad.css +325 -0
  34. data/lua-hooks/ext/luajit/doc/changes.html +804 -0
  35. data/lua-hooks/ext/luajit/doc/contact.html +104 -0
  36. data/lua-hooks/ext/luajit/doc/ext_c_api.html +189 -0
  37. data/lua-hooks/ext/luajit/doc/ext_ffi.html +332 -0
  38. data/lua-hooks/ext/luajit/doc/ext_ffi_api.html +570 -0
  39. data/lua-hooks/ext/luajit/doc/ext_ffi_semantics.html +1261 -0
  40. data/lua-hooks/ext/luajit/doc/ext_ffi_tutorial.html +603 -0
  41. data/lua-hooks/ext/luajit/doc/ext_jit.html +201 -0
  42. data/lua-hooks/ext/luajit/doc/ext_profiler.html +365 -0
  43. data/lua-hooks/ext/luajit/doc/extensions.html +448 -0
  44. data/lua-hooks/ext/luajit/doc/faq.html +186 -0
  45. data/lua-hooks/ext/luajit/doc/img/contact.png +0 -0
  46. data/lua-hooks/ext/luajit/doc/install.html +659 -0
  47. data/lua-hooks/ext/luajit/doc/luajit.html +236 -0
  48. data/lua-hooks/ext/luajit/doc/running.html +309 -0
  49. data/lua-hooks/ext/luajit/doc/status.html +118 -0
  50. data/lua-hooks/ext/luajit/dynasm/dasm_arm.h +456 -0
  51. data/lua-hooks/ext/luajit/dynasm/dasm_arm.lua +1125 -0
  52. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.h +518 -0
  53. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.lua +1166 -0
  54. data/lua-hooks/ext/luajit/dynasm/dasm_mips.h +416 -0
  55. data/lua-hooks/ext/luajit/dynasm/dasm_mips.lua +953 -0
  56. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.h +419 -0
  57. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.lua +1919 -0
  58. data/lua-hooks/ext/luajit/dynasm/dasm_proto.h +83 -0
  59. data/lua-hooks/ext/luajit/dynasm/dasm_x64.lua +12 -0
  60. data/lua-hooks/ext/luajit/dynasm/dasm_x86.h +471 -0
  61. data/lua-hooks/ext/luajit/dynasm/dasm_x86.lua +1945 -0
  62. data/lua-hooks/ext/luajit/dynasm/dynasm.lua +1094 -0
  63. data/lua-hooks/ext/luajit/etc/luajit.1 +88 -0
  64. data/lua-hooks/ext/luajit/etc/luajit.pc +25 -0
  65. data/lua-hooks/ext/luajit/src/Makefile +697 -0
  66. data/lua-hooks/ext/luajit/src/Makefile.dep +244 -0
  67. data/lua-hooks/ext/luajit/src/host/README +4 -0
  68. data/lua-hooks/ext/luajit/src/host/buildvm +0 -0
  69. data/lua-hooks/ext/luajit/src/host/buildvm.c +518 -0
  70. data/lua-hooks/ext/luajit/src/host/buildvm.h +105 -0
  71. data/lua-hooks/ext/luajit/src/host/buildvm.o +0 -0
  72. data/lua-hooks/ext/luajit/src/host/buildvm_arch.h +7449 -0
  73. data/lua-hooks/ext/luajit/src/host/buildvm_asm.c +345 -0
  74. data/lua-hooks/ext/luajit/src/host/buildvm_asm.o +0 -0
  75. data/lua-hooks/ext/luajit/src/host/buildvm_fold.c +229 -0
  76. data/lua-hooks/ext/luajit/src/host/buildvm_fold.o +0 -0
  77. data/lua-hooks/ext/luajit/src/host/buildvm_lib.c +457 -0
  78. data/lua-hooks/ext/luajit/src/host/buildvm_lib.o +0 -0
  79. data/lua-hooks/ext/luajit/src/host/buildvm_libbc.h +45 -0
  80. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.c +368 -0
  81. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.o +0 -0
  82. data/lua-hooks/ext/luajit/src/host/genlibbc.lua +197 -0
  83. data/lua-hooks/ext/luajit/src/host/genminilua.lua +428 -0
  84. data/lua-hooks/ext/luajit/src/host/minilua +0 -0
  85. data/lua-hooks/ext/luajit/src/host/minilua.c +7770 -0
  86. data/lua-hooks/ext/luajit/src/host/minilua.o +0 -0
  87. data/lua-hooks/ext/luajit/src/jit/bc.lua +190 -0
  88. data/lua-hooks/ext/luajit/src/jit/bcsave.lua +661 -0
  89. data/lua-hooks/ext/luajit/src/jit/dis_arm.lua +689 -0
  90. data/lua-hooks/ext/luajit/src/jit/dis_mips.lua +428 -0
  91. data/lua-hooks/ext/luajit/src/jit/dis_mipsel.lua +17 -0
  92. data/lua-hooks/ext/luajit/src/jit/dis_ppc.lua +591 -0
  93. data/lua-hooks/ext/luajit/src/jit/dis_x64.lua +17 -0
  94. data/lua-hooks/ext/luajit/src/jit/dis_x86.lua +838 -0
  95. data/lua-hooks/ext/luajit/src/jit/dump.lua +706 -0
  96. data/lua-hooks/ext/luajit/src/jit/p.lua +310 -0
  97. data/lua-hooks/ext/luajit/src/jit/v.lua +170 -0
  98. data/lua-hooks/ext/luajit/src/jit/vmdef.lua +362 -0
  99. data/lua-hooks/ext/luajit/src/jit/zone.lua +45 -0
  100. data/lua-hooks/ext/{lua → luajit/src}/lauxlib.h +10 -17
  101. data/lua-hooks/ext/luajit/src/lib_aux.c +356 -0
  102. data/lua-hooks/ext/luajit/src/lib_aux.o +0 -0
  103. data/lua-hooks/ext/luajit/src/lib_aux_dyn.o +0 -0
  104. data/lua-hooks/ext/luajit/src/lib_base.c +664 -0
  105. data/lua-hooks/ext/luajit/src/lib_base.o +0 -0
  106. data/lua-hooks/ext/luajit/src/lib_base_dyn.o +0 -0
  107. data/lua-hooks/ext/luajit/src/lib_bit.c +180 -0
  108. data/lua-hooks/ext/luajit/src/lib_bit.o +0 -0
  109. data/lua-hooks/ext/luajit/src/lib_bit_dyn.o +0 -0
  110. data/lua-hooks/ext/luajit/src/lib_debug.c +405 -0
  111. data/lua-hooks/ext/luajit/src/lib_debug.o +0 -0
  112. data/lua-hooks/ext/luajit/src/lib_debug_dyn.o +0 -0
  113. data/lua-hooks/ext/luajit/src/lib_ffi.c +872 -0
  114. data/lua-hooks/ext/luajit/src/lib_ffi.o +0 -0
  115. data/lua-hooks/ext/luajit/src/lib_ffi_dyn.o +0 -0
  116. data/lua-hooks/ext/luajit/src/lib_init.c +55 -0
  117. data/lua-hooks/ext/luajit/src/lib_init.o +0 -0
  118. data/lua-hooks/ext/luajit/src/lib_init_dyn.o +0 -0
  119. data/lua-hooks/ext/luajit/src/lib_io.c +541 -0
  120. data/lua-hooks/ext/luajit/src/lib_io.o +0 -0
  121. data/lua-hooks/ext/luajit/src/lib_io_dyn.o +0 -0
  122. data/lua-hooks/ext/luajit/src/lib_jit.c +767 -0
  123. data/lua-hooks/ext/luajit/src/lib_jit.o +0 -0
  124. data/lua-hooks/ext/luajit/src/lib_jit_dyn.o +0 -0
  125. data/lua-hooks/ext/luajit/src/lib_math.c +230 -0
  126. data/lua-hooks/ext/luajit/src/lib_math.o +0 -0
  127. data/lua-hooks/ext/luajit/src/lib_math_dyn.o +0 -0
  128. data/lua-hooks/ext/luajit/src/lib_os.c +292 -0
  129. data/lua-hooks/ext/luajit/src/lib_os.o +0 -0
  130. data/lua-hooks/ext/luajit/src/lib_os_dyn.o +0 -0
  131. data/lua-hooks/ext/luajit/src/lib_package.c +610 -0
  132. data/lua-hooks/ext/luajit/src/lib_package.o +0 -0
  133. data/lua-hooks/ext/luajit/src/lib_package_dyn.o +0 -0
  134. data/lua-hooks/ext/luajit/src/lib_string.c +752 -0
  135. data/lua-hooks/ext/luajit/src/lib_string.o +0 -0
  136. data/lua-hooks/ext/luajit/src/lib_string_dyn.o +0 -0
  137. data/lua-hooks/ext/luajit/src/lib_table.c +307 -0
  138. data/lua-hooks/ext/luajit/src/lib_table.o +0 -0
  139. data/lua-hooks/ext/luajit/src/lib_table_dyn.o +0 -0
  140. data/lua-hooks/ext/luajit/src/libluajit.a +0 -0
  141. data/lua-hooks/ext/luajit/src/libluajit.so +0 -0
  142. data/lua-hooks/ext/luajit/src/lj.supp +26 -0
  143. data/lua-hooks/ext/luajit/src/lj_alloc.c +1398 -0
  144. data/lua-hooks/ext/luajit/src/lj_alloc.h +17 -0
  145. data/lua-hooks/ext/luajit/src/lj_alloc.o +0 -0
  146. data/lua-hooks/ext/luajit/src/lj_alloc_dyn.o +0 -0
  147. data/lua-hooks/ext/luajit/src/lj_api.c +1210 -0
  148. data/lua-hooks/ext/luajit/src/lj_api.o +0 -0
  149. data/lua-hooks/ext/luajit/src/lj_api_dyn.o +0 -0
  150. data/lua-hooks/ext/luajit/src/lj_arch.h +509 -0
  151. data/lua-hooks/ext/luajit/src/lj_asm.c +2278 -0
  152. data/lua-hooks/ext/luajit/src/lj_asm.h +17 -0
  153. data/lua-hooks/ext/luajit/src/lj_asm.o +0 -0
  154. data/lua-hooks/ext/luajit/src/lj_asm_arm.h +2217 -0
  155. data/lua-hooks/ext/luajit/src/lj_asm_dyn.o +0 -0
  156. data/lua-hooks/ext/luajit/src/lj_asm_mips.h +1833 -0
  157. data/lua-hooks/ext/luajit/src/lj_asm_ppc.h +2015 -0
  158. data/lua-hooks/ext/luajit/src/lj_asm_x86.h +2634 -0
  159. data/lua-hooks/ext/luajit/src/lj_bc.c +14 -0
  160. data/lua-hooks/ext/luajit/src/lj_bc.h +265 -0
  161. data/lua-hooks/ext/luajit/src/lj_bc.o +0 -0
  162. data/lua-hooks/ext/luajit/src/lj_bc_dyn.o +0 -0
  163. data/lua-hooks/ext/luajit/src/lj_bcdef.h +220 -0
  164. data/lua-hooks/ext/luajit/src/lj_bcdump.h +68 -0
  165. data/lua-hooks/ext/luajit/src/lj_bcread.c +457 -0
  166. data/lua-hooks/ext/luajit/src/lj_bcread.o +0 -0
  167. data/lua-hooks/ext/luajit/src/lj_bcread_dyn.o +0 -0
  168. data/lua-hooks/ext/luajit/src/lj_bcwrite.c +361 -0
  169. data/lua-hooks/ext/luajit/src/lj_bcwrite.o +0 -0
  170. data/lua-hooks/ext/luajit/src/lj_bcwrite_dyn.o +0 -0
  171. data/lua-hooks/ext/luajit/src/lj_buf.c +234 -0
  172. data/lua-hooks/ext/luajit/src/lj_buf.h +105 -0
  173. data/lua-hooks/ext/luajit/src/lj_buf.o +0 -0
  174. data/lua-hooks/ext/luajit/src/lj_buf_dyn.o +0 -0
  175. data/lua-hooks/ext/luajit/src/lj_carith.c +429 -0
  176. data/lua-hooks/ext/luajit/src/lj_carith.h +37 -0
  177. data/lua-hooks/ext/luajit/src/lj_carith.o +0 -0
  178. data/lua-hooks/ext/luajit/src/lj_carith_dyn.o +0 -0
  179. data/lua-hooks/ext/luajit/src/lj_ccall.c +984 -0
  180. data/lua-hooks/ext/luajit/src/lj_ccall.h +178 -0
  181. data/lua-hooks/ext/luajit/src/lj_ccall.o +0 -0
  182. data/lua-hooks/ext/luajit/src/lj_ccall_dyn.o +0 -0
  183. data/lua-hooks/ext/luajit/src/lj_ccallback.c +712 -0
  184. data/lua-hooks/ext/luajit/src/lj_ccallback.h +25 -0
  185. data/lua-hooks/ext/luajit/src/lj_ccallback.o +0 -0
  186. data/lua-hooks/ext/luajit/src/lj_ccallback_dyn.o +0 -0
  187. data/lua-hooks/ext/luajit/src/lj_cconv.c +752 -0
  188. data/lua-hooks/ext/luajit/src/lj_cconv.h +70 -0
  189. data/lua-hooks/ext/luajit/src/lj_cconv.o +0 -0
  190. data/lua-hooks/ext/luajit/src/lj_cconv_dyn.o +0 -0
  191. data/lua-hooks/ext/luajit/src/lj_cdata.c +288 -0
  192. data/lua-hooks/ext/luajit/src/lj_cdata.h +76 -0
  193. data/lua-hooks/ext/luajit/src/lj_cdata.o +0 -0
  194. data/lua-hooks/ext/luajit/src/lj_cdata_dyn.o +0 -0
  195. data/lua-hooks/ext/luajit/src/lj_char.c +43 -0
  196. data/lua-hooks/ext/luajit/src/lj_char.h +42 -0
  197. data/lua-hooks/ext/luajit/src/lj_char.o +0 -0
  198. data/lua-hooks/ext/luajit/src/lj_char_dyn.o +0 -0
  199. data/lua-hooks/ext/luajit/src/lj_clib.c +418 -0
  200. data/lua-hooks/ext/luajit/src/lj_clib.h +29 -0
  201. data/lua-hooks/ext/luajit/src/lj_clib.o +0 -0
  202. data/lua-hooks/ext/luajit/src/lj_clib_dyn.o +0 -0
  203. data/lua-hooks/ext/luajit/src/lj_cparse.c +1862 -0
  204. data/lua-hooks/ext/luajit/src/lj_cparse.h +65 -0
  205. data/lua-hooks/ext/luajit/src/lj_cparse.o +0 -0
  206. data/lua-hooks/ext/luajit/src/lj_cparse_dyn.o +0 -0
  207. data/lua-hooks/ext/luajit/src/lj_crecord.c +1834 -0
  208. data/lua-hooks/ext/luajit/src/lj_crecord.h +38 -0
  209. data/lua-hooks/ext/luajit/src/lj_crecord.o +0 -0
  210. data/lua-hooks/ext/luajit/src/lj_crecord_dyn.o +0 -0
  211. data/lua-hooks/ext/luajit/src/lj_ctype.c +635 -0
  212. data/lua-hooks/ext/luajit/src/lj_ctype.h +461 -0
  213. data/lua-hooks/ext/luajit/src/lj_ctype.o +0 -0
  214. data/lua-hooks/ext/luajit/src/lj_ctype_dyn.o +0 -0
  215. data/lua-hooks/ext/luajit/src/lj_debug.c +699 -0
  216. data/lua-hooks/ext/luajit/src/lj_debug.h +65 -0
  217. data/lua-hooks/ext/luajit/src/lj_debug.o +0 -0
  218. data/lua-hooks/ext/luajit/src/lj_debug_dyn.o +0 -0
  219. data/lua-hooks/ext/luajit/src/lj_def.h +365 -0
  220. data/lua-hooks/ext/luajit/src/lj_dispatch.c +557 -0
  221. data/lua-hooks/ext/luajit/src/lj_dispatch.h +138 -0
  222. data/lua-hooks/ext/luajit/src/lj_dispatch.o +0 -0
  223. data/lua-hooks/ext/luajit/src/lj_dispatch_dyn.o +0 -0
  224. data/lua-hooks/ext/luajit/src/lj_emit_arm.h +356 -0
  225. data/lua-hooks/ext/luajit/src/lj_emit_mips.h +211 -0
  226. data/lua-hooks/ext/luajit/src/lj_emit_ppc.h +238 -0
  227. data/lua-hooks/ext/luajit/src/lj_emit_x86.h +462 -0
  228. data/lua-hooks/ext/luajit/src/lj_err.c +794 -0
  229. data/lua-hooks/ext/luajit/src/lj_err.h +41 -0
  230. data/lua-hooks/ext/luajit/src/lj_err.o +0 -0
  231. data/lua-hooks/ext/luajit/src/lj_err_dyn.o +0 -0
  232. data/lua-hooks/ext/luajit/src/lj_errmsg.h +190 -0
  233. data/lua-hooks/ext/luajit/src/lj_ff.h +18 -0
  234. data/lua-hooks/ext/luajit/src/lj_ffdef.h +209 -0
  235. data/lua-hooks/ext/luajit/src/lj_ffrecord.c +1247 -0
  236. data/lua-hooks/ext/luajit/src/lj_ffrecord.h +24 -0
  237. data/lua-hooks/ext/luajit/src/lj_ffrecord.o +0 -0
  238. data/lua-hooks/ext/luajit/src/lj_ffrecord_dyn.o +0 -0
  239. data/lua-hooks/ext/luajit/src/lj_folddef.h +1138 -0
  240. data/lua-hooks/ext/luajit/src/lj_frame.h +259 -0
  241. data/lua-hooks/ext/luajit/src/lj_func.c +185 -0
  242. data/lua-hooks/ext/luajit/src/lj_func.h +24 -0
  243. data/lua-hooks/ext/luajit/src/lj_func.o +0 -0
  244. data/lua-hooks/ext/luajit/src/lj_func_dyn.o +0 -0
  245. data/lua-hooks/ext/luajit/src/lj_gc.c +845 -0
  246. data/lua-hooks/ext/luajit/src/lj_gc.h +134 -0
  247. data/lua-hooks/ext/luajit/src/lj_gc.o +0 -0
  248. data/lua-hooks/ext/luajit/src/lj_gc_dyn.o +0 -0
  249. data/lua-hooks/ext/luajit/src/lj_gdbjit.c +787 -0
  250. data/lua-hooks/ext/luajit/src/lj_gdbjit.h +22 -0
  251. data/lua-hooks/ext/luajit/src/lj_gdbjit.o +0 -0
  252. data/lua-hooks/ext/luajit/src/lj_gdbjit_dyn.o +0 -0
  253. data/lua-hooks/ext/luajit/src/lj_ir.c +505 -0
  254. data/lua-hooks/ext/luajit/src/lj_ir.h +577 -0
  255. data/lua-hooks/ext/luajit/src/lj_ir.o +0 -0
  256. data/lua-hooks/ext/luajit/src/lj_ir_dyn.o +0 -0
  257. data/lua-hooks/ext/luajit/src/lj_ircall.h +321 -0
  258. data/lua-hooks/ext/luajit/src/lj_iropt.h +161 -0
  259. data/lua-hooks/ext/luajit/src/lj_jit.h +440 -0
  260. data/lua-hooks/ext/luajit/src/lj_lex.c +482 -0
  261. data/lua-hooks/ext/luajit/src/lj_lex.h +86 -0
  262. data/lua-hooks/ext/luajit/src/lj_lex.o +0 -0
  263. data/lua-hooks/ext/luajit/src/lj_lex_dyn.o +0 -0
  264. data/lua-hooks/ext/luajit/src/lj_lib.c +303 -0
  265. data/lua-hooks/ext/luajit/src/lj_lib.h +115 -0
  266. data/lua-hooks/ext/luajit/src/lj_lib.o +0 -0
  267. data/lua-hooks/ext/luajit/src/lj_lib_dyn.o +0 -0
  268. data/lua-hooks/ext/luajit/src/lj_libdef.h +414 -0
  269. data/lua-hooks/ext/luajit/src/lj_load.c +168 -0
  270. data/lua-hooks/ext/luajit/src/lj_load.o +0 -0
  271. data/lua-hooks/ext/luajit/src/lj_load_dyn.o +0 -0
  272. data/lua-hooks/ext/luajit/src/lj_mcode.c +386 -0
  273. data/lua-hooks/ext/luajit/src/lj_mcode.h +30 -0
  274. data/lua-hooks/ext/luajit/src/lj_mcode.o +0 -0
  275. data/lua-hooks/ext/luajit/src/lj_mcode_dyn.o +0 -0
  276. data/lua-hooks/ext/luajit/src/lj_meta.c +477 -0
  277. data/lua-hooks/ext/luajit/src/lj_meta.h +38 -0
  278. data/lua-hooks/ext/luajit/src/lj_meta.o +0 -0
  279. data/lua-hooks/ext/luajit/src/lj_meta_dyn.o +0 -0
  280. data/lua-hooks/ext/luajit/src/lj_obj.c +50 -0
  281. data/lua-hooks/ext/luajit/src/lj_obj.h +976 -0
  282. data/lua-hooks/ext/luajit/src/lj_obj.o +0 -0
  283. data/lua-hooks/ext/luajit/src/lj_obj_dyn.o +0 -0
  284. data/lua-hooks/ext/luajit/src/lj_opt_dce.c +78 -0
  285. data/lua-hooks/ext/luajit/src/lj_opt_dce.o +0 -0
  286. data/lua-hooks/ext/luajit/src/lj_opt_dce_dyn.o +0 -0
  287. data/lua-hooks/ext/luajit/src/lj_opt_fold.c +2488 -0
  288. data/lua-hooks/ext/luajit/src/lj_opt_fold.o +0 -0
  289. data/lua-hooks/ext/luajit/src/lj_opt_fold_dyn.o +0 -0
  290. data/lua-hooks/ext/luajit/src/lj_opt_loop.c +449 -0
  291. data/lua-hooks/ext/luajit/src/lj_opt_loop.o +0 -0
  292. data/lua-hooks/ext/luajit/src/lj_opt_loop_dyn.o +0 -0
  293. data/lua-hooks/ext/luajit/src/lj_opt_mem.c +935 -0
  294. data/lua-hooks/ext/luajit/src/lj_opt_mem.o +0 -0
  295. data/lua-hooks/ext/luajit/src/lj_opt_mem_dyn.o +0 -0
  296. data/lua-hooks/ext/luajit/src/lj_opt_narrow.c +652 -0
  297. data/lua-hooks/ext/luajit/src/lj_opt_narrow.o +0 -0
  298. data/lua-hooks/ext/luajit/src/lj_opt_narrow_dyn.o +0 -0
  299. data/lua-hooks/ext/luajit/src/lj_opt_sink.c +245 -0
  300. data/lua-hooks/ext/luajit/src/lj_opt_sink.o +0 -0
  301. data/lua-hooks/ext/luajit/src/lj_opt_sink_dyn.o +0 -0
  302. data/lua-hooks/ext/luajit/src/lj_opt_split.c +856 -0
  303. data/lua-hooks/ext/luajit/src/lj_opt_split.o +0 -0
  304. data/lua-hooks/ext/luajit/src/lj_opt_split_dyn.o +0 -0
  305. data/lua-hooks/ext/luajit/src/lj_parse.c +2725 -0
  306. data/lua-hooks/ext/luajit/src/lj_parse.h +18 -0
  307. data/lua-hooks/ext/luajit/src/lj_parse.o +0 -0
  308. data/lua-hooks/ext/luajit/src/lj_parse_dyn.o +0 -0
  309. data/lua-hooks/ext/luajit/src/lj_profile.c +368 -0
  310. data/lua-hooks/ext/luajit/src/lj_profile.h +21 -0
  311. data/lua-hooks/ext/luajit/src/lj_profile.o +0 -0
  312. data/lua-hooks/ext/luajit/src/lj_profile_dyn.o +0 -0
  313. data/lua-hooks/ext/luajit/src/lj_recdef.h +270 -0
  314. data/lua-hooks/ext/luajit/src/lj_record.c +2554 -0
  315. data/lua-hooks/ext/luajit/src/lj_record.h +45 -0
  316. data/lua-hooks/ext/luajit/src/lj_record.o +0 -0
  317. data/lua-hooks/ext/luajit/src/lj_record_dyn.o +0 -0
  318. data/lua-hooks/ext/luajit/src/lj_snap.c +870 -0
  319. data/lua-hooks/ext/luajit/src/lj_snap.h +34 -0
  320. data/lua-hooks/ext/luajit/src/lj_snap.o +0 -0
  321. data/lua-hooks/ext/luajit/src/lj_snap_dyn.o +0 -0
  322. data/lua-hooks/ext/luajit/src/lj_state.c +300 -0
  323. data/lua-hooks/ext/luajit/src/lj_state.h +35 -0
  324. data/lua-hooks/ext/luajit/src/lj_state.o +0 -0
  325. data/lua-hooks/ext/luajit/src/lj_state_dyn.o +0 -0
  326. data/lua-hooks/ext/luajit/src/lj_str.c +197 -0
  327. data/lua-hooks/ext/luajit/src/lj_str.h +27 -0
  328. data/lua-hooks/ext/luajit/src/lj_str.o +0 -0
  329. data/lua-hooks/ext/luajit/src/lj_str_dyn.o +0 -0
  330. data/lua-hooks/ext/luajit/src/lj_strfmt.c +554 -0
  331. data/lua-hooks/ext/luajit/src/lj_strfmt.h +125 -0
  332. data/lua-hooks/ext/luajit/src/lj_strfmt.o +0 -0
  333. data/lua-hooks/ext/luajit/src/lj_strfmt_dyn.o +0 -0
  334. data/lua-hooks/ext/luajit/src/lj_strscan.c +547 -0
  335. data/lua-hooks/ext/luajit/src/lj_strscan.h +39 -0
  336. data/lua-hooks/ext/luajit/src/lj_strscan.o +0 -0
  337. data/lua-hooks/ext/luajit/src/lj_strscan_dyn.o +0 -0
  338. data/lua-hooks/ext/luajit/src/lj_tab.c +666 -0
  339. data/lua-hooks/ext/luajit/src/lj_tab.h +73 -0
  340. data/lua-hooks/ext/luajit/src/lj_tab.o +0 -0
  341. data/lua-hooks/ext/luajit/src/lj_tab_dyn.o +0 -0
  342. data/lua-hooks/ext/luajit/src/lj_target.h +164 -0
  343. data/lua-hooks/ext/luajit/src/lj_target_arm.h +270 -0
  344. data/lua-hooks/ext/luajit/src/lj_target_arm64.h +97 -0
  345. data/lua-hooks/ext/luajit/src/lj_target_mips.h +260 -0
  346. data/lua-hooks/ext/luajit/src/lj_target_ppc.h +280 -0
  347. data/lua-hooks/ext/luajit/src/lj_target_x86.h +345 -0
  348. data/lua-hooks/ext/luajit/src/lj_trace.c +859 -0
  349. data/lua-hooks/ext/luajit/src/lj_trace.h +54 -0
  350. data/lua-hooks/ext/luajit/src/lj_trace.o +0 -0
  351. data/lua-hooks/ext/luajit/src/lj_trace_dyn.o +0 -0
  352. data/lua-hooks/ext/luajit/src/lj_traceerr.h +63 -0
  353. data/lua-hooks/ext/luajit/src/lj_udata.c +34 -0
  354. data/lua-hooks/ext/luajit/src/lj_udata.h +14 -0
  355. data/lua-hooks/ext/luajit/src/lj_udata.o +0 -0
  356. data/lua-hooks/ext/luajit/src/lj_udata_dyn.o +0 -0
  357. data/lua-hooks/ext/luajit/src/lj_vm.S +2730 -0
  358. data/lua-hooks/ext/luajit/src/lj_vm.h +114 -0
  359. data/lua-hooks/ext/luajit/src/lj_vm.o +0 -0
  360. data/lua-hooks/ext/luajit/src/lj_vm_dyn.o +0 -0
  361. data/lua-hooks/ext/luajit/src/lj_vmevent.c +58 -0
  362. data/lua-hooks/ext/luajit/src/lj_vmevent.h +59 -0
  363. data/lua-hooks/ext/luajit/src/lj_vmevent.o +0 -0
  364. data/lua-hooks/ext/luajit/src/lj_vmevent_dyn.o +0 -0
  365. data/lua-hooks/ext/luajit/src/lj_vmmath.c +152 -0
  366. data/lua-hooks/ext/luajit/src/lj_vmmath.o +0 -0
  367. data/lua-hooks/ext/luajit/src/lj_vmmath_dyn.o +0 -0
  368. data/lua-hooks/ext/luajit/src/ljamalg.c +96 -0
  369. data/lua-hooks/ext/{lua → luajit/src}/lua.h +12 -7
  370. data/lua-hooks/ext/luajit/src/lua.hpp +9 -0
  371. data/lua-hooks/ext/luajit/src/luaconf.h +156 -0
  372. data/lua-hooks/ext/luajit/src/luajit +0 -0
  373. data/lua-hooks/ext/luajit/src/luajit.c +570 -0
  374. data/lua-hooks/ext/luajit/src/luajit.h +79 -0
  375. data/lua-hooks/ext/luajit/src/luajit.o +0 -0
  376. data/lua-hooks/ext/luajit/src/lualib.h +43 -0
  377. data/lua-hooks/ext/luajit/src/msvcbuild.bat +114 -0
  378. data/lua-hooks/ext/luajit/src/ps4build.bat +103 -0
  379. data/lua-hooks/ext/luajit/src/psvitabuild.bat +93 -0
  380. data/lua-hooks/ext/luajit/src/vm_arm.dasc +4585 -0
  381. data/lua-hooks/ext/luajit/src/vm_arm64.dasc +3764 -0
  382. data/lua-hooks/ext/luajit/src/vm_mips.dasc +4355 -0
  383. data/lua-hooks/ext/luajit/src/vm_ppc.dasc +5252 -0
  384. data/lua-hooks/ext/luajit/src/vm_x64.dasc +4902 -0
  385. data/lua-hooks/ext/luajit/src/vm_x86.dasc +5710 -0
  386. data/lua-hooks/ext/luajit/src/xb1build.bat +101 -0
  387. data/lua-hooks/ext/luajit/src/xedkbuild.bat +92 -0
  388. data/lua-hooks/ext/luautf8/lutf8lib.c +3 -3
  389. data/lua-hooks/lib/boot.lua +37 -2
  390. metadata +372 -69
  391. data/lua-hooks/ext/bitop/README +0 -22
  392. data/lua-hooks/ext/bitop/bit.c +0 -189
  393. data/lua-hooks/ext/extconf.rb +0 -38
  394. data/lua-hooks/ext/lua/COPYRIGHT +0 -34
  395. data/lua-hooks/ext/lua/lapi.c +0 -1087
  396. data/lua-hooks/ext/lua/lapi.h +0 -16
  397. data/lua-hooks/ext/lua/lauxlib.c +0 -652
  398. data/lua-hooks/ext/lua/lbaselib.c +0 -659
  399. data/lua-hooks/ext/lua/lcode.c +0 -831
  400. data/lua-hooks/ext/lua/lcode.h +0 -76
  401. data/lua-hooks/ext/lua/ldblib.c +0 -398
  402. data/lua-hooks/ext/lua/ldebug.c +0 -638
  403. data/lua-hooks/ext/lua/ldebug.h +0 -33
  404. data/lua-hooks/ext/lua/ldo.c +0 -519
  405. data/lua-hooks/ext/lua/ldo.h +0 -57
  406. data/lua-hooks/ext/lua/ldump.c +0 -164
  407. data/lua-hooks/ext/lua/lfunc.c +0 -174
  408. data/lua-hooks/ext/lua/lfunc.h +0 -34
  409. data/lua-hooks/ext/lua/lgc.c +0 -710
  410. data/lua-hooks/ext/lua/lgc.h +0 -110
  411. data/lua-hooks/ext/lua/linit.c +0 -38
  412. data/lua-hooks/ext/lua/liolib.c +0 -556
  413. data/lua-hooks/ext/lua/llex.c +0 -463
  414. data/lua-hooks/ext/lua/llex.h +0 -81
  415. data/lua-hooks/ext/lua/llimits.h +0 -128
  416. data/lua-hooks/ext/lua/lmathlib.c +0 -263
  417. data/lua-hooks/ext/lua/lmem.c +0 -86
  418. data/lua-hooks/ext/lua/lmem.h +0 -49
  419. data/lua-hooks/ext/lua/loadlib.c +0 -705
  420. data/lua-hooks/ext/lua/loadlib_rel.c +0 -760
  421. data/lua-hooks/ext/lua/lobject.c +0 -214
  422. data/lua-hooks/ext/lua/lobject.h +0 -381
  423. data/lua-hooks/ext/lua/lopcodes.c +0 -102
  424. data/lua-hooks/ext/lua/lopcodes.h +0 -268
  425. data/lua-hooks/ext/lua/loslib.c +0 -243
  426. data/lua-hooks/ext/lua/lparser.c +0 -1339
  427. data/lua-hooks/ext/lua/lparser.h +0 -82
  428. data/lua-hooks/ext/lua/lstate.c +0 -214
  429. data/lua-hooks/ext/lua/lstate.h +0 -169
  430. data/lua-hooks/ext/lua/lstring.c +0 -111
  431. data/lua-hooks/ext/lua/lstring.h +0 -31
  432. data/lua-hooks/ext/lua/lstrlib.c +0 -871
  433. data/lua-hooks/ext/lua/ltable.c +0 -588
  434. data/lua-hooks/ext/lua/ltable.h +0 -40
  435. data/lua-hooks/ext/lua/ltablib.c +0 -287
  436. data/lua-hooks/ext/lua/ltm.c +0 -75
  437. data/lua-hooks/ext/lua/ltm.h +0 -54
  438. data/lua-hooks/ext/lua/lua.c +0 -392
  439. data/lua-hooks/ext/lua/lua.def +0 -131
  440. data/lua-hooks/ext/lua/lua.rc +0 -28
  441. data/lua-hooks/ext/lua/lua_dll.rc +0 -26
  442. data/lua-hooks/ext/lua/luac.c +0 -200
  443. data/lua-hooks/ext/lua/luac.rc +0 -1
  444. data/lua-hooks/ext/lua/luaconf.h +0 -763
  445. data/lua-hooks/ext/lua/luaconf.h.in +0 -724
  446. data/lua-hooks/ext/lua/luaconf.h.orig +0 -763
  447. data/lua-hooks/ext/lua/lualib.h +0 -53
  448. data/lua-hooks/ext/lua/lundump.c +0 -227
  449. data/lua-hooks/ext/lua/lundump.h +0 -36
  450. data/lua-hooks/ext/lua/lvm.c +0 -767
  451. data/lua-hooks/ext/lua/lvm.h +0 -36
  452. data/lua-hooks/ext/lua/lzio.c +0 -82
  453. data/lua-hooks/ext/lua/lzio.h +0 -67
  454. data/lua-hooks/ext/lua/print.c +0 -227
@@ -0,0 +1,1166 @@
1
+ ------------------------------------------------------------------------------
2
+ -- DynASM ARM64 module.
3
+ --
4
+ -- Copyright (C) 2005-2015 Mike Pall. All rights reserved.
5
+ -- See dynasm.lua for full copyright notice.
6
+ ------------------------------------------------------------------------------
7
+
8
+ -- Module information:
9
+ local _info = {
10
+ arch = "arm",
11
+ description = "DynASM ARM64 module",
12
+ version = "1.3.0",
13
+ vernum = 10300,
14
+ release = "2014-12-03",
15
+ author = "Mike Pall",
16
+ license = "MIT",
17
+ }
18
+
19
+ -- Exported glue functions for the arch-specific module.
20
+ local _M = { _info = _info }
21
+
22
+ -- Cache library functions.
23
+ local type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs
24
+ local assert, setmetatable, rawget = assert, setmetatable, rawget
25
+ local _s = string
26
+ local sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char
27
+ local match, gmatch, gsub = _s.match, _s.gmatch, _s.gsub
28
+ local concat, sort, insert = table.concat, table.sort, table.insert
29
+ local bit = bit or require("bit")
30
+ local band, shl, shr, sar = bit.band, bit.lshift, bit.rshift, bit.arshift
31
+ local ror, tohex = bit.ror, bit.tohex
32
+
33
+ -- Inherited tables and callbacks.
34
+ local g_opt, g_arch
35
+ local wline, werror, wfatal, wwarn
36
+
37
+ -- Action name list.
38
+ -- CHECK: Keep this in sync with the C code!
39
+ local action_names = {
40
+ "STOP", "SECTION", "ESC", "REL_EXT",
41
+ "ALIGN", "REL_LG", "LABEL_LG",
42
+ "REL_PC", "LABEL_PC", "IMM", "IMM6", "IMM12", "IMM13W", "IMM13X", "IMML",
43
+ }
44
+
45
+ -- Maximum number of section buffer positions for dasm_put().
46
+ -- CHECK: Keep this in sync with the C code!
47
+ local maxsecpos = 25 -- Keep this low, to avoid excessively long C lines.
48
+
49
+ -- Action name -> action number.
50
+ local map_action = {}
51
+ for n,name in ipairs(action_names) do
52
+ map_action[name] = n-1
53
+ end
54
+
55
+ -- Action list buffer.
56
+ local actlist = {}
57
+
58
+ -- Argument list for next dasm_put(). Start with offset 0 into action list.
59
+ local actargs = { 0 }
60
+
61
+ -- Current number of section buffer positions for dasm_put().
62
+ local secpos = 1
63
+
64
+ ------------------------------------------------------------------------------
65
+
66
+ -- Dump action names and numbers.
67
+ local function dumpactions(out)
68
+ out:write("DynASM encoding engine action codes:\n")
69
+ for n,name in ipairs(action_names) do
70
+ local num = map_action[name]
71
+ out:write(format(" %-10s %02X %d\n", name, num, num))
72
+ end
73
+ out:write("\n")
74
+ end
75
+
76
+ -- Write action list buffer as a huge static C array.
77
+ local function writeactions(out, name)
78
+ local nn = #actlist
79
+ if nn == 0 then nn = 1; actlist[0] = map_action.STOP end
80
+ out:write("static const unsigned int ", name, "[", nn, "] = {\n")
81
+ for i = 1,nn-1 do
82
+ assert(out:write("0x", tohex(actlist[i]), ",\n"))
83
+ end
84
+ assert(out:write("0x", tohex(actlist[nn]), "\n};\n\n"))
85
+ end
86
+
87
+ ------------------------------------------------------------------------------
88
+
89
+ -- Add word to action list.
90
+ local function wputxw(n)
91
+ assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, "word out of range")
92
+ actlist[#actlist+1] = n
93
+ end
94
+
95
+ -- Add action to list with optional arg. Advance buffer pos, too.
96
+ local function waction(action, val, a, num)
97
+ local w = assert(map_action[action], "bad action name `"..action.."'")
98
+ wputxw(w * 0x10000 + (val or 0))
99
+ if a then actargs[#actargs+1] = a end
100
+ if a or num then secpos = secpos + (num or 1) end
101
+ end
102
+
103
+ -- Flush action list (intervening C code or buffer pos overflow).
104
+ local function wflush(term)
105
+ if #actlist == actargs[1] then return end -- Nothing to flush.
106
+ if not term then waction("STOP") end -- Terminate action list.
107
+ wline(format("dasm_put(Dst, %s);", concat(actargs, ", ")), true)
108
+ actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put().
109
+ secpos = 1 -- The actionlist offset occupies a buffer position, too.
110
+ end
111
+
112
+ -- Put escaped word.
113
+ local function wputw(n)
114
+ if n <= 0x000fffff then waction("ESC") end
115
+ wputxw(n)
116
+ end
117
+
118
+ -- Reserve position for word.
119
+ local function wpos()
120
+ local pos = #actlist+1
121
+ actlist[pos] = ""
122
+ return pos
123
+ end
124
+
125
+ -- Store word to reserved position.
126
+ local function wputpos(pos, n)
127
+ assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, "word out of range")
128
+ if n <= 0x000fffff then
129
+ insert(actlist, pos+1, n)
130
+ n = map_action.ESC * 0x10000
131
+ end
132
+ actlist[pos] = n
133
+ end
134
+
135
+ ------------------------------------------------------------------------------
136
+
137
+ -- Global label name -> global label number. With auto assignment on 1st use.
138
+ local next_global = 20
139
+ local map_global = setmetatable({}, { __index = function(t, name)
140
+ if not match(name, "^[%a_][%w_]*$") then werror("bad global label") end
141
+ local n = next_global
142
+ if n > 2047 then werror("too many global labels") end
143
+ next_global = n + 1
144
+ t[name] = n
145
+ return n
146
+ end})
147
+
148
+ -- Dump global labels.
149
+ local function dumpglobals(out, lvl)
150
+ local t = {}
151
+ for name, n in pairs(map_global) do t[n] = name end
152
+ out:write("Global labels:\n")
153
+ for i=20,next_global-1 do
154
+ out:write(format(" %s\n", t[i]))
155
+ end
156
+ out:write("\n")
157
+ end
158
+
159
+ -- Write global label enum.
160
+ local function writeglobals(out, prefix)
161
+ local t = {}
162
+ for name, n in pairs(map_global) do t[n] = name end
163
+ out:write("enum {\n")
164
+ for i=20,next_global-1 do
165
+ out:write(" ", prefix, t[i], ",\n")
166
+ end
167
+ out:write(" ", prefix, "_MAX\n};\n")
168
+ end
169
+
170
+ -- Write global label names.
171
+ local function writeglobalnames(out, name)
172
+ local t = {}
173
+ for name, n in pairs(map_global) do t[n] = name end
174
+ out:write("static const char *const ", name, "[] = {\n")
175
+ for i=20,next_global-1 do
176
+ out:write(" \"", t[i], "\",\n")
177
+ end
178
+ out:write(" (const char *)0\n};\n")
179
+ end
180
+
181
+ ------------------------------------------------------------------------------
182
+
183
+ -- Extern label name -> extern label number. With auto assignment on 1st use.
184
+ local next_extern = 0
185
+ local map_extern_ = {}
186
+ local map_extern = setmetatable({}, { __index = function(t, name)
187
+ -- No restrictions on the name for now.
188
+ local n = next_extern
189
+ if n > 2047 then werror("too many extern labels") end
190
+ next_extern = n + 1
191
+ t[name] = n
192
+ map_extern_[n] = name
193
+ return n
194
+ end})
195
+
196
+ -- Dump extern labels.
197
+ local function dumpexterns(out, lvl)
198
+ out:write("Extern labels:\n")
199
+ for i=0,next_extern-1 do
200
+ out:write(format(" %s\n", map_extern_[i]))
201
+ end
202
+ out:write("\n")
203
+ end
204
+
205
+ -- Write extern label names.
206
+ local function writeexternnames(out, name)
207
+ out:write("static const char *const ", name, "[] = {\n")
208
+ for i=0,next_extern-1 do
209
+ out:write(" \"", map_extern_[i], "\",\n")
210
+ end
211
+ out:write(" (const char *)0\n};\n")
212
+ end
213
+
214
+ ------------------------------------------------------------------------------
215
+
216
+ -- Arch-specific maps.
217
+
218
+ -- Ext. register name -> int. name.
219
+ local map_archdef = { xzr = "@x31", wzr = "@w31", lr = "x30", }
220
+
221
+ -- Int. register name -> ext. name.
222
+ local map_reg_rev = { ["@x31"] = "xzr", ["@w31"] = "wzr", x30 = "lr", }
223
+
224
+ local map_type = {} -- Type name -> { ctype, reg }
225
+ local ctypenum = 0 -- Type number (for Dt... macros).
226
+
227
+ -- Reverse defines for registers.
228
+ function _M.revdef(s)
229
+ return map_reg_rev[s] or s
230
+ end
231
+
232
+ local map_shift = { lsl = 0, lsr = 1, asr = 2, }
233
+
234
+ local map_extend = {
235
+ uxtb = 0, uxth = 1, uxtw = 2, uxtx = 3,
236
+ sxtb = 4, sxth = 5, sxtw = 6, sxtx = 7,
237
+ }
238
+
239
+ local map_cond = {
240
+ eq = 0, ne = 1, cs = 2, cc = 3, mi = 4, pl = 5, vs = 6, vc = 7,
241
+ hi = 8, ls = 9, ge = 10, lt = 11, gt = 12, le = 13, al = 14,
242
+ hs = 2, lo = 3,
243
+ }
244
+
245
+ ------------------------------------------------------------------------------
246
+
247
+ local parse_reg_type
248
+
249
+ local function parse_reg(expr)
250
+ if not expr then werror("expected register name") end
251
+ local tname, ovreg = match(expr, "^([%w_]+):(@?%l%d+)$")
252
+ local tp = map_type[tname or expr]
253
+ if tp then
254
+ local reg = ovreg or tp.reg
255
+ if not reg then
256
+ werror("type `"..(tname or expr).."' needs a register override")
257
+ end
258
+ expr = reg
259
+ end
260
+ local ok31, rt, r = match(expr, "^(@?)([xwqdshb])([123]?[0-9])$")
261
+ if r then
262
+ r = tonumber(r)
263
+ if r <= 30 or (r == 31 and ok31 ~= "" or (rt ~= "w" and rt ~= "x")) then
264
+ if not parse_reg_type then
265
+ parse_reg_type = rt
266
+ elseif parse_reg_type ~= rt then
267
+ werror("register size mismatch")
268
+ end
269
+ return r, tp
270
+ end
271
+ end
272
+ werror("bad register name `"..expr.."'")
273
+ end
274
+
275
+ local function parse_reg_base(expr)
276
+ if expr == "sp" then return 0x3e0 end
277
+ local base, tp = parse_reg(expr)
278
+ if parse_reg_type ~= "x" then werror("bad register type") end
279
+ parse_reg_type = false
280
+ return shl(base, 5), tp
281
+ end
282
+
283
+ local parse_ctx = {}
284
+
285
+ local loadenv = setfenv and function(s)
286
+ local code = loadstring(s, "")
287
+ if code then setfenv(code, parse_ctx) end
288
+ return code
289
+ end or function(s)
290
+ return load(s, "", nil, parse_ctx)
291
+ end
292
+
293
+ -- Try to parse simple arithmetic, too, since some basic ops are aliases.
294
+ local function parse_number(n)
295
+ local x = tonumber(n)
296
+ if x then return x end
297
+ local code = loadenv("return "..n)
298
+ if code then
299
+ local ok, y = pcall(code)
300
+ if ok then return y end
301
+ end
302
+ return nil
303
+ end
304
+
305
+ local function parse_imm(imm, bits, shift, scale, signed)
306
+ imm = match(imm, "^#(.*)$")
307
+ if not imm then werror("expected immediate operand") end
308
+ local n = parse_number(imm)
309
+ if n then
310
+ local m = sar(n, scale)
311
+ if shl(m, scale) == n then
312
+ if signed then
313
+ local s = sar(m, bits-1)
314
+ if s == 0 then return shl(m, shift)
315
+ elseif s == -1 then return shl(m + shl(1, bits), shift) end
316
+ else
317
+ if sar(m, bits) == 0 then return shl(m, shift) end
318
+ end
319
+ end
320
+ werror("out of range immediate `"..imm.."'")
321
+ else
322
+ waction("IMM", (signed and 32768 or 0)+scale*1024+bits*32+shift, imm)
323
+ return 0
324
+ end
325
+ end
326
+
327
+ local function parse_imm12(imm)
328
+ imm = match(imm, "^#(.*)$")
329
+ if not imm then werror("expected immediate operand") end
330
+ local n = parse_number(imm)
331
+ if n then
332
+ if shr(n, 12) == 0 then
333
+ return shl(n, 10)
334
+ elseif band(n, 0xff000fff) == 0 then
335
+ return shr(n, 2) + 0x00400000
336
+ end
337
+ werror("out of range immediate `"..imm.."'")
338
+ else
339
+ waction("IMM12", 0, imm)
340
+ return 0
341
+ end
342
+ end
343
+
344
+ local function parse_imm13(imm)
345
+ imm = match(imm, "^#(.*)$")
346
+ if not imm then werror("expected immediate operand") end
347
+ local n = parse_number(imm)
348
+ local r64 = parse_reg_type == "x"
349
+ if n and n % 1 == 0 and n >= 0 and n <= 0xffffffff then
350
+ local inv = false
351
+ if band(n, 1) == 1 then n = bit.bnot(n); inv = true end
352
+ local t = {}
353
+ for i=1,32 do t[i] = band(n, 1); n = shr(n, 1) end
354
+ local b = table.concat(t)
355
+ b = b..(r64 and (inv and "1" or "0"):rep(32) or b)
356
+ local p0, p1, p0a, p1a = b:match("^(0+)(1+)(0*)(1*)")
357
+ if p0 then
358
+ local w = p1a == "" and (r64 and 64 or 32) or #p1+#p0a
359
+ if band(w, w-1) == 0 and b == b:sub(1, w):rep(64/w) then
360
+ local s = band(-2*w, 0x3f) - 1
361
+ if w == 64 then s = s + 0x1000 end
362
+ if inv then
363
+ return shl(w-#p1-#p0, 16) + shl(s+w-#p1, 10)
364
+ else
365
+ return shl(w-#p0, 16) + shl(s+#p1, 10)
366
+ end
367
+ end
368
+ end
369
+ werror("out of range immediate `"..imm.."'")
370
+ elseif r64 then
371
+ waction("IMM13X", 0, format("(unsigned int)(%s)", imm))
372
+ actargs[#actargs+1] = format("(unsigned int)((unsigned long long)(%s)>>32)", imm)
373
+ return 0
374
+ else
375
+ waction("IMM13W", 0, imm)
376
+ return 0
377
+ end
378
+ end
379
+
380
+ local function parse_imm6(imm)
381
+ imm = match(imm, "^#(.*)$")
382
+ if not imm then werror("expected immediate operand") end
383
+ local n = parse_number(imm)
384
+ if n then
385
+ if n >= 0 and n <= 63 then
386
+ return shl(band(n, 0x1f), 19) + (n >= 32 and 0x80000000 or 0)
387
+ end
388
+ werror("out of range immediate `"..imm.."'")
389
+ else
390
+ waction("IMM6", 0, imm)
391
+ return 0
392
+ end
393
+ end
394
+
395
+ local function parse_imm_load(imm, scale)
396
+ local n = parse_number(imm)
397
+ if n then
398
+ local m = sar(n, scale)
399
+ if shl(m, scale) == n and m >= 0 and m < 0x1000 then
400
+ return shl(m, 10) + 0x01000000 -- Scaled, unsigned 12 bit offset.
401
+ elseif n >= -256 and n < 256 then
402
+ return shl(band(n, 511), 12) -- Unscaled, signed 9 bit offset.
403
+ end
404
+ werror("out of range immediate `"..imm.."'")
405
+ else
406
+ waction("IMML", 0, imm)
407
+ return 0
408
+ end
409
+ end
410
+
411
+ local function parse_fpimm(imm)
412
+ imm = match(imm, "^#(.*)$")
413
+ if not imm then werror("expected immediate operand") end
414
+ local n = parse_number(imm)
415
+ if n then
416
+ local m, e = math.frexp(n)
417
+ local s, e2 = 0, band(e-2, 7)
418
+ if m < 0 then m = -m; s = 0x00100000 end
419
+ m = m*32-16
420
+ if m % 1 == 0 and m >= 0 and m <= 15 and sar(shl(e2, 29), 29)+2 == e then
421
+ return s + shl(e2, 17) + shl(m, 13)
422
+ end
423
+ werror("out of range immediate `"..imm.."'")
424
+ else
425
+ werror("NYI fpimm action")
426
+ end
427
+ end
428
+
429
+ local function parse_shift(expr)
430
+ local s, s2 = match(expr, "^(%S+)%s*(.*)$")
431
+ s = map_shift[s]
432
+ if not s then werror("expected shift operand") end
433
+ return parse_imm(s2, 6, 10, 0, false) + shl(s, 22)
434
+ end
435
+
436
+ local function parse_lslx16(expr)
437
+ local n = match(expr, "^lsl%s*#(%d+)$")
438
+ n = tonumber(n)
439
+ if not n then werror("expected shift operand") end
440
+ if band(n, parse_reg_type == "x" and 0xffffffcf or 0xffffffef) ~= 0 then
441
+ werror("bad shift amount")
442
+ end
443
+ return shl(n, 17)
444
+ end
445
+
446
+ local function parse_extend(expr)
447
+ local s, s2 = match(expr, "^(%S+)%s*(.*)$")
448
+ if s == "lsl" then
449
+ s = parse_reg_type == "x" and 3 or 2
450
+ else
451
+ s = map_extend[s]
452
+ end
453
+ if not s then werror("expected extend operand") end
454
+ return (s2 == "" and 0 or parse_imm(s2, 3, 10, 0, false)) + shl(s, 13)
455
+ end
456
+
457
+ local function parse_cond(expr, inv)
458
+ local c = map_cond[expr]
459
+ if not c then werror("expected condition operand") end
460
+ return shl(bit.bxor(c, inv), 12)
461
+ end
462
+
463
+ local function parse_load(params, nparams, n, op)
464
+ if params[n+2] then werror("too many operands") end
465
+ local pn, p2 = params[n], params[n+1]
466
+ local p1, wb = match(pn, "^%[%s*(.-)%s*%](!?)$")
467
+ if not p1 then
468
+ if not p2 then
469
+ local reg, tailr = match(pn, "^([%w_:]+)%s*(.*)$")
470
+ if reg and tailr ~= "" then
471
+ local base, tp = parse_reg_base(reg)
472
+ if tp then
473
+ waction("IMML", 0, format(tp.ctypefmt, tailr))
474
+ return op + base
475
+ end
476
+ end
477
+ end
478
+ werror("expected address operand")
479
+ end
480
+ local scale = shr(op, 30)
481
+ if p2 then
482
+ if wb == "!" then werror("bad use of '!'") end
483
+ op = op + parse_reg_base(p1) + parse_imm(p2, 9, 12, 0, true) + 0x400
484
+ elseif wb == "!" then
485
+ local p1a, p2a = match(p1, "^([^,%s]*)%s*,%s*(.*)$")
486
+ if not p1a then werror("bad use of '!'") end
487
+ op = op + parse_reg_base(p1a) + parse_imm(p2a, 9, 12, 0, true) + 0xc00
488
+ else
489
+ local p1a, p2a = match(p1, "^([^,%s]*)%s*(.*)$")
490
+ op = op + parse_reg_base(p1a)
491
+ if p2a ~= "" then
492
+ local imm = match(p2a, "^,%s*#(.*)$")
493
+ if imm then
494
+ op = op + parse_imm_load(imm, scale)
495
+ else
496
+ local p2b, p3b, p3s = match(p2a, "^,%s*([^,%s]*)%s*,?%s*(%S*)%s*(.*)$")
497
+ op = op + shl(parse_reg(p2b), 16) + 0x00200800
498
+ if parse_reg_type ~= "x" and parse_reg_type ~= "w" then
499
+ werror("bad index register type")
500
+ end
501
+ if p3b == "" then
502
+ if parse_reg_type ~= "x" then werror("bad index register type") end
503
+ op = op + 0x6000
504
+ else
505
+ if p3s == "" or p3s == "#0" then
506
+ elseif p3s == "#"..scale then
507
+ op = op + 0x1000
508
+ else
509
+ werror("bad scale")
510
+ end
511
+ if parse_reg_type == "x" then
512
+ if p3b == "lsl" and p3s ~= "" then op = op + 0x6000
513
+ elseif p3b == "sxtx" then op = op + 0xe000
514
+ else
515
+ werror("bad extend/shift specifier")
516
+ end
517
+ else
518
+ if p3b == "uxtw" then op = op + 0x4000
519
+ elseif p3b == "sxtw" then op = op + 0xc000
520
+ else
521
+ werror("bad extend/shift specifier")
522
+ end
523
+ end
524
+ end
525
+ end
526
+ else
527
+ if wb == "!" then werror("bad use of '!'") end
528
+ op = op + 0x01000000
529
+ end
530
+ end
531
+ return op
532
+ end
533
+
534
+ local function parse_load_pair(params, nparams, n, op)
535
+ if params[n+2] then werror("too many operands") end
536
+ local pn, p2 = params[n], params[n+1]
537
+ local scale = shr(op, 30) == 0 and 2 or 3
538
+ local p1, wb = match(pn, "^%[%s*(.-)%s*%](!?)$")
539
+ if not p1 then
540
+ if not p2 then
541
+ local reg, tailr = match(pn, "^([%w_:]+)%s*(.*)$")
542
+ if reg and tailr ~= "" then
543
+ local base, tp = parse_reg_base(reg)
544
+ if tp then
545
+ waction("IMM", 32768+7*32+15+scale*1024, format(tp.ctypefmt, tailr))
546
+ return op + base + 0x01000000
547
+ end
548
+ end
549
+ end
550
+ werror("expected address operand")
551
+ end
552
+ if p2 then
553
+ if wb == "!" then werror("bad use of '!'") end
554
+ op = op + 0x00800000
555
+ else
556
+ local p1a, p2a = match(p1, "^([^,%s]*)%s*,%s*(.*)$")
557
+ if p1a then p1, p2 = p1a, p2a else p2 = "#0" end
558
+ op = op + (wb == "!" and 0x01800000 or 0x01000000)
559
+ end
560
+ return op + parse_reg_base(p1) + parse_imm(p2, 7, 15, scale, true)
561
+ end
562
+
563
+ local function parse_label(label, def)
564
+ local prefix = sub(label, 1, 2)
565
+ -- =>label (pc label reference)
566
+ if prefix == "=>" then
567
+ return "PC", 0, sub(label, 3)
568
+ end
569
+ -- ->name (global label reference)
570
+ if prefix == "->" then
571
+ return "LG", map_global[sub(label, 3)]
572
+ end
573
+ if def then
574
+ -- [1-9] (local label definition)
575
+ if match(label, "^[1-9]$") then
576
+ return "LG", 10+tonumber(label)
577
+ end
578
+ else
579
+ -- [<>][1-9] (local label reference)
580
+ local dir, lnum = match(label, "^([<>])([1-9])$")
581
+ if dir then -- Fwd: 1-9, Bkwd: 11-19.
582
+ return "LG", lnum + (dir == ">" and 0 or 10)
583
+ end
584
+ -- extern label (extern label reference)
585
+ local extname = match(label, "^extern%s+(%S+)$")
586
+ if extname then
587
+ return "EXT", map_extern[extname]
588
+ end
589
+ end
590
+ werror("bad label `"..label.."'")
591
+ end
592
+
593
+ local function branch_type(op)
594
+ if band(op, 0x7c000000) == 0x14000000 then return 0 -- B, BL
595
+ elseif shr(op, 24) == 0x54 or band(op, 0x7e000000) == 0x34000000 or
596
+ band(op, 0x3b000000) == 0x18000000 then
597
+ return 0x800 -- B.cond, CBZ, CBNZ, LDR* literal
598
+ elseif band(op, 0x7e000000) == 0x36000000 then return 0x1000 -- TBZ, TBNZ
599
+ elseif band(op, 0x9f000000) == 0x10000000 then return 0x2000 -- ADR
600
+ elseif band(op, 0x9f000000) == band(0x90000000) then return 0x3000 -- ADRP
601
+ else
602
+ assert(false, "unknown branch type")
603
+ end
604
+ end
605
+
606
+ ------------------------------------------------------------------------------
607
+
608
+ local map_op, op_template
609
+
610
+ local function op_alias(opname, f)
611
+ return function(params, nparams)
612
+ if not params then return "-> "..opname:sub(1, -3) end
613
+ f(params, nparams)
614
+ op_template(params, map_op[opname], nparams)
615
+ end
616
+ end
617
+
618
+ local function alias_bfx(p)
619
+ p[4] = "#("..p[3]:sub(2)..")+("..p[4]:sub(2)..")-1"
620
+ end
621
+
622
+ local function alias_bfiz(p)
623
+ parse_reg(p[1])
624
+ if parse_reg_type == "w" then
625
+ p[3] = "#-("..p[3]:sub(2)..")%32"
626
+ p[4] = "#("..p[4]:sub(2)..")-1"
627
+ else
628
+ p[3] = "#-("..p[3]:sub(2)..")%64"
629
+ p[4] = "#("..p[4]:sub(2)..")-1"
630
+ end
631
+ end
632
+
633
+ local alias_lslimm = op_alias("ubfm_4", function(p)
634
+ parse_reg(p[1])
635
+ local sh = p[3]:sub(2)
636
+ if parse_reg_type == "w" then
637
+ p[3] = "#-("..sh..")%32"
638
+ p[4] = "#31-("..sh..")"
639
+ else
640
+ p[3] = "#-("..sh..")%64"
641
+ p[4] = "#63-("..sh..")"
642
+ end
643
+ end)
644
+
645
+ -- Template strings for ARM instructions.
646
+ map_op = {
647
+ -- Basic data processing instructions.
648
+ add_3 = "0b000000DNMg|11000000pDpNIg|8b206000pDpNMx",
649
+ add_4 = "0b000000DNMSg|0b200000DNMXg|8b200000pDpNMXx|8b200000pDpNxMwX",
650
+ adds_3 = "2b000000DNMg|31000000DpNIg|ab206000DpNMx",
651
+ adds_4 = "2b000000DNMSg|2b200000DNMXg|ab200000DpNMXx|ab200000DpNxMwX",
652
+ cmn_2 = "2b00001fNMg|3100001fpNIg|ab20601fpNMx",
653
+ cmn_3 = "2b00001fNMSg|2b20001fNMXg|ab20001fpNMXx|ab20001fpNxMwX",
654
+
655
+ sub_3 = "4b000000DNMg|51000000pDpNIg|cb206000pDpNMx",
656
+ sub_4 = "4b000000DNMSg|4b200000DNMXg|cb200000pDpNMXx|cb200000pDpNxMwX",
657
+ subs_3 = "6b000000DNMg|71000000DpNIg|eb206000DpNMx",
658
+ subs_4 = "6b000000DNMSg|6b200000DNMXg|eb200000DpNMXx|eb200000DpNxMwX",
659
+ cmp_2 = "6b00001fNMg|7100001fpNIg|eb20601fpNMx",
660
+ cmp_3 = "6b00001fNMSg|6b20001fNMXg|eb20001fpNMXx|eb20001fpNxMwX",
661
+
662
+ neg_2 = "4b0003e0DMg",
663
+ neg_3 = "4b0003e0DMSg",
664
+ negs_2 = "6b0003e0DMg",
665
+ negs_3 = "6b0003e0DMSg",
666
+
667
+ adc_3 = "1a000000DNMg",
668
+ adcs_3 = "3a000000DNMg",
669
+ sbc_3 = "5a000000DNMg",
670
+ sbcs_3 = "7a000000DNMg",
671
+ ngc_2 = "5a0003e0DMg",
672
+ ngcs_2 = "7a0003e0DMg",
673
+
674
+ and_3 = "0a000000DNMg|12000000pDNig",
675
+ and_4 = "0a000000DNMSg",
676
+ orr_3 = "2a000000DNMg|32000000pDNig",
677
+ orr_4 = "2a000000DNMSg",
678
+ eor_3 = "4a000000DNMg|52000000pDNig",
679
+ eor_4 = "4a000000DNMSg",
680
+ ands_3 = "6a000000DNMg|72000000DNig",
681
+ ands_4 = "6a000000DNMSg",
682
+ tst_2 = "6a00001fNMg|7200001fNig",
683
+ tst_3 = "6a00001fNMSg",
684
+
685
+ bic_3 = "0a200000DNMg",
686
+ bic_4 = "0a200000DNMSg",
687
+ orn_3 = "2a200000DNMg",
688
+ orn_4 = "2a200000DNMSg",
689
+ eon_3 = "4a200000DNMg",
690
+ eon_4 = "4a200000DNMSg",
691
+ bics_3 = "6a200000DNMg",
692
+ bics_4 = "6a200000DNMSg",
693
+
694
+ movn_2 = "12800000DWg",
695
+ movn_3 = "12800000DWRg",
696
+ movz_2 = "52800000DWg",
697
+ movz_3 = "52800000DWRg",
698
+ movk_2 = "72800000DWg",
699
+ movk_3 = "72800000DWRg",
700
+
701
+ -- TODO: this doesn't cover all valid immediates for mov reg, #imm.
702
+ mov_2 = "2a0003e0DMg|52800000DW|320003e0pDig|11000000pDpNg",
703
+ mov_3 = "2a0003e0DMSg",
704
+ mvn_2 = "2a2003e0DMg",
705
+ mvn_3 = "2a2003e0DMSg",
706
+
707
+ adr_2 = "10000000DBx",
708
+ adrp_2 = "90000000DBx",
709
+
710
+ csel_4 = "1a800000DNMCg",
711
+ csinc_4 = "1a800400DNMCg",
712
+ csinv_4 = "5a800000DNMCg",
713
+ csneg_4 = "5a800400DNMCg",
714
+ cset_2 = "1a9f07e0Dcg",
715
+ csetm_2 = "5a9f03e0Dcg",
716
+ cinc_3 = "1a800400DNmcg",
717
+ cinv_3 = "5a800000DNmcg",
718
+ cneg_3 = "5a800400DNmcg",
719
+
720
+ ccmn_4 = "3a400000NMVCg|3a400800N5VCg",
721
+ ccmp_4 = "7a400000NMVCg|7a400800N5VCg",
722
+
723
+ madd_4 = "1b000000DNMAg",
724
+ msub_4 = "1b008000DNMAg",
725
+ mul_3 = "1b007c00DNMg",
726
+ mneg_3 = "1b00fc00DNMg",
727
+
728
+ smaddl_4 = "9b200000DxNMwAx",
729
+ smsubl_4 = "9b208000DxNMwAx",
730
+ smull_3 = "9b207c00DxNMw",
731
+ smnegl_3 = "9b20fc00DxNMw",
732
+ smulh_3 = "9b407c00DNMx",
733
+ umaddl_4 = "9ba00000DxNMwAx",
734
+ umsubl_4 = "9ba08000DxNMwAx",
735
+ umull_3 = "9ba07c00DxNMw",
736
+ umnegl_3 = "9ba0fc00DxNMw",
737
+ umulh_3 = "9bc07c00DNMx",
738
+
739
+ udiv_3 = "1ac00800DNMg",
740
+ sdiv_3 = "1ac00c00DNMg",
741
+
742
+ -- Bit operations.
743
+ sbfm_4 = "13000000DN12w|93400000DN12x",
744
+ bfm_4 = "33000000DN12w|b3400000DN12x",
745
+ ubfm_4 = "53000000DN12w|d3400000DN12x",
746
+ extr_4 = "13800000DNM2w|93c00000DNM2x",
747
+
748
+ sxtb_2 = "13001c00DNw|93401c00DNx",
749
+ sxth_2 = "13003c00DNw|93403c00DNx",
750
+ sxtw_2 = "93407c00DxNw",
751
+ uxtb_2 = "53001c00DNw",
752
+ uxth_2 = "53003c00DNw",
753
+
754
+ sbfx_4 = op_alias("sbfm_4", alias_bfx),
755
+ bfxil_4 = op_alias("bfm_4", alias_bfx),
756
+ ubfx_4 = op_alias("ubfm_4", alias_bfx),
757
+ sbfiz_4 = op_alias("sbfm_4", alias_bfiz),
758
+ bfi_4 = op_alias("bfm_4", alias_bfiz),
759
+ ubfiz_4 = op_alias("ubfm_4", alias_bfiz),
760
+
761
+ lsl_3 = function(params, nparams)
762
+ if params and params[3]:byte() == 35 then
763
+ return alias_lslimm(params, nparams)
764
+ else
765
+ return op_template(params, "1ac02000DNMg", nparams)
766
+ end
767
+ end,
768
+ lsr_3 = "1ac02400DNMg|53007c00DN1w|d340fc00DN1x",
769
+ asr_3 = "1ac02800DNMg|13007c00DN1w|9340fc00DN1x",
770
+ ror_3 = "1ac02c00DNMg|13800000DNm2w|93c00000DNm2x",
771
+
772
+ clz_2 = "5ac01000DNg",
773
+ cls_2 = "5ac01400DNg",
774
+ rbit_2 = "5ac00000DNg",
775
+ rev_2 = "5ac00800DNw|dac00c00DNx",
776
+ rev16_2 = "5ac00400DNg",
777
+ rev32_2 = "dac00800DNx",
778
+
779
+ -- Loads and stores.
780
+ ["strb_*"] = "38000000DwL",
781
+ ["ldrb_*"] = "38400000DwL",
782
+ ["ldrsb_*"] = "38c00000DwL|38800000DxL",
783
+ ["strh_*"] = "78000000DwL",
784
+ ["ldrh_*"] = "78400000DwL",
785
+ ["ldrsh_*"] = "78c00000DwL|78800000DxL",
786
+ ["str_*"] = "b8000000DwL|f8000000DxL|bc000000DsL|fc000000DdL",
787
+ ["ldr_*"] = "18000000DwB|58000000DxB|1c000000DsB|5c000000DdB|b8400000DwL|f8400000DxL|bc400000DsL|fc400000DdL",
788
+ ["ldrsw_*"] = "98000000DxB|b8800000DxL",
789
+ -- NOTE: ldur etc. are handled by ldr et al.
790
+
791
+ ["stp_*"] = "28000000DAwP|a8000000DAxP|2c000000DAsP|6c000000DAdP",
792
+ ["ldp_*"] = "28400000DAwP|a8400000DAxP|2c400000DAsP|6c400000DAdP",
793
+ ["ldpsw_*"] = "68400000DAxP",
794
+
795
+ -- Branches.
796
+ b_1 = "14000000B",
797
+ bl_1 = "94000000B",
798
+ blr_1 = "d63f0000Nx",
799
+ br_1 = "d61f0000Nx",
800
+ ret_0 = "d65f03c0",
801
+ ret_1 = "d65f0000Nx",
802
+ -- b.cond is added below.
803
+ cbz_2 = "34000000DBg",
804
+ cbnz_2 = "35000000DBg",
805
+ tbz_3 = "36000000DTBw|36000000DTBx",
806
+ tbnz_3 = "37000000DTBw|37000000DTBx",
807
+
808
+ -- Miscellaneous instructions.
809
+ -- TODO: hlt, hvc, smc, svc, eret, dcps[123], drps, mrs, msr
810
+ -- TODO: sys, sysl, ic, dc, at, tlbi
811
+ -- TODO: hint, yield, wfe, wfi, sev, sevl
812
+ -- TODO: clrex, dsb, dmb, isb
813
+ nop_0 = "d503201f",
814
+ brk_0 = "d4200000",
815
+ brk_1 = "d4200000W",
816
+
817
+ -- Floating point instructions.
818
+ fmov_2 = "1e204000DNf|1e260000DwNs|1e270000DsNw|9e660000DxNd|9e670000DdNx|1e201000DFf",
819
+ fabs_2 = "1e20c000DNf",
820
+ fneg_2 = "1e214000DNf",
821
+ fsqrt_2 = "1e21c000DNf",
822
+
823
+ fcvt_2 = "1e22c000DdNs|1e624000DsNd",
824
+
825
+ -- TODO: half-precision and fixed-point conversions.
826
+ fcvtas_2 = "1e240000DwNs|9e240000DxNs|1e640000DwNd|9e640000DxNd",
827
+ fcvtau_2 = "1e250000DwNs|9e250000DxNs|1e650000DwNd|9e650000DxNd",
828
+ fcvtms_2 = "1e300000DwNs|9e300000DxNs|1e700000DwNd|9e700000DxNd",
829
+ fcvtmu_2 = "1e310000DwNs|9e310000DxNs|1e710000DwNd|9e710000DxNd",
830
+ fcvtns_2 = "1e200000DwNs|9e200000DxNs|1e600000DwNd|9e600000DxNd",
831
+ fcvtnu_2 = "1e210000DwNs|9e210000DxNs|1e610000DwNd|9e610000DxNd",
832
+ fcvtps_2 = "1e280000DwNs|9e280000DxNs|1e680000DwNd|9e680000DxNd",
833
+ fcvtpu_2 = "1e290000DwNs|9e290000DxNs|1e690000DwNd|9e690000DxNd",
834
+ fcvtzs_2 = "1e380000DwNs|9e380000DxNs|1e780000DwNd|9e780000DxNd",
835
+ fcvtzu_2 = "1e390000DwNs|9e390000DxNs|1e790000DwNd|9e790000DxNd",
836
+
837
+ scvtf_2 = "1e220000DsNw|9e220000DsNx|1e620000DdNw|9e620000DdNx",
838
+ ucvtf_2 = "1e230000DsNw|9e230000DsNx|1e630000DdNw|9e630000DdNx",
839
+
840
+ frintn_2 = "1e244000DNf",
841
+ frintp_2 = "1e24c000DNf",
842
+ frintm_2 = "1e254000DNf",
843
+ frintz_2 = "1e25c000DNf",
844
+ frinta_2 = "1e264000DNf",
845
+ frintx_2 = "1e274000DNf",
846
+ frinti_2 = "1e27c000DNf",
847
+
848
+ fadd_3 = "1e202800DNMf",
849
+ fsub_3 = "1e203800DNMf",
850
+ fmul_3 = "1e200800DNMf",
851
+ fnmul_3 = "1e208800DNMf",
852
+ fdiv_3 = "1e201800DNMf",
853
+
854
+ fmadd_4 = "1f000000DNMAf",
855
+ fmsub_4 = "1f008000DNMAf",
856
+ fnmadd_4 = "1f200000DNMAf",
857
+ fnmsub_4 = "1f208000DNMAf",
858
+
859
+ fmax_3 = "1e204800DNMf",
860
+ fmaxnm_3 = "1e206800DNMf",
861
+ fmin_3 = "1e205800DNMf",
862
+ fminnm_3 = "1e207800DNMf",
863
+
864
+ fcmp_2 = "1e202000NMf|1e202008NZf",
865
+ fcmpe_2 = "1e202010NMf|1e202018NZf",
866
+
867
+ fccmp_4 = "1e200400NMVCf",
868
+ fccmpe_4 = "1e200410NMVCf",
869
+
870
+ fcsel_4 = "1e200c00DNMCf",
871
+
872
+ -- TODO: crc32*, aes*, sha*, pmull
873
+ -- TODO: SIMD instructions.
874
+ }
875
+
876
+ for cond,c in pairs(map_cond) do
877
+ map_op["b"..cond.."_1"] = tohex(0x54000000+c).."B"
878
+ end
879
+
880
+ ------------------------------------------------------------------------------
881
+
882
+ -- Handle opcodes defined with template strings.
883
+ local function parse_template(params, template, nparams, pos)
884
+ local op = tonumber(sub(template, 1, 8), 16)
885
+ local n = 1
886
+ local rtt = {}
887
+
888
+ parse_reg_type = false
889
+
890
+ -- Process each character.
891
+ for p in gmatch(sub(template, 9), ".") do
892
+ local q = params[n]
893
+ if p == "D" then
894
+ op = op + parse_reg(q); n = n + 1
895
+ elseif p == "N" then
896
+ op = op + shl(parse_reg(q), 5); n = n + 1
897
+ elseif p == "M" then
898
+ op = op + shl(parse_reg(q), 16); n = n + 1
899
+ elseif p == "A" then
900
+ op = op + shl(parse_reg(q), 10); n = n + 1
901
+ elseif p == "m" then
902
+ op = op + shl(parse_reg(params[n-1]), 16)
903
+
904
+ elseif p == "p" then
905
+ if q == "sp" then params[n] = "@x31" end
906
+ elseif p == "g" then
907
+ if parse_reg_type == "x" then
908
+ op = op + 0x80000000
909
+ elseif parse_reg_type ~= "w" then
910
+ werror("bad register type")
911
+ end
912
+ parse_reg_type = false
913
+ elseif p == "f" then
914
+ if parse_reg_type == "d" then
915
+ op = op + 0x00400000
916
+ elseif parse_reg_type ~= "s" then
917
+ werror("bad register type")
918
+ end
919
+ parse_reg_type = false
920
+ elseif p == "x" or p == "w" or p == "d" or p == "s" then
921
+ if parse_reg_type ~= p then
922
+ werror("register size mismatch")
923
+ end
924
+ parse_reg_type = false
925
+
926
+ elseif p == "L" then
927
+ op = parse_load(params, nparams, n, op)
928
+ elseif p == "P" then
929
+ op = parse_load_pair(params, nparams, n, op)
930
+
931
+ elseif p == "B" then
932
+ local mode, v, s = parse_label(q, false); n = n + 1
933
+ local m = branch_type(op)
934
+ waction("REL_"..mode, v+m, s, 1)
935
+
936
+ elseif p == "I" then
937
+ op = op + parse_imm12(q); n = n + 1
938
+ elseif p == "i" then
939
+ op = op + parse_imm13(q); n = n + 1
940
+ elseif p == "W" then
941
+ op = op + parse_imm(q, 16, 5, 0, false); n = n + 1
942
+ elseif p == "T" then
943
+ op = op + parse_imm6(q); n = n + 1
944
+ elseif p == "1" then
945
+ op = op + parse_imm(q, 6, 16, 0, false); n = n + 1
946
+ elseif p == "2" then
947
+ op = op + parse_imm(q, 6, 10, 0, false); n = n + 1
948
+ elseif p == "5" then
949
+ op = op + parse_imm(q, 5, 16, 0, false); n = n + 1
950
+ elseif p == "V" then
951
+ op = op + parse_imm(q, 4, 0, 0, false); n = n + 1
952
+ elseif p == "F" then
953
+ op = op + parse_fpimm(q); n = n + 1
954
+ elseif p == "Z" then
955
+ if q ~= "#0" and q ~= "#0.0" then werror("expected zero immediate") end
956
+ n = n + 1
957
+
958
+ elseif p == "S" then
959
+ op = op + parse_shift(q); n = n + 1
960
+ elseif p == "X" then
961
+ op = op + parse_extend(q); n = n + 1
962
+ elseif p == "R" then
963
+ op = op + parse_lslx16(q); n = n + 1
964
+ elseif p == "C" then
965
+ op = op + parse_cond(q, 0); n = n + 1
966
+ elseif p == "c" then
967
+ op = op + parse_cond(q, 1); n = n + 1
968
+
969
+ else
970
+ assert(false)
971
+ end
972
+ end
973
+ wputpos(pos, op)
974
+ end
975
+
976
+ function op_template(params, template, nparams)
977
+ if not params then return template:gsub("%x%x%x%x%x%x%x%x", "") end
978
+
979
+ -- Limit number of section buffer positions used by a single dasm_put().
980
+ -- A single opcode needs a maximum of 3 positions.
981
+ if secpos+3 > maxsecpos then wflush() end
982
+ local pos = wpos()
983
+ local lpos, apos, spos = #actlist, #actargs, secpos
984
+
985
+ local ok, err
986
+ for t in gmatch(template, "[^|]+") do
987
+ ok, err = pcall(parse_template, params, t, nparams, pos)
988
+ if ok then return end
989
+ secpos = spos
990
+ actlist[lpos+1] = nil
991
+ actlist[lpos+2] = nil
992
+ actlist[lpos+3] = nil
993
+ actargs[apos+1] = nil
994
+ actargs[apos+2] = nil
995
+ actargs[apos+3] = nil
996
+ end
997
+ error(err, 0)
998
+ end
999
+
1000
+ map_op[".template__"] = op_template
1001
+
1002
+ ------------------------------------------------------------------------------
1003
+
1004
+ -- Pseudo-opcode to mark the position where the action list is to be emitted.
1005
+ map_op[".actionlist_1"] = function(params)
1006
+ if not params then return "cvar" end
1007
+ local name = params[1] -- No syntax check. You get to keep the pieces.
1008
+ wline(function(out) writeactions(out, name) end)
1009
+ end
1010
+
1011
+ -- Pseudo-opcode to mark the position where the global enum is to be emitted.
1012
+ map_op[".globals_1"] = function(params)
1013
+ if not params then return "prefix" end
1014
+ local prefix = params[1] -- No syntax check. You get to keep the pieces.
1015
+ wline(function(out) writeglobals(out, prefix) end)
1016
+ end
1017
+
1018
+ -- Pseudo-opcode to mark the position where the global names are to be emitted.
1019
+ map_op[".globalnames_1"] = function(params)
1020
+ if not params then return "cvar" end
1021
+ local name = params[1] -- No syntax check. You get to keep the pieces.
1022
+ wline(function(out) writeglobalnames(out, name) end)
1023
+ end
1024
+
1025
+ -- Pseudo-opcode to mark the position where the extern names are to be emitted.
1026
+ map_op[".externnames_1"] = function(params)
1027
+ if not params then return "cvar" end
1028
+ local name = params[1] -- No syntax check. You get to keep the pieces.
1029
+ wline(function(out) writeexternnames(out, name) end)
1030
+ end
1031
+
1032
+ ------------------------------------------------------------------------------
1033
+
1034
+ -- Label pseudo-opcode (converted from trailing colon form).
1035
+ map_op[".label_1"] = function(params)
1036
+ if not params then return "[1-9] | ->global | =>pcexpr" end
1037
+ if secpos+1 > maxsecpos then wflush() end
1038
+ local mode, n, s = parse_label(params[1], true)
1039
+ if mode == "EXT" then werror("bad label definition") end
1040
+ waction("LABEL_"..mode, n, s, 1)
1041
+ end
1042
+
1043
+ ------------------------------------------------------------------------------
1044
+
1045
+ -- Pseudo-opcodes for data storage.
1046
+ map_op[".long_*"] = function(params)
1047
+ if not params then return "imm..." end
1048
+ for _,p in ipairs(params) do
1049
+ local n = tonumber(p)
1050
+ if not n then werror("bad immediate `"..p.."'") end
1051
+ if n < 0 then n = n + 2^32 end
1052
+ wputw(n)
1053
+ if secpos+2 > maxsecpos then wflush() end
1054
+ end
1055
+ end
1056
+
1057
+ -- Alignment pseudo-opcode.
1058
+ map_op[".align_1"] = function(params)
1059
+ if not params then return "numpow2" end
1060
+ if secpos+1 > maxsecpos then wflush() end
1061
+ local align = tonumber(params[1])
1062
+ if align then
1063
+ local x = align
1064
+ -- Must be a power of 2 in the range (2 ... 256).
1065
+ for i=1,8 do
1066
+ x = x / 2
1067
+ if x == 1 then
1068
+ waction("ALIGN", align-1, nil, 1) -- Action byte is 2**n-1.
1069
+ return
1070
+ end
1071
+ end
1072
+ end
1073
+ werror("bad alignment")
1074
+ end
1075
+
1076
+ ------------------------------------------------------------------------------
1077
+
1078
+ -- Pseudo-opcode for (primitive) type definitions (map to C types).
1079
+ map_op[".type_3"] = function(params, nparams)
1080
+ if not params then
1081
+ return nparams == 2 and "name, ctype" or "name, ctype, reg"
1082
+ end
1083
+ local name, ctype, reg = params[1], params[2], params[3]
1084
+ if not match(name, "^[%a_][%w_]*$") then
1085
+ werror("bad type name `"..name.."'")
1086
+ end
1087
+ local tp = map_type[name]
1088
+ if tp then
1089
+ werror("duplicate type `"..name.."'")
1090
+ end
1091
+ -- Add #type to defines. A bit unclean to put it in map_archdef.
1092
+ map_archdef["#"..name] = "sizeof("..ctype..")"
1093
+ -- Add new type and emit shortcut define.
1094
+ local num = ctypenum + 1
1095
+ map_type[name] = {
1096
+ ctype = ctype,
1097
+ ctypefmt = format("Dt%X(%%s)", num),
1098
+ reg = reg,
1099
+ }
1100
+ wline(format("#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)", num, ctype))
1101
+ ctypenum = num
1102
+ end
1103
+ map_op[".type_2"] = map_op[".type_3"]
1104
+
1105
+ -- Dump type definitions.
1106
+ local function dumptypes(out, lvl)
1107
+ local t = {}
1108
+ for name in pairs(map_type) do t[#t+1] = name end
1109
+ sort(t)
1110
+ out:write("Type definitions:\n")
1111
+ for _,name in ipairs(t) do
1112
+ local tp = map_type[name]
1113
+ local reg = tp.reg or ""
1114
+ out:write(format(" %-20s %-20s %s\n", name, tp.ctype, reg))
1115
+ end
1116
+ out:write("\n")
1117
+ end
1118
+
1119
+ ------------------------------------------------------------------------------
1120
+
1121
+ -- Set the current section.
1122
+ function _M.section(num)
1123
+ waction("SECTION", num)
1124
+ wflush(true) -- SECTION is a terminal action.
1125
+ end
1126
+
1127
+ ------------------------------------------------------------------------------
1128
+
1129
+ -- Dump architecture description.
1130
+ function _M.dumparch(out)
1131
+ out:write(format("DynASM %s version %s, released %s\n\n",
1132
+ _info.arch, _info.version, _info.release))
1133
+ dumpactions(out)
1134
+ end
1135
+
1136
+ -- Dump all user defined elements.
1137
+ function _M.dumpdef(out, lvl)
1138
+ dumptypes(out, lvl)
1139
+ dumpglobals(out, lvl)
1140
+ dumpexterns(out, lvl)
1141
+ end
1142
+
1143
+ ------------------------------------------------------------------------------
1144
+
1145
+ -- Pass callbacks from/to the DynASM core.
1146
+ function _M.passcb(wl, we, wf, ww)
1147
+ wline, werror, wfatal, wwarn = wl, we, wf, ww
1148
+ return wflush
1149
+ end
1150
+
1151
+ -- Setup the arch-specific module.
1152
+ function _M.setup(arch, opt)
1153
+ g_arch, g_opt = arch, opt
1154
+ end
1155
+
1156
+ -- Merge the core maps and the arch-specific maps.
1157
+ function _M.mergemaps(map_coreop, map_def)
1158
+ setmetatable(map_op, { __index = map_coreop })
1159
+ setmetatable(map_def, { __index = map_archdef })
1160
+ return map_op, map_def
1161
+ end
1162
+
1163
+ return _M
1164
+
1165
+ ------------------------------------------------------------------------------
1166
+