1*4882a593Smuzhiyun=============================================== 2*4882a593SmuzhiyunPower Architecture 64-bit Linux system call ABI 3*4882a593Smuzhiyun=============================================== 4*4882a593Smuzhiyun 5*4882a593Smuzhiyunsyscall 6*4882a593Smuzhiyun======= 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunInvocation 9*4882a593Smuzhiyun---------- 10*4882a593SmuzhiyunThe syscall is made with the sc instruction, and returns with execution 11*4882a593Smuzhiyuncontinuing at the instruction following the sc instruction. 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunIf PPC_FEATURE2_SCV appears in the AT_HWCAP2 ELF auxiliary vector, the 14*4882a593Smuzhiyunscv 0 instruction is an alternative that may provide better performance, 15*4882a593Smuzhiyunwith some differences to calling sequence. 16*4882a593Smuzhiyun 17*4882a593Smuzhiyunsyscall calling sequence\ [1]_ matches the Power Architecture 64-bit ELF ABI 18*4882a593Smuzhiyunspecification C function calling sequence, including register preservation 19*4882a593Smuzhiyunrules, with the following differences. 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun.. [1] Some syscalls (typically low-level management functions) may have 22*4882a593Smuzhiyun different calling sequences (e.g., rt_sigreturn). 23*4882a593Smuzhiyun 24*4882a593SmuzhiyunParameters 25*4882a593Smuzhiyun---------- 26*4882a593SmuzhiyunThe system call number is specified in r0. 27*4882a593Smuzhiyun 28*4882a593SmuzhiyunThere is a maximum of 6 integer parameters to a syscall, passed in r3-r8. 29*4882a593Smuzhiyun 30*4882a593SmuzhiyunReturn value 31*4882a593Smuzhiyun------------ 32*4882a593Smuzhiyun- For the sc instruction, both a value and an error condition are returned. 33*4882a593Smuzhiyun cr0.SO is the error condition, and r3 is the return value. When cr0.SO is 34*4882a593Smuzhiyun clear, the syscall succeeded and r3 is the return value. When cr0.SO is set, 35*4882a593Smuzhiyun the syscall failed and r3 is the error value (that normally corresponds to 36*4882a593Smuzhiyun errno). 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun- For the scv 0 instruction, the return value indicates failure if it is 39*4882a593Smuzhiyun -4095..-1 (i.e., it is >= -MAX_ERRNO (-4095) as an unsigned comparison), 40*4882a593Smuzhiyun in which case the error value is the negated return value. 41*4882a593Smuzhiyun 42*4882a593SmuzhiyunStack 43*4882a593Smuzhiyun----- 44*4882a593SmuzhiyunSystem calls do not modify the caller's stack frame. For example, the caller's 45*4882a593Smuzhiyunstack frame LR and CR save fields are not used. 46*4882a593Smuzhiyun 47*4882a593SmuzhiyunRegister preservation rules 48*4882a593Smuzhiyun--------------------------- 49*4882a593SmuzhiyunRegister preservation rules match the ELF ABI calling sequence with the 50*4882a593Smuzhiyunfollowing differences: 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun+------------------------------------------------------------------------+ 53*4882a593Smuzhiyun| For the sc instruction, differences with the ELF ABI | 54*4882a593Smuzhiyun+--------------+--------------+------------------------------------------+ 55*4882a593Smuzhiyun| r0 | Volatile | (System call number.) | 56*4882a593Smuzhiyun| rr3 | Volatile | (Parameter 1, and return value.) | 57*4882a593Smuzhiyun| rr4-r8 | Volatile | (Parameters 2-6.) | 58*4882a593Smuzhiyun| rcr0 | Volatile | (cr0.SO is the return error condition.) | 59*4882a593Smuzhiyun| rcr1, cr5-7 | Nonvolatile | | 60*4882a593Smuzhiyun| rlr | Nonvolatile | | 61*4882a593Smuzhiyun+--------------+--------------+------------------------------------------+ 62*4882a593Smuzhiyun| For the scv 0 instruction, differences with the ELF ABI | 63*4882a593Smuzhiyun+--------------+--------------+------------------------------------------+ 64*4882a593Smuzhiyun| r0 | Volatile | (System call number.) | 65*4882a593Smuzhiyun| r3 | Volatile | (Parameter 1, and return value.) | 66*4882a593Smuzhiyun| r4-r8 | Volatile | (Parameters 2-6.) | 67*4882a593Smuzhiyun+--------------+--------------+------------------------------------------+ 68*4882a593Smuzhiyun 69*4882a593SmuzhiyunAll floating point and vector data registers as well as control and status 70*4882a593Smuzhiyunregisters are nonvolatile. 71*4882a593Smuzhiyun 72*4882a593SmuzhiyunTransactional Memory 73*4882a593Smuzhiyun-------------------- 74*4882a593SmuzhiyunSyscall behavior can change if the processor is in transactional or suspended 75*4882a593Smuzhiyuntransaction state, and the syscall can affect the behavior of the transaction. 76*4882a593Smuzhiyun 77*4882a593SmuzhiyunIf the processor is in suspended state when a syscall is made, the syscall 78*4882a593Smuzhiyunwill be performed as normal, and will return as normal. The syscall will be 79*4882a593Smuzhiyunperformed in suspended state, so its side effects will be persistent according 80*4882a593Smuzhiyunto the usual transactional memory semantics. A syscall may or may not result 81*4882a593Smuzhiyunin the transaction being doomed by hardware. 82*4882a593Smuzhiyun 83*4882a593SmuzhiyunIf the processor is in transactional state when a syscall is made, then the 84*4882a593Smuzhiyunbehavior depends on the presence of PPC_FEATURE2_HTM_NOSC in the AT_HWCAP2 ELF 85*4882a593Smuzhiyunauxiliary vector. 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun- If present, which is the case for newer kernels, then the syscall will not 88*4882a593Smuzhiyun be performed and the transaction will be doomed by the kernel with the 89*4882a593Smuzhiyun failure code TM_CAUSE_SYSCALL | TM_CAUSE_PERSISTENT in the TEXASR SPR. 90*4882a593Smuzhiyun 91*4882a593Smuzhiyun- If not present (older kernels), then the kernel will suspend the 92*4882a593Smuzhiyun transactional state and the syscall will proceed as in the case of a 93*4882a593Smuzhiyun suspended state syscall, and will resume the transactional state before 94*4882a593Smuzhiyun returning to the caller. This case is not well defined or supported, so this 95*4882a593Smuzhiyun behavior should not be relied upon. 96*4882a593Smuzhiyun 97*4882a593Smuzhiyunscv 0 syscalls will always behave as PPC_FEATURE2_HTM_NOSC. 98*4882a593Smuzhiyun 99*4882a593Smuzhiyunptrace 100*4882a593Smuzhiyun------ 101*4882a593SmuzhiyunWhen ptracing system calls (PTRACE_SYSCALL), the pt_regs.trap value contains 102*4882a593Smuzhiyunthe system call type that can be used to distinguish between sc and scv 0 103*4882a593Smuzhiyunsystem calls, and the different register conventions can be accounted for. 104*4882a593Smuzhiyun 105*4882a593SmuzhiyunIf the value of (pt_regs.trap & 0xfff0) is 0xc00 then the system call was 106*4882a593Smuzhiyunperformed with the sc instruction, if it is 0x3000 then the system call was 107*4882a593Smuzhiyunperformed with the scv 0 instruction. 108*4882a593Smuzhiyun 109*4882a593Smuzhiyunvsyscall 110*4882a593Smuzhiyun======== 111*4882a593Smuzhiyun 112*4882a593Smuzhiyunvsyscall calling sequence matches the syscall calling sequence, with the 113*4882a593Smuzhiyunfollowing differences. Some vsyscalls may have different calling sequences. 114*4882a593Smuzhiyun 115*4882a593SmuzhiyunParameters and return value 116*4882a593Smuzhiyun--------------------------- 117*4882a593Smuzhiyunr0 is not used as an input. The vsyscall is selected by its address. 118*4882a593Smuzhiyun 119*4882a593SmuzhiyunStack 120*4882a593Smuzhiyun----- 121*4882a593SmuzhiyunThe vsyscall may or may not use the caller's stack frame save areas. 122*4882a593Smuzhiyun 123*4882a593SmuzhiyunRegister preservation rules 124*4882a593Smuzhiyun--------------------------- 125*4882a593Smuzhiyun 126*4882a593Smuzhiyun=========== ======== 127*4882a593Smuzhiyunr0 Volatile 128*4882a593Smuzhiyuncr1, cr5-7 Volatile 129*4882a593Smuzhiyunlr Volatile 130*4882a593Smuzhiyun=========== ======== 131*4882a593Smuzhiyun 132*4882a593SmuzhiyunInvocation 133*4882a593Smuzhiyun---------- 134*4882a593SmuzhiyunThe vsyscall is performed with a branch-with-link instruction to the vsyscall 135*4882a593Smuzhiyunfunction address. 136*4882a593Smuzhiyun 137*4882a593SmuzhiyunTransactional Memory 138*4882a593Smuzhiyun-------------------- 139*4882a593Smuzhiyunvsyscalls will run in the same transactional state as the caller. A vsyscall 140*4882a593Smuzhiyunmay or may not result in the transaction being doomed by hardware. 141