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.
51 * 64-bit system call stack frame layout defines and helpers, for
52 * assembly code (note that the seemingly unnecessary parentheses
53 * are to prevent cpp from inserting spaces in expressions that get
64 /* arguments: interrupts/non tracing syscalls only save up to here: */
74 #define ORIG_RAX (120) /* + error_code */
75 /* end of arguments */
77 /* cpu exception frame or undefined in case of fast syscall: */
85 #define SWFRAME ORIG_RAX
87 .macro SAVE_ARGS addskip
=0, norcx
=0, nor891011
=0
88 subq $
9*8+\addskip
, %rsp
89 CFI_ADJUST_CFA_OFFSET
9*8+\addskip
91 CFI_REL_OFFSET rdi
, 8*8
93 CFI_REL_OFFSET rsi
, 7*8
95 CFI_REL_OFFSET rdx
, 6*8
99 CFI_REL_OFFSET rcx
, 5*8
102 CFI_REL_OFFSET rax
, 4*8
106 CFI_REL_OFFSET r8
, 3*8
108 CFI_REL_OFFSET r9
, 2*8
110 CFI_REL_OFFSET r10
, 1*8
112 CFI_REL_OFFSET r11
, 0*8
116 #define ARG_SKIP (9*8)
118 .macro RESTORE_ARGS skiprax
=0, addskip
=0, skiprcx
=0, skipr11
=0, \
119 skipr8910
=0, skiprdx
=0
153 .if ARG_SKIP
+\addskip
> 0
154 addq $ARG_SKIP
+\addskip
, %rsp
155 CFI_ADJUST_CFA_OFFSET
-(ARG_SKIP
+\addskip
)
159 .macro LOAD_ARGS offset
, skiprax
=0
160 movq \
offset(%rsp
), %r11
161 movq \offset
+8(%rsp
), %r10
162 movq \offset
+16(%rsp
), %r9
163 movq \offset
+24(%rsp
), %r8
164 movq \offset
+40(%rsp
), %rcx
165 movq \offset
+48(%rsp
), %rdx
166 movq \offset
+56(%rsp
), %rsi
167 movq \offset
+64(%rsp
), %rdi
170 movq \offset
+72(%rsp
), %rax
174 #define REST_SKIP (6*8)
177 subq $REST_SKIP
, %rsp
178 CFI_ADJUST_CFA_OFFSET REST_SKIP
180 CFI_REL_OFFSET rbx
, 5*8
182 CFI_REL_OFFSET rbp
, 4*8
184 CFI_REL_OFFSET r12
, 3*8
186 CFI_REL_OFFSET r13
, 2*8
188 CFI_REL_OFFSET r14
, 1*8
190 CFI_REL_OFFSET r15
, 0*8
206 addq $REST_SKIP
, %rsp
207 CFI_ADJUST_CFA_OFFSET
-(REST_SKIP
)
215 .macro RESTORE_ALL addskip
=0
217 RESTORE_ARGS
0, \addskip