syscall64-abi.rst 6.4 KB

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