blob: fc2c5a6c262a20356c1fc1dc5e475fa84d97189c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Some macros to handle stack frames in assembly.
3 */
4
5#include <linux/config.h>
6
7#define R15 0
8#define R14 8
9#define R13 16
10#define R12 24
11#define RBP 32
12#define RBX 40
13/* arguments: interrupts/non tracing syscalls only save upto here*/
14#define R11 48
15#define R10 56
16#define R9 64
17#define R8 72
18#define RAX 80
19#define RCX 88
20#define RDX 96
21#define RSI 104
22#define RDI 112
23#define ORIG_RAX 120 /* + error_code */
24/* end of arguments */
25/* cpu exception frame or undefined in case of fast syscall. */
26#define RIP 128
27#define CS 136
28#define EFLAGS 144
29#define RSP 152
30#define SS 160
31#define ARGOFFSET R11
32#define SWFRAME ORIG_RAX
33
34 .macro SAVE_ARGS addskip=0,norcx=0,nor891011=0
35 subq $9*8+\addskip,%rsp
36 CFI_ADJUST_CFA_OFFSET 9*8+\addskip
37 movq %rdi,8*8(%rsp)
38 CFI_REL_OFFSET rdi,8*8
39 movq %rsi,7*8(%rsp)
40 CFI_REL_OFFSET rsi,7*8
41 movq %rdx,6*8(%rsp)
42 CFI_REL_OFFSET rdx,6*8
43 .if \norcx
44 .else
45 movq %rcx,5*8(%rsp)
46 CFI_REL_OFFSET rcx,5*8
47 .endif
48 movq %rax,4*8(%rsp)
49 CFI_REL_OFFSET rax,4*8
50 .if \nor891011
51 .else
52 movq %r8,3*8(%rsp)
53 CFI_REL_OFFSET r8,3*8
54 movq %r9,2*8(%rsp)
55 CFI_REL_OFFSET r9,2*8
56 movq %r10,1*8(%rsp)
57 CFI_REL_OFFSET r10,1*8
58 movq %r11,(%rsp)
59 CFI_REL_OFFSET r11,0*8
60 .endif
61 .endm
62
63#define ARG_SKIP 9*8
64 .macro RESTORE_ARGS skiprax=0,addskip=0,skiprcx=0,skipr11=0,skipr8910=0,skiprdx=0
65 .if \skipr11
66 .else
67 movq (%rsp),%r11
Jan Beulich7effaa82005-09-12 18:49:24 +020068 CFI_RESTORE r11
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 .endif
70 .if \skipr8910
71 .else
72 movq 1*8(%rsp),%r10
Jan Beulich7effaa82005-09-12 18:49:24 +020073 CFI_RESTORE r10
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 movq 2*8(%rsp),%r9
Jan Beulich7effaa82005-09-12 18:49:24 +020075 CFI_RESTORE r9
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 movq 3*8(%rsp),%r8
Jan Beulich7effaa82005-09-12 18:49:24 +020077 CFI_RESTORE r8
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 .endif
79 .if \skiprax
80 .else
81 movq 4*8(%rsp),%rax
Jan Beulich7effaa82005-09-12 18:49:24 +020082 CFI_RESTORE rax
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 .endif
84 .if \skiprcx
85 .else
86 movq 5*8(%rsp),%rcx
Jan Beulich7effaa82005-09-12 18:49:24 +020087 CFI_RESTORE rcx
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 .endif
89 .if \skiprdx
90 .else
91 movq 6*8(%rsp),%rdx
Jan Beulich7effaa82005-09-12 18:49:24 +020092 CFI_RESTORE rdx
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 .endif
94 movq 7*8(%rsp),%rsi
Jan Beulich7effaa82005-09-12 18:49:24 +020095 CFI_RESTORE rsi
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 movq 8*8(%rsp),%rdi
Jan Beulich7effaa82005-09-12 18:49:24 +020097 CFI_RESTORE rdi
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 .if ARG_SKIP+\addskip > 0
99 addq $ARG_SKIP+\addskip,%rsp
100 CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
101 .endif
102 .endm
103
104 .macro LOAD_ARGS offset
105 movq \offset(%rsp),%r11
106 movq \offset+8(%rsp),%r10
107 movq \offset+16(%rsp),%r9
108 movq \offset+24(%rsp),%r8
109 movq \offset+40(%rsp),%rcx
110 movq \offset+48(%rsp),%rdx
111 movq \offset+56(%rsp),%rsi
112 movq \offset+64(%rsp),%rdi
113 movq \offset+72(%rsp),%rax
114 .endm
115
116#define REST_SKIP 6*8
117 .macro SAVE_REST
118 subq $REST_SKIP,%rsp
119 CFI_ADJUST_CFA_OFFSET REST_SKIP
120 movq %rbx,5*8(%rsp)
121 CFI_REL_OFFSET rbx,5*8
122 movq %rbp,4*8(%rsp)
123 CFI_REL_OFFSET rbp,4*8
124 movq %r12,3*8(%rsp)
125 CFI_REL_OFFSET r12,3*8
126 movq %r13,2*8(%rsp)
127 CFI_REL_OFFSET r13,2*8
128 movq %r14,1*8(%rsp)
129 CFI_REL_OFFSET r14,1*8
130 movq %r15,(%rsp)
131 CFI_REL_OFFSET r15,0*8
132 .endm
133
134 .macro RESTORE_REST
135 movq (%rsp),%r15
Jan Beulich7effaa82005-09-12 18:49:24 +0200136 CFI_RESTORE r15
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 movq 1*8(%rsp),%r14
Jan Beulich7effaa82005-09-12 18:49:24 +0200138 CFI_RESTORE r14
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 movq 2*8(%rsp),%r13
Jan Beulich7effaa82005-09-12 18:49:24 +0200140 CFI_RESTORE r13
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 movq 3*8(%rsp),%r12
Jan Beulich7effaa82005-09-12 18:49:24 +0200142 CFI_RESTORE r12
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 movq 4*8(%rsp),%rbp
Jan Beulich7effaa82005-09-12 18:49:24 +0200144 CFI_RESTORE rbp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 movq 5*8(%rsp),%rbx
Jan Beulich7effaa82005-09-12 18:49:24 +0200146 CFI_RESTORE rbx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 addq $REST_SKIP,%rsp
148 CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
149 .endm
150
151 .macro SAVE_ALL
152 SAVE_ARGS
153 SAVE_REST
154 .endm
155
156 .macro RESTORE_ALL addskip=0
157 RESTORE_REST
158 RESTORE_ARGS 0,\addskip
159 .endm
160
161 .macro icebp
162 .byte 0xf1
163 .endm