Kyle Swenson | 8d8f654 | 2021-03-15 11:02:55 -0600 | [diff] [blame^] | 1 | #ifndef _ASM_PARISC_UNISTD_H_ |
| 2 | #define _ASM_PARISC_UNISTD_H_ |
| 3 | |
| 4 | #include <uapi/asm/unistd.h> |
| 5 | |
| 6 | #ifndef __ASSEMBLY__ |
| 7 | |
| 8 | #define SYS_ify(syscall_name) __NR_##syscall_name |
| 9 | |
| 10 | #ifndef ASM_LINE_SEP |
| 11 | # define ASM_LINE_SEP ; |
| 12 | #endif |
| 13 | |
| 14 | /* Definition taken from glibc 2.3.3 |
| 15 | * sysdeps/unix/sysv/linux/hppa/sysdep.h |
| 16 | */ |
| 17 | |
| 18 | #ifdef PIC |
| 19 | /* WARNING: CANNOT BE USED IN A NOP! */ |
| 20 | # define K_STW_ASM_PIC " copy %%r19, %%r4\n" |
| 21 | # define K_LDW_ASM_PIC " copy %%r4, %%r19\n" |
| 22 | # define K_USING_GR4 "%r4", |
| 23 | #else |
| 24 | # define K_STW_ASM_PIC " \n" |
| 25 | # define K_LDW_ASM_PIC " \n" |
| 26 | # define K_USING_GR4 |
| 27 | #endif |
| 28 | |
| 29 | /* GCC has to be warned that a syscall may clobber all the ABI |
| 30 | registers listed as "caller-saves", see page 8, Table 2 |
| 31 | in section 2.2.6 of the PA-RISC RUN-TIME architecture |
| 32 | document. However! r28 is the result and will conflict with |
| 33 | the clobber list so it is left out. Also the input arguments |
| 34 | registers r20 -> r26 will conflict with the list so they |
| 35 | are treated specially. Although r19 is clobbered by the syscall |
| 36 | we cannot say this because it would violate ABI, thus we say |
| 37 | r4 is clobbered and use that register to save/restore r19 |
| 38 | across the syscall. */ |
| 39 | |
| 40 | #define K_CALL_CLOB_REGS "%r1", "%r2", K_USING_GR4 \ |
| 41 | "%r20", "%r29", "%r31" |
| 42 | |
| 43 | #undef K_INLINE_SYSCALL |
| 44 | #define K_INLINE_SYSCALL(name, nr, args...) ({ \ |
| 45 | long __sys_res; \ |
| 46 | { \ |
| 47 | register unsigned long __res __asm__("r28"); \ |
| 48 | K_LOAD_ARGS_##nr(args) \ |
| 49 | /* FIXME: HACK stw/ldw r19 around syscall */ \ |
| 50 | __asm__ volatile( \ |
| 51 | K_STW_ASM_PIC \ |
| 52 | " ble 0x100(%%sr2, %%r0)\n" \ |
| 53 | " ldi %1, %%r20\n" \ |
| 54 | K_LDW_ASM_PIC \ |
| 55 | : "=r" (__res) \ |
| 56 | : "i" (SYS_ify(name)) K_ASM_ARGS_##nr \ |
| 57 | : "memory", K_CALL_CLOB_REGS K_CLOB_ARGS_##nr \ |
| 58 | ); \ |
| 59 | __sys_res = (long)__res; \ |
| 60 | } \ |
| 61 | if ( (unsigned long)__sys_res >= (unsigned long)-4095 ){ \ |
| 62 | errno = -__sys_res; \ |
| 63 | __sys_res = -1; \ |
| 64 | } \ |
| 65 | __sys_res; \ |
| 66 | }) |
| 67 | |
| 68 | #define K_LOAD_ARGS_0() |
| 69 | #define K_LOAD_ARGS_1(r26) \ |
| 70 | register unsigned long __r26 __asm__("r26") = (unsigned long)(r26); \ |
| 71 | K_LOAD_ARGS_0() |
| 72 | #define K_LOAD_ARGS_2(r26,r25) \ |
| 73 | register unsigned long __r25 __asm__("r25") = (unsigned long)(r25); \ |
| 74 | K_LOAD_ARGS_1(r26) |
| 75 | #define K_LOAD_ARGS_3(r26,r25,r24) \ |
| 76 | register unsigned long __r24 __asm__("r24") = (unsigned long)(r24); \ |
| 77 | K_LOAD_ARGS_2(r26,r25) |
| 78 | #define K_LOAD_ARGS_4(r26,r25,r24,r23) \ |
| 79 | register unsigned long __r23 __asm__("r23") = (unsigned long)(r23); \ |
| 80 | K_LOAD_ARGS_3(r26,r25,r24) |
| 81 | #define K_LOAD_ARGS_5(r26,r25,r24,r23,r22) \ |
| 82 | register unsigned long __r22 __asm__("r22") = (unsigned long)(r22); \ |
| 83 | K_LOAD_ARGS_4(r26,r25,r24,r23) |
| 84 | #define K_LOAD_ARGS_6(r26,r25,r24,r23,r22,r21) \ |
| 85 | register unsigned long __r21 __asm__("r21") = (unsigned long)(r21); \ |
| 86 | K_LOAD_ARGS_5(r26,r25,r24,r23,r22) |
| 87 | |
| 88 | /* Even with zero args we use r20 for the syscall number */ |
| 89 | #define K_ASM_ARGS_0 |
| 90 | #define K_ASM_ARGS_1 K_ASM_ARGS_0, "r" (__r26) |
| 91 | #define K_ASM_ARGS_2 K_ASM_ARGS_1, "r" (__r25) |
| 92 | #define K_ASM_ARGS_3 K_ASM_ARGS_2, "r" (__r24) |
| 93 | #define K_ASM_ARGS_4 K_ASM_ARGS_3, "r" (__r23) |
| 94 | #define K_ASM_ARGS_5 K_ASM_ARGS_4, "r" (__r22) |
| 95 | #define K_ASM_ARGS_6 K_ASM_ARGS_5, "r" (__r21) |
| 96 | |
| 97 | /* The registers not listed as inputs but clobbered */ |
| 98 | #define K_CLOB_ARGS_6 |
| 99 | #define K_CLOB_ARGS_5 K_CLOB_ARGS_6, "%r21" |
| 100 | #define K_CLOB_ARGS_4 K_CLOB_ARGS_5, "%r22" |
| 101 | #define K_CLOB_ARGS_3 K_CLOB_ARGS_4, "%r23" |
| 102 | #define K_CLOB_ARGS_2 K_CLOB_ARGS_3, "%r24" |
| 103 | #define K_CLOB_ARGS_1 K_CLOB_ARGS_2, "%r25" |
| 104 | #define K_CLOB_ARGS_0 K_CLOB_ARGS_1, "%r26" |
| 105 | |
| 106 | #define _syscall0(type,name) \ |
| 107 | type name(void) \ |
| 108 | { \ |
| 109 | return K_INLINE_SYSCALL(name, 0); \ |
| 110 | } |
| 111 | |
| 112 | #define _syscall1(type,name,type1,arg1) \ |
| 113 | type name(type1 arg1) \ |
| 114 | { \ |
| 115 | return K_INLINE_SYSCALL(name, 1, arg1); \ |
| 116 | } |
| 117 | |
| 118 | #define _syscall2(type,name,type1,arg1,type2,arg2) \ |
| 119 | type name(type1 arg1, type2 arg2) \ |
| 120 | { \ |
| 121 | return K_INLINE_SYSCALL(name, 2, arg1, arg2); \ |
| 122 | } |
| 123 | |
| 124 | #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ |
| 125 | type name(type1 arg1, type2 arg2, type3 arg3) \ |
| 126 | { \ |
| 127 | return K_INLINE_SYSCALL(name, 3, arg1, arg2, arg3); \ |
| 128 | } |
| 129 | |
| 130 | #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ |
| 131 | type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ |
| 132 | { \ |
| 133 | return K_INLINE_SYSCALL(name, 4, arg1, arg2, arg3, arg4); \ |
| 134 | } |
| 135 | |
| 136 | /* select takes 5 arguments */ |
| 137 | #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \ |
| 138 | type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \ |
| 139 | { \ |
| 140 | return K_INLINE_SYSCALL(name, 5, arg1, arg2, arg3, arg4, arg5); \ |
| 141 | } |
| 142 | |
| 143 | #define __ARCH_WANT_OLD_READDIR |
| 144 | #define __ARCH_WANT_STAT64 |
| 145 | #define __ARCH_WANT_SYS_ALARM |
| 146 | #define __ARCH_WANT_SYS_GETHOSTNAME |
| 147 | #define __ARCH_WANT_SYS_PAUSE |
| 148 | #define __ARCH_WANT_SYS_SIGNAL |
| 149 | #define __ARCH_WANT_SYS_TIME |
| 150 | #define __ARCH_WANT_COMPAT_SYS_TIME |
| 151 | #define __ARCH_WANT_COMPAT_SYS_SCHED_RR_GET_INTERVAL |
| 152 | #define __ARCH_WANT_SYS_UTIME |
| 153 | #define __ARCH_WANT_SYS_WAITPID |
| 154 | #define __ARCH_WANT_SYS_SOCKETCALL |
| 155 | #define __ARCH_WANT_SYS_FADVISE64 |
| 156 | #define __ARCH_WANT_SYS_GETPGRP |
| 157 | #define __ARCH_WANT_SYS_LLSEEK |
| 158 | #define __ARCH_WANT_SYS_NICE |
| 159 | #define __ARCH_WANT_SYS_OLD_GETRLIMIT |
| 160 | #define __ARCH_WANT_SYS_OLDUMOUNT |
| 161 | #define __ARCH_WANT_SYS_SIGPENDING |
| 162 | #define __ARCH_WANT_SYS_SIGPROCMASK |
| 163 | #define __ARCH_WANT_SYS_FORK |
| 164 | #define __ARCH_WANT_SYS_VFORK |
| 165 | #define __ARCH_WANT_SYS_CLONE |
| 166 | #define __ARCH_WANT_COMPAT_SYS_SENDFILE |
| 167 | |
| 168 | #endif /* __ASSEMBLY__ */ |
| 169 | |
| 170 | #undef STR |
| 171 | |
| 172 | #endif /* _ASM_PARISC_UNISTD_H_ */ |