Home | History | Annotate | Line # | Download | only in powerpc
switchcontext.S revision 1.1.1.2
      1 /* PowerPC support code for fibers and multithreading.
      2    Copyright (C) 2019-2020 Free Software Foundation, Inc.
      3 
      4 This file is part of GCC.
      5 
      6 GCC is free software; you can redistribute it and/or modify it under
      7 the terms of the GNU General Public License as published by the Free
      8 Software Foundation; either version 3, or (at your option) any later
      9 version.
     10 
     11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
     12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14 for more details.
     15 
     16 Under Section 7 of GPL version 3, you are granted additional
     17 permissions described in the GCC Runtime Library Exception, version
     18 3.1, as published by the Free Software Foundation.
     19 
     20 You should have received a copy of the GNU General Public License and
     21 a copy of the GCC Runtime Library Exception along with this program;
     22 see 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(__PPC64__)
     28 
     29 /**
     30  * Performs a context switch.
     31  *
     32  * r3 - old context pointer
     33  * r4 - new context pointer
     34  *
     35  */
     36     .text
     37     .globl CSYM(fiber_switchContext)
     38     .type CSYM(fiber_switchContext), @function
     39     .align 2
     40 CSYM(fiber_switchContext):
     41     .cfi_startproc
     42     /* Save linkage area */
     43     mflr        0
     44     mfcr        5
     45     stw     0, 8(1)
     46     stw     5, 4(1)
     47 
     48     /* Save GPRs */
     49     stw     11, (-1 * 4)(1)
     50     stw     13, (-2 * 4)(1)
     51     stw     14, (-3 * 4)(1)
     52     stw     15, (-4 * 4)(1)
     53     stw     16, (-5 * 4)(1)
     54     stw     17, (-6 * 4)(1)
     55     stw     18, (-7 * 4)(1)
     56     stw     19, (-8 * 4)(1)
     57     stw     20, (-9 * 4)(1)
     58     stw     21, (-10 * 4)(1)
     59     stw     22, (-11 * 4)(1)
     60     stw     23, (-12 * 4)(1)
     61     stw     24, (-13 * 4)(1)
     62     stw     25, (-14 * 4)(1)
     63     stw     26, (-15 * 4)(1)
     64     stw     27, (-16 * 4)(1)
     65     stw     28, (-17 * 4)(1)
     66     stw     29, (-18 * 4)(1)
     67     stw     30, (-19 * 4)(1)
     68     stwu    31, (-20 * 4)(1)
     69 
     70     /* We update the stack pointer here, since we do not want the GC to
     71        scan the floating point registers. */
     72 
     73     /* Save FPRs */
     74     stfd    14, (-1 * 8)(1)
     75     stfd    15, (-2 * 8)(1)
     76     stfd    16, (-3 * 8)(1)
     77     stfd    17, (-4 * 8)(1)
     78     stfd    18, (-5 * 8)(1)
     79     stfd    19, (-6 * 8)(1)
     80     stfd    20, (-7 * 8)(1)
     81     stfd    21, (-8 * 8)(1)
     82     stfd    22, (-9 * 8)(1)
     83     stfd    23, (-10 * 8)(1)
     84     stfd    24, (-11 * 8)(1)
     85     stfd    25, (-12 * 8)(1)
     86     stfd    26, (-13 * 8)(1)
     87     stfd    27, (-14 * 8)(1)
     88     stfd    28, (-15 * 8)(1)
     89     stfd    29, (-16 * 8)(1)
     90     stfd    30, (-17 * 8)(1)
     91     stfd    31, (-18 * 8)(1)
     92 
     93     /* Update the old stack pointer */
     94     stw     1, 0(3)
     95 
     96     /* Set new stack pointer */
     97     addi        1, 4, 20 * 4
     98 
     99     /* Restore linkage area */
    100     lwz     0, 8(1)
    101     lwz     5, 4(1)
    102 
    103     /* Restore GPRs */
    104     lwz     11, (-1 * 4)(1)
    105     lwz     13, (-2 * 4)(1)
    106     lwz     14, (-3 * 4)(1)
    107     lwz     15, (-4 * 4)(1)
    108     lwz     16, (-5 * 4)(1)
    109     lwz     17, (-6 * 4)(1)
    110     lwz     18, (-7 * 4)(1)
    111     lwz     19, (-8 * 4)(1)
    112     lwz     20, (-9 * 4)(1)
    113     lwz     21, (-10 * 4)(1)
    114     lwz     22, (-11 * 4)(1)
    115     lwz     23, (-12 * 4)(1)
    116     lwz     24, (-13 * 4)(1)
    117     lwz     25, (-14 * 4)(1)
    118     lwz     26, (-15 * 4)(1)
    119     lwz     27, (-16 * 4)(1)
    120     lwz     28, (-17 * 4)(1)
    121     lwz     29, (-18 * 4)(1)
    122     lwz     30, (-19 * 4)(1)
    123     lwz     31, (-20 * 4)(1)
    124 
    125     /* Restore FPRs */
    126     lfd     14, (-1 * 8)(4)
    127     lfd     15, (-2 * 8)(4)
    128     lfd     16, (-3 * 8)(4)
    129     lfd     17, (-4 * 8)(4)
    130     lfd     18, (-5 * 8)(4)
    131     lfd     19, (-6 * 8)(4)
    132     lfd     20, (-7 * 8)(4)
    133     lfd     21, (-8 * 8)(4)
    134     lfd     22, (-9 * 8)(4)
    135     lfd     23, (-10 * 8)(4)
    136     lfd     24, (-11 * 8)(4)
    137     lfd     25, (-12 * 8)(4)
    138     lfd     26, (-13 * 8)(4)
    139     lfd     27, (-14 * 8)(4)
    140     lfd     28, (-15 * 8)(4)
    141     lfd     29, (-16 * 8)(4)
    142     lfd     30, (-17 * 8)(4)
    143     lfd     31, (-18 * 8)(4)
    144 
    145     /* Set condition and link register */
    146     mtcr        5
    147     mtlr        0
    148 
    149     /* Return and switch context */
    150     blr
    151     .cfi_endproc
    152     .size CSYM(fiber_switchContext),.-CSYM(fiber_switchContext)
    153 
    154 #endif /* !defined(__PPC64__) */
    155