-
Notifications
You must be signed in to change notification settings - Fork 68
/
UnicornX64Simulator.class.st
525 lines (365 loc) · 11.5 KB
/
UnicornX64Simulator.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
Class {
#name : #UnicornX64Simulator,
#superclass : #UnicornSimulator,
#category : #'VMMakerTests-Unicorn'
}
{ #category : #registers }
UnicornX64Simulator >> arg0Register [
^ UcX86Registers rdi
]
{ #category : #registers }
UnicornX64Simulator >> arg1Register [
^ UcX86Registers rsi
]
{ #category : #accessing }
UnicornX64Simulator >> argument1RegisterValue: anInteger [
self writeRegister: UcX86Registers rsi value: anInteger
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> baseRegister [
^ UcX86Registers rbx
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> cResultRegister [
^ UcX86Registers rax
]
{ #category : #registers }
UnicornX64Simulator >> carg0Register [
"Assume SysV"
^ UcX86Registers rdi
]
{ #category : #registers }
UnicornX64Simulator >> carg1Register [
"Assume SysV"
^ UcX86Registers rsi
]
{ #category : #registers }
UnicornX64Simulator >> carg2Register [
"Assume SysV"
^ UcX86Registers rdx
]
{ #category : #registers }
UnicornX64Simulator >> carg3Register [
"Assume SysV"
^ UcX86Registers rcx
]
{ #category : #'virtual-registers' }
UnicornX64Simulator >> classRegister [
^ UcX86Registers rcx
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> createUnicorn [
^ Unicorn x8664
]
{ #category : #disassembling }
UnicornX64Simulator >> disassembler [
^ LLVMDisassembler amd64
]
{ #category : #registers }
UnicornX64Simulator >> doublePrecisionFloatingPointRegister0 [
^ UcX86Registers xmm0
]
{ #category : #registers }
UnicornX64Simulator >> doublePrecisionFloatingPointRegister1 [
^ UcX86Registers xmm1
]
{ #category : #registers }
UnicornX64Simulator >> doublePrecisionFloatingPointRegister2 [
^ UcX86Registers xmm2
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> extractDestinationRegisterFromAssembly: aLLVMInstruction [
| registerName |
registerName := (aLLVMInstruction assemblyCodeString substrings: ',') last trimBoth.
(registerName beginsWith: '%')
ifTrue: [ registerName := registerName allButFirst ].
^ registerName
]
{ #category : #'virtual-registers' }
UnicornX64Simulator >> framePointerRegister [
^ UcX86Registers rbp
]
{ #category : #accessing }
UnicornX64Simulator >> getReturnAddress [
^ self peekAddress
]
{ #category : #testing }
UnicornX64Simulator >> hasLinkRegister [
^ false
]
{ #category : #initialization }
UnicornX64Simulator >> initializeRegisterAliases [
registerAliases
at: #rcx put: #classRegister;
at: #rdx put: #receiverRegister;
at: #r9 put: #sendNumberOfArgumentsRegister;
at: #rbx put: #baseRegister;
at: #rbp put: #framePointerRegister
]
{ #category : #'virtual-registers' }
UnicornX64Simulator >> instructionPointerRegister [
^ UcX86Registers rip
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> integerRegisterState [
^ #()
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> postCallArgumentsNumArgs: numArgs in: aMemory [
"Answer an argument vector of the requested size after a Win64 or SysV
ABI call. On X64 this simply means accessing register arguments.
For compatibility with Cog/Slang we answer unsigned values."
self assert: numArgs <= 4.
^((CogX64Compiler isSysV
ifTrue: [#(rdi rsi rdx rcx r8 r9)]
ifFalse: [#(rcx rdx r8 r9)]) copyFrom: 1 to: numArgs) collect:
[:getter|
self perform: getter]
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> r10 [
^ self readRegister: UcX86Registers r10
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> r10: anInteger [
^ self writeRegister: UcX86Registers r10 value: anInteger
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> r11 [
^ self readRegister: UcX86Registers r11
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> r11: anInteger [
^ self writeRegister: UcX86Registers r11 value: anInteger
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> r12 [
^ self readRegister: UcX86Registers r12
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> r12: anInteger [
^ self writeRegister: UcX86Registers r12 value: anInteger
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> r13: anInteger [
self writeRegister: UcX86Registers r13 value: anInteger
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> r14: anInteger [
self writeRegister: UcX86Registers r14 value: anInteger
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> r15: anInteger [
self writeRegister: UcX86Registers r15 value: anInteger
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> r1: anInteger [
^ self writeRegister: UcX86Registers r1 value: anInteger
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> r2: anInteger [
^ self writeRegister: UcX86Registers r2 value: anInteger
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> r3: anInteger [
^ self writeRegister: UcX86Registers r3 value: anInteger
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> r4: anInteger [
^ self writeRegister: UcX86Registers r4 value: anInteger
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> r5: anInteger [
^ self writeRegister: UcX86Registers r5 value: anInteger
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> r6: anInteger [
^ self writeRegister: UcX86Registers r6 value: anInteger
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> r7: anInteger [
^ self writeRegister: UcX86Registers r7 value: anInteger
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> r8 [
^ self readRegister: UcX86Registers r8
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> r8: anInteger [
^ self writeRegister: UcX86Registers r8 value: anInteger
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> r9 [
^ self readRegister: UcX86Registers r9
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> r9: anInteger [
^ self writeRegister: UcX86Registers r9 value: anInteger
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> r9b: anInteger [
self writeRegister: UcX86Registers r9b value: anInteger
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> rax [
^ self readRegister: UcX86Registers rax
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> rax: anInteger [
self writeRegister: UcX86Registers rax value: anInteger
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> rbp [
^ self readRegister: UcX86Registers rbp
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> rbp: anInteger [
^ self writeRegister: UcX86Registers rbp value: anInteger
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> rbx [
^ self readRegister: UcX86Registers rbx
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> rbx: aValue [
^ self writeRegister: UcX86Registers rbx value: aValue
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> rcx [
^ self readRegister: UcX86Registers rcx
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> rcx: anInteger [
^ self writeRegister: UcX86Registers rcx value: anInteger
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> rdi [
^ self readRegister: UcX86Registers rdi
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> rdi: anInteger [
self writeRegister: UcX86Registers rdi value: anInteger
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> rdx [
^ self readRegister: UcX86Registers rdx
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> rdx: anInteger [
^ self writeRegister: UcX86Registers rdx value: anInteger
]
{ #category : #'virtual-registers' }
UnicornX64Simulator >> receiverRegister [
^ UcX86Registers rdx
]
{ #category : #accessing }
UnicornX64Simulator >> registerList [
^ #(rip rax rbx rcx rdx rsp rbp r8 r9 r10 r11 r12 rsi rdi)
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> retpcIn: aSpurSimulatedMemory [
^ memory long64At: self rbp + 8
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> rip [
^ self readRegister: UcX86Registers rip
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> rip: anInteger [
self writeRegister: UcX86Registers rip value: anInteger
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> rsi [
^ self readRegister: UcX86Registers rsi
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> rsi: anInteger [
self writeRegister: UcX86Registers rsi value: anInteger
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> rsp [
^ self readRegister: UcX86Registers rsp
]
{ #category : #'phisical-registers' }
UnicornX64Simulator >> rsp: anInteger [
^ self writeRegister: UcX86Registers rsp value: anInteger
]
{ #category : #'virtual-registers' }
UnicornX64Simulator >> sendNumberOfArgumentsRegister [
^ UcX86Registers r9
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> simulateJumpCallOf: address memory: aMemory [
"Simulate a frame-building jump call of address (i.e. do not push the return pc
as this has already been done). Build a frame since
a) this is used for calls into the run-time which are unlikely to be leaf-calls, and
b) stack alignment needs to be realistic for assert checking for platforms such as Mac OS X"
"From the System V ABI:
3.2.2 The Stack Frame
... The end of the input argument area shall be aligned on a 16 (32, if __m256 is
passed on stack) byte boundary. In other words, the value (%rsp + 8) is always
a multiple of 16 (32) when control is transferred to the function entry point."
self pushWord: self rbp.
self rbp: self rsp.
self rip: address
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> simulateLeafCallOf: address nextpc: nextpc memory: aMemory [
self pushWord: nextpc.
self rip: address
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> simulateReturnIn: aMemory [
self rbp: (self popWord).
self rip: (self popWord)
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> smashCallerSavedRegistersWithValuesFrom: base by: step in: aMemory [
| volatileRegisters |
CogX64Compiler isSysV
ifTrue:
[volatileRegisters := #(rax: rcx: rdx: rsi: rdi: r8: r9: r10: r11:)]
ifFalse: "We should also save the registers to the shadow parameter space."
[volatileRegisters := #(rax: rcx: rdx: r8: r9: r10: r11:).
#(rcx rdx r8 r9) withIndexDo:
[:getter :index|
aMemory
unsignedLong64At: self rbp + 9 + (index * 8) "skip saved fp and retpc; aMemory is 1-relative"
put: (self perform: getter)]].
volatileRegisters withIndexDo:
[:setter :index|
self perform: setter with: index - 1 * step + base]
]
{ #category : #'as yet unclassified' }
UnicornX64Simulator >> smashRegisterAccessors [
^#(rax: rbx: rcx: rdx: rsi: rdi: r8: r9: r10: r11: r12: r13: r14: r15:)
]
{ #category : #'virtual-registers' }
UnicornX64Simulator >> stackPointerRegister [
^ UcX86Registers rsp
]
{ #category : #registers }
UnicornX64Simulator >> temporaryRegister [
"Both in System V and Windows"
^ UcX86Registers rax
]
{ #category : #accessing }
UnicornX64Simulator >> vectorRegister0Value [
^ simulator readRegisterId: UcX86Registers xmm0 size: 16
]
{ #category : #accessing }
UnicornX64Simulator >> wordSize [
^ 8
]
{ #category : #'accessing - registers' }
UnicornX64Simulator >> xmm0 [
^ simulator readRegisterId: UcX86Registers xmm0 size: 16
]
{ #category : #accessing }
UnicornX64Simulator >> xmm1 [
^ simulator readRegisterId: UcX86Registers xmm1 size: 16
]
{ #category : #registers }
UnicornX64Simulator >> xmm2 [
^ simulator readRegisterId: UcX86Registers xmm2 size: 16
]