요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
===============================================
Power Architecture 64-bit Linux system call ABI
===============================================
syscall
=======
Invocation
----------
The syscall is made with the sc instruction, and returns with execution
continuing at the instruction following the sc instruction.
If PPC_FEATURE2_SCV appears in the AT_HWCAP2 ELF auxiliary vector, the
scv 0 instruction is an alternative that may provide better performance,
with some differences to calling sequence.
syscall calling sequence\ [1]_ matches the Power Architecture 64-bit ELF ABI
specification C function calling sequence, including register preservation
rules, with the following differences.
.. [1] Some syscalls (typically low-level management functions) may have
different calling sequences (e.g., rt_sigreturn).
Parameters
----------
The system call number is specified in r0.
There is a maximum of 6 integer parameters to a syscall, passed in r3-r8.
Return value
------------
- For the sc instruction, both a value and an error condition are returned.
cr0.SO is the error condition, and r3 is the return value. When cr0.SO is
clear, the syscall succeeded and r3 is the return value. When cr0.SO is set,
the syscall failed and r3 is the error value (that normally corresponds to
errno).
- For the scv 0 instruction, the return value indicates failure if it is
-4095..-1 (i.e., it is >= -MAX_ERRNO (-4095) as an unsigned comparison),
in which case the error value is the negated return value.
Stack
-----
System calls do not modify the caller's stack frame. For example, the caller's
stack frame LR and CR save fields are not used.
Register preservation rules
---------------------------
Register preservation rules match the ELF ABI calling sequence with some
differences.
For the sc instruction, the differences from the ELF ABI are as follows:
+--------------+--------------------+-----------------------------------------+
| Register | Preservation Rules | Purpose |
+==============+====================+=========================================+
| r0 | Volatile | (System call number.) |
+--------------+--------------------+-----------------------------------------+
| r3 | Volatile | (Parameter 1, and return value.) |
+--------------+--------------------+-----------------------------------------+
| r4-r8 | Volatile | (Parameters 2-6.) |
+--------------+--------------------+-----------------------------------------+
| cr0 | Volatile | (cr0.SO is the return error condition.) |
+--------------+--------------------+-----------------------------------------+
| cr1, cr5-7 | Nonvolatile | |
+--------------+--------------------+-----------------------------------------+
| lr | Nonvolatile | |
+--------------+--------------------+-----------------------------------------+
For the scv 0 instruction, the differences from the ELF ABI are as follows:
+--------------+--------------------+-----------------------------------------+
| Register | Preservation Rules | Purpose |
+==============+====================+=========================================+
| r0 | Volatile | (System call number.) |
+--------------+--------------------+-----------------------------------------+
| r3 | Volatile | (Parameter 1, and return value.) |
+--------------+--------------------+-----------------------------------------+
| r4-r8 | Volatile | (Parameters 2-6.) |
+--------------+--------------------+-----------------------------------------+
All floating point and vector data registers as well as control and status
registers are nonvolatile.
Transactional Memory
--------------------
Syscall behavior can change if the processor is in transactional or suspended
transaction state, and the syscall can affect the behavior of the transaction.
If the processor is in suspended state when a syscall is made, the syscall
will be performed as normal, and will return as normal. The syscall will be
performed in suspended state, so its side effects will be persistent according
to the usual transactional memory semantics. A syscall may or may not result
in the transaction being doomed by hardware.
If the processor is in transactional state when a syscall is made, then the
behavior depends on the presence of PPC_FEATURE2_HTM_NOSC in the AT_HWCAP2 ELF
auxiliary vector.
- If present, which is the case for newer kernels, then the syscall will not
be performed and the transaction will be doomed by the kernel with the
failure code TM_CAUSE_SYSCALL | TM_CAUSE_PERSISTENT in the TEXASR SPR.
- If not present (older kernels), then the kernel will suspend the
transactional state and the syscall will proceed as in the case of a
suspended state syscall, and will resume the transactional state before
returning to the caller. This case is not well defined or supported, so this
behavior should not be relied upon.
scv 0 syscalls will always behave as PPC_FEATURE2_HTM_NOSC.
ptrace
------
When ptracing system calls (PTRACE_SYSCALL), the pt_regs.trap value contains
the system call type that can be used to distinguish between sc and scv 0
system calls, and the different register conventions can be accounted for.
If the value of (pt_regs.trap & 0xfff0) is 0xc00 then the system call was
performed with the sc instruction, if it is 0x3000 then the system call was
performed with the scv 0 instruction.
vsyscall
========
vsyscall calling sequence matches the syscall calling sequence, with the
following differences. Some vsyscalls may have different calling sequences.
Parameters and return value
---------------------------
r0 is not used as an input. The vsyscall is selected by its address.
Stack
-----
The vsyscall may or may not use the caller's stack frame save areas.
Register preservation rules
---------------------------
=========== ========
r0 Volatile
cr1, cr5-7 Volatile
lr Volatile
=========== ========
Invocation
----------
The vsyscall is performed with a branch-with-link instruction to the vsyscall
function address.
Transactional Memory
--------------------
vsyscalls will run in the same transactional state as the caller. A vsyscall
may or may not result in the transaction being doomed by hardware.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Power Architecture 64-bit Linux system call ABI
1-4이 문서는 Power Architecture 64-bit Linux의 `syscall`과 `vsyscall` 호출 규약, register 보존, transactional memory 및 ptrace 식별 방식을 정의합니다.
System call invocation
5-23System call은 `sc` instruction으로 호출하며, 반환되면 `sc` 바로 다음 instruction부터 실행을 계속합니다.
`AT_HWCAP2` ELF auxiliary vector에 `PPC_FEATURE2_SCV`가 있으면 `scv 0` instruction을 대안으로 사용할 수 있습니다. 더 나은 성능을 제공할 수 있지만 calling sequence에 차이가 있습니다.
System call calling sequence는 register 보존 규칙을 포함해 Power Architecture 64-bit ELF ABI의 C function calling sequence를 따르되 아래 차이가 있습니다. `rt_sigreturn` 같은 일부 low-level management syscall은 별도 calling sequence를 사용할 수 있습니다.
HWCAP2 feature에 따라 두 instruction 중 가능한 경로를 선택합니다.
System call parameters
24-29System call number는 `r0`에 둡니다. Integer parameter는 최대 6개이며 `r3-r8`로 전달합니다.
Return value와 error
30-41`sc`는 value와 error condition을 함께 반환합니다. `cr0.SO`가 clear이면 성공이며 `r3`가 return value입니다. `cr0.SO`가 set이면 실패이며 `r3`는 보통 `errno`에 대응하는 error value입니다.
`scv 0`에서는 return value가 `-4095..-1`이면 실패입니다. Unsigned comparison으로 `>= -MAX_ERRNO (-4095)`인 경우이며 error value는 return value의 부호를 반전한 값입니다.
Caller stack frame
42-46System call은 caller의 stack frame을 변경하지 않습니다. 예를 들어 caller stack frame의 LR 및 CR save field를 사용하지 않습니다.
Register preservation rules
47-84Register 보존 규칙은 일부 차이를 제외하면 ELF ABI calling sequence와 같습니다. `sc` instruction의 차이는 다음과 같습니다.
| Register | Preservation | Purpose |
|---|---|---|
| `r0` | Volatile | System call number |
| `r3` | Volatile | Parameter 1 및 return value |
| `r4-r8` | Volatile | Parameters 2-6 |
| `cr0` | Volatile | `cr0.SO`가 return error condition |
| `cr1`, `cr5-7` | Nonvolatile | ELF ABI와 다른 보존 규칙 |
| `lr` | Nonvolatile | ELF ABI와 다른 보존 규칙 |
`scv 0` instruction에서 ELF ABI와 다른 부분은 다음과 같습니다.
| Register | Preservation | Purpose |
|---|---|---|
| `r0` | Volatile | System call number |
| `r3` | Volatile | Parameter 1 및 return value |
| `r4-r8` | Volatile | Parameters 2-6 |
모든 floating-point 및 vector data register와 control/status register는 nonvolatile입니다.
Transactional Memory에서의 syscall
85-111Processor가 transactional 또는 suspended transaction state이면 syscall 동작과 transaction 결과가 달라질 수 있습니다.
Suspended state에서 syscall하면 정상 실행하고 정상 반환합니다. Side effect는 일반 transactional memory semantics에 따라 persistent하며, hardware가 transaction을 doomed 상태로 만들 수도 있고 아닐 수도 있습니다.
Transactional state에서 syscall한 경우 `AT_HWCAP2`의 `PPC_FEATURE2_HTM_NOSC` 존재 여부에 따라 달라집니다.
- Feature가 있는 newer kernel은 syscall을 실행하지 않고 `TEXASR` SPR에 `TM_CAUSE_SYSCALL | TM_CAUSE_PERSISTENT` failure code를 기록해 transaction을 doomed 상태로 만듭니다.
- Feature가 없는 older kernel은 transactional state를 suspend하고 syscall을 수행한 뒤 caller로 돌아가기 전에 transactional state를 resume합니다. 이 동작은 명확히 정의되거나 지원되지 않으므로 의존하면 안 됩니다.
- `scv 0` syscall은 항상 `PPC_FEATURE2_HTM_NOSC`가 있는 경우처럼 동작합니다.
진입 state와 HWCAP2 feature에 따라 syscall 실행 여부와 transaction 결과가 결정됩니다.
Ptrace에서 sc/scv 식별
112-121`PTRACE_SYSCALL`로 system call을 추적할 때 `pt_regs.trap`에 system call type이 들어 있어 `sc`와 `scv 0`의 register convention 차이를 처리할 수 있습니다.
`(pt_regs.trap & 0xfff0) == 0xc00`이면 `sc`, `== 0x3000`이면 `scv 0`으로 수행한 system call입니다.
Mask를 적용한 trap 값으로 instruction 종류를 분류합니다.
Vsyscall parameters, stack와 register
122-144Vsyscall calling sequence는 아래 차이를 제외하면 syscall calling sequence와 같습니다. 일부 vsyscall은 별도 calling sequence를 사용할 수 있습니다.
`r0`는 input으로 사용하지 않습니다. 호출할 vsyscall은 function address로 선택합니다. Vsyscall은 caller stack frame의 save area를 사용할 수도 있고 사용하지 않을 수도 있습니다.
| Register | Preservation |
|---|---|
| `r0` | Volatile |
| `cr1`, `cr5-7` | Volatile |
| `lr` | Volatile |
Vsyscall invocation과 Transactional Memory
145-153Vsyscall은 vsyscall function address로 branch-with-link instruction을 실행하여 호출합니다.
Vsyscall은 caller와 같은 transactional state에서 실행됩니다. Hardware가 transaction을 doomed 상태로 만들 수도 있고 아닐 수도 있습니다.
요약과 해설
syscall64-abi.rst:1-153`sc`는 `cr0.SO`로 error를 알리고 `scv 0`은 `-4095..-1` return range로 실패를 나타냅니다. 두 경로의 register 보존과 transactional state 처리, ptrace trap 식별 규칙을 함께 봐야 정확한 ABI 구현이 됩니다.