metasm 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/BUGS +11 -0
  2. data/CREDITS +17 -0
  3. data/README +270 -0
  4. data/TODO +114 -0
  5. data/doc/code_organisation.txt +146 -0
  6. data/doc/const_missing.txt +16 -0
  7. data/doc/core_classes.txt +75 -0
  8. data/doc/feature_list.txt +53 -0
  9. data/doc/index.txt +59 -0
  10. data/doc/install_notes.txt +170 -0
  11. data/doc/style.css +3 -0
  12. data/doc/use_cases.txt +18 -0
  13. data/lib/metasm.rb +80 -0
  14. data/lib/metasm/arm.rb +12 -0
  15. data/lib/metasm/arm/debug.rb +39 -0
  16. data/lib/metasm/arm/decode.rb +167 -0
  17. data/lib/metasm/arm/encode.rb +77 -0
  18. data/lib/metasm/arm/main.rb +75 -0
  19. data/lib/metasm/arm/opcodes.rb +177 -0
  20. data/lib/metasm/arm/parse.rb +130 -0
  21. data/lib/metasm/arm/render.rb +55 -0
  22. data/lib/metasm/compile_c.rb +1457 -0
  23. data/lib/metasm/dalvik.rb +8 -0
  24. data/lib/metasm/dalvik/decode.rb +196 -0
  25. data/lib/metasm/dalvik/main.rb +60 -0
  26. data/lib/metasm/dalvik/opcodes.rb +366 -0
  27. data/lib/metasm/decode.rb +213 -0
  28. data/lib/metasm/decompile.rb +2659 -0
  29. data/lib/metasm/disassemble.rb +2068 -0
  30. data/lib/metasm/disassemble_api.rb +1280 -0
  31. data/lib/metasm/dynldr.rb +1329 -0
  32. data/lib/metasm/encode.rb +333 -0
  33. data/lib/metasm/exe_format/a_out.rb +194 -0
  34. data/lib/metasm/exe_format/autoexe.rb +82 -0
  35. data/lib/metasm/exe_format/bflt.rb +189 -0
  36. data/lib/metasm/exe_format/coff.rb +455 -0
  37. data/lib/metasm/exe_format/coff_decode.rb +901 -0
  38. data/lib/metasm/exe_format/coff_encode.rb +1078 -0
  39. data/lib/metasm/exe_format/dex.rb +457 -0
  40. data/lib/metasm/exe_format/dol.rb +145 -0
  41. data/lib/metasm/exe_format/elf.rb +923 -0
  42. data/lib/metasm/exe_format/elf_decode.rb +979 -0
  43. data/lib/metasm/exe_format/elf_encode.rb +1375 -0
  44. data/lib/metasm/exe_format/macho.rb +827 -0
  45. data/lib/metasm/exe_format/main.rb +228 -0
  46. data/lib/metasm/exe_format/mz.rb +164 -0
  47. data/lib/metasm/exe_format/nds.rb +172 -0
  48. data/lib/metasm/exe_format/pe.rb +437 -0
  49. data/lib/metasm/exe_format/serialstruct.rb +246 -0
  50. data/lib/metasm/exe_format/shellcode.rb +114 -0
  51. data/lib/metasm/exe_format/xcoff.rb +167 -0
  52. data/lib/metasm/gui.rb +23 -0
  53. data/lib/metasm/gui/cstruct.rb +373 -0
  54. data/lib/metasm/gui/dasm_coverage.rb +199 -0
  55. data/lib/metasm/gui/dasm_decomp.rb +369 -0
  56. data/lib/metasm/gui/dasm_funcgraph.rb +103 -0
  57. data/lib/metasm/gui/dasm_graph.rb +1354 -0
  58. data/lib/metasm/gui/dasm_hex.rb +543 -0
  59. data/lib/metasm/gui/dasm_listing.rb +599 -0
  60. data/lib/metasm/gui/dasm_main.rb +906 -0
  61. data/lib/metasm/gui/dasm_opcodes.rb +291 -0
  62. data/lib/metasm/gui/debug.rb +1228 -0
  63. data/lib/metasm/gui/gtk.rb +884 -0
  64. data/lib/metasm/gui/qt.rb +495 -0
  65. data/lib/metasm/gui/win32.rb +3004 -0
  66. data/lib/metasm/gui/x11.rb +621 -0
  67. data/lib/metasm/ia32.rb +14 -0
  68. data/lib/metasm/ia32/compile_c.rb +1523 -0
  69. data/lib/metasm/ia32/debug.rb +193 -0
  70. data/lib/metasm/ia32/decode.rb +1167 -0
  71. data/lib/metasm/ia32/decompile.rb +564 -0
  72. data/lib/metasm/ia32/encode.rb +314 -0
  73. data/lib/metasm/ia32/main.rb +233 -0
  74. data/lib/metasm/ia32/opcodes.rb +872 -0
  75. data/lib/metasm/ia32/parse.rb +327 -0
  76. data/lib/metasm/ia32/render.rb +91 -0
  77. data/lib/metasm/main.rb +1193 -0
  78. data/lib/metasm/mips.rb +11 -0
  79. data/lib/metasm/mips/compile_c.rb +7 -0
  80. data/lib/metasm/mips/decode.rb +253 -0
  81. data/lib/metasm/mips/encode.rb +51 -0
  82. data/lib/metasm/mips/main.rb +72 -0
  83. data/lib/metasm/mips/opcodes.rb +443 -0
  84. data/lib/metasm/mips/parse.rb +51 -0
  85. data/lib/metasm/mips/render.rb +43 -0
  86. data/lib/metasm/os/gnu_exports.rb +270 -0
  87. data/lib/metasm/os/linux.rb +1112 -0
  88. data/lib/metasm/os/main.rb +1686 -0
  89. data/lib/metasm/os/remote.rb +527 -0
  90. data/lib/metasm/os/windows.rb +2027 -0
  91. data/lib/metasm/os/windows_exports.rb +745 -0
  92. data/lib/metasm/parse.rb +876 -0
  93. data/lib/metasm/parse_c.rb +3938 -0
  94. data/lib/metasm/pic16c/decode.rb +42 -0
  95. data/lib/metasm/pic16c/main.rb +17 -0
  96. data/lib/metasm/pic16c/opcodes.rb +68 -0
  97. data/lib/metasm/ppc.rb +11 -0
  98. data/lib/metasm/ppc/decode.rb +264 -0
  99. data/lib/metasm/ppc/decompile.rb +251 -0
  100. data/lib/metasm/ppc/encode.rb +51 -0
  101. data/lib/metasm/ppc/main.rb +129 -0
  102. data/lib/metasm/ppc/opcodes.rb +410 -0
  103. data/lib/metasm/ppc/parse.rb +52 -0
  104. data/lib/metasm/preprocessor.rb +1277 -0
  105. data/lib/metasm/render.rb +130 -0
  106. data/lib/metasm/sh4.rb +8 -0
  107. data/lib/metasm/sh4/decode.rb +336 -0
  108. data/lib/metasm/sh4/main.rb +292 -0
  109. data/lib/metasm/sh4/opcodes.rb +381 -0
  110. data/lib/metasm/x86_64.rb +12 -0
  111. data/lib/metasm/x86_64/compile_c.rb +1025 -0
  112. data/lib/metasm/x86_64/debug.rb +59 -0
  113. data/lib/metasm/x86_64/decode.rb +268 -0
  114. data/lib/metasm/x86_64/encode.rb +264 -0
  115. data/lib/metasm/x86_64/main.rb +135 -0
  116. data/lib/metasm/x86_64/opcodes.rb +118 -0
  117. data/lib/metasm/x86_64/parse.rb +68 -0
  118. data/misc/bottleneck.rb +61 -0
  119. data/misc/cheader-findpppath.rb +58 -0
  120. data/misc/hexdiff.rb +74 -0
  121. data/misc/hexdump.rb +55 -0
  122. data/misc/metasm-all.rb +13 -0
  123. data/misc/objdiff.rb +47 -0
  124. data/misc/objscan.rb +40 -0
  125. data/misc/pdfparse.rb +661 -0
  126. data/misc/ppc_pdf2oplist.rb +192 -0
  127. data/misc/tcp_proxy_hex.rb +84 -0
  128. data/misc/txt2html.rb +440 -0
  129. data/samples/a.out.rb +31 -0
  130. data/samples/asmsyntax.rb +77 -0
  131. data/samples/bindiff.rb +555 -0
  132. data/samples/compilation-steps.rb +49 -0
  133. data/samples/cparser_makestackoffset.rb +55 -0
  134. data/samples/dasm-backtrack.rb +38 -0
  135. data/samples/dasmnavig.rb +318 -0
  136. data/samples/dbg-apihook.rb +228 -0
  137. data/samples/dbghelp.rb +143 -0
  138. data/samples/disassemble-gui.rb +102 -0
  139. data/samples/disassemble.rb +133 -0
  140. data/samples/dump_upx.rb +95 -0
  141. data/samples/dynamic_ruby.rb +1929 -0
  142. data/samples/elf_list_needed.rb +46 -0
  143. data/samples/elf_listexports.rb +33 -0
  144. data/samples/elfencode.rb +25 -0
  145. data/samples/exeencode.rb +128 -0
  146. data/samples/factorize-headers-elfimports.rb +77 -0
  147. data/samples/factorize-headers-peimports.rb +109 -0
  148. data/samples/factorize-headers.rb +43 -0
  149. data/samples/gdbclient.rb +583 -0
  150. data/samples/generate_libsigs.rb +102 -0
  151. data/samples/hotfix_gtk_dbg.rb +59 -0
  152. data/samples/install_win_env.rb +78 -0
  153. data/samples/lindebug.rb +924 -0
  154. data/samples/linux_injectsyscall.rb +95 -0
  155. data/samples/machoencode.rb +31 -0
  156. data/samples/metasm-shell.rb +91 -0
  157. data/samples/pe-hook.rb +69 -0
  158. data/samples/pe-ia32-cpuid.rb +203 -0
  159. data/samples/pe-mips.rb +35 -0
  160. data/samples/pe-shutdown.rb +78 -0
  161. data/samples/pe-testrelocs.rb +51 -0
  162. data/samples/pe-testrsrc.rb +24 -0
  163. data/samples/pe_listexports.rb +31 -0
  164. data/samples/peencode.rb +19 -0
  165. data/samples/peldr.rb +494 -0
  166. data/samples/preprocess-flatten.rb +19 -0
  167. data/samples/r0trace.rb +308 -0
  168. data/samples/rubstop.rb +399 -0
  169. data/samples/scan_pt_gnu_stack.rb +54 -0
  170. data/samples/scanpeexports.rb +62 -0
  171. data/samples/shellcode-c.rb +40 -0
  172. data/samples/shellcode-dynlink.rb +146 -0
  173. data/samples/source.asm +34 -0
  174. data/samples/struct_offset.rb +47 -0
  175. data/samples/testpe.rb +32 -0
  176. data/samples/testraw.rb +45 -0
  177. data/samples/win32genloader.rb +132 -0
  178. data/samples/win32hooker-advanced.rb +169 -0
  179. data/samples/win32hooker.rb +96 -0
  180. data/samples/win32livedasm.rb +33 -0
  181. data/samples/win32remotescan.rb +133 -0
  182. data/samples/wintrace.rb +92 -0
  183. data/tests/all.rb +8 -0
  184. data/tests/dasm.rb +39 -0
  185. data/tests/dynldr.rb +35 -0
  186. data/tests/encodeddata.rb +132 -0
  187. data/tests/ia32.rb +82 -0
  188. data/tests/mips.rb +116 -0
  189. data/tests/parse_c.rb +239 -0
  190. data/tests/preprocessor.rb +269 -0
  191. data/tests/x86_64.rb +62 -0
  192. metadata +255 -0
@@ -0,0 +1,292 @@
1
+ # This file is part of Metasm, the Ruby assembly manipulation suite
2
+ # Copyright (C) 2006-2010 Yoann GUILLOT
3
+ #
4
+ # Licence is LGPL, see LICENCE in the top-level directory
5
+
6
+ require 'metasm/main'
7
+
8
+ module Metasm
9
+
10
+ class Sh4 < CPU
11
+ def initialize(e = :little, transfersz = 0, fpprecision = 0)
12
+ super()
13
+ @endianness = e
14
+
15
+ # transfer size mode
16
+ # When SZ = 1 and big endian mode is selected, FMOV can
17
+ # be used for double-precision floating-point data load or
18
+ # store operations. In little endian mode, two 32-bit data size
19
+ # moves must be executed, with SZ = 0, to load or store a
20
+ # double-precision floating-point number.
21
+ transfersz = 0 if @endianness == :little
22
+ @transfersz = transfersz
23
+
24
+ # PR = 0 : Floating point instructions are executed as single
25
+ # precision operations.
26
+ # PR = 1 : Floating point instructions are executed as double-
27
+ # precision operations (the result of instructions for
28
+ # which double-precision is not supported is undefined).
29
+ # Setting [transfersz = fpprecision = 1] is reserved.
30
+ # FPU operations are undefined in this mode.
31
+ @fpprecision = fpprecision
32
+
33
+ @size = 32
34
+ end
35
+
36
+ class Reg
37
+ include Renderable
38
+
39
+ def ==(o)
40
+ o.class == self.class and (not respond_to?(:i) or o.i == i)
41
+ end
42
+ end
43
+
44
+ # general purpose reg
45
+ class GPR < Reg
46
+ attr_accessor :i
47
+
48
+ def initialize(i); @i = i end
49
+ Sym = (0..15).map { |i| "r#{i}".to_sym }
50
+
51
+ def symbolic ; Sym[@i] end
52
+
53
+ def render ; ["r#@i"] end
54
+ end
55
+
56
+ class RBANK < Reg
57
+ attr_accessor :i
58
+
59
+ def initialize(i); @i = i end
60
+ Sym = (0..7).map { |i| "r#{i}_bank".to_sym }
61
+
62
+ def symbolic ; Sym[@i] end
63
+
64
+ def render ; ["r#{@i}_bank"] end
65
+ end
66
+
67
+ # floatting-point registers
68
+ class FR < Reg
69
+ attr_accessor :i
70
+
71
+ def initialize(i); @i = i end
72
+ Sym = (0..15).map { |i| "fr#{i}".to_sym }
73
+
74
+ def symbolic ; Sym[@i] end
75
+
76
+ def render ; ["fr#@i"] end
77
+ end
78
+
79
+ # DR registers: double-precision floating-point registers
80
+ # DR0 = {FR0, FR1}
81
+ # DR2 = {FR2, FR3}
82
+ # DR4 = {FR4, FR5}
83
+ # DR6 = {FR6, FR7}
84
+ # DR8 = {FR8, FR9}
85
+ # DR10 = {FR10, FR11}
86
+ # DR12 = {FR12, FR13}
87
+ # DR14 = {FR14, FR15}
88
+ class DR < Reg
89
+ attr_accessor :i
90
+
91
+ def initialize(i); @i = i end
92
+ Sym = (0..7).map { |i| "dr#{i*2}".to_sym }
93
+
94
+ def symbolic ; Sym[@i/2] end
95
+
96
+ def render ; ["dr#@i"] end
97
+ end
98
+
99
+ # Single-precision floating-point vector registers
100
+ # FV0 = {FR0, FR1, FR2, FR3}
101
+ # FV4 = {FR4, FR5, FR6, FR7},
102
+ # FV8 = {FR8, FR9, FR10, FR11}
103
+ # FV12 = {FR12, FR13, FR14, FR15}
104
+ class FVR < Reg
105
+ attr_accessor :i
106
+
107
+ def initialize(i); @i = i end
108
+ Sym = (0..3).map { |i| "fv#{i*4}".to_sym }
109
+
110
+ def symbolic ; Sym[@i/4] end
111
+
112
+ def render ; ["fv#@i"] end
113
+ end
114
+
115
+ # Single-precision floating-point extended registers
116
+ class XFR < Reg
117
+ attr_accessor :i
118
+
119
+ def initialize(i); @i = i end
120
+ Sym = (0..15).map { |i| "xf#{i}".to_sym }
121
+
122
+ def symbolic ; Sym[@i] end
123
+
124
+ def render ; ["xf#@i"] end
125
+ end
126
+
127
+ # XD registers: single-precision floating-point vector registers
128
+ # XD0 = {XF0, XF1}
129
+ # XD2 = {XF2, XF3}
130
+ # XD4 = {XF4, XF5}
131
+ # XD6 = {XF6, XF7}
132
+ # XD8 = {XF8, XF9}
133
+ # XD10 = {XF10, XF11}
134
+ # XD12 = {XF12, XF13}
135
+ # XD14 = {XF14, XF15}
136
+ class XDR < Reg
137
+ attr_accessor :i
138
+
139
+ def initialize(i); @i = i end
140
+ Sym = (0..7).map { |i| "xd#{i*2}".to_sym }
141
+
142
+ def symbolic ; Sym[@i/2] end
143
+
144
+ def render ; ["xd#@i"] end
145
+ end
146
+
147
+ # Single-precision floating-point extended register matrix
148
+ class XMTRX < Reg
149
+ def symbolic ; :xmtrx ; end
150
+ def render ; ['xmtrx'] ; end
151
+ end
152
+
153
+
154
+ # Multiply-and-accumulate register high
155
+ class MACH < Reg
156
+
157
+ def symbolic ; :mach end
158
+ def render ; ['mach'] end
159
+ end
160
+
161
+ # Multiply-and-accumulate register low
162
+ class MACL < Reg
163
+
164
+ def symbolic ; :macl end
165
+ def render ; ['macl'] end
166
+ end
167
+
168
+ # Procedure register
169
+ class PR < Reg
170
+
171
+ def symbolic ; :pr end
172
+ def render ; ['pr'] end
173
+ end
174
+
175
+ # Floating-point communication register
176
+ class FPUL < Reg
177
+
178
+ def symbolic ; :fpul end
179
+ def render ; ['fpul'] end
180
+ end
181
+
182
+ # Program counter
183
+ class PC < Reg
184
+
185
+ def symbolic ; :pc end
186
+ def render ; ['pc'] end
187
+ end
188
+
189
+ # Floating-point status/control register
190
+ class FPSCR < Reg
191
+
192
+ def symbolic ; :fpscr end
193
+ def render ; ['fpscr'] end
194
+ end
195
+
196
+ #----------------------- Control registers -----------------------------
197
+
198
+ # Status register
199
+ class SR < Reg
200
+
201
+ def symbolic ; :sr end
202
+ def render ; ['sr'] end
203
+ end
204
+
205
+ # Saved status register
206
+ class SSR < Reg
207
+
208
+ def symbolic ; :ssr end
209
+ def render ; ['ssr'] end
210
+ end
211
+
212
+ # Saved program counter
213
+ class SPC < Reg
214
+
215
+ def symbolic ; :spc end
216
+ def render ; ['spc'] end
217
+ end
218
+
219
+ # Global base register
220
+ class GBR < Reg
221
+
222
+ def symbolic ; :spc end
223
+ def render ; ['gbr'] end
224
+ end
225
+
226
+ # Vector base register
227
+ class VBR < Reg
228
+
229
+ def symbolic ; :spc end
230
+ def render ; ['vbr'] end
231
+ end
232
+
233
+ # Saved general register
234
+ class SGR < Reg
235
+
236
+ def symbolic ; :sgr end
237
+ def render ; ['sgr'] end
238
+ end
239
+
240
+ # Debug base register
241
+ class DBR < Reg
242
+
243
+ def symbolic ; :dbr end
244
+ def render ; ['dbr'] end
245
+ end
246
+
247
+ class Memref
248
+ # action: pre/post (inc/dec)rement
249
+ attr_accessor :base, :disp, :action
250
+
251
+ def initialize(base, offset, action = nil)
252
+ base = Expression[base] if base.kind_of? Integer
253
+ @base, @disp, @action = base, offset, action
254
+ end
255
+
256
+ def symbolic(orig=nil, sz=32)
257
+ b = @base
258
+ b = b.symbolic if b.kind_of? Reg
259
+
260
+ if disp
261
+ o = @disp
262
+ o = o.symbolic if o.kind_of? Reg
263
+ e = Expression[b, :+, o].reduce
264
+ else
265
+ e = Expression[b].reduce
266
+ end
267
+
268
+ Indirection[e, sz, orig]
269
+ end
270
+
271
+ include Renderable
272
+
273
+ def render
274
+ if @disp
275
+ ['@(', @base, ',', @disp, ')']
276
+ else
277
+ case @action
278
+ when :pre then ['@-', @base]
279
+ when :post then ['@', @base, '+']
280
+ else ['@', @base]
281
+ end
282
+ end
283
+ end
284
+
285
+ end
286
+
287
+ def init_opcode_list
288
+ init
289
+ end
290
+
291
+ end
292
+ end
@@ -0,0 +1,381 @@
1
+ # This file is part of Metasm, the Ruby assembly manipulation suite
2
+ # Copyright (C) 2006-2010 Yoann GUILLOT
3
+ #
4
+ # Licence is LGPL, see LICENCE in the top-level directory
5
+
6
+ require 'metasm/sh4/main'
7
+
8
+ module Metasm
9
+ class Sh4
10
+ def addop(name, bin, *args)
11
+ o = Opcode.new name, bin
12
+
13
+ o.args.concat(args & @fields_mask.keys)
14
+ (args & @valid_props).each { |p| o.props[p] = true }
15
+
16
+ (args & @fields_mask.keys).each { |f|
17
+ o.fields[f] = [@fields_mask[f], @fields_shift[f]]
18
+ }
19
+
20
+ @opcode_list << o
21
+ end
22
+
23
+ def init
24
+ @opcode_list = []
25
+
26
+ # :@rm_ is used for @Rm+
27
+ # :@_rn is used for @-Rn
28
+ # :@r0rm is used for @(R0, Rm) (same for r0rn)
29
+ # :@r0gbr is used for @(R0, GBR)
30
+ @fields_mask = {
31
+ :rm => 0xf, :rn => 0xf,
32
+ :@rm => 0xf, :@rn => 0xf,
33
+ :@rm_ => 0xf, :@rn_ => 0xf,
34
+ :@_rn => 0xf,
35
+
36
+ :frm => 0xf, :frn => 0xf,
37
+ :xdm => 0x7, :xdn => 0x7,
38
+ :drm => 0x7, :drn => 0x7,
39
+ :fvm => 0x3, :fvn => 0x3,
40
+
41
+ :@r0rm => 0xf, :@r0rn => 0xf,
42
+ :rm_bank => 0x7, :rn_bank => 0x7,
43
+
44
+ :@disprm => 0xff, :@dispr0rn => 0xff, :@disprmrn => 0xf0f,
45
+ :@dispgbr => 0xff, :@disppc => 0xff,
46
+ :disp8 => 0xff, :disp12 => 0xfff, :disppc => 0xff,
47
+
48
+ :i8 => 0xff, # zero-extendded 8-bit immediate
49
+ :s8 => 0xff, # 8-bit displacement s is sign-extended, doubled and added to PC+4
50
+ }
51
+
52
+ @fields_shift = {
53
+ :rm => 4, :rn => 8,
54
+ :@rm => 4, :@rn => 8,
55
+ :@rm_ => 4, :@rn_ => 8,
56
+ :@_rn => 8,
57
+
58
+ :frm => 4, :frn => 8,
59
+ :xdm => 5, :xdn => 9,
60
+ :drm => 5, :drn => 9,
61
+ :fvm => 8, :fvn => 10,
62
+
63
+ :@r0rm => 4, :@r0rn => 8,
64
+ :rm_bank => 7, :rn_bank => 4,
65
+
66
+ :@disprm => 0, :@dispr0rn => 0, :@disprmrn => 0,
67
+ :@dispgbr => 0, :@disppc => 0,
68
+ :disp8 => 0, :disp12 => 0, :disppc => 0,
69
+
70
+ :i8 => 0,
71
+ :s8 => 0,
72
+ }
73
+
74
+ # implicit operands
75
+ [:vbr, :gbr, :sr, :ssr, :spc, :sgr, :dbr, :mach, :macl, :pr, :fpul, :fpscr, :dbr, :pc, :r0].each { |a| @fields_mask[a] = @fields_shift[a] = 0 }
76
+
77
+ @valid_props = [:setip, :saveip, :stopexec , :delay_slot]
78
+
79
+ addop 'add', 0b0011 << 12 | 0b1100, :rm, :rn
80
+ addop 'add', 0b0111 << 12, :s8, :rn
81
+ addop 'addc', 0b0011 << 12 | 0b1110, :rm, :rn
82
+ addop 'addv', 0b0011 << 12 | 0b1111, :rm, :rn
83
+
84
+ addop 'and', 0b0010 << 12 | 0b1001, :rm, :rn
85
+ addop 'and', 0b11001001 << 8, :i8, :r0
86
+ addop 'and.b', 0b11001101 << 8, :i8, :@r0gbr
87
+
88
+ addop 'bf', 0b10001011 << 8, :disp8, :setip
89
+ addop 'bf/s', 0b10001111 << 8, :disp8, :setip, :delay_slot
90
+ addop 'bra', 0b1010 << 12, :disp12, :setip, :stopexec, :delay_slot
91
+ addop 'braf', 0b0000 << 12 | 0b00100011, :rn, :setip, :stopexec, :delay_slot
92
+ addop 'brk', 0b0000000000111011, :stopexec # causes a pre-execution BREAK exception
93
+ addop 'bsr', 0b1011 << 12, :disp12, :setip, :saveip, :stopexec, :delay_slot
94
+ addop 'bsrf', 0b0000 << 12 | 0b00000011, :rn, :setip, :saveip, :stopexec, :delay_slot
95
+ addop 'bt', 0b10001001 << 8, :disp8, :setip
96
+ addop 'bt/s', 0b10001101 << 8, :disp8, :setip, :delay_slot
97
+
98
+ addop 'clrmac', 0b0000000000101000
99
+ addop 'clrs', 0b0000000001001000
100
+ addop 'clrt', 0b0000000000001000
101
+
102
+ addop 'cmp/eq', 0b0011 << 12 | 0b0000, :rm, :rn
103
+ addop 'cmp/eq', 0b10001000 << 8, :s8, :r0
104
+ addop 'cmp/ge', 0b0011 << 12 | 0b0011, :rm, :rn
105
+ addop 'cmp/gt', 0b0011 << 12 | 0b0111, :rm, :rn
106
+ addop 'cmp/hi', 0b0011 << 12 | 0b0110, :rm, :rn
107
+ addop 'cmp/hs', 0b0011 << 12 | 0b0010, :rm, :rn
108
+ addop 'cmp/pl', 0b0100 << 12 | 0b00010101, :rn
109
+ addop 'cmp/pz', 0b0100 << 12 | 0b00010001, :rn
110
+ addop 'cmp/str', 0b0010 << 12 | 0b1100, :rm, :rn
111
+
112
+ addop 'div0s', 0b0010 << 12 | 0b0111, :rm, :rn
113
+ addop 'div0u', 0b0000000000011001
114
+ addop 'div1', 0b0011 << 12 | 0b0100, :rm, :rn
115
+
116
+ addop 'dmuls.l', 0b0011 << 12 | 0b1101, :rm, :rn
117
+ addop 'dmulu.l', 0b0011 << 12 | 0b0101, :rm, :rn
118
+
119
+ addop 'dt', 0b0100 << 12 | 0b00010000, :rn
120
+
121
+ addop 'exts.b', 0b0110 << 12 | 0b1110, :rm, :rn
122
+ addop 'exts.w', 0b0110 << 12 | 0b1111, :rm, :rn
123
+ addop 'extu.b', 0b0110 << 12 | 0b1100, :rm, :rn
124
+ addop 'extu.w', 0b0110 << 12 | 0b1101, :rm, :rn
125
+
126
+ # fpu instructions
127
+ addop 'fabs', 0b1111 << 12 | 0b001011101, :drn
128
+ addop 'fabs', 0b1111 << 12 | 0b01011101, :frn
129
+
130
+ addop 'fadd', 0b1111 << 12 | 0b0 << 8 | 0b00000, :drm, :drn
131
+ addop 'fadd', 0b1111 << 12 | 0b0000, :frm, :frn
132
+
133
+ addop 'fcmp/eq', 0b1111 << 12 | 0b0 << 8 | 0b00100, :drm, :drn
134
+ addop 'fcmp/eq', 0b1111 << 12 | 0b0100, :frm, :frn
135
+
136
+ addop 'fcmp/gt', 0b1111 << 12 | 0b0 << 8 | 0b00101, :drm, :drn
137
+ addop 'fcmp/gt', 0b1111 << 12 | 0b0101, :frm, :frn
138
+
139
+ addop 'fcnvds', 0b1111 << 12 | 0b010111101, :drn, :fpul
140
+ addop 'fcnvsd', 0b1111 << 12 | 0b010101101, :fpul, :drn
141
+
142
+ addop 'fdiv', 0b1111 << 12 | 0b0 << 8 | 0b00011, :drm, :drn
143
+ addop 'fdiv', 0b1111 << 12 | 0b0011, :frm, :frn
144
+ addop 'fipr', 0b1111 << 12 | 0b11101101, :fvm, :fvn
145
+
146
+ addop 'flds', 0b1111 << 12 | 0b00011101, :frn, :fpul
147
+ addop 'fldi0', 0b1111 << 12 | 0b10001101, :frn
148
+ addop 'fldi1', 0b1111 << 12 | 0b10011101, :frn
149
+
150
+ addop 'float', 0b1111 << 12 | 0b000101101, :fpul, :drn
151
+ addop 'float', 0b1111 << 12 | 0b00101101, :fpul, :frn
152
+
153
+ addop 'fmac', 0b1111 << 12 | 0b1110, :fr0, :frm, :frn
154
+
155
+ addop 'fmov', 0b1111 << 12 | 0b0 << 8 | 0b01100, :drm, :drn
156
+ addop 'fmov', 0b1111 << 12 | 0b1 << 8 | 0b01100, :drm, :xdn
157
+ addop 'fmov', 0b1111 << 12 | 0b01010, :drm, :@rn
158
+ addop 'fmov', 0b1111 << 12 | 0b01011, :drm, :@_rn
159
+ addop 'fmov', 0b1111 << 12 | 0b00111, :drm, :@r0rn
160
+
161
+ addop 'fmov.s', 0b1111 << 12 | 0b1100, :frm, :frn
162
+ addop 'fmov.s', 0b1111 << 12 | 0b1010, :frm, :@rn
163
+ addop 'fmov.s', 0b1111 << 12 | 0b1011, :frm, :@_rn
164
+ addop 'fmov.s', 0b1111 << 12 | 0b0111, :frm, :@r0rn
165
+
166
+ addop 'fmov', 0b1111 << 12 | 0b0 << 8 | 0b11100, :xdm, :drn
167
+ addop 'fmov', 0b1111 << 12 | 0b1 << 8 | 0b11100, :xdm, :xdn
168
+ addop 'fmov', 0b1111 << 12 | 0b11010, :xdm, :@rn
169
+ addop 'fmov', 0b1111 << 12 | 0b11011, :xdm, :@_rn
170
+ addop 'fmov', 0b1111 << 12 | 0b10111, :xdm, :@r0rn
171
+
172
+ addop 'fmov', 0b1111 << 12 | 0b0 << 8 | 0b1000, :@rm, :drn
173
+ addop 'fmov', 0b1111 << 12 | 0b0 << 8 | 0b1001, :@rm_, :drn
174
+ addop 'fmov', 0b1111 << 12 | 0b0 << 8 | 0b0110, :@r0rm, :drn
175
+
176
+ addop 'fmov.s', 0b1111 << 12 | 0b1000, :@rm, :frn
177
+ addop 'fmov.s', 0b1111 << 12 | 0b1001, :@rm_, :frn
178
+ addop 'fmov.s', 0b1111 << 12 | 0b0110, :@r0rm, :frn
179
+
180
+ addop 'fmov', 0b1111 << 12 | 0b1 << 8 | 0b1000, :@rm, :xdn
181
+ addop 'fmov', 0b1111 << 12 | 0b1 << 8 | 0b1001, :@rm_, :xdn
182
+ addop 'fmov', 0b1111 << 12 | 0b1 << 8 | 0b0110, :@r0rm, :xdn
183
+
184
+ addop 'fmul', 0b1111 << 12 | 0b0 << 8 | 0b00010, :drm, :drn
185
+ addop 'fmul', 0b1111 << 12 | 0b0010, :frm, :frn
186
+
187
+ addop 'fneg', 0b1111 << 12 | 0b001001101, :drn
188
+ addop 'fneg', 0b1111 << 12 | 0b01001101, :frn
189
+
190
+ addop 'frchg', 0b1111101111111101
191
+ addop 'fschg', 0b1111001111111101
192
+
193
+ addop 'fsqrt', 0b1111 << 12 | 0b001101101, :drn
194
+ addop 'fsqrt', 0b1111 << 12 | 0b01101101, :frn
195
+ addop 'fsts', 0b1111 << 12 | 0b00001101, :fpul, :frn
196
+
197
+ addop 'fsub', 0b1111 << 12 | 0b0 << 8 | 0b00001, :@drm, :drn
198
+ addop 'fsub', 0b1111 << 12 | 0b0001, :frm, :frn
199
+
200
+ addop 'ftrc', 0b1111 << 12 | 0b000111101, :drn, :fpul
201
+ addop 'ftrc', 0b1111 << 12 | 0b00111101, :frn, :fpul
202
+ addop 'ftrv', 0b1111 << 12 | 0b0111111101, :xmtrx, :fvn
203
+
204
+ addop 'jmp', 0b0100 << 12 | 0b00101011, :rn, :setip, :stopexec, :delay_slot
205
+ addop 'jsr', 0b0100 << 12 | 0b00001011, :rn, :setip, :saveip, :stopexec, :delay_slot
206
+
207
+ addop 'ldc', 0b0100 << 12 | 0b00011110, :rn, :gbr
208
+ addop 'ldc', 0b0100 << 12 | 0b00001110, :rn, :sr # privileged instruction
209
+ addop 'ldc', 0b0100 << 12 | 0b00101110, :rn, :vbr # privileged instruction
210
+ addop 'ldc', 0b0100 << 12 | 0b00111110, :rn, :ssr # privileged instruction
211
+ addop 'ldc', 0b0100 << 12 | 0b01001110, :rn, :spc # privileged instruction
212
+ addop 'ldc', 0b0100 << 12 | 0b11111010, :rn, :dbr # privileged instruction
213
+ addop 'ldc', 0b0100 << 12 | 0b1 << 7 | 0b1110, :rn, :rn_bank # privileged instruction
214
+
215
+ addop 'ldc.l', 0b0100 << 12 | 0b00010111, :@rn_, :gbr
216
+ addop 'ldc.l', 0b0100 << 12 | 0b00000111, :@rn_, :sr # privileged instruction
217
+ addop 'ldc.l', 0b0100 << 12 | 0b00100111, :@rn_, :vbr # privileged instruction
218
+ addop 'ldc.l', 0b0100 << 12 | 0b00110111, :@rn_, :ssr # privileged instruction
219
+ addop 'ldc.l', 0b0100 << 12 | 0b01000111, :@rn_, :spc # privileged instruction
220
+ addop 'ldc.l', 0b0100 << 12 | 0b11110110, :@rn_, :dbr # privileged instruction
221
+ addop 'ldc.l', 0b0100 << 12 | 0b1 << 7 | 0b0111, :@rn_, :rn_bank # privileged instruction
222
+
223
+ addop 'lds', 0b0100 << 12 | 0b01101010, :rn, :fpscr
224
+ addop 'lds.l', 0b0100 << 12 | 0b01100110, :@rn_, :fpscr
225
+ addop 'lds', 0b0100 << 12 | 0b01011010, :rn, :fpul
226
+ addop 'lds.l', 0b0100 << 12 | 0b01010110, :@rn_, :fpul
227
+ addop 'lds', 0b0100 << 12 | 0b00001010, :rn, :mach
228
+ addop 'lds.l', 0b0100 << 12 | 0b00000110, :@rn_, :mach
229
+ addop 'lds', 0b0100 << 12 | 0b00011010, :rn, :macl
230
+ addop 'lds.l', 0b0100 << 12 | 0b00010110, :@rn_, :macl
231
+ addop 'lds', 0b0100 << 12 | 0b00101010, :rn, :pr
232
+ addop 'lds.l', 0b0100 << 12 | 0b00100110, :@rn_, :pr
233
+
234
+ addop 'ldtlb', 0b0000000000111000
235
+
236
+ addop 'mac.l', 0b0000 << 12 | 0b1111, :@rm_, :@rn_
237
+ addop 'mac.w', 0b0100 << 12 | 0b1111, :@rm_, :@rn_
238
+
239
+ addop 'mov', 0b0110 << 12 | 0b0011, :rm, :rn
240
+ addop 'mov', 0b1110 << 12, :s8, :rn
241
+
242
+ addop 'mov.b', 0b0010 << 12 | 0b0000, :rm, :@rn
243
+ addop 'mov.b', 0b0010 << 12 | 0b0100, :rm, :@_rn
244
+ addop 'mov.b', 0b0000 << 12 | 0b0100, :rm, :@r0rn
245
+ addop 'mov.b', 0b11000000 << 8, :r0, :@dispgbr
246
+ addop 'mov.b', 0b10000000 << 8, :r0, :@dispr0rn
247
+ addop 'mov.b', 0b0110 << 12 | 0b0000, :@rm, :rn
248
+ addop 'mov.b', 0b0110 << 12 | 0b0100, :@rm_, :rn
249
+ addop 'mov.b', 0b0000 << 12 | 0b1100, :@r0rm, :rn
250
+ addop 'mov.b', 0b11000100 << 8, :@dispgbr, :r0
251
+ addop 'mov.b', 0b10000100 << 8, :@dispr0rn, :r0
252
+
253
+ addop 'mov.l', 0b0010 << 12 | 0b0010, :rm, :@rn
254
+ addop 'mov.l', 0b0010 << 12 | 0b0110, :rm, :@_rn
255
+ addop 'mov.l', 0b0000 << 12 | 0b0110, :rm, :@r0rn
256
+ addop 'mov.l', 0b11000010 << 8, :r0, :@dispgbr
257
+ addop 'mov.l', 0b0001 << 12, :rm, :@disprmrn
258
+ addop 'mov.l', 0b0110 << 12 | 0b0010, :@rm, :rn
259
+ addop 'mov.l', 0b0110 << 12 | 0b0110, :@rm_, :rn
260
+ addop 'mov.l', 0b0000 << 12 | 0b1110, :@r0rm, :rn
261
+ addop 'mov.l', 0b11000110 << 8, :@dispgbr, :r0
262
+ addop 'mov.l', 0b1101 << 12, :@disppc, :rn
263
+ addop 'mov.l', 0b0101 << 12, :@disprm, :rn
264
+
265
+ addop 'mov.w', 0b0010 << 12 | 0b0001, :rm, :@rn
266
+ addop 'mov.w', 0b0010 << 12 | 0b0101, :rm, :@_rn
267
+ addop 'mov.w', 0b0000 << 12 | 0b0101, :rm, :@r0rn
268
+ addop 'mov.w', 0b11000001 << 8, :r0, :@dispgbr
269
+ addop 'mov.w', 0b10000001 << 8, :r0, :@dispr0rn
270
+ addop 'mov.w', 0b0110 << 12 | 0b0001, :@rm, :rn
271
+ addop 'mov.w', 0b0110 << 12 | 0b0101, :@rm_, :rn
272
+ addop 'mov.w', 0b0000 << 12 | 0b1101, :@r0rm, :rn
273
+ addop 'mov.w', 0b11000101 << 8, :@dispgbr, :r0
274
+ addop 'mov.w', 0b1001 << 12, :@disppc, :rn
275
+ addop 'mov.w', 0b10000101 << 8, :@disprm, :r0
276
+
277
+ addop 'mova', 0b11000111 << 8, :disppc, :r0 # calculates an effective address using PC-relative with displacement addressing
278
+ addop 'movca.l', 0b0000 << 12 | 11000011, :r0, :@rn # stores the long-word in R0 to memory at the effective address specified in Rn.
279
+
280
+ addop 'movt', 0b0000 << 12 | 0b00101001, :rn # copies the T-bit to Rn
281
+
282
+ addop 'mul.l', 0b0000 << 12 | 0b0111, :rm, :rn
283
+ addop 'muls.w', 0b0010 << 12 | 0b1111, :rm, :rn
284
+ addop 'mulu.w', 0b0010 << 12 | 0b1110, :rm, :rn
285
+
286
+ addop 'neg', 0b0110 << 12 | 0b1011, :rm, :rn
287
+ addop 'negc', 0b0110 << 12 | 0b1010, :rm, :rn
288
+
289
+ addop 'nop', 0b0000000000001001
290
+
291
+ addop 'not', 0b0110 << 12 | 0b0111, :rm, :rn
292
+
293
+ addop 'ocbi', 0b0000 << 12 | 0b10010011, :@rn # invalidates an operand cache block
294
+ addop 'ocbp', 0b0000 << 12 | 0b10100011, :@rn # purges an operand cache block
295
+ addop 'ocbwb', 0b0000 << 12 | 0b10110011, :@rn # write-backs an operand cache block
296
+
297
+ addop 'or', 0b0010 << 12 | 0b1011, :rm, :rn
298
+ addop 'or', 0b11001011 << 8, :i8, :r0
299
+ addop 'or.b', 0b11001111 << 8, :i8, :@r0gbr
300
+
301
+ addop 'pref', 0b0000 | 0b10000011, :@rn # indicates a software-directed data prefetch
302
+
303
+ addop 'rotcl', 0b0100 | 0b00100100, :rn
304
+ addop 'rotcr', 0b0100 | 0b00100101, :rn
305
+ addop 'rotl', 0b0100 | 0b00000100, :rn
306
+ addop 'rotr', 0b0100 | 0b00000101, :rn
307
+
308
+ addop 'rte', 0b0000000000101011, :setip, :stopexec, :delay_slot # returns from an exception or interrupt handling routine, privileged instruction
309
+ addop 'rts', 0b0000000000001011, :setip, :stopexec, :delay_slot # returns from a subroutine
310
+
311
+ addop 'sets', 0b0000000001011000
312
+ addop 'sett', 0b0000000000011000
313
+
314
+ addop 'shad', 0b0100 << 12 | 0b1100, :rm, :rn
315
+ addop 'shal', 0b0100 << 12 | 0b00100000, :rn
316
+ addop 'shar', 0b0100 << 12 | 0b00100001, :rn
317
+ addop 'shld', 0b0100 << 12 | 0b1101, :rm, :rn
318
+ addop 'shll', 0b0100 << 12 | 0b00000000, :rn
319
+ addop 'shll2', 0b0100 << 12 | 0b00001000, :rn
320
+ addop 'shll8', 0b0100 << 12 | 0b00011000, :rn
321
+ addop 'shll16', 0b0100 << 12 | 0b00101000, :rn
322
+ addop 'shlr', 0b0100 << 12 | 0b00000001, :rn
323
+ addop 'shlr2', 0b0100 << 12 | 0b00001001, :rn
324
+ addop 'shlr8', 0b0100 << 12 | 0b00011001, :rn
325
+ addop 'shlr16', 0b0100 << 12 | 0b00101001, :rn
326
+
327
+ addop 'sleep', 0b0000000000011011 # privileged instruction
328
+
329
+ addop 'stc', 0b0000 << 12 | 0b00000010, :sr, :rn
330
+ addop 'stc', 0b0000 << 12 | 0b00100010, :vbr, :rn
331
+ addop 'stc', 0b0000 << 12 | 0b00110010, :ssr, :rn
332
+ addop 'stc', 0b0000 << 12 | 0b01000010, :spc, :rn
333
+ addop 'stc', 0b0000 << 12 | 0b00111010, :sgr, :rn
334
+ addop 'stc', 0b0000 << 12 | 0b11111010, :dbr, :rn
335
+ addop 'stc', 0b0000 << 12 | 0b1 << 7 | 0b0010, :rm_bank, :@_rn
336
+ addop 'stc', 0b0000 << 12 | 0b00010010, :gbr, :rn
337
+
338
+ addop 'stc.l', 0b0100 << 12 | 0b00000011, :sr, :@_rn
339
+ addop 'stc.l', 0b0100 << 12 | 0b00100011, :vbr, :@_rn
340
+ addop 'stc.l', 0b0100 << 12 | 0b00110011, :ssr, :@_rn
341
+ addop 'stc.l', 0b0100 << 12 | 0b01000011, :spc, :@_rn
342
+ addop 'stc.l', 0b0100 << 12 | 0b00110010, :sgr, :@_rn
343
+ addop 'stc.l', 0b0100 << 12 | 0b11110010, :dbr, :@_rn
344
+ addop 'stc.l', 0b0100 << 12 | 0b1 << 7 | 0b0011, :rm_bank, :@_rn
345
+ addop 'stc.l', 0b0100 << 12 | 0b00010011, :gbr, :@_rn
346
+
347
+ addop 'sts', 0b0000 << 12 | 0b01101010, :fpscr, :rn
348
+ addop 'sts.l', 0b0100 << 12 | 0b01100010, :fpscr, :@_rn
349
+ addop 'sts', 0b0000 << 12 | 0b01011010, :fpul, :rn
350
+ addop 'sts.l', 0b0100 << 12 | 0b01010010, :fpul, :@_rn
351
+ addop 'sts', 0b0000 << 12 | 0b00001010, :mach, :rn
352
+ addop 'sts.l', 0b0100 << 12 | 0b00000010, :mach, :@_rn
353
+ addop 'sts', 0b0000 << 12 | 0b00011010, :macl, :rn
354
+ addop 'sts.l', 0b0100 << 12 | 0b00010010, :macl, :@_rn
355
+ addop 'sts', 0b0000 << 12 | 0b00101010, :pr, :rn
356
+ addop 'sts.l', 0b0100 << 12 | 0b00100010, :pr, :@_rn
357
+
358
+ addop 'sub', 0b0011 << 12 | 0b1000, :rm, :rn
359
+ addop 'subc', 0b0011 << 12 | 0b1010, :rm, :rn
360
+ addop 'subv', 0b0011 << 12 | 0b1011, :rm, :rn
361
+
362
+ addop 'swap.b', 0b0110 << 12 | 0b1000, :rm, :rn
363
+ addop 'swap.w', 0b0110 << 12 | 0b1001, :rm, :rn
364
+
365
+ addop 'tas.b', 0b0100 << 12 | 0b00011011, :@rn
366
+ addop 'trapa', 0b11000011 << 8, :i8, :setip, :stopexec # This instruction causes a pre-execution trap.
367
+
368
+ addop 'tst', 0b0010 << 12 | 0b1000, :rm, :rn
369
+ addop 'tst', 0b11001000 << 8, :i8, :r0
370
+ addop 'tst.b', 0b11001100 << 8, :i8, :@r0gbr
371
+
372
+ addop 'xor', 0b0010 << 12 | 0b1010, :rm, :rn
373
+ addop 'xor', 0b11001010 << 8, :i8, :r0
374
+ addop 'xob.b', 0b11001110 << 8, :i8, :@r0gbr
375
+
376
+ addop 'xtrct', 0b0010 << 12 | 0b1101, :rm, :rn
377
+ end
378
+
379
+ end
380
+
381
+ end