Update copyright notices with scripts/update-copyrights
[glibc.git] / ports / sysdeps / unix / sysv / linux / m68k / m680x0 / makecontext.S
blob0d98753eecc1ce75b192a8f00432ac3a09565f9c
1 /* Create new context.
2    Copyright (C) 2012-2014 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <http://www.gnu.org/licenses/>.  */
19 #include <sysdep.h>
21 #include "ucontext_i.h"
24 ENTRY(__makecontext)
25         move.l  4(%sp), %a0
27         /* Get the address of the function we are supposed to run.  */
28         move.l  8(%sp), oPC(%a0)
30         /* Compute the address of the stack.  The information comes from
31            to us_stack element.  */
32         move.l  oSS_SP(%a0), %a1
33         add.l   oSS_SIZE(%a0), %a1
35         /* Remember the number of parameters for the exit handler since
36            it has to remove them.  We store the number in the D7 register
37            which the function we will call must preserve.  */
38         move.l  12(%sp), %d1
39         move.l  %d1, oGREGS+7*4(%a0)
41         /* Make room on the new stack for the parameters.
42            Room for the arguments, return address (== 1f) and
43            oLINK pointer is needed.  */
44         neg.l   %d1
45         lea     -8(%a1,%d1.l*4), %a1
46         neg.l   %d1
48         /* Store the future stack pointer.  */
49         move.l  %a1, oSP(%a0)
51         /* Put the next context on the new stack (from the uc_link
52            element).  */
53         move.l  oLINK(%a0), 4(%a1,%d1.l*4)
55         /* Copy all the parameters.  */
56 1:      subq.l  #1,%d1
57         jmi     2f
58         move.l  16(%sp,%d1.l*4), 4(%a1,%d1.l*4)
59         jra     1b
62         /* If the function we call returns we must continue with the
63            context which is given in the uc_link element.  To do this
64            set the return address for the function the user provides
65            to a little bit of helper code which does the magic (see
66            below).  */
67         lea     1f(%pc), %a0
68         move.l  %a0, (%a1)
69         /* 'makecontext' returns no value.  */
70         rts
72         /* This is the helper code which gets called if a function which
73            is registered with 'makecontext' returns.  In this case we
74            have to install the context listed in the uc_link element of
75            the context 'makecontext' manipulated at the time of the
76            'makecontext' call.  If the pointer is NULL the process must
77            terminate.  */
78         cfi_endproc
80         /* This removes the parameters passed to the function given to
81            'makecontext' from the stack.  D7 contains the number of
82            parameters (see above).  */
83         lea     (%sp,%d7.l*4), %sp
85         tst.l   (%sp)                   /* Check the next context.  */
86         jeq     2f                      /* If it is zero exit.  */
88         jbsr    JUMPTARGET(__setcontext)
89         /* If this returns (which can happen if the syscall fails) we'll
90            exit the program with the return error value (-1).  */
92         move.l  %d0, (%sp)
93 2:      jbsr    HIDDEN_JUMPTARGET(exit)
94         /* The 'exit' call should never return.  In case it does cause
95            the process to terminate.  */
96         illegal
97         cfi_startproc
98 END(__makecontext)
100 weak_alias (__makecontext, makecontext)