This repository has been 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.7k
/
Copy pathasmhelpers.S
1487 lines (1166 loc) · 49.1 KB
/
asmhelpers.S
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 "unixasmmacros.inc"
#include "asmconstants.h"
.syntax unified
.thumb
// LPVOID __stdcall GetCurrentIP(void)//
LEAF_ENTRY GetCurrentIP, _TEXT
mov r0, lr
bx lr
LEAF_END GetCurrentIP, _TEXT
// LPVOID __stdcall GetCurrentSP(void)//
LEAF_ENTRY GetCurrentSP, _TEXT
mov r0, sp
bx lr
LEAF_END GetCurrentSP, _TEXT
//-----------------------------------------------------------------------------
// This helper routine enregisters the appropriate arguments and makes the
// actual call.
//-----------------------------------------------------------------------------
//void CallDescrWorkerInternal(CallDescrData * pCallDescrData)//
NESTED_ENTRY CallDescrWorkerInternal,_TEXT,NoHandler
PROLOG_PUSH "{r4,r5,r7,lr}"
PROLOG_STACK_SAVE_OFFSET r7, #8
mov r5,r0 // save pCallDescrData in r5
ldr r1, [r5,#CallDescrData__numStackSlots]
cbz r1, LOCAL_LABEL(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
LOCAL_LABEL(Lstackloop):
ldr r2, [r0,#-4]!
str r2, [sp,#-4]!
subs r1, r1, #1
bne LOCAL_LABEL(Lstackloop)
LOCAL_LABEL(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, LOCAL_LABEL(LNoFloatingPoint)
vldm r3, {s0-s15}
LOCAL_LABEL(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, LOCAL_LABEL(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 LOCAL_LABEL(LNoFloatReturn)
vmov r0, s0
b LOCAL_LABEL(LFloatingPointReturnDone)
LOCAL_LABEL(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 LOCAL_LABEL(LNoDoubleReturn)
vmov r0, r1, s0, s1
b LOCAL_LABEL(LFloatingPointReturnDone)
LOCAL_LABEL(LNoDoubleReturn):
add r2, r5, #CallDescrData__returnValue
cmp r3, #16
bne LOCAL_LABEL(LNoFloatHFAReturn)
vstm r2, {s0-s3}
b LOCAL_LABEL(LReturnDone)
LOCAL_LABEL(LNoFloatHFAReturn):
cmp r3, #32
bne LOCAL_LABEL(LNoDoubleHFAReturn)
vstm r2, {d0-d3}
b LOCAL_LABEL(LReturnDone)
LOCAL_LABEL(LNoDoubleHFAReturn):
EMIT_BREAKPOINT // Unreachable
LOCAL_LABEL(LFloatingPointReturnDone):
// Save return value into retbuf
str r0, [r5, #(CallDescrData__returnValue + 0)]
str r1, [r5, #(CallDescrData__returnValue + 4)]
LOCAL_LABEL(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_OFFSET r7, #8
EPILOG_POP "{r4,r5,r7,pc}"
NESTED_END CallDescrWorkerInternal,_TEXT
//-----------------------------------------------------------------------------
// 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, _TEXT, NoHandler
//
// 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_OFFSET r7, #12
//
// 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 C_FUNC(TailCallHelperStub)
//
// with the real return address pointing to this real epilog
//
C_FUNC(JIT_TailCallHelperStub_ReturnAddress):
.global C_FUNC(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 LOCAL_LABEL(GoodGSCookie)
bl C_FUNC(DoJITFailFast)
LOCAL_LABEL(GoodGSCookie):
#endif // _DEBUG
//
// unlink the TailCallFrame
//
str r5, [r6, #Thread__m_pFrame]
//
// epilog
//
EPILOG_STACK_RESTORE_OFFSET r7, #12
EPILOG_POP "{r4-r11,lr}"
bx lr
NESTED_END TailCallHelperStub, _TEXT
// ------------------------------------------------------------------
// void LazyMachStateCaptureState(struct LazyMachState *pState)//
LEAF_ENTRY LazyMachStateCaptureState, _TEXT
// 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 LazyMachStateCaptureState, _TEXT
// void SinglecastDelegateInvokeStub(Delegate *pThis)
LEAF_ENTRY SinglecastDelegateInvokeStub, _TEXT
cmp r0, #0
beq LOCAL_LABEL(LNullThis)
ldr r12, [r0, #DelegateObject___methodPtr]
ldr r0, [r0, #DelegateObject___target]
bx r12
LOCAL_LABEL(LNullThis):
mov r0, #CORINFO_NullReferenceException_ASM
b C_FUNC(JIT_InternalThrow)
LEAF_END SinglecastDelegateInvokeStub, _TEXT
//
// r12 = UMEntryThunk*
//
NESTED_ENTRY TheUMEntryPrestub,_TEXT,NoHandler
PROLOG_PUSH "{r0-r4,r7,r8,lr}" // add r8 to make stack aligned by 8B
PROLOG_STACK_SAVE_OFFSET r7, #20
PROLOG_VPUSH {d0-d7}
CHECK_STACK_ALIGNMENT
mov r0, r12
bl C_FUNC(TheUMEntryPrestubWorker)
// Record real target address in r12.
mov r12, r0
// Epilog
EPILOG_VPOP {d0-d7}
EPILOG_POP "{r0-r4,r7,r8,lr}"
bx r12
NESTED_END TheUMEntryPrestub,_TEXT
//
// r12 = UMEntryThunk*
//
NESTED_ENTRY UMThunkStub,_TEXT,UnhandledExceptionHandlerUnix
PROLOG_PUSH "{r4,r5,r7,r11,lr}"
PROLOG_STACK_SAVE_OFFSET r7, #8
alloc_stack 4 * 5
stm sp, {r0-r3,r12}
//GBLA UMThunkStub_HiddenArgOffest // offset of saved UMEntryThunk *
//GBLA UMThunkStub_StackArgsOffest // offset of original stack args
//GBLA UMThunkStub_StackArgsSize // total size of UMThunkStub frame
UMThunkStub_HiddenArgOffset = (-3)*4
UMThunkStub_StackArgsOffset = 3*4
UMThunkStub_StackArgsSize = 10*4
CHECK_STACK_ALIGNMENT
bl C_FUNC(GetThread)
cbz r0, LOCAL_LABEL(UMThunkStub_DoThreadSetup)
LOCAL_LABEL(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, LOCAL_LABEL(UMThunkStub_DoTrapReturningThreads)
LOCAL_LABEL(UMThunkStub_InCooperativeMode):
ldr r12, [r7, #UMThunkStub_HiddenArgOffset]
ldr r3, [r12, #UMEntryThunk__m_pUMThunkMarshInfo]
ldr r2, [r3, #UMThunkMarshInfo__m_cbActualArgSize]
cbz r2, LOCAL_LABEL(UMThunkStub_ArgumentsSetup)
add r0, r7, #UMThunkStub_StackArgsOffset // 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
LOCAL_LABEL(UMThunkStub_StackLoop):
ldr r2, [r0,#-4]!
str r2, [sp,#-4]!
subs r1, r1, #1
bne LOCAL_LABEL(UMThunkStub_StackLoop)
LOCAL_LABEL(UMThunkStub_ArgumentsSetup):
ldr r4, [r3, #UMThunkMarshInfo__m_pILStub]
// reload argument registers
sub r0, r7, #28
ldm r0, {r0-r3}
CHECK_STACK_ALIGNMENT
blx r4
LOCAL_LABEL(UMThunkStub_PostCall):
mov r4, 0
str r4, [r5, #Thread__m_fPreemptiveGCDisabled]
EPILOG_STACK_RESTORE_OFFSET r7, #8
EPILOG_POP "{r4,r5,r7,r11,pc}"
LOCAL_LABEL(UMThunkStub_DoThreadSetup):
sub sp, #SIZEOF__FloatArgumentRegisters
vstm sp, {d0-d7}
bl C_FUNC(CreateThreadBlockThrow)
vldm sp, {d0-d7}
add sp, #SIZEOF__FloatArgumentRegisters
b LOCAL_LABEL(UMThunkStub_HaveThread)
LOCAL_LABEL(UMThunkStub_DoTrapReturningThreads):
sub sp, #SIZEOF__FloatArgumentRegisters
vstm sp, {d0-d7}
mov r0, r5 // Thread* pThread
ldr r1, [r7, #UMThunkStub_HiddenArgOffset] // UMEntryThunk* pUMEntry
bl C_FUNC(UMThunkStubRareDisableWorker)
vldm sp, {d0-d7}
add sp, #SIZEOF__FloatArgumentRegisters
b LOCAL_LABEL(UMThunkStub_InCooperativeMode)
NESTED_END UMThunkStub,_TEXT
// ------------------------------------------------------------------
NESTED_ENTRY ThePreStub, _TEXT, NoHandler
PROLOG_WITH_TRANSITION_BLOCK
add r0, sp, #__PWTB_TransitionBlock // pTransitionBlock
mov r1, r12 // pMethodDesc
bl C_FUNC(PreStubWorker)
mov r12, r0
EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
bx r12
NESTED_END ThePreStub, _TEXT
// ------------------------------------------------------------------
NESTED_ENTRY ThePreStubCompactARM, _TEXT, NoHandler
// r12 - address of compact entry point + PC_REG_RELATIVE_OFFSET
PROLOG_WITH_TRANSITION_BLOCK
mov r0, r12
bl C_FUNC(PreStubGetMethodDescForCompactEntryPoint)
mov r12, r0 // pMethodDesc
EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
b C_FUNC(ThePreStub)
NESTED_END ThePreStubCompactARM, _TEXT
// ------------------------------------------------------------------
// This method does nothing. It's just a fixed function for the debugger to put a breakpoint on.
LEAF_ENTRY ThePreStubPatch, _TEXT
nop
ThePreStubPatchLabel:
.global ThePreStubPatchLabel
bx lr
LEAF_END ThePreStubPatch, _TEXT
// ------------------------------------------------------------------
// The call in ndirect import precode points to this function.
NESTED_ENTRY NDirectImportThunk, _TEXT, NoHandler
PROLOG_PUSH "{r0-r4,r7,r8,lr}" // Spill general argument registers, return address and
PROLOG_STACK_SAVE_OFFSET r7, #20
// arbitrary register to keep stack aligned
PROLOG_VPUSH {d0-d7} // Spill floating point argument registers
CHECK_STACK_ALIGNMENT
mov r0, r12
bl C_FUNC(NDirectImportWorker)
mov r12, r0
EPILOG_VPOP {d0-d7}
EPILOG_POP "{r0-r4,r7,r8,lr}"
// If we got back from NDirectImportWorker, the MD has been successfully
// linked. Proceed to execute the original DLL call.
bx r12
NESTED_END NDirectImportThunk, _TEXT
// ------------------------------------------------------------------
// 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, _TEXT, NoHandler
// 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}"
b C_FUNC(ThePreStub)
NESTED_END PrecodeFixupThunk, _TEXT
// ------------------------------------------------------------------
// void ResolveWorkerAsmStub(r0, r1, r2, r3, r4:IndirectionCellAndFlags, r12:DispatchToken)
//
// The stub dispatch thunk which transfers control to VSD_ResolveWorker.
NESTED_ENTRY ResolveWorkerAsmStub, _TEXT, NoHandler
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 C_FUNC(VSD_ResolveWorker)
mov r12, r0
EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
bx r12
NESTED_END ResolveWorkerAsmStub, _TEXT
// ------------------------------------------------------------------
// void ResolveWorkerChainLookupAsmStub(r0, r1, r2, r3, r4:IndirectionCellAndFlags, r12:DispatchToken)
NESTED_ENTRY ResolveWorkerChainLookupAsmStub, _TEXT, NoHandler
// ARMSTUB TODO: implement chained lookup
b C_FUNC(ResolveWorkerAsmStub)
NESTED_END ResolveWorkerChainLookupAsmStub, _TEXT
//
// If a preserved register were pushed onto the stack between
// the managed caller and the H_M_F, _R4_R11 will point to its
// location on the stack and it would have been updated on the
// stack by the GC already and it will be popped back into the
// appropriate register when the appropriate epilog is run.
//
// Otherwise, the register is preserved across all the code
// in this HCALL or FCALL, so we need to update those registers
// here because the GC will have updated our copies in the
// frame.
//
// So, if _R4_R11 points into the MachState, we need to update
// the register here. That's what this macro does.
//
.macro RestoreRegMS regIndex, reg
// Incoming:
//
// R0 = address of MachState
//
// $regIndex: Index of the register (R4-R11). For R4, index is 4.
// For R5, index is 5, and so on.
//
// $reg: Register name (e.g. R4, R5, etc)
//
// Get the address of the specified captured register from machine state
add r2, r0, #(MachState__captureR4_R11 + ((\regIndex-4)*4))
// Get the address of the specified preserved register from machine state
ldr r3, [r0, #(MachState___R4_R11 + ((\regIndex-4)*4))]
cmp r2, r3
bne 0f
ldr \reg, [r2]
0:
.endm
#ifdef PROFILING_SUPPORTED
//
// EXTERN_C void JIT_ProfilerEnterLeaveTailcallStub(UINT_PTR ProfilerHandle)
//
LEAF_ENTRY JIT_ProfilerEnterLeaveTailcallStub, _TEXT
bx lr
LEAF_END JIT_ProfilerEnterLeaveTailcallStub, _TEXT
//
// EXTERN_C void ProfileEnterNaked(FunctionIDOrClientID functionIDOrClientID);
//
NESTED_ENTRY ProfileEnterNaked, _TEXT, NoHandler
PROLOG_PUSH "{r4, r5, r7, r11, lr}"
PROLOG_STACK_SAVE_OFFSET r7, #8
// fields of PROFILE_PLATFORM_SPECIFIC_DATA, in reverse order
// UINT32 r0; // Keep r0 & r1 contiguous to make returning 64-bit results easier
// UINT32 r1;
// void *r11;
// void *Pc;
// union // Float arg registers as 32-bit (s0-s15) and 64-bit (d0-d7)
// {
// UINT32 s[16];
// UINT64 d[8];
// };
// FunctionID functionId;
// void *probeSp; // stack pointer of managed function
// void *profiledSp; // location of arguments on stack
// LPVOID hiddenArg;
// UINT32 flags;
movw r4, #1
push { /* flags */ r4 }
movw r4, #0
push { /* hiddenArg */ r4 }
add r5, r11, #8
push { /* profiledSp */ r5 }
add r5, sp, #32
push { /* probeSp */ r5 }
push { /* functionId */ r0 }
vpush.64 { d0 - d7 }
push { lr }
push { r11 }
push { /* return value, r4 is NULL */ r4 }
push { /* return value, r4 is NULL */ r4 }
mov r1, sp
bl C_FUNC(ProfileEnter)
EPILOG_STACK_RESTORE_OFFSET r7, #8
EPILOG_POP "{r4, r5, r7, r11, pc}"
NESTED_END ProfileEnterNaked, _TEXT
//
// EXTERN_C void ProfileLeaveNaked(FunctionIDOrClientID functionIDOrClientID);
//
NESTED_ENTRY ProfileLeaveNaked, _TEXT, NoHandler
PROLOG_PUSH "{r1, r2, r4, r5, r7, r11, lr}"
PROLOG_STACK_SAVE_OFFSET r7, #16
// fields of PROFILE_PLATFORM_SPECIFIC_DATA, in reverse order
// UINT32 r0; // Keep r0 & r1 contiguous to make returning 64-bit results easier
// UINT32 r1;
// void *r11;
// void *Pc;
// union // Float arg registers as 32-bit (s0-s15) and 64-bit (d0-d7)
// {
// UINT32 s[16];
// UINT64 d[8];
// };
// FunctionID functionId;
// void *probeSp; // stack pointer of managed function
// void *profiledSp; // location of arguments on stack
// LPVOID hiddenArg;
// UINT32 flags;
movw r4, #2
push { /* flags */ r4 }
movw r4, #0
push { /* hiddenArg */ r4 }
add r5, r11, #8
push { /* profiledSp */ r5 }
add r5, sp, #40
push { /* probeSp */ r5 }
push { /* functionId */ r0 }
vpush.64 { d0 - d7 }
push { lr }
push { r11 }
push { r1 }
push { r0 }
mov r1, sp
bl C_FUNC(ProfileLeave)
EPILOG_STACK_RESTORE_OFFSET r7, #16
EPILOG_POP "{r1, r2, r4, r5, r7, r11, pc}"
NESTED_END ProfileLeaveNaked, _TEXT
//
// EXTERN_C void ProfileTailcallNaked(FunctionIDOrClientID functionIDOrClientID);
//
NESTED_ENTRY ProfileTailcallNaked, _TEXT, NoHandler
PROLOG_PUSH "{r1, r2, r4, r5, r7, r11, lr}"
PROLOG_STACK_SAVE_OFFSET r7, #16
// fields of PROFILE_PLATFORM_SPECIFIC_DATA, in reverse order
// UINT32 r0; // Keep r0 & r1 contiguous to make returning 64-bit results easier
// UINT32 r1;
// void *r11;
// void *Pc;
// union // Float arg registers as 32-bit (s0-s15) and 64-bit (d0-d7)
// {
// UINT32 s[16];
// UINT64 d[8];
// };
// FunctionID functionId;
// void *probeSp; // stack pointer of managed function
// void *profiledSp; // location of arguments on stack
// LPVOID hiddenArg;
// UINT32 flags;
movw r4, #2
push { /* flags */ r4 }
movw r4, #0
push { /* hiddenArg */ r4 }
add r5, r11, #8
push { /* profiledSp */ r5 }
add r5, sp, #40
push { /* probeSp */ r5 }
push { /* functionId */ r0 }
vpush.64 { d0 - d7 }
push { lr }
push { r11 }
push { r1 }
push { r0 }
mov r1, sp
bl C_FUNC(ProfileTailcall)
EPILOG_STACK_RESTORE_OFFSET r7, #16
EPILOG_POP "{r1, r2, r4, r5, r7, r11, pc}"
NESTED_END ProfileTailcallNaked, _TEXT
#endif
// EXTERN_C int __fastcall HelperMethodFrameRestoreState(
// INDEBUG_COMMA(HelperMethodFrame *pFrame)
// MachState *pState
// )
LEAF_ENTRY HelperMethodFrameRestoreState, _TEXT
#ifdef _DEBUG
mov r0, r1
#endif
// If machine state is invalid, then simply exit
ldr r1, [r0, #MachState__isValid]
cmp r1, #0
beq LOCAL_LABEL(Done)
RestoreRegMS 4, R4
RestoreRegMS 5, R5
RestoreRegMS 6, R6
RestoreRegMS 7, R7
RestoreRegMS 8, R8
RestoreRegMS 9, R9
RestoreRegMS 10, R10
RestoreRegMS 11, R11
LOCAL_LABEL(Done):
// Its imperative that the return value of HelperMethodFrameRestoreState is zero
// as it is used in the state machine to loop until it becomes zero.
// Refer to HELPER_METHOD_FRAME_END macro for details.
mov r0,#0
bx lr
LEAF_END HelperMethodFrameRestoreState, _TEXT
#if 0
// ------------------------------------------------------------------
// Macro to generate Redirection Stubs
//
// $reason : reason for redirection
// Eg. GCThreadControl
// NOTE: If you edit this macro, make sure you update GetCONTEXTFromRedirectedStubStackFrame.
// This function is used by both the personality routine and the debugger to retrieve the original CONTEXT.
.macro GenerateRedirectedHandledJITCaseStub reason
NESTED_ENTRY RedirectedHandledJITCaseFor\reason\()_Stub, _TEXT, NoHandler
PROLOG_PUSH "{r7,lr}" // return address
PROLOG_STACK_SAVE r7
alloc_stack 4 // stack slot to save the CONTEXT *
//REDIRECTSTUB_SP_OFFSET_CONTEXT is defined in asmconstants.h
//If CONTEXT is not saved at 0 offset from SP it must be changed as well.
//ASSERT REDIRECTSTUB_SP_OFFSET_CONTEXT == 0
// Runtime check for 8-byte alignment. This check is necessary as this function can be
// entered before complete execution of the prolog of another function.
and r0, r7, #4
sub sp, sp, r0
// stack must be 8 byte aligned
CHECK_STACK_ALIGNMENT
//
// Save a copy of the redirect CONTEXT*.
// This is needed for the debugger to unwind the stack.
//
bl GetCurrentSavedRedirectContext
str r0, [r7]
//
// Fetch the interrupted pc and save it as our return address.
//
ldr r1, [r0, #CONTEXT_Pc]
str r1, [r7, #8]
//
// Call target, which will do whatever we needed to do in the context
// of the target thread, and will RtlRestoreContext when it is done.
//
bl _RedirectedHandledJITCaseFor\reason\()_Stub@Thread@@CAXXZ
EMIT_BREAKPOINT // Unreachable
// Put a label here to tell the debugger where the end of this function is.
RedirectedHandledJITCaseFor\reason\()_StubEnd:
.global RedirectedHandledJITCaseFor\reason\()_StubEnd
NESTED_END RedirectedHandledJITCaseFor\reason\()_Stub, _TEXT
.endm
// ------------------------------------------------------------------
// Redirection Stub for GC in fully interruptible method
GenerateRedirectedHandledJITCaseStub GCThreadControl
// ------------------------------------------------------------------
GenerateRedirectedHandledJITCaseStub DbgThreadControl
// ------------------------------------------------------------------
GenerateRedirectedHandledJITCaseStub UserSuspend
#ifdef _DEBUG
// ------------------------------------------------------------------
// Redirection Stub for GC Stress
GenerateRedirectedHandledJITCaseStub GCStress
#endif
#endif
// ------------------------------------------------------------------
// Functions to probe for stack space
// Input reg r4 = amount of stack to probe for
// value of reg r4 is preserved on exit from function
// r12 is trashed
// The below two functions were copied from vctools\crt\crtw32\startup\arm\chkstk.asm
NESTED_ENTRY checkStack, _TEXT, NoHandler
subs r12,sp,r4
mrc p15,#0,r4,c13,c0,#2 // get TEB *
ldr r4,[r4,#8] // get Stack limit
bcc LOCAL_LABEL(checkStack_neg) // if r12 is less then 0 set it to 0
LOCAL_LABEL(checkStack_label1):
cmp r12, r4
bcc C_FUNC(stackProbe) // must probe to extend guardpage if r12 is beyond stackLimit
sub r4, sp, r12 // restore value of r4
bx lr
LOCAL_LABEL(checkStack_neg):
mov r12, #0
b LOCAL_LABEL(checkStack_label1)
NESTED_END checkStack, _TEXT
NESTED_ENTRY stackProbe, _TEXT, NoHandler
PROLOG_PUSH "{r5,r6}"
mov r6, r12
bfc r6, #0, #0xc // align down (4K)
LOCAL_LABEL(stackProbe_loop):
sub r4,r4,#0x1000 // dec stack Limit by 4K as page size is 4K
ldr r5,[r4] // try to read ... this should move the guard page
cmp r4,r6
bne LOCAL_LABEL(stackProbe_loop)
EPILOG_POP "{r5,r6}"
sub r4,sp,r12
bx lr
NESTED_END stackProbe, _TEXT
#ifdef FEATURE_PREJIT
//------------------------------------------------
// VirtualMethodFixupStub
//
// In NGEN images, virtual slots inherited from cross-module dependencies
// point to a jump thunk that calls into the following function that will
// call into a VM helper. The VM helper is responsible for patching up
// thunk, upon executing the precode, so that all subsequent calls go directly
// to the actual method body.
//
// This is done lazily for performance reasons.
//
// On entry:
//
// R0 = "this" pointer
// R12 = Address of thunk + 4
NESTED_ENTRY VirtualMethodFixupStub, _TEXT, NoHandler
// Save arguments and return address
PROLOG_PUSH "{r0-r3, r7,r8, lr}" // keep increase by 8B for alignment
PROLOG_STACK_SAVE_OFFSET r7, #20
// Align stack
alloc_stack SIZEOF__FloatArgumentRegisters + 4
vstm sp, {d0-d7}
CHECK_STACK_ALIGNMENT
// R12 contains an address that is 4 bytes ahead of
// where the thunk starts. Refer to ZapImportVirtualThunk::Save
// for details on this.
//
// Move the correct thunk start address in R1
sub r1, r12, #4
// Call the helper in the VM to perform the actual fixup
// and tell us where to tail call. R0 already contains
// the this pointer.
bl C_FUNC(VirtualMethodFixupWorker)
// On return, R0 contains the target to tailcall to
mov r12, r0
// pop the stack and restore original register state
vldm sp, {d0-d7}
free_stack SIZEOF__FloatArgumentRegisters + 4
EPILOG_POP "{r0-r3, r7,r8, lr}"
PATCH_LABEL VirtualMethodFixupPatchLabel
// and tailcall to the actual method
bx r12
NESTED_END VirtualMethodFixupStub, _TEXT
#endif // FEATURE_PREJIT
//------------------------------------------------
// ExternalMethodFixupStub
//
// In NGEN images, calls to cross-module external methods initially
// point to a jump thunk that calls into the following function that will
// call into a VM helper. The VM helper is responsible for patching up the
// thunk, upon executing the precode, so that all subsequent calls go directly
// to the actual method body.
//
// This is done lazily for performance reasons.
//
// On entry:
//
// R12 = Address of thunk + 4
NESTED_ENTRY ExternalMethodFixupStub, _TEXT, NoHandler
PROLOG_WITH_TRANSITION_BLOCK
add r0, sp, #__PWTB_TransitionBlock // pTransitionBlock
// Adjust (read comment above for details) and pass the address of the thunk
sub r1, r12, #4 // pThunk
mov r2, #0 // sectionIndex
mov r3, #0 // pModule
bl C_FUNC(ExternalMethodFixupWorker)
// mov the address we patched to in R12 so that we can tail call to it
mov r12, r0
EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
PATCH_LABEL ExternalMethodFixupPatchLabel
bx r12
NESTED_END ExternalMethodFixupStub, _TEXT
#ifdef FEATURE_PREJIT
//------------------------------------------------
// StubDispatchFixupStub
//
// In NGEN images, calls to interface methods initially
// point to a jump thunk that calls into the following function that will
// call into a VM helper. The VM helper is responsible for patching up the
// thunk with actual stub dispatch stub.
//
// On entry:
//
// R4 = Address of indirection cell
NESTED_ENTRY StubDispatchFixupStub, _TEXT, NoHandler
PROLOG_WITH_TRANSITION_BLOCK
// address of StubDispatchFrame
add r0, sp, #__PWTB_TransitionBlock // pTransitionBlock
mov r1, r4 // siteAddrForRegisterIndirect
mov r2, #0 // sectionIndex
mov r3, #0 // pModule
bl C_FUNC(StubDispatchFixupWorker)
// mov the address we patched to in R12 so that we can tail call to it
mov r12, r0
EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
PATCH_LABEL StubDispatchFixupPatchLabel
bx r12
NESTED_END StubDispatchFixupStub, _TEXT
#endif // FEATURE_PREJIT
//------------------------------------------------
// JIT_RareDisableHelper
//
// The JIT expects this helper to preserve registers used for return values
//
NESTED_ENTRY JIT_RareDisableHelper, _TEXT, NoHandler
PROLOG_PUSH "{r0-r1, r7,r8, r11, lr}" // save integer return value
PROLOG_STACK_SAVE_OFFSET r7, #8
PROLOG_VPUSH {d0-d3} // floating point return value
CHECK_STACK_ALIGNMENT
bl C_FUNC(JIT_RareDisableHelperWorker)
EPILOG_VPOP {d0-d3}
EPILOG_POP "{r0-r1, r7,r8, r11, pc}"
NESTED_END JIT_RareDisableHelper, _TEXT
#ifdef FEATURE_CORECLR
//
// JIT Static access helpers for single appdomain case
//