154 lines · plain
1===============================================2Power Architecture 64-bit Linux system call ABI3===============================================4 5syscall6=======7 8Invocation9----------10The syscall is made with the sc instruction, and returns with execution11continuing at the instruction following the sc instruction.12 13If PPC_FEATURE2_SCV appears in the AT_HWCAP2 ELF auxiliary vector, the14scv 0 instruction is an alternative that may provide better performance,15with some differences to calling sequence.16 17syscall calling sequence\ [1]_ matches the Power Architecture 64-bit ELF ABI18specification C function calling sequence, including register preservation19rules, with the following differences.20 21.. [1] Some syscalls (typically low-level management functions) may have22 different calling sequences (e.g., rt_sigreturn).23 24Parameters25----------26The system call number is specified in r0.27 28There is a maximum of 6 integer parameters to a syscall, passed in r3-r8.29 30Return value31------------32- For the sc instruction, both a value and an error condition are returned.33 cr0.SO is the error condition, and r3 is the return value. When cr0.SO is34 clear, the syscall succeeded and r3 is the return value. When cr0.SO is set,35 the syscall failed and r3 is the error value (that normally corresponds to36 errno).37 38- For the scv 0 instruction, the return value indicates failure if it is39 -4095..-1 (i.e., it is >= -MAX_ERRNO (-4095) as an unsigned comparison),40 in which case the error value is the negated return value.41 42Stack43-----44System calls do not modify the caller's stack frame. For example, the caller's45stack frame LR and CR save fields are not used.46 47Register preservation rules48---------------------------49Register preservation rules match the ELF ABI calling sequence with some50differences.51 52For the sc instruction, the differences from the ELF ABI are as follows:53 54+--------------+--------------------+-----------------------------------------+55| Register | Preservation Rules | Purpose |56+==============+====================+=========================================+57| r0 | Volatile | (System call number.) |58+--------------+--------------------+-----------------------------------------+59| r3 | Volatile | (Parameter 1, and return value.) |60+--------------+--------------------+-----------------------------------------+61| r4-r8 | Volatile | (Parameters 2-6.) |62+--------------+--------------------+-----------------------------------------+63| cr0 | Volatile | (cr0.SO is the return error condition.) |64+--------------+--------------------+-----------------------------------------+65| cr1, cr5-7 | Nonvolatile | |66+--------------+--------------------+-----------------------------------------+67| lr | Nonvolatile | |68+--------------+--------------------+-----------------------------------------+69 70For the scv 0 instruction, the differences from the ELF ABI are as follows:71 72+--------------+--------------------+-----------------------------------------+73| Register | Preservation Rules | Purpose |74+==============+====================+=========================================+75| r0 | Volatile | (System call number.) |76+--------------+--------------------+-----------------------------------------+77| r3 | Volatile | (Parameter 1, and return value.) |78+--------------+--------------------+-----------------------------------------+79| r4-r8 | Volatile | (Parameters 2-6.) |80+--------------+--------------------+-----------------------------------------+81 82All floating point and vector data registers as well as control and status83registers are nonvolatile.84 85Transactional Memory86--------------------87Syscall behavior can change if the processor is in transactional or suspended88transaction state, and the syscall can affect the behavior of the transaction.89 90If the processor is in suspended state when a syscall is made, the syscall91will be performed as normal, and will return as normal. The syscall will be92performed in suspended state, so its side effects will be persistent according93to the usual transactional memory semantics. A syscall may or may not result94in the transaction being doomed by hardware.95 96If the processor is in transactional state when a syscall is made, then the97behavior depends on the presence of PPC_FEATURE2_HTM_NOSC in the AT_HWCAP2 ELF98auxiliary vector.99 100- If present, which is the case for newer kernels, then the syscall will not101 be performed and the transaction will be doomed by the kernel with the102 failure code TM_CAUSE_SYSCALL | TM_CAUSE_PERSISTENT in the TEXASR SPR.103 104- If not present (older kernels), then the kernel will suspend the105 transactional state and the syscall will proceed as in the case of a106 suspended state syscall, and will resume the transactional state before107 returning to the caller. This case is not well defined or supported, so this108 behavior should not be relied upon.109 110scv 0 syscalls will always behave as PPC_FEATURE2_HTM_NOSC.111 112ptrace113------114When ptracing system calls (PTRACE_SYSCALL), the pt_regs.trap value contains115the system call type that can be used to distinguish between sc and scv 0116system calls, and the different register conventions can be accounted for.117 118If the value of (pt_regs.trap & 0xfff0) is 0xc00 then the system call was119performed with the sc instruction, if it is 0x3000 then the system call was120performed with the scv 0 instruction.121 122vsyscall123========124 125vsyscall calling sequence matches the syscall calling sequence, with the126following differences. Some vsyscalls may have different calling sequences.127 128Parameters and return value129---------------------------130r0 is not used as an input. The vsyscall is selected by its address.131 132Stack133-----134The vsyscall may or may not use the caller's stack frame save areas.135 136Register preservation rules137---------------------------138 139=========== ========140r0 Volatile141cr1, cr5-7 Volatile142lr Volatile143=========== ========144 145Invocation146----------147The vsyscall is performed with a branch-with-link instruction to the vsyscall148function address.149 150Transactional Memory151--------------------152vsyscalls will run in the same transactional state as the caller. A vsyscall153may or may not result in the transaction being doomed by hardware.154