sched, x86: Optimize the preempt_schedule() call
[deliverable/linux.git] / arch / x86 / include / asm / calling.h
CommitLineData
0c2bd5a5 1/*
063f8913
IM
2
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
a1ce3928 49#include <asm/dwarf2.h>
063f8913 50
1a338ac3
PZ
51#ifdef CONFIG_X86_64
52
063f8913 53/*
1b2b23d8
TG
54 * 64-bit system call stack frame layout defines and helpers,
55 * for assembly code:
0c2bd5a5 56 */
1da177e4 57
1b2b23d8
TG
58#define R15 0
59#define R14 8
60#define R13 16
61#define R12 24
62#define RBP 32
63#define RBX 40
1da177e4 64
063f8913 65/* arguments: interrupts/non tracing syscalls only save up to here: */
1b2b23d8
TG
66#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 */
0c2bd5a5
IM
76/* end of arguments */
77
063f8913 78/* cpu exception frame or undefined in case of fast syscall: */
1b2b23d8
TG
79#define RIP 128
80#define CS 136
81#define EFLAGS 144
82#define RSP 152
83#define SS 160
0c2bd5a5
IM
84
85#define ARGOFFSET R11
86#define SWFRAME ORIG_RAX
1da177e4 87
cac0e0a7 88 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
0c2bd5a5 89 subq $9*8+\addskip, %rsp
1da177e4 90 CFI_ADJUST_CFA_OFFSET 9*8+\addskip
a268fcfa
BP
91 movq_cfi rdi, 8*8
92 movq_cfi rsi, 7*8
93 movq_cfi rdx, 6*8
94
cac0e0a7 95 .if \save_rcx
a268fcfa 96 movq_cfi rcx, 5*8
1da177e4 97 .endif
a268fcfa
BP
98
99 movq_cfi rax, 4*8
100
cac0e0a7 101 .if \save_r891011
a268fcfa
BP
102 movq_cfi r8, 3*8
103 movq_cfi r9, 2*8
104 movq_cfi r10, 1*8
105 movq_cfi r11, 0*8
1da177e4 106 .endif
a268fcfa 107
1da177e4
LT
108 .endm
109
3234282f 110#define ARG_SKIP (9*8)
0c2bd5a5 111
838feb47
BP
112 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
113 rstor_r8910=1, rstor_rdx=1
114 .if \rstor_r11
a268fcfa 115 movq_cfi_restore 0*8, r11
1da177e4 116 .endif
a268fcfa 117
838feb47 118 .if \rstor_r8910
a268fcfa
BP
119 movq_cfi_restore 1*8, r10
120 movq_cfi_restore 2*8, r9
121 movq_cfi_restore 3*8, r8
1da177e4 122 .endif
a268fcfa 123
838feb47 124 .if \rstor_rax
a268fcfa 125 movq_cfi_restore 4*8, rax
1da177e4 126 .endif
a268fcfa 127
838feb47 128 .if \rstor_rcx
a268fcfa 129 movq_cfi_restore 5*8, rcx
1da177e4 130 .endif
a268fcfa 131
838feb47 132 .if \rstor_rdx
a268fcfa 133 movq_cfi_restore 6*8, rdx
1da177e4 134 .endif
a268fcfa
BP
135
136 movq_cfi_restore 7*8, rsi
137 movq_cfi_restore 8*8, rdi
138
1da177e4 139 .if ARG_SKIP+\addskip > 0
0c2bd5a5 140 addq $ARG_SKIP+\addskip, %rsp
1da177e4
LT
141 CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
142 .endif
0c2bd5a5 143 .endm
1da177e4 144
d4d67150 145 .macro LOAD_ARGS offset, skiprax=0
0c2bd5a5
IM
146 movq \offset(%rsp), %r11
147 movq \offset+8(%rsp), %r10
148 movq \offset+16(%rsp), %r9
149 movq \offset+24(%rsp), %r8
150 movq \offset+40(%rsp), %rcx
151 movq \offset+48(%rsp), %rdx
152 movq \offset+56(%rsp), %rsi
153 movq \offset+64(%rsp), %rdi
d4d67150
RM
154 .if \skiprax
155 .else
0c2bd5a5 156 movq \offset+72(%rsp), %rax
d4d67150 157 .endif
1da177e4 158 .endm
0c2bd5a5 159
3234282f 160#define REST_SKIP (6*8)
0c2bd5a5 161
1da177e4 162 .macro SAVE_REST
0c2bd5a5 163 subq $REST_SKIP, %rsp
1da177e4 164 CFI_ADJUST_CFA_OFFSET REST_SKIP
a268fcfa
BP
165 movq_cfi rbx, 5*8
166 movq_cfi rbp, 4*8
167 movq_cfi r12, 3*8
168 movq_cfi r13, 2*8
169 movq_cfi r14, 1*8
170 movq_cfi r15, 0*8
0c2bd5a5 171 .endm
1da177e4
LT
172
173 .macro RESTORE_REST
a268fcfa
BP
174 movq_cfi_restore 0*8, r15
175 movq_cfi_restore 1*8, r14
176 movq_cfi_restore 2*8, r13
177 movq_cfi_restore 3*8, r12
178 movq_cfi_restore 4*8, rbp
179 movq_cfi_restore 5*8, rbx
0c2bd5a5 180 addq $REST_SKIP, %rsp
1da177e4
LT
181 CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
182 .endm
0c2bd5a5 183
1da177e4
LT
184 .macro SAVE_ALL
185 SAVE_ARGS
186 SAVE_REST
187 .endm
0c2bd5a5 188
1da177e4
LT
189 .macro RESTORE_ALL addskip=0
190 RESTORE_REST
838feb47 191 RESTORE_ARGS 1, \addskip
1da177e4
LT
192 .endm
193
194 .macro icebp
195 .byte 0xf1
196 .endm
1a338ac3
PZ
197
198#else /* CONFIG_X86_64 */
199
200/*
201 * For 32bit only simplified versions of SAVE_ALL/RESTORE_ALL. These
202 * are different from the entry_32.S versions in not changing the segment
203 * registers. So only suitable for in kernel use, not when transitioning
204 * from or to user space. The resulting stack frame is not a standard
205 * pt_regs frame. The main use case is calling C code from assembler
206 * when all the registers need to be preserved.
207 */
208
209 .macro SAVE_ALL
210 pushl_cfi %eax
211 CFI_REL_OFFSET eax, 0
212 pushl_cfi %ebp
213 CFI_REL_OFFSET ebp, 0
214 pushl_cfi %edi
215 CFI_REL_OFFSET edi, 0
216 pushl_cfi %esi
217 CFI_REL_OFFSET esi, 0
218 pushl_cfi %edx
219 CFI_REL_OFFSET edx, 0
220 pushl_cfi %ecx
221 CFI_REL_OFFSET ecx, 0
222 pushl_cfi %ebx
223 CFI_REL_OFFSET ebx, 0
224 .endm
225
226 .macro RESTORE_ALL
227 popl_cfi %ebx
228 CFI_RESTORE ebx
229 popl_cfi %ecx
230 CFI_RESTORE ecx
231 popl_cfi %edx
232 CFI_RESTORE edx
233 popl_cfi %esi
234 CFI_RESTORE esi
235 popl_cfi %edi
236 CFI_RESTORE edi
237 popl_cfi %ebp
238 CFI_RESTORE ebp
239 popl_cfi %eax
240 CFI_RESTORE eax
241 .endm
242
243#endif /* CONFIG_X86_64 */
244
This page took 0.981416 seconds and 5 git commands to generate.