aarch64 2.0.2 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +42 -0
  3. data/.github/workflows/release.yml +62 -0
  4. data/README.md +26 -0
  5. data/Rakefile +42 -8
  6. data/aarch64.gemspec +1 -1
  7. data/lib/aarch64/instructions/add/addsub_ext.rb +37 -0
  8. data/lib/aarch64/instructions/add/addsub_imm.rb +34 -0
  9. data/lib/aarch64/instructions/add/addsub_shift.rb +37 -0
  10. data/lib/aarch64/instructions/add.rb +9 -0
  11. data/lib/aarch64/instructions/adds/addsub_ext.rb +37 -0
  12. data/lib/aarch64/instructions/adds/addsub_imm.rb +35 -0
  13. data/lib/aarch64/instructions/adds/addsub_shift.rb +37 -0
  14. data/lib/aarch64/instructions/adds.rb +9 -0
  15. data/lib/aarch64/instructions/adrp.rb +1 -1
  16. data/lib/aarch64/instructions/and/log_imm.rb +37 -0
  17. data/lib/aarch64/instructions/and/log_shift.rb +37 -0
  18. data/lib/aarch64/instructions/and.rb +8 -0
  19. data/lib/aarch64/instructions/ands/log_imm.rb +37 -0
  20. data/lib/aarch64/instructions/ands/log_shift.rb +37 -0
  21. data/lib/aarch64/instructions/ands.rb +8 -0
  22. data/lib/aarch64/instructions/eor/log_imm.rb +37 -0
  23. data/lib/aarch64/instructions/eor/log_shift.rb +37 -0
  24. data/lib/aarch64/instructions/eor.rb +8 -0
  25. data/lib/aarch64/instructions/orn/log_shift.rb +37 -0
  26. data/lib/aarch64/instructions/orn.rb +7 -0
  27. data/lib/aarch64/instructions/orr/log_imm.rb +37 -0
  28. data/lib/aarch64/instructions/orr/log_shift.rb +37 -0
  29. data/lib/aarch64/instructions/orr.rb +8 -0
  30. data/lib/aarch64/instructions/sub/addsub_ext.rb +37 -0
  31. data/lib/aarch64/instructions/sub/addsub_imm.rb +35 -0
  32. data/lib/aarch64/instructions/sub/addsub_shift.rb +37 -0
  33. data/lib/aarch64/instructions/sub.rb +9 -0
  34. data/lib/aarch64/instructions/subs/addsub_ext.rb +37 -0
  35. data/lib/aarch64/instructions/subs/addsub_imm.rb +35 -0
  36. data/lib/aarch64/instructions/subs/addsub_shift.rb +37 -0
  37. data/lib/aarch64/instructions/subs.rb +9 -0
  38. data/lib/aarch64/instructions.rb +9 -21
  39. data/lib/aarch64/parser.rb +1890 -153
  40. data/lib/aarch64/parser.tab.rb +2255 -2849
  41. data/lib/aarch64/parser.y +23 -12
  42. data/lib/aarch64/system_registers/mrs_msr_64.rb +6 -3
  43. data/lib/aarch64/tokenizer.rb +460 -0
  44. data/lib/aarch64/version.rb +1 -1
  45. data/lib/aarch64.rb +55 -54
  46. data/test/base_instructions_test.rb +32 -22
  47. data/test/helper.rb +3 -3
  48. data/test/parser_test.rb +113 -12
  49. metadata +39 -30
  50. data/lib/aarch64/instructions/add_addsub_ext.rb +0 -35
  51. data/lib/aarch64/instructions/add_addsub_imm.rb +0 -32
  52. data/lib/aarch64/instructions/add_addsub_shift.rb +0 -35
  53. data/lib/aarch64/instructions/adds_addsub_ext.rb +0 -35
  54. data/lib/aarch64/instructions/adds_addsub_imm.rb +0 -33
  55. data/lib/aarch64/instructions/adds_addsub_shift.rb +0 -35
  56. data/lib/aarch64/instructions/and_log_imm.rb +0 -35
  57. data/lib/aarch64/instructions/and_log_shift.rb +0 -35
  58. data/lib/aarch64/instructions/ands_log_imm.rb +0 -35
  59. data/lib/aarch64/instructions/ands_log_shift.rb +0 -35
  60. data/lib/aarch64/instructions/eor_log_imm.rb +0 -35
  61. data/lib/aarch64/instructions/eor_log_shift.rb +0 -35
  62. data/lib/aarch64/instructions/orn_log_shift.rb +0 -35
  63. data/lib/aarch64/instructions/orr_log_imm.rb +0 -35
  64. data/lib/aarch64/instructions/orr_log_shift.rb +0 -35
  65. data/lib/aarch64/instructions/sub_addsub_ext.rb +0 -35
  66. data/lib/aarch64/instructions/sub_addsub_imm.rb +0 -33
  67. data/lib/aarch64/instructions/sub_addsub_shift.rb +0 -35
  68. data/lib/aarch64/instructions/subs_addsub_ext.rb +0 -35
  69. data/lib/aarch64/instructions/subs_addsub_imm.rb +0 -33
  70. data/lib/aarch64/instructions/subs_addsub_shift.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4148547f29912a9cea29d06ba88ebafff8ffd701b187ab9aa3a0b4ee1d309b0
4
- data.tar.gz: dc7b08ee7be2e57acfb2d5181d374a9baf6806be65dee0318cd95417349a2cfc
3
+ metadata.gz: 87efdbd48c160012a9bb9611a206fddf3bffeac5a748bb6ff8bb489805653f75
4
+ data.tar.gz: dd78668280e3d37f556f2b103f4cf25c7b8d0bcb696630e507a3c6cd5fae70c4
5
5
  SHA512:
6
- metadata.gz: f215a62f40c5ad36e81ec7d1d1110e21639ab0b19950283f4b5dbde46e5b26c17081a527d41dca600c4a8e8aa07eb0fc5f1f21a68d4425084c5eaf94de8baaef
7
- data.tar.gz: 4d0027eeb4a45b5d77e409b2fc343d59ec19548b4874f1c2e61bfeabcecb991ee2527a0969133f1029aa13e2623361bef3e6637ed65f9617001f5709ab31b99a
6
+ metadata.gz: a0eab1ba04ba42218bcb13c82d38f10315363b8e4598dd75cf73c82f0f3b3665881bc10f32b94ad203a6cd038a2f38d1eb353e528e1b3afe88ee57911e726f07
7
+ data.tar.gz: d2048034588506baa2d70ca5a5b4fb0352379a9275fc9b0bd9548be96f2754fbac3888691fb1762adab3a81590fbfc27c041b8975db73c67c58a1a9460e96dbe
@@ -0,0 +1,42 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ ruby-versions:
9
+ uses: ruby/actions/.github/workflows/ruby_versions.yml@master
10
+ with:
11
+ engine: cruby
12
+
13
+ test:
14
+ needs: ruby-versions
15
+ runs-on: ubuntu-24.04-arm
16
+ strategy:
17
+ matrix:
18
+ ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
19
+
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+
23
+ - name: Set up Ruby
24
+ uses: ruby/setup-ruby-pkgs@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby }}
27
+ apt-get: "haveged libyaml-dev cmake g++"
28
+
29
+ - name: Build capstone 5 from source
30
+ run: |
31
+ git clone --depth 1 --branch 5.0.7 https://github.com/capstone-engine/capstone.git /tmp/capstone
32
+ cd /tmp/capstone
33
+ cmake -B build -DCMAKE_INSTALL_PREFIX=/usr -DCAPSTONE_BUILD_TESTS=OFF -DCAPSTONE_BUILD_CSTOOL=OFF -DBUILD_SHARED_LIBS=ON
34
+ cmake --build build -j$(nproc)
35
+ sudo cmake --install build
36
+ sudo ldconfig
37
+
38
+ - name: Install dependencies
39
+ run: bundle install
40
+
41
+ - name: Run tests
42
+ run: bundle exec rake test
@@ -0,0 +1,62 @@
1
+ name: Publish gem to rubygems.org
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ push:
13
+ if: github.repository == 'tenderlove/aarch64'
14
+ runs-on: ubuntu-24.04-arm
15
+
16
+ environment:
17
+ name: rubygems.org
18
+ url: https://rubygems.org/gems/aarch64
19
+
20
+ permissions:
21
+ contents: write
22
+ id-token: write
23
+
24
+ strategy:
25
+ matrix:
26
+ ruby: ["ruby"]
27
+
28
+ steps:
29
+ - name: Harden Runner
30
+ uses: step-security/harden-runner@v2
31
+ with:
32
+ egress-policy: audit
33
+
34
+ - uses: actions/checkout@v4
35
+
36
+ - name: Set up Ruby
37
+ uses: ruby/setup-ruby@v1
38
+ with:
39
+ ruby-version: ${{ matrix.ruby }}
40
+ apt-get: "haveged libyaml-dev cmake g++"
41
+
42
+ - name: Build capstone 5 from source
43
+ run: |
44
+ git clone --depth 1 --branch 5.0.7 https://github.com/capstone-engine/capstone.git /tmp/capstone
45
+ cd /tmp/capstone
46
+ cmake -B build -DCMAKE_INSTALL_PREFIX=/usr -DCAPSTONE_BUILD_TESTS=OFF -DCAPSTONE_BUILD_CSTOOL=OFF -DBUILD_SHARED_LIBS=ON
47
+ cmake --build build -j$(nproc)
48
+ sudo cmake --install build
49
+ sudo ldconfig
50
+
51
+ - name: Install dependencies
52
+ run: bundle install --jobs 4 --retry 3
53
+
54
+ - name: Publish to RubyGems
55
+ uses: rubygems/release-gem@v1
56
+
57
+ - name: Create GitHub release
58
+ run: |
59
+ tag_name="$(git describe --tags --abbrev=0)"
60
+ gh release create "${tag_name}" --verify-tag --generate-notes
61
+ env:
62
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
data/README.md CHANGED
@@ -70,6 +70,32 @@ asm.movk X0, 0xF00D, lsl: 16
70
70
  asm.ret
71
71
  ```
72
72
 
73
+ Here is another example of the same assembly, but using the built-in ARM64
74
+ assembly parser:
75
+
76
+ ```ruby
77
+ require "jit_buffer"
78
+ require "aarch64/parser"
79
+
80
+ parser = AArch64::Parser.new
81
+ asm = parser.parse <<~eoasm
82
+ movz x0, 0xCAFE
83
+ movk x0, 0xF00D, lsl #16
84
+ ret
85
+ eoasm
86
+
87
+ # create a JIT buffer
88
+ jit_buffer = JITBuffer.new 4096
89
+
90
+ # Write the instructions to a JIT buffer
91
+ jit_buffer.writeable!
92
+ asm.write_to jit_buffer
93
+ jit_buffer.executable!
94
+
95
+ # Execute the JIT buffer
96
+ p jit_buffer.to_function([], -Fiddle::TYPE_INT).call.to_s(16) # => f00dcafe
97
+ ```
98
+
73
99
  ## Hacking / Contributing
74
100
 
75
101
  Hacking on this gem should be similar to most. Just do:
data/Rakefile CHANGED
@@ -2,6 +2,8 @@ ENV["MT_NO_PLUGINS"] = "1"
2
2
 
3
3
  require "rake/testtask"
4
4
  require "rake/clean"
5
+ require "bundler"
6
+ Bundler::GemHelper.install_tasks
5
7
 
6
8
  XML_FILE = "tmp/onebigfile.xml"
7
9
  ISA_FILE = "tmp/ISA_A64_xml_v88A-2021-12.tar.gz"
@@ -160,12 +162,6 @@ file SYSTEM_REGS_FILE do |t|
160
162
  download SYSTEM_REGS_URL, t.name
161
163
  end
162
164
 
163
- rule ".tab.rb" => [".y"] do |t|
164
- puts "#" * 90
165
- sh "gel exec racc -E -v #{t.source}"
166
- puts "#" * 90
167
- end
168
-
169
165
  Rake::TestTask.new(:test) do |t|
170
166
  t.libs << "test/lib" << "test"
171
167
  t.test_files = FileList['test/**/*_test.rb']
@@ -173,8 +169,6 @@ Rake::TestTask.new(:test) do |t|
173
169
  t.warning = true
174
170
  end
175
171
 
176
- task :test => "lib/aarch64/parser.tab.rb"
177
-
178
172
  task :default => :test
179
173
 
180
174
  task "autotest" do
@@ -205,3 +199,43 @@ task "autotest" do
205
199
  end
206
200
  end
207
201
  end
202
+
203
+ # Make a test from the assembly in stdin.
204
+ # $ echo "brk #0x1" | rake make_test
205
+ # assert_bytes [0x20, 00, 0x20, 0xd4] do |asm|
206
+ # asm.brk #0x1
207
+ # end
208
+ task :make_test do
209
+ require "odinflex/mach-o"
210
+ require "tempfile"
211
+
212
+ begin
213
+ asm = $stdin.read
214
+ bin = Tempfile.new("bin")
215
+ source = Tempfile.new("asm")
216
+ source.puts ".global _start"
217
+ source.puts ".align 2"
218
+ source.puts "_start:"
219
+ source.puts
220
+ source.write asm
221
+ source.flush
222
+ system("as -o #{bin.path} #{source.path}")
223
+
224
+ my_macho = OdinFlex::MachO.new bin
225
+ my_macho.each do |section|
226
+ if section.section? && section.sectname == "__text"
227
+ bin.seek(section.offset, IO::SEEK_SET)
228
+ (section.size / 4).times do
229
+ bytes = bin.read(4).unpack("C4").map { |x| sprintf("%#02x", x) }.join(", ")
230
+ puts "assert_bytes [#{bytes}] do |asm|"
231
+ puts " asm.#{asm}"
232
+ puts "end"
233
+ end
234
+ #p section.start_pos
235
+ end
236
+ end
237
+ ensure
238
+ bin.unlink
239
+ source.unlink
240
+ end
241
+ end
data/aarch64.gemspec CHANGED
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.add_development_dependency 'jit_buffer', '~> 1.0.0'
19
19
  s.add_development_dependency 'minitest', '~> 5.15'
20
20
  s.add_development_dependency 'rake', '~> 13.0'
21
- s.add_development_dependency 'racc', '~> 1.6'
21
+ s.add_development_dependency 'odinflex', '~> 1.0'
22
22
  end
@@ -0,0 +1,37 @@
1
+ module AArch64
2
+ module Instructions
3
+ module ADD
4
+ # ADD (extended register) -- A64
5
+ # Add (extended register)
6
+ # ADD <Wd|WSP>, <Wn|WSP>, <Wm>{, <extend> {#<amount>}}
7
+ # ADD <Xd|SP>, <Xn|SP>, <R><m>{, <extend> {#<amount>}}
8
+ class ADDSUB_ext < Instruction
9
+ def initialize rd, rn, rm, extend, amount, sf
10
+ @rd = check_mask(rd, 0x1f)
11
+ @rn = check_mask(rn, 0x1f)
12
+ @rm = check_mask(rm, 0x1f)
13
+ @extend = check_mask(extend, 0x07)
14
+ @amount = check_mask(amount, 0x07)
15
+ @sf = check_mask(sf, 0x01)
16
+ end
17
+
18
+ def encode _
19
+ ADD_addsub_ext(@sf, @rm, @extend, @amount, @rn, @rd)
20
+ end
21
+
22
+ private
23
+
24
+ def ADD_addsub_ext sf, rm, option, imm3, rn, rd
25
+ insn = 0b0_0_0_01011_00_1_00000_000_000_00000_00000
26
+ insn |= ((sf) << 31)
27
+ insn |= ((rm) << 16)
28
+ insn |= ((option) << 13)
29
+ insn |= ((imm3) << 10)
30
+ insn |= ((rn) << 5)
31
+ insn |= (rd)
32
+ insn
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,34 @@
1
+ module AArch64
2
+ module Instructions
3
+ module ADD
4
+ # ADD (immediate) -- A64
5
+ # Add (immediate)
6
+ # ADD <Wd|WSP>, <Wn|WSP>, #<imm>{, <shift>}
7
+ class ADDSUB_imm < Instruction
8
+ def initialize rd, rn, imm12, sh, sf
9
+ @rd = check_mask(rd, 0x1f)
10
+ @rn = check_mask(rn, 0x1f)
11
+ @imm12 = check_mask(imm12, 0xfff)
12
+ @sh = check_mask(sh, 0x01)
13
+ @sf = check_mask(sf, 0x01)
14
+ end
15
+
16
+ def encode _
17
+ ADD_addsub_imm(@sf, @sh, @imm12, @rn, @rd)
18
+ end
19
+
20
+ private
21
+
22
+ def ADD_addsub_imm sf, sh, imm12, rn, rd
23
+ insn = 0b0_0_0_100010_0_000000000000_00000_00000
24
+ insn |= ((sf) << 31)
25
+ insn |= ((sh) << 22)
26
+ insn |= ((imm12) << 10)
27
+ insn |= ((rn) << 5)
28
+ insn |= (rd)
29
+ insn
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ module AArch64
2
+ module Instructions
3
+ module ADD
4
+ # ADD (shifted register) -- A64
5
+ # Add (shifted register)
6
+ # ADD <Wd>, <Wn>, <Wm>{, <shift> #<amount>}
7
+ # ADD <Xd>, <Xn>, <Xm>{, <shift> #<amount>}
8
+ class ADDSUB_shift < Instruction
9
+ def initialize xd, xn, xm, shift, amount, sf
10
+ @xd = check_mask(xd, 0x1f)
11
+ @xn = check_mask(xn, 0x1f)
12
+ @xm = check_mask(xm, 0x1f)
13
+ @shift = check_mask(shift, 0x03)
14
+ @amount = check_mask(amount, 0x3f)
15
+ @sf = check_mask(sf, 0x01)
16
+ end
17
+
18
+ def encode _
19
+ ADD_addsub_shift(@sf, @shift, @xm, @amount, @xn, @xd)
20
+ end
21
+
22
+ private
23
+
24
+ def ADD_addsub_shift sf, shift, rm, imm6, rn, rd
25
+ insn = 0b0_0_0_01011_00_0_00000_000000_00000_00000
26
+ insn |= ((sf) << 31)
27
+ insn |= ((shift) << 22)
28
+ insn |= ((rm) << 16)
29
+ insn |= ((imm6) << 10)
30
+ insn |= ((rn) << 5)
31
+ insn |= (rd)
32
+ insn
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,9 @@
1
+ module AArch64
2
+ module Instructions
3
+ module ADD
4
+ autoload :ADDSUB_ext, "aarch64/instructions/add/addsub_ext"
5
+ autoload :ADDSUB_imm, "aarch64/instructions/add/addsub_imm"
6
+ autoload :ADDSUB_shift, "aarch64/instructions/add/addsub_shift"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,37 @@
1
+ module AArch64
2
+ module Instructions
3
+ module ADDS
4
+ # ADDS (extended register) -- A64
5
+ # Add (extended register), setting flags
6
+ # ADDS <Wd>, <Wn|WSP>, <Wm>{, <extend> {#<amount>}}
7
+ # ADDS <Xd>, <Xn|SP>, <R><m>{, <extend> {#<amount>}}
8
+ class ADDSUB_ext < Instruction
9
+ def initialize d, n, m, extend, amount, sf
10
+ @d = check_mask(d, 0x1f)
11
+ @n = check_mask(n, 0x1f)
12
+ @m = check_mask(m, 0x1f)
13
+ @extend = check_mask(extend, 0x07)
14
+ @amount = check_mask(amount, 0x07)
15
+ @sf = check_mask(sf, 0x01)
16
+ end
17
+
18
+ def encode _
19
+ ADDS_addsub_ext(@sf, @m, @extend, @amount, @n, @d)
20
+ end
21
+
22
+ private
23
+
24
+ def ADDS_addsub_ext sf, rm, option, imm3, rn, rd
25
+ insn = 0b0_0_1_01011_00_1_00000_000_000_00000_00000
26
+ insn |= ((sf) << 31)
27
+ insn |= ((rm) << 16)
28
+ insn |= ((option) << 13)
29
+ insn |= ((imm3) << 10)
30
+ insn |= ((rn) << 5)
31
+ insn |= (rd)
32
+ insn
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,35 @@
1
+ module AArch64
2
+ module Instructions
3
+ module ADDS
4
+ # ADDS (immediate) -- A64
5
+ # Add (immediate), setting flags
6
+ # ADDS <Wd>, <Wn|WSP>, #<imm>{, <shift>}
7
+ # ADDS <Xd>, <Xn|SP>, #<imm>{, <shift>}
8
+ class ADDSUB_imm < Instruction
9
+ def initialize d, n, imm, shift, sf
10
+ @d = check_mask(d, 0x1f)
11
+ @n = check_mask(n, 0x1f)
12
+ @imm = check_mask(imm, 0xfff)
13
+ @shift = check_mask(shift, 0x01)
14
+ @sf = check_mask(sf, 0x01)
15
+ end
16
+
17
+ def encode _
18
+ ADDS_addsub_imm(@sf, @shift, @imm, @n, @d)
19
+ end
20
+
21
+ private
22
+
23
+ def ADDS_addsub_imm sf, sh, imm12, rn, rd
24
+ insn = 0b0_0_1_100010_0_000000000000_00000_00000
25
+ insn |= ((sf) << 31)
26
+ insn |= ((sh) << 22)
27
+ insn |= ((imm12) << 10)
28
+ insn |= ((rn) << 5)
29
+ insn |= (rd)
30
+ insn
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ module AArch64
2
+ module Instructions
3
+ module ADDS
4
+ # ADDS (shifted register) -- A64
5
+ # Add (shifted register), setting flags
6
+ # ADDS <Wd>, <Wn>, <Wm>{, <shift> #<amount>}
7
+ # ADDS <Xd>, <Xn>, <Xm>{, <shift> #<amount>}
8
+ class ADDSUB_shift < Instruction
9
+ def initialize xd, xn, xm, shift, amount, sf
10
+ @xd = check_mask(xd, 0x1f)
11
+ @xn = check_mask(xn, 0x1f)
12
+ @xm = check_mask(xm, 0x1f)
13
+ @shift = check_mask(shift, 0x03)
14
+ @amount = check_mask(amount, 0x3f)
15
+ @sf = check_mask(sf, 0x01)
16
+ end
17
+
18
+ def encode _
19
+ ADDS_addsub_shift(@sf, @shift, @xm, @amount, @xn, @xd)
20
+ end
21
+
22
+ private
23
+
24
+ def ADDS_addsub_shift sf, shift, rm, imm6, rn, rd
25
+ insn = 0b0_0_1_01011_00_0_00000_000000_00000_00000
26
+ insn |= ((sf) << 31)
27
+ insn |= ((shift) << 22)
28
+ insn |= ((rm) << 16)
29
+ insn |= ((imm6) << 10)
30
+ insn |= ((rn) << 5)
31
+ insn |= (rd)
32
+ insn
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,9 @@
1
+ module AArch64
2
+ module Instructions
3
+ module ADDS
4
+ autoload :ADDSUB_ext, "aarch64/instructions/adds/addsub_ext"
5
+ autoload :ADDSUB_imm, "aarch64/instructions/adds/addsub_imm"
6
+ autoload :ADDSUB_shift, "aarch64/instructions/adds/addsub_shift"
7
+ end
8
+ end
9
+ end
@@ -10,7 +10,7 @@ module AArch64
10
10
  end
11
11
 
12
12
  def encode _
13
- label = @label / 4096
13
+ label = unwrap_label(@label, 0) / 4096
14
14
  ADRP(label & 0x3, check_mask(label >> 2, 0x7ffff), @xd)
15
15
  end
16
16
 
@@ -0,0 +1,37 @@
1
+ module AArch64
2
+ module Instructions
3
+ module AND
4
+ # AND (immediate) -- A64
5
+ # Bitwise AND (immediate)
6
+ # AND <Wd|WSP>, <Wn>, #<imm>
7
+ # AND <Xd|SP>, <Xn>, #<imm>
8
+ class LOG_imm < Instruction
9
+ def initialize rd, rn, immr, imms, n, sf
10
+ @rd = check_mask(rd, 0x1f)
11
+ @rn = check_mask(rn, 0x1f)
12
+ @immr = check_mask(immr, 0x3f)
13
+ @imms = check_mask(imms, 0x3f)
14
+ @n = check_mask(n, 0x01)
15
+ @sf = check_mask(sf, 0x01)
16
+ end
17
+
18
+ def encode _
19
+ AND_log_imm(@sf, @n, @immr, @imms, @rn, @rd)
20
+ end
21
+
22
+ private
23
+
24
+ def AND_log_imm sf, n, immr, imms, rn, rd
25
+ insn = 0b0_00_100100_0_000000_000000_00000_00000
26
+ insn |= ((sf) << 31)
27
+ insn |= ((n) << 22)
28
+ insn |= ((immr) << 16)
29
+ insn |= ((imms) << 10)
30
+ insn |= ((rn) << 5)
31
+ insn |= (rd)
32
+ insn
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ module AArch64
2
+ module Instructions
3
+ module AND
4
+ # AND (shifted register) -- A64
5
+ # Bitwise AND (shifted register)
6
+ # AND <Wd>, <Wn>, <Wm>{, <shift> #<amount>}
7
+ # AND <Xd>, <Xn>, <Xm>{, <shift> #<amount>}
8
+ class LOG_shift < Instruction
9
+ def initialize xd, xn, xm, shift, amount, sf
10
+ @xd = check_mask(xd, 0x1f)
11
+ @xn = check_mask(xn, 0x1f)
12
+ @xm = check_mask(xm, 0x1f)
13
+ @shift = check_mask(shift, 0x03)
14
+ @amount = check_mask(amount, 0x3f)
15
+ @sf = check_mask(sf, 0x01)
16
+ end
17
+
18
+ def encode _
19
+ AND_log_shift(@sf, @shift, @xm, @amount, @xn, @xd)
20
+ end
21
+
22
+ private
23
+
24
+ def AND_log_shift sf, shift, rm, imm6, rn, rd
25
+ insn = 0b0_00_01010_00_0_00000_000000_00000_00000
26
+ insn |= ((sf) << 31)
27
+ insn |= ((shift) << 22)
28
+ insn |= ((rm) << 16)
29
+ insn |= ((imm6) << 10)
30
+ insn |= ((rn) << 5)
31
+ insn |= (rd)
32
+ insn
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,8 @@
1
+ module AArch64
2
+ module Instructions
3
+ module AND
4
+ autoload :LOG_imm, "aarch64/instructions/and/log_imm"
5
+ autoload :LOG_shift, "aarch64/instructions/and/log_shift"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,37 @@
1
+ module AArch64
2
+ module Instructions
3
+ module ANDS
4
+ # ANDS (immediate) -- A64
5
+ # Bitwise AND (immediate), setting flags
6
+ # ANDS <Wd>, <Wn>, #<imm>
7
+ # ANDS <Xd>, <Xn>, #<imm>
8
+ class LOG_imm < Instruction
9
+ def initialize rd, rn, immr, imms, n, sf
10
+ @rd = check_mask(rd, 0x1f)
11
+ @rn = check_mask(rn, 0x1f)
12
+ @immr = check_mask(immr, 0x3f)
13
+ @imms = check_mask(imms, 0x3f)
14
+ @n = check_mask(n, 0x01)
15
+ @sf = check_mask(sf, 0x01)
16
+ end
17
+
18
+ def encode _
19
+ ANDS_log_imm(@sf, @n, @immr, @imms, @rn, @rd)
20
+ end
21
+
22
+ private
23
+
24
+ def ANDS_log_imm sf, n, immr, imms, rn, rd
25
+ insn = 0b0_11_100100_0_000000_000000_00000_00000
26
+ insn |= ((sf) << 31)
27
+ insn |= ((n) << 22)
28
+ insn |= ((immr) << 16)
29
+ insn |= ((imms) << 10)
30
+ insn |= ((rn) << 5)
31
+ insn |= (rd)
32
+ insn
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ module AArch64
2
+ module Instructions
3
+ module ANDS
4
+ # ANDS (shifted register) -- A64
5
+ # Bitwise AND (shifted register), setting flags
6
+ # ANDS <Wd>, <Wn>, <Wm>{, <shift> #<amount>}
7
+ # ANDS <Xd>, <Xn>, <Xm>{, <shift> #<amount>}
8
+ class LOG_shift < Instruction
9
+ def initialize xd, xn, xm, shift, amount, sf
10
+ @xd = check_mask(xd, 0x1f)
11
+ @xn = check_mask(xn, 0x1f)
12
+ @xm = check_mask(xm, 0x1f)
13
+ @shift = check_mask(shift, 0x03)
14
+ @amount = check_mask(amount, 0x3f)
15
+ @sf = check_mask(sf, 0x01)
16
+ end
17
+
18
+ def encode _
19
+ ANDS_log_shift(@sf, @shift, @xm, @amount, @xn, @xd)
20
+ end
21
+
22
+ private
23
+
24
+ def ANDS_log_shift sf, shift, rm, imm6, rn, rd
25
+ insn = 0b0_11_01010_00_0_00000_000000_00000_00000
26
+ insn |= ((sf) << 31)
27
+ insn |= ((shift) << 22)
28
+ insn |= ((rm) << 16)
29
+ insn |= ((imm6) << 10)
30
+ insn |= ((rn) << 5)
31
+ insn |= (rd)
32
+ insn
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,8 @@
1
+ module AArch64
2
+ module Instructions
3
+ module ANDS
4
+ autoload :LOG_imm, "aarch64/instructions/ands/log_imm"
5
+ autoload :LOG_shift, "aarch64/instructions/ands/log_shift"
6
+ end
7
+ end
8
+ end