1 | /* Save current context. C-SKY ABIV2 version. |
2 | Copyright (C) 2018-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 | |
21 | #include "ucontext_i.h" |
22 | |
23 | /* int getcontext (ucontext_t *ucp) */ |
24 | |
25 | ENTRY (__getcontext) |
26 | /* No need to save r2-r7 or a0-a3. */ |
27 | mov t0, a0 |
28 | |
29 | addi a0, MCONTEXT_CSKY_R4 |
30 | |
31 | stm r4-r13, (a0) /* Save r4-r13. */ |
32 | stw sp, (t0, MCONTEXT_CSKY_SP) /* Save sp. */ |
33 | stw r15, (t0, MCONTEXT_CSKY_LR) /* Save lr. */ |
34 | stw r15, (t0, MCONTEXT_CSKY_PC) /* Return to PC. */ |
35 | addi a0, t0, MCONTEXT_CSKY_R16 |
36 | stm r16-r31, (a0) /* Save r16-r31. */ |
37 | movi a0, 0 |
38 | stw a0, (t0, MCONTEXT_CSKY_A0) /* Return zero. */ |
39 | |
40 | subi sp, 8 |
41 | stw t0, (sp, 0) /* Save t0 after "save sp". */ |
42 | |
43 | /* __sigprocmask (SIG_BLOCK, NULL, &(ucontext->uc_sigmask)) */ |
44 | movi a0, SIG_BLOCK |
45 | movi a1, 0 |
46 | addi a2, t0, UCONTEXT_SIGMASK |
47 | |
48 | /* Do sigprocmask syscall. */ |
49 | #ifdef __PIC__ |
50 | subi sp, 8 |
51 | stw gb, (sp, 0) |
52 | grs gb, .Lgetpc |
53 | .Lgetpc: |
54 | lrw a3, .Lgetpc@GOTPC |
55 | addu gb, gb, a3 |
56 | lrw a3, __sigprocmask@PLT |
57 | ldr.w a3, (gb, a3 << 0) |
58 | jsr a3 |
59 | ldw gb, (sp, 0) |
60 | addi sp, 8 |
61 | #else |
62 | jsri __sigprocmask |
63 | #endif |
64 | |
65 | ldw t0, (sp, 0) |
66 | addi sp, 8 |
67 | /* Restore r15 for sigprocmask changes. */ |
68 | ldw r15, (t0, MCONTEXT_CSKY_LR) |
69 | movi a0, 0 /* Return 0. */ |
70 | jmp r15 |
71 | END (__getcontext) |
72 | |
73 | weak_alias (__getcontext, getcontext) |
74 | |