This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathasmhelpers.asm
More file actions
2136 lines (1678 loc) · 72.3 KB
/
asmhelpers.asm
File metadata and controls
2136 lines (1678 loc) · 72.3 KB
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
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; Licensed to the .NET Foundation under one or more agreements.
; The .NET Foundation licenses this file to you under the MIT license.
; See the LICENSE file in the project root for more information.
;; ==++==
;;
;;
;; ==--==
#include "ksarm.h"
#include "asmconstants.h"
#include "asmmacros.h"
SETALIAS CTPMethodTable__s_pThunkTable, ?s_pThunkTable@CTPMethodTable@@0PAVMethodTable@@A
SETALIAS g_pObjectClass, ?g_pObjectClass@@3PAVMethodTable@@A
IMPORT JIT_InternalThrow
IMPORT JIT_WriteBarrier
IMPORT TheUMEntryPrestubWorker
IMPORT CreateThreadBlockThrow
IMPORT UMThunkStubRareDisableWorker
IMPORT PreStubWorker
IMPORT PreStubGetMethodDescForCompactEntryPoint
IMPORT NDirectImportWorker
IMPORT ObjIsInstanceOfNoGC
IMPORT ArrayStoreCheck
IMPORT VSD_ResolveWorker
IMPORT $g_pObjectClass
#ifdef WRITE_BARRIER_CHECK
SETALIAS g_GCShadow, ?g_GCShadow@@3PAEA
SETALIAS g_GCShadowEnd, ?g_GCShadowEnd@@3PAEA
IMPORT g_lowest_address
IMPORT $g_GCShadow
IMPORT $g_GCShadowEnd
#endif // WRITE_BARRIER_CHECK
#ifdef FEATURE_COMINTEROP
IMPORT CLRToCOMWorker
IMPORT ComPreStubWorker
IMPORT COMToCLRWorker
#endif
IMPORT CallDescrWorkerUnwindFrameChainHandler
IMPORT UMEntryPrestubUnwindFrameChainHandler
IMPORT UMThunkStubUnwindFrameChainHandler
#ifdef FEATURE_COMINTEROP
IMPORT ReverseComUnwindFrameChainHandler
#endif
#ifdef FEATURE_HIJACK
IMPORT OnHijackWorker
#endif ;FEATURE_HIJACK
IMPORT GetCurrentSavedRedirectContext
;; Imports to support virtual import fixup for ngen images
IMPORT VirtualMethodFixupWorker
;; Import to support cross-moodule external method invocation in ngen images
IMPORT ExternalMethodFixupWorker
IMPORT StubDispatchFixupWorker
#ifdef FEATURE_READYTORUN
IMPORT DynamicHelperWorker
#endif
IMPORT JIT_RareDisableHelperWorker
IMPORT DoJITFailFast
IMPORT s_gsCookie
IMPORT g_TrapReturningThreads
;; Imports for singleDomain statics helpers
IMPORT JIT_GetSharedNonGCStaticBase_Helper
IMPORT JIT_GetSharedGCStaticBase_Helper
TEXTAREA
;; LPVOID __stdcall GetCurrentIP(void);
LEAF_ENTRY GetCurrentIP
mov r0, lr
bx lr
LEAF_END
;; LPVOID __stdcall GetCurrentSP(void);
LEAF_ENTRY GetCurrentSP
mov r0, sp
bx lr
LEAF_END
;;-----------------------------------------------------------------------------
;; This helper routine enregisters the appropriate arguments and makes the
;; actual call.
;;-----------------------------------------------------------------------------
;;void CallDescrWorkerInternal(CallDescrData * pCallDescrData);
NESTED_ENTRY CallDescrWorkerInternal,,CallDescrWorkerUnwindFrameChainHandler
PROLOG_PUSH {r4,r5,r7,lr}
PROLOG_STACK_SAVE r7
mov r5,r0 ; save pCallDescrData in r5
ldr r1, [r5,#CallDescrData__numStackSlots]
cbz r1, Ldonestack
;; Add frame padding to ensure frame size is a multiple of 8 (a requirement of the OS ABI).
;; We push four registers (above) and numStackSlots arguments (below). If this comes to an odd number
;; of slots we must pad with another. This simplifies to "if the low bit of numStackSlots is set,
;; extend the stack another four bytes".
lsls r2, r1, #2
and r3, r2, #4
sub sp, sp, r3
;; This loop copies numStackSlots words
;; from [pSrcEnd-4,pSrcEnd-8,...] to [sp-4,sp-8,...]
ldr r0, [r5,#CallDescrData__pSrc]
add r0,r0,r2
Lstackloop
ldr r2, [r0,#-4]!
str r2, [sp,#-4]!
subs r1, r1, #1
bne Lstackloop
Ldonestack
;; If FP arguments are supplied in registers (r3 != NULL) then initialize all of them from the pointer
;; given in r3. Do not use "it" since it faults in floating point even when the instruction is not executed.
ldr r3, [r5,#CallDescrData__pFloatArgumentRegisters]
cbz r3, LNoFloatingPoint
vldm r3, {s0-s15}
LNoFloatingPoint
;; Copy [pArgumentRegisters, ..., pArgumentRegisters + 12]
;; into r0, ..., r3
ldr r4, [r5,#CallDescrData__pArgumentRegisters]
ldm r4, {r0-r3}
CHECK_STACK_ALIGNMENT
;; call pTarget
;; Note that remoting expect target in r4.
ldr r4, [r5,#CallDescrData__pTarget]
blx r4
ldr r3, [r5,#CallDescrData__fpReturnSize]
;; Save FP return value if appropriate
cbz r3, LFloatingPointReturnDone
;; Float return case
;; Do not use "it" since it faults in floating point even when the instruction is not executed.
cmp r3, #4
bne LNoFloatReturn
vmov r0, s0
b LFloatingPointReturnDone
LNoFloatReturn
;; Double return case
;; Do not use "it" since it faults in floating point even when the instruction is not executed.
cmp r3, #8
bne LNoDoubleReturn
vmov r0, r1, s0, s1
b LFloatingPointReturnDone
LNoDoubleReturn
add r2, r5, #CallDescrData__returnValue
cmp r3, #16
bne LNoFloatHFAReturn
vstm r2, {s0-s3}
b LReturnDone
LNoFloatHFAReturn
cmp r3, #32
bne LNoDoubleHFAReturn
vstm r2, {d0-d3}
b LReturnDone
LNoDoubleHFAReturn
EMIT_BREAKPOINT ; Unreachable
LFloatingPointReturnDone
;; Save return value into retbuf
str r0, [r5, #(CallDescrData__returnValue + 0)]
str r1, [r5, #(CallDescrData__returnValue + 4)]
LReturnDone
#ifdef _DEBUG
;; trash the floating point registers to ensure that the HFA return values
;; won't survive by accident
vldm sp, {d0-d3}
#endif
EPILOG_STACK_RESTORE r7
EPILOG_POP {r4,r5,r7,pc}
NESTED_END
;;-----------------------------------------------------------------------------
;; This helper routine is where returns for irregular tail calls end up
:: so they can dynamically pop their stack arguments.
;;-----------------------------------------------------------------------------
;
; Stack Layout (stack grows up, 0 at the top, offsets relative to frame pointer, r7):
;
; sp -> callee stack arguments
; :
; :
; -0Ch gsCookie
; TailCallHelperFrame ->
; -08h __VFN_table
; -04h m_Next
; r7 ->
; +00h m_calleeSavedRgisters.r4
; +04h .r5
; +08h .r6
; +0Ch .r7
; +10h .r8
; +14h .r9
; +18h .r10
; r11->
; +1Ch .r11
; +20h .r14 -or- m_ReturnAddress
;
; r6 -> GetThread()
; r5 -> r6->m_pFrame (old Frame chain head)
; r11 is used to preserve the ETW call stack
NESTED_ENTRY TailCallHelperStub
;
; This prolog is never executed, but we keep it here for reference
; and for the unwind data it generates
;
; Spill callee saved registers and return address.
PROLOG_PUSH {r4-r11,lr}
PROLOG_STACK_SAVE r7
;
; This is the code that would have to run to setup this frame
; like the C++ helper does before calling RtlRestoreContext
;
; Allocate space for the rest of the frame and GSCookie.
; PROLOG_STACK_ALLOC 0x0C
;
; Set r11 for frame chain
;add r11, r7, 0x1C
;
; Set the vtable for TailCallFrame
;bl TCF_GETMETHODFRAMEVPTR
;str r0, [r7, #-8]
;
; Initialize the GSCookie within the Frame
;ldr r0, =s_gsCookie
;str r0, [r7, #-0x0C]
;
; Link the TailCallFrameinto the Frame chain
; and initialize r5 & r6 for unlinking later
;CALL_GETTHREAD
;mov r6, r0
;ldr r5, [r6, #Thread__m_pFrame]
;str r5, [r7, #-4]
;sub r0, r7, 8
;str r0, [r6, #Thread__m_pFrame]
;
; None of the previous stuff is ever executed,
; but we keep it here for reference
;
;
; Here's the pretend call (make it real so the unwinder
; doesn't think we're in the prolog)
;
bl TailCallHelperStub
;
; with the real return address pointing to this real epilog
;
JIT_TailCallHelperStub_ReturnAddress
EXPORT JIT_TailCallHelperStub_ReturnAddress
;
; Our epilog (which also unlinks the StubHelperFrame)
; Be careful not to trash the return registers
;
#ifdef _DEBUG
ldr r3, =s_gsCookie
ldr r3, [r3]
ldr r2, [r7, #-0x0C]
cmp r2, r3
beq GoodGSCookie
bl DoJITFailFast
GoodGSCookie
#endif ; _DEBUG
;
; unlink the TailCallFrame
;
str r5, [r6, #Thread__m_pFrame]
;
; epilog
;
EPILOG_STACK_RESTORE r7
EPILOG_POP {r4-r11,lr}
EPILOG_RETURN
NESTED_END
; ------------------------------------------------------------------
; void LazyMachStateCaptureState(struct LazyMachState *pState);
LEAF_ENTRY LazyMachStateCaptureState
;; marks that this is not yet valid
mov r1, #0
str r1, [r0, #MachState__isValid]
str lr, [r0, #LazyMachState_captureIp]
str sp, [r0, #LazyMachState_captureSp]
add r1, r0, #LazyMachState_captureR4_R11
stm r1, {r4-r11}
mov pc, lr
LEAF_END
; void SinglecastDelegateInvokeStub(Delegate *pThis)
LEAF_ENTRY SinglecastDelegateInvokeStub
cmp r0, #0
beq LNullThis
ldr r12, [r0, #DelegateObject___methodPtr]
ldr r0, [r0, #DelegateObject___target]
bx r12
LNullThis
mov r0, #CORINFO_NullReferenceException_ASM
b JIT_InternalThrow
LEAF_END
;
; r12 = UMEntryThunk*
;
NESTED_ENTRY TheUMEntryPrestub,,UMEntryPrestubUnwindFrameChainHandler
PROLOG_PUSH {r0-r4,lr}
PROLOG_VPUSH {d0-d7}
CHECK_STACK_ALIGNMENT
mov r0, r12
bl TheUMEntryPrestubWorker
; Record real target address in r12.
mov r12, r0
; Epilog
EPILOG_VPOP {d0-d7}
EPILOG_POP {r0-r4,lr}
EPILOG_BRANCH_REG r12
NESTED_END
;
; r12 = UMEntryThunk*
;
NESTED_ENTRY UMThunkStub,,UMThunkStubUnwindFrameChainHandler
PROLOG_PUSH {r4,r5,r7,r11,lr}
PROLOG_PUSH {r0-r3,r12}
PROLOG_STACK_SAVE r7
GBLA UMThunkStub_HiddenArg ; offset of saved UMEntryThunk *
GBLA UMThunkStub_StackArgs ; offset of original stack args (total size of UMThunkStub frame)
UMThunkStub_HiddenArg SETA 4*4
UMThunkStub_StackArgs SETA 10*4
CHECK_STACK_ALIGNMENT
; r0 = GetThread(). Trashes r5
INLINE_GETTHREAD r0, r5
cbz r0, UMThunkStub_DoThreadSetup
UMThunkStub_HaveThread
mov r5, r0 ; r5 = Thread *
ldr r2, =g_TrapReturningThreads
mov r4, 1
str r4, [r5, #Thread__m_fPreemptiveGCDisabled]
ldr r3, [r2]
cbnz r3, UMThunkStub_DoTrapReturningThreads
UMThunkStub_InCooperativeMode
ldr r12, [r7, #UMThunkStub_HiddenArg]
ldr r3, [r12, #UMEntryThunk__m_pUMThunkMarshInfo]
ldr r2, [r3, #UMThunkMarshInfo__m_cbActualArgSize]
cbz r2, UMThunkStub_ArgumentsSetup
add r0, r7, #UMThunkStub_StackArgs ; Source pointer
add r0, r0, r2
lsr r1, r2, #2 ; Count of stack slots to copy
and r2, r2, #4 ; Align the stack
sub sp, sp, r2
UMThunkStub_StackLoop
ldr r2, [r0,#-4]!
str r2, [sp,#-4]!
subs r1, r1, #1
bne UMThunkStub_StackLoop
UMThunkStub_ArgumentsSetup
ldr r4, [r3, #UMThunkMarshInfo__m_pILStub]
; reload argument registers
ldm r7, {r0-r3}
CHECK_STACK_ALIGNMENT
blx r4
UMThunkStub_PostCall
mov r4, 0
str r4, [r5, #Thread__m_fPreemptiveGCDisabled]
EPILOG_STACK_RESTORE r7
EPILOG_STACK_FREE 4 * 5
EPILOG_POP {r4,r5,r7,r11,pc}
UMThunkStub_DoThreadSetup
sub sp, #SIZEOF__FloatArgumentRegisters
vstm sp, {d0-d7}
bl CreateThreadBlockThrow
vldm sp, {d0-d7}
add sp, #SIZEOF__FloatArgumentRegisters
b UMThunkStub_HaveThread
UMThunkStub_DoTrapReturningThreads
sub sp, #SIZEOF__FloatArgumentRegisters
vstm sp, {d0-d7}
mov r0, r5 ; Thread* pThread
ldr r1, [r7, #UMThunkStub_HiddenArg] ; UMEntryThunk* pUMEntry
bl UMThunkStubRareDisableWorker
vldm sp, {d0-d7}
add sp, #SIZEOF__FloatArgumentRegisters
b UMThunkStub_InCooperativeMode
NESTED_END
INLINE_GETTHREAD_CONSTANT_POOL
; ------------------------------------------------------------------
NESTED_ENTRY ThePreStub
PROLOG_WITH_TRANSITION_BLOCK
add r0, sp, #__PWTB_TransitionBlock ; pTransitionBlock
mov r1, r12 ; pMethodDesc
bl PreStubWorker
mov r12, r0
EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
EPILOG_BRANCH_REG r12
NESTED_END
; ------------------------------------------------------------------
NESTED_ENTRY ThePreStubCompactARM
; r12 - address of compact entry point + PC_REG_RELATIVE_OFFSET
PROLOG_WITH_TRANSITION_BLOCK
mov r0, r12
bl PreStubGetMethodDescForCompactEntryPoint
mov r12, r0 ; pMethodDesc
EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
b ThePreStub
NESTED_END
; ------------------------------------------------------------------
; This method does nothing. It's just a fixed function for the debugger to put a breakpoint on.
LEAF_ENTRY ThePreStubPatch
nop
ThePreStubPatchLabel
EXPORT ThePreStubPatchLabel
bx lr
LEAF_END
; ------------------------------------------------------------------
; The call in ndirect import precode points to this function.
NESTED_ENTRY NDirectImportThunk
PROLOG_PUSH {r0-r4,lr} ; Spill general argument registers, return address and
; arbitrary register to keep stack aligned
PROLOG_VPUSH {d0-d7} ; Spill floating point argument registers
CHECK_STACK_ALIGNMENT
mov r0, r12
bl NDirectImportWorker
mov r12, r0
EPILOG_VPOP {d0-d7}
EPILOG_POP {r0-r4,lr}
; If we got back from NDirectImportWorker, the MD has been successfully
; linked. Proceed to execute the original DLL call.
EPILOG_BRANCH_REG r12
NESTED_END
; ------------------------------------------------------------------
; The call in fixup precode initally points to this function.
; The pupose of this function is to load the MethodDesc and forward the call the prestub.
NESTED_ENTRY PrecodeFixupThunk
; r12 = FixupPrecode *
PROLOG_PUSH {r0-r1}
; Inline computation done by FixupPrecode::GetMethodDesc()
ldrb r0, [r12, #3] ; m_PrecodeChunkIndex
ldrb r1, [r12, #2] ; m_MethodDescChunkIndex
add r12,r12,r0,lsl #3
add r0,r12,r0,lsl #2
ldr r0, [r0,#8]
add r12,r0,r1,lsl #2
EPILOG_POP {r0-r1}
EPILOG_BRANCH ThePreStub
NESTED_END
; ------------------------------------------------------------------
; void ResolveWorkerAsmStub(r0, r1, r2, r3, r4:IndirectionCellAndFlags, r12:DispatchToken)
;
; The stub dispatch thunk which transfers control to VSD_ResolveWorker.
NESTED_ENTRY ResolveWorkerAsmStub
PROLOG_WITH_TRANSITION_BLOCK
add r0, sp, #__PWTB_TransitionBlock ; pTransitionBlock
mov r2, r12 ; token
; indirection cell in r4 - should be consistent with REG_ARM_STUB_SPECIAL
bic r1, r4, #3 ; indirection cell
and r3, r4, #3 ; flags
bl VSD_ResolveWorker
mov r12, r0
EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
EPILOG_BRANCH_REG r12
NESTED_END
; ------------------------------------------------------------------
; void ResolveWorkerChainLookupAsmStub(r0, r1, r2, r3, r4:IndirectionCellAndFlags, r12:DispatchToken)
NESTED_ENTRY ResolveWorkerChainLookupAsmStub
; ARMSTUB TODO: implement chained lookup
b ResolveWorkerAsmStub
NESTED_END
#if defined(FEATURE_COMINTEROP)
; ------------------------------------------------------------------
; setStubReturnValue
; r0 - size of floating point return value (MetaSig::GetFPReturnSize())
; r1 - pointer to the return buffer in the stub frame
LEAF_ENTRY setStubReturnValue
cbz r0, NoFloatingPointRetVal
;; Float return case
;; Do not use "it" since it faults in floating point even when the instruction is not executed.
cmp r0, #4
bne LNoFloatRetVal
vldr s0, [r1]
bx lr
LNoFloatRetVal
;; Double return case
;; Do not use "it" since it faults in floating point even when the instruction is not executed.
cmp r0, #8
bne LNoDoubleRetVal
vldr d0, [r1]
bx lr
LNoDoubleRetVal
cmp r0, #16
bne LNoFloatHFARetVal
vldm r1, {s0-s3}
bx lr
LNoFloatHFARetVal
cmp r0, #32
bne LNoDoubleHFARetVal
vldm r1, {d0-d3}
bx lr
LNoDoubleHFARetVal
EMIT_BREAKPOINT ; Unreachable
NoFloatingPointRetVal
;; Restore the return value from retbuf
ldr r0, [r1]
ldr r1, [r1, #4]
bx lr
LEAF_END
#endif // FEATURE_COMINTEROP
#if defined(FEATURE_COMINTEROP)
; ------------------------------------------------------------------
; Function used by remoting/COM interop to get floating point return value (since it's not in the same
; register(s) as non-floating point values).
;
; On entry;
; r0 : size of the FP result (4 or 8 bytes)
; r1 : pointer to 64-bit buffer to receive result
;
; On exit:
; buffer pointed to by r1 on entry contains the float or double argument as appropriate
;
LEAF_ENTRY getFPReturn
cmp r0, #4
bne LgetFP8
vmov r2, s0
str r2, [r1]
bx lr
LgetFP8
vmov r2, r3, d0
strd r2, r3, [r1]
bx lr
LEAF_END
; ------------------------------------------------------------------
; Function used by remoting/COM interop to set floating point return value (since it's not in the same
; register(s) as non-floating point values).
;
; On entry:
; r0 : size of the FP result (4 or 8 bytes)
; r2/r3 : 32-bit or 64-bit FP result
;
; On exit:
; s0 : float result if r0 == 4
; d0 : double result if r0 == 8
;
LEAF_ENTRY setFPReturn
cmp r0, #4
bne LsetFP8
vmov s0, r2
bx lr
LsetFP8
vmov d0, r2, r3
bx lr
LEAF_END
#endif defined(FEATURE_COMINTEROP)
#ifdef FEATURE_COMINTEROP
; ------------------------------------------------------------------
; GenericComPlusCallStub that erects a ComPlusMethodFrame and calls into the runtime
; (CLRToCOMWorker) to dispatch rare cases of the interface call.
;
; On entry:
; r0 : 'this' object
; r12 : Interface MethodDesc*
; plus user arguments in registers and on the stack
;
; On exit:
; r0/r1/s0/d0 set to return value of the call as appropriate
;
NESTED_ENTRY GenericComPlusCallStub
PROLOG_WITH_TRANSITION_BLOCK 0x20
add r0, sp, #__PWTB_TransitionBlock ; pTransitionBlock
mov r1, r12 ; pMethodDesc
; Call CLRToCOMWorker(pFrame). This call will set up the rest of the frame (including the vfptr,
; the GS cookie and linking to the thread), make the client call and return with correct registers set
; (r0/r1/s0-s3/d0-d3 as appropriate).
bl CLRToCOMWorker
; r0 = fpRetSize
; return value is stored before float argument registers
add r1, sp, #(__PWTB_FloatArgumentRegisters - 0x20)
bl setStubReturnValue
EPILOG_WITH_TRANSITION_BLOCK_RETURN
NESTED_END
; ------------------------------------------------------------------
; COM to CLR stub called the first time a particular method is invoked.
;
; On entry:
; r12 : (MethodDesc* - ComCallMethodDesc_Offset_FromR12) provided by prepad thunk
; plus user arguments in registers and on the stack
;
; On exit:
; tail calls to real method
;
NESTED_ENTRY ComCallPreStub
GBLA ComCallPreStub_FrameSize
GBLA ComCallPreStub_FramePad
GBLA ComCallPreStub_StackAlloc
GBLA ComCallPreStub_Frame
GBLA ComCallPreStub_ErrorReturn
; Set the defaults
ComCallPreStub_FramePad SETA 8 ; error return
ComCallPreStub_FrameSize SETA (ComCallPreStub_FramePad + SIZEOF__GSCookie + SIZEOF__ComMethodFrame)
IF ComCallPreStub_FrameSize:MOD:8 != 0
ComCallPreStub_FramePad SETA ComCallPreStub_FramePad + 4
ComCallPreStub_FrameSize SETA ComCallPreStub_FrameSize + 4
ENDIF
ComCallPreStub_StackAlloc SETA ComCallPreStub_FrameSize - SIZEOF__ArgumentRegisters - 2 * 4
ComCallPreStub_Frame SETA SIZEOF__FloatArgumentRegisters + ComCallPreStub_FramePad + SIZEOF__GSCookie
ComCallPreStub_ErrorReturn SETA SIZEOF__FloatArgumentRegisters
PROLOG_PUSH {r0-r3} ; Spill general argument registers
PROLOG_PUSH {r11,lr} ; Save return address
PROLOG_STACK_ALLOC ComCallPreStub_StackAlloc ; Alloc non-spill portion of stack frame
PROLOG_VPUSH {d0-d7} ; Spill floating point argument registers
CHECK_STACK_ALIGNMENT
; Finish initializing the frame. The C++ helper will fill in the GS cookie and vfptr and link us to
; the Thread frame chain (see ComPrestubMethodFrame::Push). That leaves us with m_pFuncDesc.
; The prepad thunk passes us a value which is the MethodDesc* - ComCallMethodDesc_Offset_FromR12 (due to encoding limitations in the
; thunk). So we must correct this by adding 4 before storing the pointer.
add r12, #(ComCallMethodDesc_Offset_FromR12)
str r12, [sp, #(ComCallPreStub_Frame + UnmanagedToManagedFrame__m_pvDatum)]
; Call the C++ worker: ComPreStubWorker(&Frame)
add r0, sp, #(ComCallPreStub_Frame)
add r1, sp, #(ComCallPreStub_ErrorReturn)
bl ComPreStubWorker
; Handle failure case.
cbz r0, ErrorExit
; Stash real target address where it won't be overwritten by restoring the calling state.
mov r12, r0
EPILOG_VPOP {d0-d7} ; Restore floating point argument registers
EPILOG_STACK_FREE ComCallPreStub_StackAlloc
EPILOG_POP {r11,lr}
EPILOG_POP {r0-r3} ; Restore argument registers
; Tail call the real target. Actually ComPreStubWorker returns the address of the prepad thunk on ARM,
; that way we don't run out of volatile registers trying to remember both the new target address and
; the hidden MethodDesc* argument. ComPreStubWorker patched the prepad though so the second time
; through we won't end up here again.
EPILOG_BRANCH_REG r12
ErrorExit
; Failed to find a stub to call. Retrieve the return value ComPreStubWorker set for us.
ldr r0, [sp, #(ComCallPreStub_ErrorReturn)]
ldr r1, [sp, #(ComCallPreStub_ErrorReturn+4)]
EPILOG_STACK_FREE ComCallPreStub_StackAlloc + SIZEOF__FloatArgumentRegisters
EPILOG_POP {r11,lr}
EPILOG_STACK_FREE SIZEOF__ArgumentRegisters
EPILOG_RETURN
NESTED_END
; ------------------------------------------------------------------
; COM to CLR stub which sets up a ComMethodFrame and calls COMToCLRWorker.
;
; On entry:
; r12 : (MethodDesc* - ComCallMethodDesc_Offset_FromR12) provided by prepad thunk
; plus user arguments in registers and on the stack
;
; On exit:
; Result in r0/r1/s0/d0 as per the real method being called
;
NESTED_ENTRY GenericComCallStub,,ReverseComUnwindFrameChainHandler
; Calculate space needed on stack for alignment padding, a GS cookie and a ComMethodFrame (minus the last
; field, m_ReturnAddress, which we'll push explicitly).
GBLA GenericComCallStub_FrameSize
GBLA GenericComCallStub_FramePad
GBLA GenericComCallStub_StackAlloc
GBLA GenericComCallStub_Frame
; Set the defaults
GenericComCallStub_FramePad SETA 0
GenericComCallStub_FrameSize SETA (GenericComCallStub_FramePad + SIZEOF__GSCookie + SIZEOF__ComMethodFrame)
IF GenericComCallStub_FrameSize:MOD:8 != 0
GenericComCallStub_FramePad SETA 4
GenericComCallStub_FrameSize SETA GenericComCallStub_FrameSize + GenericComCallStub_FramePad
ENDIF
GenericComCallStub_StackAlloc SETA GenericComCallStub_FrameSize - SIZEOF__ArgumentRegisters - 2 * 4
GenericComCallStub_Frame SETA SIZEOF__FloatArgumentRegisters + GenericComCallStub_FramePad + SIZEOF__GSCookie
PROLOG_PUSH {r0-r3} ; Spill general argument registers
PROLOG_PUSH {r11,lr} ; Save return address
PROLOG_STACK_ALLOC GenericComCallStub_StackAlloc ; Alloc non-spill portion of stack frame
PROLOG_VPUSH {d0-d7} ; Spill floating point argument registers
CHECK_STACK_ALIGNMENT
; Store MethodDesc* in frame. Due to a limitation of the prepad, r12 actually contains a value
; "ComCallMethodDesc_Offset_FromR12" less than the pointer we want, so fix that up.
add r12, r12, #(ComCallMethodDesc_Offset_FromR12)
str r12, [sp, #(GenericComCallStub_Frame + UnmanagedToManagedFrame__m_pvDatum)]
; Call COMToCLRWorker(pThread, pFrame). Note that pThread is computed inside the method so we don't
; need to set it up here.
;
; Setup R1 to point to the start of the explicit frame. We account for alignment padding and
; space for GSCookie.
add r1, sp, #(GenericComCallStub_Frame)
bl COMToCLRWorker
EPILOG_STACK_FREE GenericComCallStub_StackAlloc + SIZEOF__FloatArgumentRegisters
EPILOG_POP {r11,lr}
EPILOG_STACK_FREE SIZEOF__ArgumentRegisters
EPILOG_RETURN
NESTED_END
; ------------------------------------------------------------------
; COM to CLR stub called from COMToCLRWorker that actually dispatches to the real managed method.
;
; On entry:
; r0 : dwStackSlots, count of argument stack slots to copy
; r1 : pFrame, ComMethodFrame pushed by GenericComCallStub above
; r2 : pTarget, address of code to call
; r3 : pSecretArg, hidden argument passed to target above in r12
; [sp, #0] : pDangerousThis, managed 'this' reference
;
; On exit:
; Result in r0/r1/s0/d0 as per the real method being called
;
NESTED_ENTRY COMToCLRDispatchHelper,,CallDescrWorkerUnwindFrameChainHandler
PROLOG_PUSH {r4-r5,r7,lr}
PROLOG_STACK_SAVE r7
; Copy stack-based arguments. Make sure the eventual SP ends up 8-byte aligned. Note that the
; following calculations assume that the prolog has left the stack already aligned.
CHECK_STACK_ALIGNMENT
cbz r0, COMToCLRDispatchHelper_ArgumentsSetup
lsl r4, r0, #2 ; r4 = (dwStackSlots * 4)
and r5, r4, #4 ; Align the stack
sub sp, sp, r5
add r5, r1, #SIZEOF__ComMethodFrame
add r5, r5, r4
COMToCLRDispatchHelper_StackLoop
ldr r4, [r5,#-4]!
str r4, [sp,#-4]!
subs r0, r0, #1
bne COMToCLRDispatchHelper_StackLoop
CHECK_STACK_ALIGNMENT
COMToCLRDispatchHelper_ArgumentsSetup
; Load floating point argument registers.
sub r4, r1, #(GenericComCallStub_Frame)
vldm r4, {d0-d7}
; Prepare the call target and hidden argument prior to overwriting r0-r3.
mov r12, r3 ; r12 = hidden argument
mov lr, r2 ; lr = target code
; Load general argument registers except r0.
add r4, r1, #(SIZEOF__ComMethodFrame - SIZEOF__ArgumentRegisters + 4)
ldm r4, {r1-r3}
; Load r0 from the managed this, not the original incoming IUnknown*.
ldr r0, [r7, #(4 * 4)]
; Make the call.
blx lr
EPILOG_STACK_RESTORE r7
EPILOG_POP {r4-r5,r7,pc}
NESTED_END
#endif // FEATURE_COMINTEROP
#ifdef PROFILING_SUPPORTED
PROFILE_ENTER equ 1
PROFILE_LEAVE equ 2
PROFILE_TAILCALL equ 4
; Define the layout of the PROFILE_PLATFORM_SPECIFIC_DATA we push on the stack for all profiler
; helpers.
map 0
field 4 ; r0
field 4 ; r1
field 4 ; r11
field 4 ; Pc (caller's PC, i.e. LR)
field SIZEOF__FloatArgumentRegisters ; spilled floating point argument registers
functionId field 4
probeSp field 4
profiledSp field 4
hiddenArg field 4
flags field 4
SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA field 0
; ------------------------------------------------------------------
; Macro used to generate profiler helpers. In all cases we push a partially initialized
; PROFILE_PLATFORM_SPECIFIC_DATA structure on the stack and call into a C++ helper to continue processing.
;
; On entry:
; r0 : clientInfo
; r1/r2 : return values (in case of leave)
; frame pointer(r11) must be set (in case of enter)
; all arguments are on stack at frame pointer (r11) + 8bytes (save lr & prev r11).
;
; On exit:
; All register values are preserved including volatile registers
;
MACRO
DefineProfilerHelper $HelperName, $Flags
GBLS __ProfilerHelperFunc
__ProfilerHelperFunc SETS "$HelperName":CC:"Naked"
NESTED_ENTRY $__ProfilerHelperFunc
IMPORT $HelperName ; The C++ helper which does most of the work
PROLOG_PUSH {r0,r3,r9,r12} ; save volatile general purpose registers. remaining r1 & r2 are saved below...saving r9 as it is required for virtualunwinding
PROLOG_STACK_ALLOC (6*4) ; Reserve space for tail end of structure (5*4 bytes) and extra 4 bytes is for aligning the stack at 8-byte boundary
PROLOG_VPUSH {d0-d7} ; Spill floting point argument registers
PROLOG_PUSH {r1,r11,lr} ; Save possible return value in r1, frame pointer and return address
PROLOG_PUSH {r2} ; Save possible return value in r0. Before calling Leave Hook Jit moves contents of r0 to r2
; so pushing r2 instead of r0. This push statement cannot be combined with the above push
; as r2 gets pushed before r1.
CHECK_STACK_ALIGNMENT
; Zero r1 for use clearing fields in the PROFILE_PLATFORM_SPECIFIC_DATA.
eor r1, r1
; Clear functionId.
str r1, [sp, #functionId]
; Save caller's SP (at the point this helper was called).
add r2, sp, #(SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA + 20)
str r2, [sp, #probeSp]
; Save caller's SP (at the point where only argument registers have been spilled).
ldr r2, [r11]
add r2, r2, #8 ; location of arguments is at frame pointer(r11) + 8 (lr & prev frame ptr is saved before changing
str r2, [sp, #profiledSp]