2 #include "rts/Constants.h"
4 /* If the RTS mini interpreter is used, e.g. for unregisterised builds,
5 * then functions StgRun/StgReturn are implemented in file StgCRun.c */
6 #if !defined(USE_MINIINTERPRETER)
8 #if defined(powerpc64le_HOST_ARCH) || defined(powerpc64_HOST_ARCH)
9 # if defined(_CALL_ELF) && _CALL_ELF == 2
10 /* 64-bit PowerPC ELF V2 ABI Revision 1.5
12 * Stack frame organization (see Figure 2.18, ELF V2 ABI Revision 1.5, p 34)
14 * +-> Back Chain (points to the prevoius stack frame)
15 * | Floating point register save area (f14-f31)
16 * | General register save area (r14-r31)
17 * | ... unused (optional) save areas (size 0)
18 * | Local variable space
19 * | Parameter save area (8 doublewords)
20 * | ... stack header (TOC, LR, CR)
21 * +-- Back chain <---- SP (r1)
23 * We save all callee-saves general purpose registers (r14-r31, _savegpr1_14)
24 * and all callee-saves floating point registers (f14-31, _savefpr14) and
25 * the return address of the caller (LR), which is saved in the caller's
26 * stack frame as required by the ABI. We only modify the CR0 and CR1 fields
27 * of the condition register and those are caller-saves, so we don't save CR.
29 * StgReturn restores all saved registers from their respective locations
30 * on the stack before returning to the caller.
32 * There is no need to save the TOC register (r2) because we will return
33 * through StgReturn. All calls to StgReturn will be to the global entry
34 * point and we compute the TOC from the entry address of StgReturn, which
35 * is required to be in r12 by the ABI.
37 # define STACK_FRAME_SIZE (RESERVED_C_STACK_BYTES+288+15) & ~15
45 .type StgRun,@function
47 .localentry StgRun,.-StgRun
52 stdu 1, -(STACK_FRAME_SIZE)(1)
59 .type StgReturn,@function
61 addis 2,12,.TOC.-StgReturn@ha
62 addi 2,2,.TOC.-StgReturn@l
63 .localentry StgReturn,.-StgReturn
65 la 1, STACK_FRAME_SIZE(1)
70 .section .note.GNU-stack,"",@progbits
72 // ELF v1 is in StgCrun.c
75 #elif defined(powerpc_HOST_ARCH)
76 # if defined(aix_HOST_OS)
77 # define STACK_FRAME_SIZE RESERVED_C_STACK_BYTES+224
81 .long .StgRun, TOC[TC0], 0
88 stwu 1,-(STACK_FRAME_SIZE)(1)
116 la 5,(STACK_FRAME_SIZE)(1)
142 # endif // aix_HOST_OS
144 #elif defined(s390x_HOST_ARCH)
145 # define STACK_FRAME_SIZE (RESERVED_C_STACK_BYTES+160)
149 .type StgRun, @function
152 /* save callee-saved registers */
153 stmg %r6,%r14,16(%r15)
180 /* allocate stack frame */
181 aghi %r15,-STACK_FRAME_SIZE
182 .cfi_def_cfa_offset -(STACK_FRAME_SIZE+160)
183 /* set STGs BaseReg from S390Xs r3 */
185 /* jump to STG function */
188 .size StgRun, .-StgRun
193 .type StgReturn, @function
196 /* set return value from STGs R1 (S390Xs r11) */
198 /* deallocate stack frame */
199 aghi %r15,STACK_FRAME_SIZE
200 .cfi_def_cfa_offset (STACK_FRAME_SIZE+160)
201 /* restore callee-saved registers */
202 lmg %r6,%r14, 16(%r15)
229 /* jump back to caller of StgRun() */
232 .size StgReturn, .-StgReturn
234 #elif defined(riscv64_HOST_ARCH)
235 # define STACK_FRAME_SIZE (RESERVED_C_STACK_BYTES+208)
239 .type StgRun, @function
243 .cfi_def_cfa_offset 208
244 /* save callee-saved registers plus ra */
270 /* allocate stack frame */
271 li t0,RESERVED_C_STACK_BYTES
273 .cfi_def_cfa_offset STACK_FRAME_SIZE
299 /* set STGs BaseReg from RISCV a1 */
301 /* jump to STG function */
304 .size StgRun, .-StgRun
309 .type StgReturn, @function
312 /* set return value from STGs R1 (RISCV s4) */
314 /* deallocate stack frame */
315 li t0,RESERVED_C_STACK_BYTES
317 .cfi_def_cfa_offset 208
318 /* restore callee-saved registers and ra */
370 .cfi_def_cfa_offset 0
371 /* jump back to caller of StgRun() */
374 .size StgReturn, .-StgReturn
376 #elif defined(loongarch64_HOST_ARCH)
377 # define STACK_FRAME_SIZE (RESERVED_C_STACK_BYTES+160)
381 .type StgRun, @function
385 .cfi_def_cfa_offset 160
386 /* save callee-saved registers plus ra */
406 /* allocate stack frame */
407 li.d $t0,RESERVED_C_STACK_BYTES
409 .cfi_def_cfa_offset STACK_FRAME_SIZE
429 /* set STGs BaseReg from LoongArch a1 */
431 /* jump to STG function */
434 .size StgRun, .-StgRun
439 .type StgReturn, @function
442 /* set return value from STGs R1 (LoongArch64 s3) */
444 /* deallocate stack frame */
445 li.d $t0,RESERVED_C_STACK_BYTES
447 .cfi_def_cfa_offset 160
448 /* restore callee-saved registers and ra */
488 .cfi_def_cfa_offset 0
489 /* jump back to caller of StgRun() */
492 .size StgReturn, .-StgReturn
494 .section .note.GNU-stack,"",@progbits
497 #endif /* !USE_MINIINTERPRETER */
499 /* mark stack as nonexecutable */
500 #if defined(HAVE_GNU_NONEXEC_STACK)
501 .section .note.GNU-stack,"",@progbits