xref: /netbsd-src/external/gpl3/gcc.old/dist/libphobos/libdruntime/config/powerpc64/callwithstack.S (revision 627f7eb200a4419d89b531d55fccd2ee3ffdcde0)
1/* PowerPC64 support code for fibers and multithreading.
2   Copyright (C) 2019 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14for more details.
15
16Under Section 7 of GPL version 3, you are granted additional
17permissions described in the GCC Runtime Library Exception, version
183.1, as published by the Free Software Foundation.
19
20You should have received a copy of the GNU General Public License and
21a copy of the GCC Runtime Library Exception along with this program;
22see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23<http://www.gnu.org/licenses/>.  */
24
25#include "../common/threadasm.S"
26
27#if defined(_CALL_ELF) && _CALL_ELF == 2
28#define USE_ABI_2
29#define LINKAGE_SZ   32
30#define LR_OFS       16
31#define TOC_OFS      24
32#define GPR_OFS      32
33#define STACK_SZ     (LINKAGE_SZ + 26*8)
34#define OFS_R3_R10   GPR_OFS
35#define OFS_R14_R31  (GPR_OFS+8*8)
36#else
37#define LINKAGE_SZ   48
38#define LR_OFS       16
39#define TOC_OFS      40
40#define GPR_OFS      112
41#define STACK_SZ     (LINKAGE_SZ + 8*8 + 18*8)
42#define OFS_R3_R10   (STACK_SZ+LINKAGE_SZ)
43#define OFS_R14_R31  GPR_OFS
44#endif
45
46    .text
47#if defined( USE_ABI_2 )
48    .abiversion 2
49#endif
50    .globl  _D4core6thread18callWithStackShellFNbMDFNbPvZvZv
51    .align  2
52    .type   _D4core6thread18callWithStackShellFNbMDFNbPvZvZv,@function
53#if defined( USE_ABI_2 )
54    .section .text._D4core6thread18callWithStackShellFNbMDFNbPvZvZv,"a",@progbits
55#else
56    .section .opd,"aw",@progbits
57#endif
58_D4core6thread18callWithStackShellFNbMDFNbPvZvZv:
59#if !defined( USE_ABI_2 )
60    .align  3
61    .quad .L._D4core6thread18callWithStackShellFNbMDFNbPvZvZv
62    .quad .TOC.@tocbase
63    .quad 0
64#endif
65    .text
66/*
67 * Called with:
68 * r3: pointer context
69 * r4: pointer to function
70 */
71.L._D4core6thread18callWithStackShellFNbMDFNbPvZvZv:
72    .cfi_startproc
73    stdu    1, -STACK_SZ(1)
74    mflr    0
75    std     0, LR_OFS(1)
76    .cfi_def_cfa_offset 256
77    .cfi_offset lr, 16
78
79    /* Save r14-r31 in general register save area */
80    std     14, (OFS_R14_R31 + 0 * 8)(1)
81    std     15, (OFS_R14_R31 + 1 * 8)(1)
82    std     16, (OFS_R14_R31 + 2 * 8)(1)
83    std     17, (OFS_R14_R31 + 3 * 8)(1)
84    std     18, (OFS_R14_R31 + 4 * 8)(1)
85    std     19, (OFS_R14_R31 + 5 * 8)(1)
86    std     20, (OFS_R14_R31 + 6 * 8)(1)
87    std     21, (OFS_R14_R31 + 7 * 8)(1)
88    std     22, (OFS_R14_R31 + 8 * 8)(1)
89    std     23, (OFS_R14_R31 + 9 * 8)(1)
90    std     24, (OFS_R14_R31 + 10 * 8)(1)
91    std     25, (OFS_R14_R31 + 11 * 8)(1)
92    std     26, (OFS_R14_R31 + 12 * 8)(1)
93    std     27, (OFS_R14_R31 + 13 * 8)(1)
94    std     28, (OFS_R14_R31 + 14 * 8)(1)
95    std     29, (OFS_R14_R31 + 15 * 8)(1)
96    std     30, (OFS_R14_R31 + 16 * 8)(1)
97    std     31, (OFS_R14_R31 + 17 * 8)(1)
98
99    /* Save r3-r10 in parameter save area of caller */
100    std     3, (OFS_R3_R10 + 0 * 8)(1)
101    std     4, (OFS_R3_R10 + 1 * 8)(1)
102    std     5, (OFS_R3_R10 + 2 * 8)(1)
103    std     6, (OFS_R3_R10 + 3 * 8)(1)
104    std     7, (OFS_R3_R10 + 4 * 8)(1)
105    std     8, (OFS_R3_R10 + 5 * 8)(1)
106    std     9, (OFS_R3_R10 + 6 * 8)(1)
107    std     10, (OFS_R3_R10 + 7 * 8)(1)
108
109    /* Save r2 in TOC save area */
110    std     2, TOC_OFS(1)
111
112    /* Do not save r11, r12 and r13. */
113
114    /* Call delegate:
115     * r3: pointer to context
116     * r4: pointer to stack
117     */
118    mr      5, 4
119    mr      4, 1
120    ld      6, 0(5)
121    ld      11, 16(5)
122    ld      2, 8(5)
123    mtctr   6
124    bctrl
125    nop
126
127    /* Restore r2 from TOC save area */
128    ld      2, TOC_OFS(1)
129
130    /* Restore r3-r10 from local variable space */
131    ld      3, (OFS_R3_R10 + 0 * 8)(1)
132    ld      4, (OFS_R3_R10 + 1 * 8)(1)
133    ld      5, (OFS_R3_R10 + 2 * 8)(1)
134    ld      6, (OFS_R3_R10 + 3 * 8)(1)
135    ld      7, (OFS_R3_R10 + 4 * 8)(1)
136    ld      8, (OFS_R3_R10 + 5 * 8)(1)
137    ld      9, (OFS_R3_R10 + 6 * 8)(1)
138    ld      10, (OFS_R3_R10 + 7 * 8)(1)
139
140    /* Restore r14-r31 from general register save area */
141    ld      14, (OFS_R14_R31 + 0 * 8)(1)
142    ld      15, (OFS_R14_R31 + 1 * 8)(1)
143    ld      16, (OFS_R14_R31 + 2 * 8)(1)
144    ld      17, (OFS_R14_R31 + 3 * 8)(1)
145    ld      18, (OFS_R14_R31 + 4 * 8)(1)
146    ld      19, (OFS_R14_R31 + 5 * 8)(1)
147    ld      20, (OFS_R14_R31 + 6 * 8)(1)
148    ld      21, (OFS_R14_R31 + 7 * 8)(1)
149    ld      22, (OFS_R14_R31 + 8 * 8)(1)
150    ld      23, (OFS_R14_R31 + 9 * 8)(1)
151    ld      24, (OFS_R14_R31 + 10 * 8)(1)
152    ld      25, (OFS_R14_R31 + 11 * 8)(1)
153    ld      26, (OFS_R14_R31 + 12 * 8)(1)
154    ld      27, (OFS_R14_R31 + 13 * 8)(1)
155    ld      28, (OFS_R14_R31 + 14 * 8)(1)
156    ld      29, (OFS_R14_R31 + 15 * 8)(1)
157    ld      30, (OFS_R14_R31 + 16 * 8)(1)
158    ld      31, (OFS_R14_R31 + 17 * 8)(1)
159
160    ld      0, LR_OFS(1)
161    mtlr    0
162    addi    1, 1, STACK_SZ
163    blr
164    .long 0
165    .quad 0
166.Lend:
167    .size _D4core6thread18callWithStackShellFNbMDFNbPvZvZv, .Lend-.L._D4core6thread18callWithStackShellFNbMDFNbPvZvZv
168    .cfi_endproc
169