1/* Save current context. OpenRISC version.
2 Copyright (C) 2022-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19#include <sysdep.h>
20#include "ucontext_i.h"
21
22/* int getcontext (ucontext_t *ucp)
23
24 Returns 0 on success -1 and errno on failure.
25 */
26 .text
27ENTRY(__getcontext)
28 /* Store r1, the stack pointer. */
29 l.sw (UCONTEXT_MCONTEXT + 1*4)(r3), r1
30 /* Store r2, the frame pointer. */
31 l.sw (UCONTEXT_MCONTEXT + 2*4)(r3), r2
32 /* Store r9, the link register. */
33 l.sw (UCONTEXT_MCONTEXT + 9*4)(r3), r9
34 /* Store r9 to reg[11] too, as we need two links for makecontext. */
35 l.sw (UCONTEXT_MCONTEXT + 11*4)(r3), r9
36 /* Store r10, the TLS register. */
37 l.sw (UCONTEXT_MCONTEXT + 10*4)(r3), r10
38 /* Store r14-r30 even, callee saved registers. */
39 l.sw (UCONTEXT_MCONTEXT + 14*4)(r3), r14
40 l.sw (UCONTEXT_MCONTEXT + 16*4)(r3), r16
41 l.sw (UCONTEXT_MCONTEXT + 18*4)(r3), r18
42 l.sw (UCONTEXT_MCONTEXT + 20*4)(r3), r20
43 l.sw (UCONTEXT_MCONTEXT + 22*4)(r3), r22
44 l.sw (UCONTEXT_MCONTEXT + 24*4)(r3), r24
45 l.sw (UCONTEXT_MCONTEXT + 26*4)(r3), r26
46 l.sw (UCONTEXT_MCONTEXT + 28*4)(r3), r28
47 l.sw (UCONTEXT_MCONTEXT + 30*4)(r3), r30
48
49 /* Get signal mask. */
50 /* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */
51 l.ori r6, r0, _NSIG8
52 l.addi r5, r3, UCONTEXT_SIGMASK
53 l.ori r4, r0, 0
54 l.ori r3, r0, SIG_BLOCK
55 l.ori r11, r0, SYS_ify (rt_sigprocmask)
56 /* Do the syscall. */
57 l.sys 1
58 l.nop
59
60 /* if -4096 < ret < 0 holds, it's an error */
61 l.sfgeui r11, 0xf001
62 l.bf 1f
63 l.nop
64
65 l.jr r9
66 l.ori r11, r0, 0
67
681: l.j __syscall_error
69 l.ori r3, r11, 0
70
71END(__getcontext)
72weak_alias(__getcontext, getcontext)
73

source code of glibc/sysdeps/unix/sysv/linux/or1k/getcontext.S