-
Notifications
You must be signed in to change notification settings - Fork 65
/
UnicornARMv8Simulator.class.st
712 lines (487 loc) · 17.2 KB
/
UnicornARMv8Simulator.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
Class {
#name : #UnicornARMv8Simulator,
#superclass : #UnicornSimulator,
#category : #'VMMakerTests-Unicorn'
}
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> arg0Register [
^ UcARM64Registers x3
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> arg1Register [
^ UcARM64Registers x4
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> arg2Register [
^ UcARM64Registers x2
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> arg3Register [
^ UcARM64Registers x3
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> argument1RegisterValue: anInteger [
self writeRegister: UcARM64Registers x4 value: anInteger
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> baseRegister [
^ UcARM64Registers x24
]
{ #category : #'c calling convention' }
UnicornARMv8Simulator >> cResultRegister [
^ UcARM64Registers x0
]
{ #category : #'c calling convention' }
UnicornARMv8Simulator >> carg0Register [
^ UcARM64Registers x0
]
{ #category : #'c calling convention' }
UnicornARMv8Simulator >> carg1Register [
^ UcARM64Registers x1
]
{ #category : #'c calling convention' }
UnicornARMv8Simulator >> carg2Register [
^ UcARM64Registers x2
]
{ #category : #'c calling convention' }
UnicornARMv8Simulator >> carg3Register [
^ UcARM64Registers x3
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> carry [
^ (self nzcv bitAnd: (1<<29))~= 0
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> classRegister [
^ UcARM64Registers x22
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> cpacr_el1 [
^ self readRegister: UcARM64Registers cpacr_el1
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> cpacr_el1: anInteger [
self writeRegister: UcARM64Registers cpacr_el1 value: anInteger
]
{ #category : #initialization }
UnicornARMv8Simulator >> createUnicorn [
simulator := Unicorn arm64.
"Enable floating point..."
self cpacr_el1: (self cpacr_el1 bitOr: 2r11 << 20).
^ simulator
]
{ #category : #disassembling }
UnicornARMv8Simulator >> disassembler [
^ LLVMARMDisassembler aarch64
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> doublePrecisionFloatingPointRegister0 [
^ UcARM64Registers d0
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> doublePrecisionFloatingPointRegister1 [
^ UcARM64Registers d1
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> doublePrecisionFloatingPointRegister2 [
^ UcARM64Registers d2
]
{ #category : #disassembling }
UnicornARMv8Simulator >> extractDestinationRegisterFromAssembly: aLLVMInstruction [
"In ARM, instructions are usually encoded asSpotterCandidateLink
INST Destination, Source
"
^ (aLLVMInstruction assemblyCodeString substrings: String tab, ',') second trimBoth.
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> framePointerRegister [
^ UcARM64Registers fp
]
{ #category : #'simulation-support' }
UnicornARMv8Simulator >> getReturnAddress [
^ self linkRegisterValue
]
{ #category : #testing }
UnicornARMv8Simulator >> hasLinkRegister [
^ true
]
{ #category : #initialization }
UnicornARMv8Simulator >> initializeRegisterAliases [
registerAliases
at: #x22 put: #classRegister;
at: #x23 put: #receiverRegister;
at: #x25 put: #sendNumberOfArgumentsRegister;
at: #x24 put: #baseRegister;
at: #x28 put: #vmStackPointer;
at: #x29 put: #framePointerRegister;
at: #x30 put: #linkRegister
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> instructionPointerRegister [
^ UcARM64Registers pc
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> linkRegister [
^ UcARM64Registers x30
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> negative [
^ (self nzcv bitAnd: (1<<31))~= 0
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> nzcv [
^ self readRegister: UcARM64Registers nzcv
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> overflow [
^ (self nzcv bitAnd: (1<<28)) ~= 0
]
{ #category : #'simulation-support' }
UnicornARMv8Simulator >> postCallArgumentsNumArgs: numArgs "<Integer>" in: aMemory [ "<ByteArray|Bitmap>"
"Answer an argument vector of the requested size after a vanilla
ABI call. For ARM the Procedure Calling Specification can be found in IHI0042D_aapcs.pdf.
On ARM this typically means accessing r0 through r3 and fetching additional arguments from the stack, acording to pages 20f. aapcs.
We assume that all arguments are single word arguments, which can not be supplied on co-processor-registers.
For compatibility with Cog/Slang we answer unsigned values."
^(1 to: numArgs) collect: [:i |
i < 5
ifTrue: [self perform: (self registerStateGetters at: i)]
"ARM uses a full descending stack. Directly after calling a procedure, nothing but the arguments are pushed."
ifFalse: [memory unsignedLongAt: self sp + (i-5)*4 bigEndian: false]].
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> receiverRegister [
^ UcARM64Registers x23
]
{ #category : #accessing }
UnicornARMv8Simulator >> registerList [
^ #(lr pc sp fp x28 x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x16 x19 x20 x21 x22 x23 x24 x25 x26 x27 zero negative carry overflow v0 v1 v2)
]
{ #category : #'simulation-support' }
UnicornARMv8Simulator >> registerStateGetters [
^#( x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x12 sp lr pc)
]
{ #category : #'simulation-support' }
UnicornARMv8Simulator >> retpcIn: aMemory [
^ memory longAt: self fp + 8
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> sendNumberOfArgumentsRegister [
^ UcARM64Registers x25
]
{ #category : #'simulation-support' }
UnicornARMv8Simulator >> simulateJumpCallOf: address memory: aMemory [
"Simulate a frame-building jump of address. Build a frame since
a) this is used for calls into the run-time which are unlikely to be leaf-calls"
"This method builds a stack frame as expected by the simulator, not as defined by ARM aapcs-abi.
In ARM aapcs, every method can define for itself, wether it wants to push lr (nextpc), and wether it
uses a frame pointer. The standard never mentions a fp. It merely defines r4-r11 to be callee-saved."
self assert: self sp \\ 8 = 0. "This check ensures, that we conform with ARM abi. Before doing anything to the stack, we ensure 2-word alignment."
self pushWord: self linkRegisterValue.
self pushWord: self fp.
self framePointerRegisterValue: self stackPointerRegisterValue.
self instructionPointerRegisterValue: address
]
{ #category : #'simulation-support' }
UnicornARMv8Simulator >> simulateLeafCallOf: address nextpc: nextpc memory: aMemory [
self lr: nextpc.
self pc: address
]
{ #category : #'simulation-support' }
UnicornARMv8Simulator >> simulateReturnIn: aSpurSimulatedMemory [
self framePointerRegisterValue: self popWord.
self linkRegisterValue: self popWord.
self instructionPointerRegisterValue: self linkRegisterValue
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> smalltalkStackPointerRegister [
"Internally to execute Smalltalk code we use X28 as the stack pointer register"
^ UcARM64Registers x28
]
{ #category : #'simulation-support' }
UnicornARMv8Simulator >> smashCallerSavedRegistersWithValuesFrom: base by: step in: aMemory [
#(x0: x1: x2: x3: x4: x5: lr:) withIndexDo:
[:accessor :index|
self perform: accessor with: index - 1 * step + base]
]
{ #category : #'simulation-support' }
UnicornARMv8Simulator >> smashRegisterAccessors [
"Caller saved registers to smash"
^#( x0: x1: x2: x3: x4: x5: x6: x7: x8: x9: x10: x11: x12: )
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> stackPointerRegister [
^ UcARM64Registers sp
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> temporaryRegister [
^ UcARM64Registers x1
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> v0 [
^ self readRawRegister: UcARM64Registers v0 size: 16
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> v1 [
^ self readRawRegister: UcARM64Registers v1 size: 16
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> v2 [
^ self readRawRegister: UcARM64Registers v2 size: 16
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> vectorRegister0Value [
^ simulator readRegisterId: UcARM64Registers v0 size: 16
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> vectorRegister1Value [
^ simulator readRegisterId: UcARM64Registers v1 size: 16
]
{ #category : #'accessing-registers-abstract' }
UnicornARMv8Simulator >> vectorRegister2Value [
^ simulator readRegisterId: UcARM64Registers v2 size: 16
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> w25: anInteger [
self writeRegister: UcARM64Registers w25 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> w6: anInteger [
self writeRegister: UcARM64Registers w6 value: anInteger
]
{ #category : #accessing }
UnicornARMv8Simulator >> wordSize [
^ 8
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x0 [
^ self readRegister: UcARM64Registers x0
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x0: anInteger [
self writeRegister: UcARM64Registers x0 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x1 [
^ self readRegister: UcARM64Registers x1
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x10 [
^ self readRegister: UcARM64Registers x10
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x10: anInteger [
^ self writeRegister: UcARM64Registers x10 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x11 [
^ self readRegister: UcARM64Registers x11
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x11: anInteger [
^ self writeRegister: UcARM64Registers x11 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x12 [
^ self readRegister: UcARM64Registers x12
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x12: anInteger [
^ self writeRegister: UcARM64Registers x12 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x13: anInteger [
self writeRegister: UcARM64Registers x13 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x14: anInteger [
self writeRegister: UcARM64Registers x14 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x15: anInteger [
self writeRegister: UcARM64Registers x15 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x16 [
^ self readRegister: UcARM64Registers x16
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x16: anInteger [
self writeRegister: UcARM64Registers x16 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x17: anInteger [
self writeRegister: UcARM64Registers x17 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x18: anInteger [
self writeRegister: UcARM64Registers x18 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x19 [
^ self readRegister: UcARM64Registers x19
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x19: anInteger [
self writeRegister: UcARM64Registers x19 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x1: anInteger [
^ self writeRegister: UcARM64Registers x1 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x2 [
^ self readRegister: UcARM64Registers x2
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x20 [
^ self readRegister: UcARM64Registers x20
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x20: anInteger [
self writeRegister: UcARM64Registers x20 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x21 [
^ self readRegister: UcARM64Registers x21
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x21: anInteger [
self writeRegister: UcARM64Registers x21 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x22 [
^ self readRegister: UcARM64Registers x22
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x22: anInteger [
self writeRegister: UcARM64Registers x22 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x23 [
^ self readRegister: UcARM64Registers x23
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x23: anInteger [
self writeRegister: UcARM64Registers x23 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x24 [
^ self readRegister: UcARM64Registers x24
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x24: anInteger [
self writeRegister: UcARM64Registers x24 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x25 [
^ self readRegister: UcARM64Registers x25
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x25: anInteger [
self writeRegister: UcARM64Registers x25 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x26 [
^ self readRegister: UcARM64Registers x26
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x26: anInteger [
self writeRegister: UcARM64Registers x26 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x27 [
^ self readRegister: UcARM64Registers x27
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x27: anInteger [
self writeRegister: UcARM64Registers x27 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x28 [
^ self readRegister: UcARM64Registers x28
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x28: anInteger [
self writeRegister: UcARM64Registers x28 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x29: anInteger [
^ self writeRegister: UcARM64Registers x29 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x2: anInteger [
^ self writeRegister: UcARM64Registers x2 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x3 [
^ self readRegister: UcARM64Registers x3
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x30: anInteger [
self writeRegister: UcARM64Registers x30 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x3: anInteger [
^ self writeRegister: UcARM64Registers x3 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x4 [
^ self readRegister: UcARM64Registers x4
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x4: anInteger [
^ self writeRegister: UcARM64Registers x4 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x5 [
^ self readRegister: UcARM64Registers x5
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x5: anInteger [
^ self writeRegister: UcARM64Registers x5 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x6 [
^ self readRegister: UcARM64Registers x6
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x6: anInteger [
^ self writeRegister: UcARM64Registers x6 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x7 [
^ self readRegister: UcARM64Registers x7
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x7: anInteger [
^ self writeRegister: UcARM64Registers x7 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x8 [
^ self readRegister: UcARM64Registers x8
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x8: anInteger [
^ self writeRegister: UcARM64Registers x8 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x9 [
^ self readRegister: UcARM64Registers x9
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> x9: anInteger [
^ self writeRegister: UcARM64Registers x9 value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> xzr [
^ self readRegister: UcARM64Registers xzr
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> xzr: anInteger [
^ self writeRegister: UcARM64Registers xzr value: anInteger
]
{ #category : #'accessing-registers-physical' }
UnicornARMv8Simulator >> zero [
^ (self nzcv bitAnd: (1<<30)) ~= 0
]