18c2ecf20Sopenharmony_ci=============================================== 28c2ecf20Sopenharmony_ciPower Architecture 64-bit Linux system call ABI 38c2ecf20Sopenharmony_ci=============================================== 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_cisyscall 68c2ecf20Sopenharmony_ci======= 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ciInvocation 98c2ecf20Sopenharmony_ci---------- 108c2ecf20Sopenharmony_ciThe syscall is made with the sc instruction, and returns with execution 118c2ecf20Sopenharmony_cicontinuing at the instruction following the sc instruction. 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciIf PPC_FEATURE2_SCV appears in the AT_HWCAP2 ELF auxiliary vector, the 148c2ecf20Sopenharmony_ciscv 0 instruction is an alternative that may provide better performance, 158c2ecf20Sopenharmony_ciwith some differences to calling sequence. 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_cisyscall calling sequence\ [1]_ matches the Power Architecture 64-bit ELF ABI 188c2ecf20Sopenharmony_cispecification C function calling sequence, including register preservation 198c2ecf20Sopenharmony_cirules, with the following differences. 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci.. [1] Some syscalls (typically low-level management functions) may have 228c2ecf20Sopenharmony_ci different calling sequences (e.g., rt_sigreturn). 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ciParameters 258c2ecf20Sopenharmony_ci---------- 268c2ecf20Sopenharmony_ciThe system call number is specified in r0. 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ciThere is a maximum of 6 integer parameters to a syscall, passed in r3-r8. 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ciReturn value 318c2ecf20Sopenharmony_ci------------ 328c2ecf20Sopenharmony_ci- For the sc instruction, both a value and an error condition are returned. 338c2ecf20Sopenharmony_ci cr0.SO is the error condition, and r3 is the return value. When cr0.SO is 348c2ecf20Sopenharmony_ci clear, the syscall succeeded and r3 is the return value. When cr0.SO is set, 358c2ecf20Sopenharmony_ci the syscall failed and r3 is the error value (that normally corresponds to 368c2ecf20Sopenharmony_ci errno). 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci- For the scv 0 instruction, the return value indicates failure if it is 398c2ecf20Sopenharmony_ci -4095..-1 (i.e., it is >= -MAX_ERRNO (-4095) as an unsigned comparison), 408c2ecf20Sopenharmony_ci in which case the error value is the negated return value. 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ciStack 438c2ecf20Sopenharmony_ci----- 448c2ecf20Sopenharmony_ciSystem calls do not modify the caller's stack frame. For example, the caller's 458c2ecf20Sopenharmony_cistack frame LR and CR save fields are not used. 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ciRegister preservation rules 488c2ecf20Sopenharmony_ci--------------------------- 498c2ecf20Sopenharmony_ciRegister preservation rules match the ELF ABI calling sequence with the 508c2ecf20Sopenharmony_cifollowing differences: 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci+------------------------------------------------------------------------+ 538c2ecf20Sopenharmony_ci| For the sc instruction, differences with the ELF ABI | 548c2ecf20Sopenharmony_ci+--------------+--------------+------------------------------------------+ 558c2ecf20Sopenharmony_ci| r0 | Volatile | (System call number.) | 568c2ecf20Sopenharmony_ci| rr3 | Volatile | (Parameter 1, and return value.) | 578c2ecf20Sopenharmony_ci| rr4-r8 | Volatile | (Parameters 2-6.) | 588c2ecf20Sopenharmony_ci| rcr0 | Volatile | (cr0.SO is the return error condition.) | 598c2ecf20Sopenharmony_ci| rcr1, cr5-7 | Nonvolatile | | 608c2ecf20Sopenharmony_ci| rlr | Nonvolatile | | 618c2ecf20Sopenharmony_ci+--------------+--------------+------------------------------------------+ 628c2ecf20Sopenharmony_ci| For the scv 0 instruction, differences with the ELF ABI | 638c2ecf20Sopenharmony_ci+--------------+--------------+------------------------------------------+ 648c2ecf20Sopenharmony_ci| r0 | Volatile | (System call number.) | 658c2ecf20Sopenharmony_ci| r3 | Volatile | (Parameter 1, and return value.) | 668c2ecf20Sopenharmony_ci| r4-r8 | Volatile | (Parameters 2-6.) | 678c2ecf20Sopenharmony_ci+--------------+--------------+------------------------------------------+ 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ciAll floating point and vector data registers as well as control and status 708c2ecf20Sopenharmony_ciregisters are nonvolatile. 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ciTransactional Memory 738c2ecf20Sopenharmony_ci-------------------- 748c2ecf20Sopenharmony_ciSyscall behavior can change if the processor is in transactional or suspended 758c2ecf20Sopenharmony_citransaction state, and the syscall can affect the behavior of the transaction. 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ciIf the processor is in suspended state when a syscall is made, the syscall 788c2ecf20Sopenharmony_ciwill be performed as normal, and will return as normal. The syscall will be 798c2ecf20Sopenharmony_ciperformed in suspended state, so its side effects will be persistent according 808c2ecf20Sopenharmony_cito the usual transactional memory semantics. A syscall may or may not result 818c2ecf20Sopenharmony_ciin the transaction being doomed by hardware. 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ciIf the processor is in transactional state when a syscall is made, then the 848c2ecf20Sopenharmony_cibehavior depends on the presence of PPC_FEATURE2_HTM_NOSC in the AT_HWCAP2 ELF 858c2ecf20Sopenharmony_ciauxiliary vector. 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci- If present, which is the case for newer kernels, then the syscall will not 888c2ecf20Sopenharmony_ci be performed and the transaction will be doomed by the kernel with the 898c2ecf20Sopenharmony_ci failure code TM_CAUSE_SYSCALL | TM_CAUSE_PERSISTENT in the TEXASR SPR. 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci- If not present (older kernels), then the kernel will suspend the 928c2ecf20Sopenharmony_ci transactional state and the syscall will proceed as in the case of a 938c2ecf20Sopenharmony_ci suspended state syscall, and will resume the transactional state before 948c2ecf20Sopenharmony_ci returning to the caller. This case is not well defined or supported, so this 958c2ecf20Sopenharmony_ci behavior should not be relied upon. 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ciscv 0 syscalls will always behave as PPC_FEATURE2_HTM_NOSC. 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ciptrace 1008c2ecf20Sopenharmony_ci------ 1018c2ecf20Sopenharmony_ciWhen ptracing system calls (PTRACE_SYSCALL), the pt_regs.trap value contains 1028c2ecf20Sopenharmony_cithe system call type that can be used to distinguish between sc and scv 0 1038c2ecf20Sopenharmony_cisystem calls, and the different register conventions can be accounted for. 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ciIf the value of (pt_regs.trap & 0xfff0) is 0xc00 then the system call was 1068c2ecf20Sopenharmony_ciperformed with the sc instruction, if it is 0x3000 then the system call was 1078c2ecf20Sopenharmony_ciperformed with the scv 0 instruction. 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_civsyscall 1108c2ecf20Sopenharmony_ci======== 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_civsyscall calling sequence matches the syscall calling sequence, with the 1138c2ecf20Sopenharmony_cifollowing differences. Some vsyscalls may have different calling sequences. 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ciParameters and return value 1168c2ecf20Sopenharmony_ci--------------------------- 1178c2ecf20Sopenharmony_cir0 is not used as an input. The vsyscall is selected by its address. 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ciStack 1208c2ecf20Sopenharmony_ci----- 1218c2ecf20Sopenharmony_ciThe vsyscall may or may not use the caller's stack frame save areas. 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ciRegister preservation rules 1248c2ecf20Sopenharmony_ci--------------------------- 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci=========== ======== 1278c2ecf20Sopenharmony_cir0 Volatile 1288c2ecf20Sopenharmony_cicr1, cr5-7 Volatile 1298c2ecf20Sopenharmony_cilr Volatile 1308c2ecf20Sopenharmony_ci=========== ======== 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ciInvocation 1338c2ecf20Sopenharmony_ci---------- 1348c2ecf20Sopenharmony_ciThe vsyscall is performed with a branch-with-link instruction to the vsyscall 1358c2ecf20Sopenharmony_cifunction address. 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ciTransactional Memory 1388c2ecf20Sopenharmony_ci-------------------- 1398c2ecf20Sopenharmony_civsyscalls will run in the same transactional state as the caller. A vsyscall 1408c2ecf20Sopenharmony_cimay or may not result in the transaction being doomed by hardware. 141