blob: b0b7d90d3054eb7c766c75714c9338aa24387a72 [file] [log] [blame]
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +01001/*
Ingo Molnar063f8912009-02-03 18:02:36 +01002
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 [**]
9
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.)
13
14 [*] In the frame-pointers case rbp is fixed to the stack frame.
15
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.
23
24For 32-bit we have the following conventions - kernel is built with
25-mregparm=3 and -freg-struct-return:
26
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 [**]
33
34 ( here too esp is obviously invariant across normal function calls. eflags
35 is clobbered. Leftover arguments are passed over the stack frame. )
36
37 [*] In the frame-pointers case ebp is fixed to the stack frame.
38
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.
46
47*/
48
Borislav Petkova268fcf2011-05-31 22:21:51 +020049#include "dwarf2.h"
Ingo Molnar063f8912009-02-03 18:02:36 +010050
51/*
Jan Beulich32342822010-10-19 14:52:26 +010052 * 64-bit system call stack frame layout defines and helpers, for
53 * assembly code (note that the seemingly unnecessary parentheses
54 * are to prevent cpp from inserting spaces in expressions that get
55 * passed to macros):
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +010056 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Jan Beulich32342822010-10-19 14:52:26 +010058#define R15 (0)
59#define R14 (8)
60#define R13 (16)
61#define R12 (24)
62#define RBP (32)
63#define RBX (40)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Ingo Molnar063f8912009-02-03 18:02:36 +010065/* arguments: interrupts/non tracing syscalls only save up to here: */
Jan Beulich32342822010-10-19 14:52:26 +010066#define R11 (48)
67#define R10 (56)
68#define R9 (64)
69#define R8 (72)
70#define RAX (80)
71#define RCX (88)
72#define RDX (96)
73#define RSI (104)
74#define RDI (112)
75#define ORIG_RAX (120) /* + error_code */
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +010076/* end of arguments */
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Ingo Molnar063f8912009-02-03 18:02:36 +010078/* cpu exception frame or undefined in case of fast syscall: */
Jan Beulich32342822010-10-19 14:52:26 +010079#define RIP (128)
80#define CS (136)
81#define EFLAGS (144)
82#define RSP (152)
83#define SS (160)
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +010084
85#define ARGOFFSET R11
86#define SWFRAME ORIG_RAX
87
Borislav Petkovcac0e0a2011-05-31 22:21:52 +020088 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +010089 subq $9*8+\addskip, %rsp
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 CFI_ADJUST_CFA_OFFSET 9*8+\addskip
Borislav Petkova268fcf2011-05-31 22:21:51 +020091 movq_cfi rdi, 8*8
92 movq_cfi rsi, 7*8
93 movq_cfi rdx, 6*8
94
Borislav Petkovcac0e0a2011-05-31 22:21:52 +020095 .if \save_rcx
Borislav Petkova268fcf2011-05-31 22:21:51 +020096 movq_cfi rcx, 5*8
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 .endif
Borislav Petkova268fcf2011-05-31 22:21:51 +020098
99 movq_cfi rax, 4*8
100
Borislav Petkovcac0e0a2011-05-31 22:21:52 +0200101 .if \save_r891011
Borislav Petkova268fcf2011-05-31 22:21:51 +0200102 movq_cfi r8, 3*8
103 movq_cfi r9, 2*8
104 movq_cfi r10, 1*8
105 movq_cfi r11, 0*8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 .endif
Borislav Petkova268fcf2011-05-31 22:21:51 +0200107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 .endm
109
Jan Beulich32342822010-10-19 14:52:26 +0100110#define ARG_SKIP (9*8)
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +0100111
112 .macro RESTORE_ARGS skiprax=0, addskip=0, skiprcx=0, skipr11=0, \
113 skipr8910=0, skiprdx=0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 .if \skipr11
115 .else
Borislav Petkova268fcf2011-05-31 22:21:51 +0200116 movq_cfi_restore 0*8, r11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 .endif
Borislav Petkova268fcf2011-05-31 22:21:51 +0200118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 .if \skipr8910
120 .else
Borislav Petkova268fcf2011-05-31 22:21:51 +0200121 movq_cfi_restore 1*8, r10
122 movq_cfi_restore 2*8, r9
123 movq_cfi_restore 3*8, r8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 .endif
Borislav Petkova268fcf2011-05-31 22:21:51 +0200125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 .if \skiprax
127 .else
Borislav Petkova268fcf2011-05-31 22:21:51 +0200128 movq_cfi_restore 4*8, rax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 .endif
Borislav Petkova268fcf2011-05-31 22:21:51 +0200130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 .if \skiprcx
132 .else
Borislav Petkova268fcf2011-05-31 22:21:51 +0200133 movq_cfi_restore 5*8, rcx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 .endif
Borislav Petkova268fcf2011-05-31 22:21:51 +0200135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 .if \skiprdx
137 .else
Borislav Petkova268fcf2011-05-31 22:21:51 +0200138 movq_cfi_restore 6*8, rdx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 .endif
Borislav Petkova268fcf2011-05-31 22:21:51 +0200140
141 movq_cfi_restore 7*8, rsi
142 movq_cfi_restore 8*8, rdi
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 .if ARG_SKIP+\addskip > 0
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +0100145 addq $ARG_SKIP+\addskip, %rsp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
147 .endif
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +0100148 .endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Roland McGrathd4d67152008-07-09 02:38:07 -0700150 .macro LOAD_ARGS offset, skiprax=0
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +0100151 movq \offset(%rsp), %r11
152 movq \offset+8(%rsp), %r10
153 movq \offset+16(%rsp), %r9
154 movq \offset+24(%rsp), %r8
155 movq \offset+40(%rsp), %rcx
156 movq \offset+48(%rsp), %rdx
157 movq \offset+56(%rsp), %rsi
158 movq \offset+64(%rsp), %rdi
Roland McGrathd4d67152008-07-09 02:38:07 -0700159 .if \skiprax
160 .else
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +0100161 movq \offset+72(%rsp), %rax
Roland McGrathd4d67152008-07-09 02:38:07 -0700162 .endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 .endm
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +0100164
Jan Beulich32342822010-10-19 14:52:26 +0100165#define REST_SKIP (6*8)
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +0100166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 .macro SAVE_REST
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +0100168 subq $REST_SKIP, %rsp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 CFI_ADJUST_CFA_OFFSET REST_SKIP
Borislav Petkova268fcf2011-05-31 22:21:51 +0200170 movq_cfi rbx, 5*8
171 movq_cfi rbp, 4*8
172 movq_cfi r12, 3*8
173 movq_cfi r13, 2*8
174 movq_cfi r14, 1*8
175 movq_cfi r15, 0*8
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +0100176 .endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178 .macro RESTORE_REST
Borislav Petkova268fcf2011-05-31 22:21:51 +0200179 movq_cfi_restore 0*8, r15
180 movq_cfi_restore 1*8, r14
181 movq_cfi_restore 2*8, r13
182 movq_cfi_restore 3*8, r12
183 movq_cfi_restore 4*8, rbp
184 movq_cfi_restore 5*8, rbx
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +0100185 addq $REST_SKIP, %rsp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
187 .endm
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +0100188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 .macro SAVE_ALL
190 SAVE_ARGS
191 SAVE_REST
192 .endm
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +0100193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 .macro RESTORE_ALL addskip=0
195 RESTORE_REST
Ingo Molnar0c2bd5a2008-01-30 13:32:49 +0100196 RESTORE_ARGS 0, \addskip
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 .endm
198
199 .macro icebp
200 .byte 0xf1
201 .endm