lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc. |
| 2 | This file is part of the GNU C Library. |
| 3 | Written by Jes Sorensen, <Jes.Sorensen@cern.ch>, April 1999. |
| 4 | Based on code originally written by David Mosberger-Tang |
| 5 | |
| 6 | The GNU C Library is free software; you can redistribute it and/or |
| 7 | modify it under the terms of the GNU Lesser General Public |
| 8 | License as published by the Free Software Foundation; either |
| 9 | version 2.1 of the License, or (at your option) any later version. |
| 10 | |
| 11 | The GNU C Library is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | Lesser General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU Lesser General Public |
| 17 | License along with the GNU C Library; if not, write to the Free |
| 18 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 19 | 02111-1307 USA. */ |
| 20 | |
| 21 | #ifndef _LINUX_IA64_SYSDEP_H |
| 22 | #define _LINUX_IA64_SYSDEP_H 1 |
| 23 | |
| 24 | #include <features.h> |
| 25 | #include <asm/unistd.h> |
| 26 | |
| 27 | #ifdef __ASSEMBLER__ |
| 28 | |
| 29 | /* Macros to help writing .prologue directives in assembly code. */ |
| 30 | #define ASM_UNW_PRLG_RP 0x8 |
| 31 | #define ASM_UNW_PRLG_PFS 0x4 |
| 32 | #define ASM_UNW_PRLG_PSP 0x2 |
| 33 | #define ASM_UNW_PRLG_PR 0x1 |
| 34 | #define ASM_UNW_PRLG_GRSAVE(ninputs) (32+(ninputs)) |
| 35 | |
| 36 | #ifdef __STDC__ |
| 37 | #define C_LABEL(name) name : |
| 38 | #else |
| 39 | #define C_LABEL(name) name/**/: |
| 40 | #endif |
| 41 | |
| 42 | #define CALL_MCOUNT |
| 43 | |
| 44 | #define ENTRY(name) \ |
| 45 | .text; \ |
| 46 | .align 32; \ |
| 47 | .proc C_SYMBOL_NAME(name); \ |
| 48 | .global C_SYMBOL_NAME(name); \ |
| 49 | C_LABEL(name) \ |
| 50 | CALL_MCOUNT |
| 51 | |
| 52 | #define LEAF(name) \ |
| 53 | .text; \ |
| 54 | .align 32; \ |
| 55 | .proc C_SYMBOL_NAME(name); \ |
| 56 | .global name; \ |
| 57 | C_LABEL(name) |
| 58 | |
| 59 | /* Mark the end of function SYM. */ |
| 60 | #undef END |
| 61 | #define END(sym) .endp C_SYMBOL_NAME(sym) |
| 62 | |
| 63 | /* For Linux we can use the system call table in the header file |
| 64 | /usr/include/asm/unistd.h |
| 65 | of the kernel. But these symbols do not follow the SYS_* syntax |
| 66 | so we have to redefine the `SYS_ify' macro here. */ |
| 67 | #undef SYS_ify |
| 68 | #ifdef __STDC__ |
| 69 | # define SYS_ify(syscall_name) __NR_##syscall_name |
| 70 | #else |
| 71 | # define SYS_ify(syscall_name) __NR_/**/syscall_name |
| 72 | #endif |
| 73 | |
| 74 | /* Linux uses a negative return value to indicate syscall errors, unlike |
| 75 | most Unices, which use the condition codes' carry flag. |
| 76 | |
| 77 | Since version 2.1 the return value of a system call might be negative |
| 78 | even if the call succeeded. E.g., the `lseek' system call might return |
| 79 | a large offset. Therefore we must not anymore test for < 0, but test |
| 80 | for a real error by making sure the value in %d0 is a real error |
| 81 | number. Linus said he will make sure the no syscall returns a value |
| 82 | in -1 .. -4095 as a valid result so we can savely test with -4095. */ |
| 83 | |
| 84 | /* We don't want the label for the error handler to be visible in the symbol |
| 85 | table when we define it here. */ |
| 86 | #define SYSCALL_ERROR_LABEL __syscall_error |
| 87 | |
| 88 | #undef PSEUDO |
| 89 | #define PSEUDO(name, syscall_name, args) \ |
| 90 | ENTRY(name) \ |
| 91 | DO_CALL (SYS_ify(syscall_name)); \ |
| 92 | cmp.eq p6,p0=-1,r10; \ |
| 93 | (p6) br.cond.spnt.few __syscall_error; |
| 94 | |
| 95 | #define DO_CALL_VIA_BREAK(num) \ |
| 96 | mov r15=num; \ |
| 97 | break __BREAK_SYSCALL |
| 98 | |
| 99 | #ifdef IA64_USE_NEW_STUB |
| 100 | # ifdef SHARED |
| 101 | # define DO_CALL(num) \ |
| 102 | .prologue; \ |
| 103 | adds r2 = SYSINFO_OFFSET, r13;; \ |
| 104 | ld8 r2 = [r2]; \ |
| 105 | .save ar.pfs, r11; \ |
| 106 | mov r11 = ar.pfs;; \ |
| 107 | .body; \ |
| 108 | mov r15 = num; \ |
| 109 | mov b7 = r2; \ |
| 110 | br.call.sptk.many b6 = b7;; \ |
| 111 | .restore sp; \ |
| 112 | mov ar.pfs = r11; \ |
| 113 | .prologue; \ |
| 114 | .body |
| 115 | # else /* !SHARED */ |
| 116 | # define DO_CALL(num) \ |
| 117 | .prologue; \ |
| 118 | mov r15 = num; \ |
| 119 | movl r2 = _dl_sysinfo;; \ |
| 120 | ld8 r2 = [r2]; \ |
| 121 | .save ar.pfs, r11; \ |
| 122 | mov r11 = ar.pfs;; \ |
| 123 | .body; \ |
| 124 | mov b7 = r2; \ |
| 125 | br.call.sptk.many b6 = b7;; \ |
| 126 | .restore sp; \ |
| 127 | mov ar.pfs = r11; \ |
| 128 | .prologue; \ |
| 129 | .body |
| 130 | # endif |
| 131 | #else |
| 132 | # define DO_CALL(num) DO_CALL_VIA_BREAK(num) |
| 133 | #endif |
| 134 | |
| 135 | #undef PSEUDO_END |
| 136 | #define PSEUDO_END(name) .endp C_SYMBOL_NAME(name); |
| 137 | |
| 138 | #undef PSEUDO_NOERRNO |
| 139 | #define PSEUDO_NOERRNO(name, syscall_name, args) \ |
| 140 | ENTRY(name) \ |
| 141 | DO_CALL (SYS_ify(syscall_name)); |
| 142 | |
| 143 | #undef PSEUDO_END_NOERRNO |
| 144 | #define PSEUDO_END_NOERRNO(name) .endp C_SYMBOL_NAME(name); |
| 145 | |
| 146 | #undef PSEUDO_ERRVAL |
| 147 | #define PSEUDO_ERRVAL(name, syscall_name, args) \ |
| 148 | ENTRY(name) \ |
| 149 | DO_CALL (SYS_ify(syscall_name)); \ |
| 150 | cmp.eq p6,p0=-1,r10; \ |
| 151 | (p6) mov r10=r8; |
| 152 | |
| 153 | |
| 154 | #undef PSEUDO_END_ERRVAL |
| 155 | #define PSEUDO_END_ERRVAL(name) .endp C_SYMBOL_NAME(name); |
| 156 | |
| 157 | #undef END |
| 158 | #define END(name) \ |
| 159 | .size C_SYMBOL_NAME(name), . - C_SYMBOL_NAME(name) ; \ |
| 160 | .endp C_SYMBOL_NAME(name) |
| 161 | |
| 162 | #define ret br.ret.sptk.few b0 |
| 163 | #define ret_NOERRNO ret |
| 164 | #define ret_ERRVAL ret |
| 165 | |
| 166 | #endif /* not __ASSEMBLER__ */ |
| 167 | |
| 168 | #endif /* linux/ia64/sysdep.h */ |