2 Copyright (C) 2005-2022 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 <https://www.gnu.org/licenses/>. */
20 #include <abort-instr.h>
22 #include "ucontext_i.h"
24 /* void __makecontext (ucontext_t *ucp, void (*func)(), int argc, ...);
25 __makecontext sets up a stack and registers for context to run a given
26 function. The registers are set up like this:
27 r4-r7: parameters 1 to 4
28 r8 : uc_link from ucontext structure
30 pr : address of exitcode
31 r15 : stack pointer for func. */
37 mov.l @(oSS_SP,r4), r1 /* r1 <- ucb->stack_base */
38 mov.l @(oSS_SIZE,r4), r2 /* r2 <- ucb->stack_size */
39 add r1, r2 /* r2 <- stack_top */
40 cmp/gt r3, r6 /* argc > 4? */
42 shlr2 r2 /* r2 <- stack_top / 4 */
46 shll2 r2 /* r2 <- stack_top - ((argc > 4) ? 4 * (argc - 4) : 0 */
49 mov.l r2, @(r0,r4) /* ucp->r15 <- r2 */
50 mov.l r1, @(oR8,r4) /* ucp->r8 <- ucp->uc_link */
52 mov.l r5, @(r0,r4) /* ucp->PC <- func */
54 cmp/pl r6 /* argc > 0? */
57 mov.l r7, @(oR4,r4) /* ucp->r4 <- argv[0] */
58 cmp/pl r6 /* argc > 1? */
62 mov.l r1, @(oR5,r4) /* ucp->r5 <- argv[1] */
63 cmp/pl r6 /* argc > 2? */
67 mov.l r1, @(oR6,r4) /* ucp->r6 <- argv[2] */
68 cmp/pl r6 /* argc > 3? */
72 mov.l r1, @(oR7,r4) /* ucp->r7 <- argv[3] */
74 .L0: /* Save remaining argv[] on the stack. */
91 mov.l r0, @r4 /* ucp->pr <- exitcode */
104 cfi_adjust_cfa_offset (4)
105 cfi_rel_offset (r12, 0)
110 tst r8, r8 /* ucb->uc_link == NULL? */
112 mov r8, r4 /* r4 <- ucb->uc_link */
113 mov.l .Lsetcontext, r1
115 cfi_adjust_cfa_offset (4)
116 cfi_rel_offset (pr, 0)
125 /* Restore to keep CFI/CFA balanced. */
127 cfi_adjust_cfa_offset (-4)
129 /* If this returns (which can happen if the syscall fails) we'll exit
130 the program with the return error value (-1). */
140 /* The 'exit' call should never return. In case it does cause the
141 process to terminate. */
142 ABORT_INSTRUCTION_ASM
147 .long _GLOBAL_OFFSET_TABLE_
149 .long __setcontext@PLT-(.LPCS0+2-(.))
151 .long HIDDEN_JUMPTARGET(exit)@GOTOFF
156 .long HIDDEN_JUMPTARGET(exit)
158 PSEUDO_END(__makecontext)
160 weak_alias (__makecontext, makecontext)