3 x86 function call convention, 64-bit:
4 -------------------------------------
5 arguments | callee-saved | extra caller-saved | return
6 [callee-clobbered] | | [callee-clobbered] |
7 ---------------------------------------------------------------------------
8 rdi rsi rdx rcx r8-9 | rbx rbp [*] r12-15 | r10-11 | rax, rdx [**]
10 ( rsp is obviously invariant across normal function calls. (gcc can 'merge'
11 functions when it sees tail-call optimization possibilities) rflags is
12 clobbered. Leftover arguments are passed over the stack frame.)
14 [*] In the frame-pointers case rbp is fixed to the stack frame.
16 [**] for struct return values wider than 64 bits the return convention is a
17 bit more complex: up to 128 bits width we return small structures
18 straight in rax, rdx. For structures larger than that (3 words or
19 larger) the caller puts a pointer to an on-stack return struct
20 [allocated in the caller's stack frame] into the first argument - i.e.
21 into rdi. All other arguments shift up by one in this case.
22 Fortunately this case is rare in the kernel.
24 For 32-bit we have the following conventions - kernel is built with
25 -mregparm=3 and -freg-struct-return:
27 x86 function calling convention, 32-bit:
28 ----------------------------------------
29 arguments | callee-saved | extra caller-saved | return
30 [callee-clobbered] | | [callee-clobbered] |
31 -------------------------------------------------------------------------
32 eax edx ecx | ebx edi esi ebp [*] | <none> | eax, edx [**]
34 ( here too esp is obviously invariant across normal function calls. eflags
35 is clobbered. Leftover arguments are passed over the stack frame. )
37 [*] In the frame-pointers case ebp is fixed to the stack frame.
39 [**] We build with -freg-struct-return, which on 32-bit means similar
40 semantics as on 64-bit: edx can be used for a second return value
41 (i.e. covering integer and structure sizes up to 64 bits) - after that
42 it gets more complex and more expensive: 3-word or larger struct returns
43 get done in the caller's frame and the pointer to the return struct goes
44 into regparm0, i.e. eax - the other arguments shift up and the
45 function's register parameters degenerate to regparm=2 in essence.
49 #include <asm/dwarf2.h>
54 * 64-bit system call stack frame layout defines and helpers,
65 /* arguments: interrupts/non tracing syscalls only save up to here: */
75 #define ORIG_RAX 120 /* + error_code */
76 /* end of arguments */
78 /* cpu exception frame or undefined in case of fast syscall: */
87 .macro SAVE_ARGS addskip
=0, save_rcx
=1, save_r891011
=1, rax_enosys
=0
88 subq $ORIG_RAX
-ARGOFFSET
+\addskip
, %rsp
89 CFI_ADJUST_CFA_OFFSET ORIG_RAX
-ARGOFFSET
+\addskip
99 movq $
-ENOSYS
, RAX(%rsp
)
111 #ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
117 #define ARG_SKIP ORIG_RAX
119 .macro RESTORE_ARGS rstor_rax
=1, addskip
=0, rstor_rcx
=1, rstor_r11
=1, \
120 rstor_r8910
=1, rstor_rdx
=1
122 #ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
123 movq_cfi_restore R12
, r12
127 movq_cfi_restore R11
, r11
131 movq_cfi_restore R10
, r10
132 movq_cfi_restore R9
, r9
133 movq_cfi_restore R8
, r8
137 movq_cfi_restore RAX
, rax
141 movq_cfi_restore RCX
, rcx
145 movq_cfi_restore RDX
, rdx
148 movq_cfi_restore RSI
, rsi
149 movq_cfi_restore RDI
, rdi
151 .if ORIG_RAX
+\addskip
> 0
152 addq $ORIG_RAX
+\addskip
, %rsp
153 CFI_ADJUST_CFA_OFFSET
-(ORIG_RAX
+\addskip
)
157 .macro LOAD_ARGS skiprax
=0
168 movq
ORIG_RAX(%rsp
), %rax
176 #ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
186 movq_cfi_restore R15
, r15
187 movq_cfi_restore R14
, r14
188 movq_cfi_restore R13
, r13
190 #ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
191 movq_cfi_restore R12
, r12
194 movq_cfi_restore RBP
, rbp
195 movq_cfi_restore RBX
, rbx
203 .macro RESTORE_ALL addskip
=0
205 RESTORE_ARGS
1, \addskip
212 #else /* CONFIG_X86_64 */
215 * For 32bit only simplified versions of SAVE_ALL/RESTORE_ALL. These
216 * are different from the entry_32.S versions in not changing the segment
217 * registers. So only suitable for in kernel use, not when transitioning
218 * from or to user space. The resulting stack frame is not a standard
219 * pt_regs frame. The main use case is calling C code from assembler
220 * when all the registers need to be preserved.
225 CFI_REL_OFFSET eax
, 0
227 CFI_REL_OFFSET ebp
, 0
229 CFI_REL_OFFSET edi
, 0
231 CFI_REL_OFFSET esi
, 0
233 CFI_REL_OFFSET edx
, 0
235 CFI_REL_OFFSET ecx
, 0
237 CFI_REL_OFFSET ebx
, 0
257 #endif /* CONFIG_X86_64 */