← Documents Documentation/arch/powerpc/syscall64-abi.rst GitHub 원문 ↗

Linux 6.18.37 · Architecture

Power Architecture 64-bit Linux system call ABI

PPC64의 sc·scv 0·vsyscall register ABI, error convention과 transactional-memory 동작입니다.

Source pathDocumentation/arch/powerpc/syscall64-abi.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

syscall64-abi.rst:1-153

`sc`는 `cr0.SO`로 error를 알리고 `scv 0`은 `-4095..-1` return range로 실패를 나타냅니다. 두 경로의 register 보존과 transactional state 처리, ptrace trap 식별 규칙을 함께 봐야 정확한 ABI 구현이 됩니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 ===============================================
2 Power Architecture 64-bit Linux system call ABI
3 ===============================================
4
5 syscall
6 =======
7
8 Invocation
9 ----------
10 The syscall is made with the sc instruction, and returns with execution
11 continuing at the instruction following the sc instruction.
12
13 If PPC_FEATURE2_SCV appears in the AT_HWCAP2 ELF auxiliary vector, the
14 scv 0 instruction is an alternative that may provide better performance,
15 with some differences to calling sequence.
16
17 syscall calling sequence\ [1]_ matches the Power Architecture 64-bit ELF ABI
18 specification C function calling sequence, including register preservation
19 rules, with the following differences.
20
21 .. [1] Some syscalls (typically low-level management functions) may have
22 different calling sequences (e.g., rt_sigreturn).
23
24 Parameters
25 ----------
26 The system call number is specified in r0.
27
28 There is a maximum of 6 integer parameters to a syscall, passed in r3-r8.
29
30 Return value
31 ------------
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 is
34 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 to
36 errno).
37
38 - For the scv 0 instruction, the return value indicates failure if it is
39 -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
42 Stack
43 -----
44 System calls do not modify the caller's stack frame. For example, the caller's
45 stack frame LR and CR save fields are not used.
46
47 Register preservation rules
48 ---------------------------
49 Register preservation rules match the ELF ABI calling sequence with some
50 differences.
51
52 For 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
70 For 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
82 All floating point and vector data registers as well as control and status
83 registers are nonvolatile.
84
85 Transactional Memory
86 --------------------
87 Syscall behavior can change if the processor is in transactional or suspended
88 transaction state, and the syscall can affect the behavior of the transaction.
89
90 If the processor is in suspended state when a syscall is made, the syscall
91 will be performed as normal, and will return as normal. The syscall will be
92 performed in suspended state, so its side effects will be persistent according
93 to the usual transactional memory semantics. A syscall may or may not result
94 in the transaction being doomed by hardware.
95
96 If the processor is in transactional state when a syscall is made, then the
97 behavior depends on the presence of PPC_FEATURE2_HTM_NOSC in the AT_HWCAP2 ELF
98 auxiliary vector.
99
100 - If present, which is the case for newer kernels, then the syscall will not
101 be performed and the transaction will be doomed by the kernel with the
102 failure code TM_CAUSE_SYSCALL | TM_CAUSE_PERSISTENT in the TEXASR SPR.
103
104 - If not present (older kernels), then the kernel will suspend the
105 transactional state and the syscall will proceed as in the case of a
106 suspended state syscall, and will resume the transactional state before
107 returning to the caller. This case is not well defined or supported, so this
108 behavior should not be relied upon.
109
110 scv 0 syscalls will always behave as PPC_FEATURE2_HTM_NOSC.
111
112 ptrace
113 ------
114 When ptracing system calls (PTRACE_SYSCALL), the pt_regs.trap value contains
115 the system call type that can be used to distinguish between sc and scv 0
116 system calls, and the different register conventions can be accounted for.
117
118 If the value of (pt_regs.trap & 0xfff0) is 0xc00 then the system call was
119 performed with the sc instruction, if it is 0x3000 then the system call was
120 performed with the scv 0 instruction.
121
122 vsyscall
123 ========
124
125 vsyscall calling sequence matches the syscall calling sequence, with the
126 following differences. Some vsyscalls may have different calling sequences.
127
128 Parameters and return value
129 ---------------------------
130 r0 is not used as an input. The vsyscall is selected by its address.
131
132 Stack
133 -----
134 The vsyscall may or may not use the caller's stack frame save areas.
135
136 Register preservation rules
137 ---------------------------
138
139 =========== ========
140 r0 Volatile
141 cr1, cr5-7 Volatile
142 lr Volatile
143 =========== ========
144
145 Invocation
146 ----------
147 The vsyscall is performed with a branch-with-link instruction to the vsyscall
148 function address.
149
150 Transactional Memory
151 --------------------
152 vsyscalls will run in the same transactional state as the caller. A vsyscall
153 may or may not result in the transaction being doomed by hardware.
154

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-23

System 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를 사용할 수 있습니다.

`sc`와 `scv 0` 진입
기본 경로`sc`다음 instruction으로 return
`PPC_FEATURE2_SCV``scv 0`별도 return/error convention

HWCAP2 feature에 따라 두 instruction 중 가능한 경로를 선택합니다.

System call parameters

24-29

System 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-46

System call은 caller의 stack frame을 변경하지 않습니다. 예를 들어 caller stack frame의 LR 및 CR save field를 사용하지 않습니다.

Register preservation rules

47-84

Register 보존 규칙은 일부 차이를 제외하면 ELF ABI calling sequence와 같습니다. `sc` instruction의 차이는 다음과 같습니다.

RegisterPreservationPurpose
`r0`VolatileSystem call number
`r3`VolatileParameter 1 및 return value
`r4-r8`VolatileParameters 2-6
`cr0`Volatile`cr0.SO`가 return error condition
`cr1`, `cr5-7`NonvolatileELF ABI와 다른 보존 규칙
`lr`NonvolatileELF ABI와 다른 보존 규칙

`scv 0` instruction에서 ELF ABI와 다른 부분은 다음과 같습니다.

RegisterPreservationPurpose
`r0`VolatileSystem call number
`r3`VolatileParameter 1 및 return value
`r4-r8`VolatileParameters 2-6

모든 floating-point 및 vector data register와 control/status register는 nonvolatile입니다.

Transactional Memory에서의 syscall

85-111

Processor가 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`가 있는 경우처럼 동작합니다.
Transactional syscall 결정
Suspended stateSyscall 실행Persistent side effects정상 return
Transactional state`PPC_FEATURE2_HTM_NOSC` 있음Syscall 미실행Transaction doomed
Transactional stateFeature 없음Suspend 후 syscallResume
`scv 0`항상 HTM_NOSC behavior

진입 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입니다.

Ptrace syscall trap 식별
ExpressionTrap valueInstruction
`pt_regs.trap & 0xfff0``0xc00``sc`
`pt_regs.trap & 0xfff0``0x3000``scv 0`

Mask를 적용한 trap 값으로 instruction 종류를 분류합니다.

Vsyscall parameters, stack와 register

122-144

Vsyscall calling sequence는 아래 차이를 제외하면 syscall calling sequence와 같습니다. 일부 vsyscall은 별도 calling sequence를 사용할 수 있습니다.

`r0`는 input으로 사용하지 않습니다. 호출할 vsyscall은 function address로 선택합니다. Vsyscall은 caller stack frame의 save area를 사용할 수도 있고 사용하지 않을 수도 있습니다.

RegisterPreservation
`r0`Volatile
`cr1`, `cr5-7`Volatile
`lr`Volatile

Vsyscall invocation과 Transactional Memory

145-153

Vsyscall은 vsyscall function address로 branch-with-link instruction을 실행하여 호출합니다.

Vsyscall은 caller와 같은 transactional state에서 실행됩니다. Hardware가 transaction을 doomed 상태로 만들 수도 있고 아닐 수도 있습니다.