blob: 6f4f63af96e1a661f215895e502155f402b40678 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Some macros to handle stack frames in assembly.
3 */
4
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
6#define R15 0
7#define R14 8
8#define R13 16
9#define R12 24
10#define RBP 32
11#define RBX 40
12/* arguments: interrupts/non tracing syscalls only save upto here*/
13#define R11 48
14#define R10 56
15#define R9 64
16#define R8 72
17#define RAX 80
18#define RCX 88
19#define RDX 96
20#define RSI 104
21#define RDI 112
22#define ORIG_RAX 120 /* + error_code */
23/* end of arguments */
24/* cpu exception frame or undefined in case of fast syscall. */
25#define RIP 128
26#define CS 136
27#define EFLAGS 144
28#define RSP 152
29#define SS 160
30#define ARGOFFSET R11
31#define SWFRAME ORIG_RAX
32
33 .macro SAVE_ARGS addskip=0,norcx=0,nor891011=0
34 subq $9*8+\addskip,%rsp
35 CFI_ADJUST_CFA_OFFSET 9*8+\addskip
36 movq %rdi,8*8(%rsp)
37 CFI_REL_OFFSET rdi,8*8
38 movq %rsi,7*8(%rsp)
39 CFI_REL_OFFSET rsi,7*8
40 movq %rdx,6*8(%rsp)
41 CFI_REL_OFFSET rdx,6*8
42 .if \norcx
43 .else
44 movq %rcx,5*8(%rsp)
45 CFI_REL_OFFSET rcx,5*8
46 .endif
47 movq %rax,4*8(%rsp)
48 CFI_REL_OFFSET rax,4*8
49 .if \nor891011
50 .else
51 movq %r8,3*8(%rsp)
52 CFI_REL_OFFSET r8,3*8
53 movq %r9,2*8(%rsp)
54 CFI_REL_OFFSET r9,2*8
55 movq %r10,1*8(%rsp)
56 CFI_REL_OFFSET r10,1*8
57 movq %r11,(%rsp)
58 CFI_REL_OFFSET r11,0*8
59 .endif
60 .endm
61
62#define ARG_SKIP 9*8
63 .macro RESTORE_ARGS skiprax=0,addskip=0,skiprcx=0,skipr11=0,skipr8910=0,skiprdx=0
64 .if \skipr11
65 .else
66 movq (%rsp),%r11
Jan Beulich7effaa82005-09-12 18:49:24 +020067 CFI_RESTORE r11
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 .endif
69 .if \skipr8910
70 .else
71 movq 1*8(%rsp),%r10
Jan Beulich7effaa82005-09-12 18:49:24 +020072 CFI_RESTORE r10
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 movq 2*8(%rsp),%r9
Jan Beulich7effaa82005-09-12 18:49:24 +020074 CFI_RESTORE r9
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 movq 3*8(%rsp),%r8
Jan Beulich7effaa82005-09-12 18:49:24 +020076 CFI_RESTORE r8
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 .endif
78 .if \skiprax
79 .else
80 movq 4*8(%rsp),%rax
Jan Beulich7effaa82005-09-12 18:49:24 +020081 CFI_RESTORE rax
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 .endif
83 .if \skiprcx
84 .else
85 movq 5*8(%rsp),%rcx
Jan Beulich7effaa82005-09-12 18:49:24 +020086 CFI_RESTORE rcx
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 .endif
88 .if \skiprdx
89 .else
90 movq 6*8(%rsp),%rdx
Jan Beulich7effaa82005-09-12 18:49:24 +020091 CFI_RESTORE rdx
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 .endif
93 movq 7*8(%rsp),%rsi
Jan Beulich7effaa82005-09-12 18:49:24 +020094 CFI_RESTORE rsi
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 movq 8*8(%rsp),%rdi
Jan Beulich7effaa82005-09-12 18:49:24 +020096 CFI_RESTORE rdi
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 .if ARG_SKIP+\addskip > 0
98 addq $ARG_SKIP+\addskip,%rsp
99 CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
100 .endif
101 .endm
102
103 .macro LOAD_ARGS offset
104 movq \offset(%rsp),%r11
105 movq \offset+8(%rsp),%r10
106 movq \offset+16(%rsp),%r9
107 movq \offset+24(%rsp),%r8
108 movq \offset+40(%rsp),%rcx
109 movq \offset+48(%rsp),%rdx
110 movq \offset+56(%rsp),%rsi
111 movq \offset+64(%rsp),%rdi
112 movq \offset+72(%rsp),%rax
113 .endm
114
115#define REST_SKIP 6*8
116 .macro SAVE_REST
117 subq $REST_SKIP,%rsp
118 CFI_ADJUST_CFA_OFFSET REST_SKIP
119 movq %rbx,5*8(%rsp)
120 CFI_REL_OFFSET rbx,5*8
121 movq %rbp,4*8(%rsp)
122 CFI_REL_OFFSET rbp,4*8
123 movq %r12,3*8(%rsp)
124 CFI_REL_OFFSET r12,3*8
125 movq %r13,2*8(%rsp)
126 CFI_REL_OFFSET r13,2*8
127 movq %r14,1*8(%rsp)
128 CFI_REL_OFFSET r14,1*8
129 movq %r15,(%rsp)
130 CFI_REL_OFFSET r15,0*8
131 .endm
132
133 .macro RESTORE_REST
134 movq (%rsp),%r15
Jan Beulich7effaa82005-09-12 18:49:24 +0200135 CFI_RESTORE r15
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 movq 1*8(%rsp),%r14
Jan Beulich7effaa82005-09-12 18:49:24 +0200137 CFI_RESTORE r14
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 movq 2*8(%rsp),%r13
Jan Beulich7effaa82005-09-12 18:49:24 +0200139 CFI_RESTORE r13
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 movq 3*8(%rsp),%r12
Jan Beulich7effaa82005-09-12 18:49:24 +0200141 CFI_RESTORE r12
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 movq 4*8(%rsp),%rbp
Jan Beulich7effaa82005-09-12 18:49:24 +0200143 CFI_RESTORE rbp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 movq 5*8(%rsp),%rbx
Jan Beulich7effaa82005-09-12 18:49:24 +0200145 CFI_RESTORE rbx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 addq $REST_SKIP,%rsp
147 CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
148 .endm
149
150 .macro SAVE_ALL
151 SAVE_ARGS
152 SAVE_REST
153 .endm
154
155 .macro RESTORE_ALL addskip=0
156 RESTORE_REST
157 RESTORE_ARGS 0,\addskip
158 .endm
159
160 .macro icebp
161 .byte 0xf1
162 .endm