xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame^] | 1 | /* Assembly macros for 32-bit PowerPC. |
| 2 | Copyright (C) 1999-2016 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 | <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #include <sysdeps/powerpc/sysdep.h> |
| 20 | |
| 21 | #ifdef __ASSEMBLER__ |
| 22 | |
| 23 | /* If compiled for profiling, call `_mcount' at the start of each |
| 24 | function. */ |
| 25 | #ifdef PROF |
| 26 | /* The mcount code relies on a the return address being on the stack |
| 27 | to locate our caller and so it can restore it; so store one just |
| 28 | for its benefit. */ |
| 29 | # define CALL_MCOUNT \ |
| 30 | mflr r0; \ |
| 31 | stw r0,4(r1); \ |
| 32 | cfi_offset (lr, 4); \ |
| 33 | bl JUMPTARGET(_mcount); |
| 34 | #else /* PROF */ |
| 35 | # define CALL_MCOUNT /* Do nothing. */ |
| 36 | #endif /* PROF */ |
| 37 | |
| 38 | #define ENTRY(name) \ |
| 39 | .globl C_SYMBOL_NAME(name); \ |
| 40 | .type C_SYMBOL_NAME(name),@function; \ |
| 41 | .align ALIGNARG(2); \ |
| 42 | C_LABEL(name) \ |
| 43 | cfi_startproc; \ |
| 44 | CALL_MCOUNT |
| 45 | |
| 46 | /* helper macro for accessing the 32-bit powerpc GOT. */ |
| 47 | |
| 48 | #define SETUP_GOT_ACCESS(regname,GOT_LABEL) \ |
| 49 | bcl 20,31,GOT_LABEL ; \ |
| 50 | GOT_LABEL: ; \ |
| 51 | mflr (regname) |
| 52 | |
| 53 | #define EALIGN_W_0 /* No words to insert. */ |
| 54 | #define EALIGN_W_1 nop |
| 55 | #define EALIGN_W_2 nop;nop |
| 56 | #define EALIGN_W_3 nop;nop;nop |
| 57 | #define EALIGN_W_4 EALIGN_W_3;nop |
| 58 | #define EALIGN_W_5 EALIGN_W_4;nop |
| 59 | #define EALIGN_W_6 EALIGN_W_5;nop |
| 60 | #define EALIGN_W_7 EALIGN_W_6;nop |
| 61 | |
| 62 | /* EALIGN is like ENTRY, but does alignment to 'words'*4 bytes |
| 63 | past a 2^align boundary. */ |
| 64 | #ifdef PROF |
| 65 | # define EALIGN(name, alignt, words) \ |
| 66 | .globl C_SYMBOL_NAME(name); \ |
| 67 | .type C_SYMBOL_NAME(name),@function; \ |
| 68 | .align ALIGNARG(2); \ |
| 69 | C_LABEL(name) \ |
| 70 | cfi_startproc; \ |
| 71 | CALL_MCOUNT \ |
| 72 | b 0f; \ |
| 73 | .align ALIGNARG(alignt); \ |
| 74 | EALIGN_W_##words; \ |
| 75 | 0: |
| 76 | #else /* PROF */ |
| 77 | # define EALIGN(name, alignt, words) \ |
| 78 | .globl C_SYMBOL_NAME(name); \ |
| 79 | .type C_SYMBOL_NAME(name),@function; \ |
| 80 | .align ALIGNARG(alignt); \ |
| 81 | EALIGN_W_##words; \ |
| 82 | C_LABEL(name) \ |
| 83 | cfi_startproc; |
| 84 | #endif |
| 85 | |
| 86 | #undef END |
| 87 | #define END(name) \ |
| 88 | cfi_endproc; \ |
| 89 | ASM_SIZE_DIRECTIVE(name) |
| 90 | |
| 91 | #if ! IS_IN(rtld) && defined (ENABLE_LOCK_ELISION) |
| 92 | # define ABORT_TRANSACTION \ |
| 93 | cmpwi 2,0; \ |
| 94 | beq 1f; \ |
| 95 | lwz 0,TM_CAPABLE(2); \ |
| 96 | cmpwi 0,0; \ |
| 97 | beq 1f; \ |
| 98 | li 11,_ABORT_SYSCALL; \ |
| 99 | tabort. 11; \ |
| 100 | .align 4; \ |
| 101 | 1: |
| 102 | #else |
| 103 | # define ABORT_TRANSACTION |
| 104 | #endif |
| 105 | |
| 106 | #define DO_CALL(syscall) \ |
| 107 | ABORT_TRANSACTION \ |
| 108 | li 0,syscall; \ |
| 109 | sc |
| 110 | |
| 111 | #undef JUMPTARGET |
| 112 | #ifdef PIC |
| 113 | # define JUMPTARGET(name) name##@plt |
| 114 | #else |
| 115 | # define JUMPTARGET(name) name |
| 116 | #endif |
| 117 | |
| 118 | #if defined SHARED && defined PIC && !defined NO_HIDDEN |
| 119 | # undef HIDDEN_JUMPTARGET |
| 120 | # define HIDDEN_JUMPTARGET(name) __GI_##name##@local |
| 121 | #endif |
| 122 | |
| 123 | #define PSEUDO(name, syscall_name, args) \ |
| 124 | .section ".text"; \ |
| 125 | ENTRY (name) \ |
| 126 | DO_CALL (SYS_ify (syscall_name)); |
| 127 | |
| 128 | #define PSEUDO_RET \ |
| 129 | bnslr+; \ |
| 130 | b __syscall_error@local |
| 131 | #define ret PSEUDO_RET |
| 132 | |
| 133 | #undef PSEUDO_END |
| 134 | #define PSEUDO_END(name) \ |
| 135 | END (name) |
| 136 | |
| 137 | #define PSEUDO_NOERRNO(name, syscall_name, args) \ |
| 138 | .section ".text"; \ |
| 139 | ENTRY (name) \ |
| 140 | DO_CALL (SYS_ify (syscall_name)); |
| 141 | |
| 142 | #define PSEUDO_RET_NOERRNO \ |
| 143 | blr |
| 144 | #define ret_NOERRNO PSEUDO_RET_NOERRNO |
| 145 | |
| 146 | #undef PSEUDO_END_NOERRNO |
| 147 | #define PSEUDO_END_NOERRNO(name) \ |
| 148 | END (name) |
| 149 | |
| 150 | #define PSEUDO_ERRVAL(name, syscall_name, args) \ |
| 151 | .section ".text"; \ |
| 152 | ENTRY (name) \ |
| 153 | DO_CALL (SYS_ify (syscall_name)); |
| 154 | |
| 155 | #define PSEUDO_RET_ERRVAL \ |
| 156 | blr |
| 157 | #define ret_ERRVAL PSEUDO_RET_ERRVAL |
| 158 | |
| 159 | #undef PSEUDO_END_ERRVAL |
| 160 | #define PSEUDO_END_ERRVAL(name) \ |
| 161 | END (name) |
| 162 | |
| 163 | /* Local labels stripped out by the linker. */ |
| 164 | #undef L |
| 165 | #define L(x) .L##x |
| 166 | |
| 167 | #define XGLUE(a,b) a##b |
| 168 | #define GLUE(a,b) XGLUE (a,b) |
| 169 | #define GENERATE_GOT_LABEL(name) GLUE (.got_label, name) |
| 170 | |
| 171 | /* Label in text section. */ |
| 172 | #define C_TEXT(name) name |
| 173 | |
| 174 | #endif /* __ASSEMBLER__ */ |