PageRenderTime 36ms CodeModel.GetById 1ms app.highlight 28ms RepoModel.GetById 2ms app.codeStats 0ms

/src/core/threadasm.S

http://github.com/AlexeyProkhin/druntime
Assembly | 335 lines | 304 code | 31 blank | 0 comment | 6 complexity | ea8772f349b98f6baa75160e9d96139a MD5 | raw file
  1/**
  2 * Support code for mutithreading.
  3 *
  4 * Copyright: Copyright Mikola Lysenko 2005 - 2012.
  5 * License:   <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
  6 * Authors:   Mikola Lysenko, Martin Nowak, Kai Nacke
  7 */
  8
  9/*
 10 *          Copyright Mikola Lysenko 2005 - 2012.
 11 * Distributed under the Boost Software License, Version 1.0.
 12 *    (See accompanying file LICENSE_1_0.txt or copy at
 13 *          http://www.boost.org/LICENSE_1_0.txt)
 14 */
 15
 16/************************************************************************************
 17 * POWER PC ASM BITS
 18 ************************************************************************************/
 19#if defined( __PPC64__ )
 20
 21
 22    .text
 23    .globl  _D4core6thread18callWithStackShellFMDFPvZvZv
 24    .align  2
 25    .type _D4core6thread18callWithStackShellFMDFPvZvZv,@function
 26    .section  .opd,"aw",@progbits
 27_D4core6thread18callWithStackShellFMDFPvZvZv:
 28    .align  3
 29    .quad .L._D4core6thread18callWithStackShellFMDFPvZvZv
 30    .quad .TOC.@tocbase
 31    .quad 0
 32    .text
 33/*
 34 * Called with:
 35 * r3: pointer context
 36 * r4: pointer to function
 37 */
 38.L._D4core6thread18callWithStackShellFMDFPvZvZv:
 39    .cfi_startproc
 40    mflr    0
 41    std     0, 16(1)                    // save LR
 42    stdu    1, -256(1)                  // stack size: 18*8 + 112 = 256
 43    .cfi_def_cfa_offset 256
 44    .cfi_offset lr, 16
 45
 46    /* Save r14-r31 in general register save area */
 47    std     14, (112 + 0 * 8)(1)
 48    std     15, (112 + 1 * 8)(1)
 49    std     16, (112 + 2 * 8)(1)
 50    std     17, (112 + 3 * 8)(1)
 51    std     18, (112 + 4 * 8)(1)
 52    std     19, (112 + 5 * 8)(1)
 53    std     20, (112 + 6 * 8)(1)
 54    std     21, (112 + 7 * 8)(1)
 55    std     22, (112 + 8 * 8)(1)
 56    std     23, (112 + 9 * 8)(1)
 57    std     24, (112 + 10 * 8)(1)
 58    std     25, (112 + 11 * 8)(1)
 59    std     26, (112 + 12 * 8)(1)
 60    std     27, (112 + 13 * 8)(1)
 61    std     28, (112 + 14 * 8)(1)
 62    std     29, (112 + 15 * 8)(1)
 63    std     30, (112 + 16 * 8)(1)
 64    std     31, (112 + 17 * 8)(1)
 65
 66    /* Save r3-r10 in parameter save area of caller */
 67    std     3, (256 + 48 + 0 * 8)(1)
 68    std     4, (256 + 48 + 1 * 8)(1)
 69    std     5, (256 + 48 + 2 * 8)(1)
 70    std     6, (256 + 48 + 3 * 8)(1)
 71    std     7, (256 + 48 + 4 * 8)(1)
 72    std     8, (256 + 48 + 5 * 8)(1)
 73    std     9, (256 + 48 + 6 * 8)(1)
 74    std     10, (256 + 48 + 7 * 8)(1)
 75
 76    /* Save r2 in TOC save area */
 77    std     2, 40(1)
 78
 79    /* Do not save r11, r12 and r13. */
 80
 81    /* Call delegate:
 82     * r3: pointer to context
 83     * r4: pointer to stack
 84     */
 85    mr      5, 4
 86    mr      4, 1
 87    ld      6, 0(5)
 88    ld      11, 16(5)
 89    ld      2, 8(5)
 90    mtctr   6
 91    bctrl
 92    nop
 93
 94    /* Restore r2 from TOC save area */
 95    ld      2, 40(1)
 96
 97    /* Restore r3-r10 from local variable space */
 98    ld      3, (256 + 48 + 0 * 8)(1)
 99    ld      4, (256 + 48 + 1 * 8)(1)
100    ld      5, (256 + 48 + 2 * 8)(1)
101    ld      6, (256 + 48 + 3 * 8)(1)
102    ld      7, (256 + 48 + 4 * 8)(1)
103    ld      8, (256 + 48 + 5 * 8)(1)
104    ld      9, (256 + 48 + 6 * 8)(1)
105    ld      10, (256 + 48 + 7 * 8)(1)
106
107    /* Restore r14-r31 from general register save area */
108    ld      14, (112 + 0 * 8)(1)
109    ld      15, (112 + 1 * 8)(1)
110    ld      16, (112 + 2 * 8)(1)
111    ld      17, (112 + 3 * 8)(1)
112    ld      18, (112 + 4 * 8)(1)
113    ld      19, (112 + 5 * 8)(1)
114    ld      20, (112 + 6 * 8)(1)
115    ld      21, (112 + 7 * 8)(1)
116    ld      22, (112 + 8 * 8)(1)
117    ld      23, (112 + 9 * 8)(1)
118    ld      24, (112 + 10 * 8)(1)
119    ld      25, (112 + 11 * 8)(1)
120    ld      26, (112 + 12 * 8)(1)
121    ld      27, (112 + 13 * 8)(1)
122    ld      28, (112 + 14 * 8)(1)
123    ld      29, (112 + 15 * 8)(1)
124    ld      30, (112 + 16 * 8)(1)
125    ld      31, (112 + 17 * 8)(1)
126
127    addi    1, 1, 256
128    ld      0, 16(1)
129    mtlr    0
130    blr
131    .long 0
132    .quad 0
133.Lend:
134    .size _D4core6thread18callWithStackShellFMDFPvZvZv, .Lend-.L._D4core6thread18callWithStackShellFMDFPvZvZv
135    .cfi_endproc
136
137#elif defined( __ppc__ ) || defined( __PPC__ ) || defined( __powerpc__ )
138
139
140/**
141 * Performs a context switch.
142 *
143 * r3 - old context pointer
144 * r4 - new context pointer
145 *
146 */
147.text
148.align 2
149.globl _fiber_switchContext
150_fiber_switchContext:
151
152    /* Save linkage area */
153    mflr        0
154    mfcr        5
155    stw     0, 8(1)
156    stw     5, 4(1)
157
158    /* Save GPRs */
159    stw     11, (-1 * 4)(1)
160    stw     13, (-2 * 4)(1)
161    stw     14, (-3 * 4)(1)
162    stw     15, (-4 * 4)(1)
163    stw     16, (-5 * 4)(1)
164    stw     17, (-6 * 4)(1)
165    stw     18, (-7 * 4)(1)
166    stw     19, (-8 * 4)(1)
167    stw     20, (-9 * 4)(1)
168    stw     21, (-10 * 4)(1)
169    stw     22, (-11 * 4)(1)
170    stw     23, (-12 * 4)(1)
171    stw     24, (-13 * 4)(1)
172    stw     25, (-14 * 4)(1)
173    stw     26, (-15 * 4)(1)
174    stw     27, (-16 * 4)(1)
175    stw     28, (-17 * 4)(1)
176    stw     29, (-18 * 4)(1)
177    stw     30, (-19 * 4)(1)
178    stwu    31, (-20 * 4)(1)
179
180    /* We update the stack pointer here, since we do not want the GC to
181       scan the floating point registers. */
182
183    /* Save FPRs */
184    stfd    14, (-1 * 8)(1)
185    stfd    15, (-2 * 8)(1)
186    stfd    16, (-3 * 8)(1)
187    stfd    17, (-4 * 8)(1)
188    stfd    18, (-5 * 8)(1)
189    stfd    19, (-6 * 8)(1)
190    stfd    20, (-7 * 8)(1)
191    stfd    21, (-8 * 8)(1)
192    stfd    22, (-9 * 8)(1)
193    stfd    23, (-10 * 8)(1)
194    stfd    24, (-11 * 8)(1)
195    stfd    25, (-12 * 8)(1)
196    stfd    26, (-13 * 8)(1)
197    stfd    27, (-14 * 8)(1)
198    stfd    28, (-15 * 8)(1)
199    stfd    29, (-16 * 8)(1)
200    stfd    30, (-17 * 8)(1)
201    stfd    31, (-18 * 8)(1)
202
203    /* Update the old stack pointer */
204    stw     1, 0(3)
205
206    /* Set new stack pointer */
207    addi        1, 4, 20 * 4
208
209    /* Restore linkage area */
210    lwz     0, 8(1)
211    lwz     5, 4(1)
212
213    /* Restore GPRs */
214    lwz     11, (-1 * 4)(1)
215    lwz     13, (-2 * 4)(1)
216    lwz     14, (-3 * 4)(1)
217    lwz     15, (-4 * 4)(1)
218    lwz     16, (-5 * 4)(1)
219    lwz     17, (-6 * 4)(1)
220    lwz     18, (-7 * 4)(1)
221    lwz     19, (-8 * 4)(1)
222    lwz     20, (-9 * 4)(1)
223    lwz     21, (-10 * 4)(1)
224    lwz     22, (-11 * 4)(1)
225    lwz     23, (-12 * 4)(1)
226    lwz     24, (-13 * 4)(1)
227    lwz     25, (-14 * 4)(1)
228    lwz     26, (-15 * 4)(1)
229    lwz     27, (-16 * 4)(1)
230    lwz     28, (-17 * 4)(1)
231    lwz     29, (-18 * 4)(1)
232    lwz     30, (-19 * 4)(1)
233    lwz     31, (-20 * 4)(1)
234
235
236    /* Restore FPRs */
237    lfd     14, (-1 * 8)(4)
238    lfd     15, (-2 * 8)(4)
239    lfd     16, (-3 * 8)(4)
240    lfd     17, (-4 * 8)(4)
241    lfd     18, (-5 * 8)(4)
242    lfd     19, (-6 * 8)(4)
243    lfd     20, (-7 * 8)(4)
244    lfd     21, (-8 * 8)(4)
245    lfd     22, (-9 * 8)(4)
246    lfd     23, (-10 * 8)(4)
247    lfd     24, (-11 * 8)(4)
248    lfd     25, (-12 * 8)(4)
249    lfd     26, (-13 * 8)(4)
250    lfd     27, (-14 * 8)(4)
251    lfd     28, (-15 * 8)(4)
252    lfd     29, (-16 * 8)(4)
253    lfd     30, (-17 * 8)(4)
254    lfd     31, (-18 * 8)(4)
255
256    /* Set condition and link register */
257    mtcr        5
258    mtlr        0
259
260    /* Return and switch context */
261    blr
262
263#elif defined(__mips__) && _MIPS_SIM == _ABIO32
264/************************************************************************************
265 * MIPS ASM BITS
266 ************************************************************************************/
267
268/**
269 * Performs a context switch.
270 *
271 * $a0 - void** - ptr to old stack pointer
272 * $a1 - void*  - new stack pointer
273 *
274 */
275.text
276.globl fiber_switchContext
277fiber_switchContext:
278    addiu $sp, $sp, -(10 * 4)
279
280    // fp regs and return address are stored below the stack
281    // because we don't want the GC to scan them.
282
283#ifdef __mips_hard_float
284#define ALIGN8(val) (val + (-val & 7))
285#define BELOW (ALIGN8(6 * 8 + 4))
286    sdcl $f20, (0 * 8 - BELOW)($sp)
287    sdcl $f22, (1 * 8 - BELOW)($sp)
288    sdcl $f24, (2 * 8 - BELOW)($sp)
289    sdcl $f26, (3 * 8 - BELOW)($sp)
290    sdcl $f28, (4 * 8 - BELOW)($sp)
291    sdcl $f30, (5 * 8 - BELOW)($sp)
292#endif
293    sw $ra, -4($sp)
294
295    sw $s0, (0 * 4)($sp)
296    sw $s1, (1 * 4)($sp)
297    sw $s2, (2 * 4)($sp)
298    sw $s3, (3 * 4)($sp)
299    sw $s4, (4 * 4)($sp)
300    sw $s5, (5 * 4)($sp)
301    sw $s6, (6 * 4)($sp)
302    sw $s7, (7 * 4)($sp)
303    sw $s8, (8 * 4)($sp)
304    sw $gp, (9 * 4)($sp)
305
306    // swap stack pointer
307    sw $sp, 0($a0)
308    move $sp, $a1
309
310#ifdef __mips_hard_float
311    ldcl $f20, (0 * 8 - BELOW)($sp)
312    ldcl $f22, (1 * 8 - BELOW)($sp)
313    ldcl $f24, (2 * 8 - BELOW)($sp)
314    ldcl $f26, (3 * 8 - BELOW)($sp)
315    ldcl $f28, (4 * 8 - BELOW)($sp)
316    ldcl $f30, (5 * 8 - BELOW)($sp)
317#endif
318    lw $ra, -4($sp)
319
320    lw $s0, (0 * 4)($sp)
321    lw $s1, (1 * 4)($sp)
322    lw $s2, (2 * 4)($sp)
323    lw $s3, (3 * 4)($sp)
324    lw $s4, (4 * 4)($sp)
325    lw $s5, (5 * 4)($sp)
326    lw $s6, (6 * 4)($sp)
327    lw $s7, (7 * 4)($sp)
328    lw $s8, (8 * 4)($sp)
329    lw $gp, (9 * 4)($sp)
330
331    addiu $sp, $sp, (10 * 4)
332
333    jr $ra // return
334
335#endif