blob: 0bf15e5c40a2d06f19c1e6a754244ffefef7c577 [file] [log] [blame]
Russell Kingbce495d2005-04-26 15:21:02 +01001#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#include <linux/linkage.h>
3
4#include <asm/assembler.h>
Sam Ravnborge6ae7442005-09-09 21:08:59 +02005#include <asm/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <asm/errno.h>
Russell Kingbce495d2005-04-26 15:21:02 +01007#include <asm/thread_info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9@ Bad Abort numbers
10@ -----------------
11@
12#define BAD_PREFETCH 0
13#define BAD_DATA 1
14#define BAD_ADDREXCPTN 2
15#define BAD_IRQ 3
16#define BAD_UNDEFINSTR 4
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018@
Russell King925c8a12005-04-26 15:18:59 +010019@ Most of the stack format comes from struct pt_regs, but with
20@ the addition of 8 bytes for storing syscall args 5 and 6.
Nicolas Pitre2dede2d2006-01-14 16:18:08 +000021@ This _must_ remain a multiple of 8 for EABI.
Linus Torvalds1da177e2005-04-16 15:20:36 -070022@
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#define S_OFF 8
24
Russell King925c8a12005-04-26 15:18:59 +010025/*
26 * The SWI code relies on the fact that R0 is at the bottom of the stack
27 * (due to slow/fast restore user regs).
28 */
29#if S_R0 != 0
30#error "Please fix"
31#endif
32
Russell Kingbce495d2005-04-26 15:21:02 +010033 .macro zero_fp
34#ifdef CONFIG_FRAME_POINTER
35 mov fp, #0
36#endif
37 .endm
38
Russell King49f680e2005-05-31 18:02:00 +010039 .macro alignment_trap, rtemp
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#ifdef CONFIG_ALIGNMENT_TRAP
Russell King49f680e2005-05-31 18:02:00 +010041 ldr \rtemp, .LCcralign
42 ldr \rtemp, [\rtemp]
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 mcr p15, 0, \rtemp, c1, c0
44#endif
45 .endm
46
Catalin Marinasb86040a2009-07-24 12:32:54 +010047 @
48 @ Store/load the USER SP and LR registers by switching to the SYS
49 @ mode. Useful in Thumb-2 mode where "stm/ldm rd, {sp, lr}^" is not
50 @ available. Should only be called from SVC mode
51 @
52 .macro store_user_sp_lr, rd, rtemp, offset = 0
53 mrs \rtemp, cpsr
54 eor \rtemp, \rtemp, #(SVC_MODE ^ SYSTEM_MODE)
55 msr cpsr_c, \rtemp @ switch to the SYS mode
56
57 str sp, [\rd, #\offset] @ save sp_usr
58 str lr, [\rd, #\offset + 4] @ save lr_usr
59
60 eor \rtemp, \rtemp, #(SVC_MODE ^ SYSTEM_MODE)
61 msr cpsr_c, \rtemp @ switch back to the SVC mode
62 .endm
63
64 .macro load_user_sp_lr, rd, rtemp, offset = 0
65 mrs \rtemp, cpsr
66 eor \rtemp, \rtemp, #(SVC_MODE ^ SYSTEM_MODE)
67 msr cpsr_c, \rtemp @ switch to the SYS mode
68
69 ldr sp, [\rd, #\offset] @ load sp_usr
70 ldr lr, [\rd, #\offset + 4] @ load lr_usr
71
72 eor \rtemp, \rtemp, #(SVC_MODE ^ SYSTEM_MODE)
73 msr cpsr_c, \rtemp @ switch back to the SVC mode
74 .endm
75
76#ifndef CONFIG_THUMB2_KERNEL
Russell King9b56feb2013-03-28 12:57:40 +000077 .macro svc_exit, rpsr, irq = 0
78 .if \irq != 0
79#ifdef CONFIG_TRACE_IRQFLAGS
80 @ The parent context IRQs must have been enabled to get here in
81 @ the first place, so there's no point checking the PSR I bit.
82 bl trace_hardirqs_on
83#endif
84 .else
85#ifdef CONFIG_TRACE_IRQFLAGS
86 tst \rpsr, #PSR_I_BIT
87 bleq trace_hardirqs_on
88 tst \rpsr, #PSR_I_BIT
89 blne trace_hardirqs_off
90#endif
91 .endif
Catalin Marinasb86040a2009-07-24 12:32:54 +010092 msr spsr_cxsf, \rpsr
Russell King7db44c72011-01-17 15:35:37 +000093#if defined(CONFIG_CPU_V6)
Catalin Marinas200b8122009-09-18 23:27:05 +010094 ldr r0, [sp]
95 strex r1, r2, [sp] @ clear the exclusive monitor
96 ldmib sp, {r1 - pc}^ @ load r1 - pc, cpsr
Russell King7db44c72011-01-17 15:35:37 +000097#elif defined(CONFIG_CPU_32v6K)
98 clrex @ clear the exclusive monitor
99 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
Nicolas Pitre9e6ec392009-09-25 16:28:02 -0400100#else
101 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
Catalin Marinas200b8122009-09-18 23:27:05 +0100102#endif
Catalin Marinasb86040a2009-07-24 12:32:54 +0100103 .endm
104
105 .macro restore_user_regs, fast = 0, offset = 0
106 ldr r1, [sp, #\offset + S_PSR] @ get calling cpsr
107 ldr lr, [sp, #\offset + S_PC]! @ get pc
108 msr spsr_cxsf, r1 @ save in spsr_svc
Russell King7db44c72011-01-17 15:35:37 +0000109#if defined(CONFIG_CPU_V6)
Catalin Marinas200b8122009-09-18 23:27:05 +0100110 strex r1, r2, [sp] @ clear the exclusive monitor
Russell King7db44c72011-01-17 15:35:37 +0000111#elif defined(CONFIG_CPU_32v6K)
112 clrex @ clear the exclusive monitor
Catalin Marinas200b8122009-09-18 23:27:05 +0100113#endif
Catalin Marinasb86040a2009-07-24 12:32:54 +0100114 .if \fast
115 ldmdb sp, {r1 - lr}^ @ get calling r1 - lr
116 .else
117 ldmdb sp, {r0 - lr}^ @ get calling r0 - lr
118 .endif
Anders Grafström8e4971f2010-03-15 16:04:14 +0100119 mov r0, r0 @ ARMv5T and earlier require a nop
120 @ after ldm {}^
Catalin Marinasb86040a2009-07-24 12:32:54 +0100121 add sp, sp, #S_FRAME_SIZE - S_PC
122 movs pc, lr @ return & move spsr_svc into cpsr
123 .endm
124
125 .macro get_thread_info, rd
126 mov \rd, sp, lsr #13
127 mov \rd, \rd, lsl #13
128 .endm
Catalin Marinasa771fe62009-10-12 17:31:20 +0100129
130 @
131 @ 32-bit wide "mov pc, reg"
132 @
133 .macro movw_pc, reg
134 mov pc, \reg
135 .endm
Catalin Marinasb86040a2009-07-24 12:32:54 +0100136#else /* CONFIG_THUMB2_KERNEL */
Russell King9b56feb2013-03-28 12:57:40 +0000137 .macro svc_exit, rpsr, irq = 0
138 .if \irq != 0
139#ifdef CONFIG_TRACE_IRQFLAGS
140 @ The parent context IRQs must have been enabled to get here in
141 @ the first place, so there's no point checking the PSR I bit.
142 bl trace_hardirqs_on
143#endif
144 .else
145#ifdef CONFIG_TRACE_IRQFLAGS
146 tst \rpsr, #PSR_I_BIT
147 bleq trace_hardirqs_on
148 tst \rpsr, #PSR_I_BIT
149 blne trace_hardirqs_off
150#endif
151 .endif
Jon Medhurst59481062011-03-18 17:32:44 +0000152 ldr lr, [sp, #S_SP] @ top of the stack
153 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
Catalin Marinas200b8122009-09-18 23:27:05 +0100154 clrex @ clear the exclusive monitor
Jon Medhurst59481062011-03-18 17:32:44 +0000155 stmdb lr!, {r0, r1, \rpsr} @ calling lr and rfe context
Catalin Marinasb86040a2009-07-24 12:32:54 +0100156 ldmia sp, {r0 - r12}
Jon Medhurst59481062011-03-18 17:32:44 +0000157 mov sp, lr
158 ldr lr, [sp], #4
Catalin Marinasb86040a2009-07-24 12:32:54 +0100159 rfeia sp!
160 .endm
161
162 .macro restore_user_regs, fast = 0, offset = 0
Catalin Marinas200b8122009-09-18 23:27:05 +0100163 clrex @ clear the exclusive monitor
Catalin Marinasb86040a2009-07-24 12:32:54 +0100164 mov r2, sp
165 load_user_sp_lr r2, r3, \offset + S_SP @ calling sp, lr
166 ldr r1, [sp, #\offset + S_PSR] @ get calling cpsr
167 ldr lr, [sp, #\offset + S_PC] @ get pc
168 add sp, sp, #\offset + S_SP
169 msr spsr_cxsf, r1 @ save in spsr_svc
170 .if \fast
171 ldmdb sp, {r1 - r12} @ get calling r1 - r12
172 .else
173 ldmdb sp, {r0 - r12} @ get calling r0 - r12
174 .endif
175 add sp, sp, #S_FRAME_SIZE - S_SP
176 movs pc, lr @ return & move spsr_svc into cpsr
177 .endm
178
179 .macro get_thread_info, rd
180 mov \rd, sp
181 lsr \rd, \rd, #13
182 mov \rd, \rd, lsl #13
183 .endm
Catalin Marinasa771fe62009-10-12 17:31:20 +0100184
185 @
186 @ 32-bit wide "mov pc, reg"
187 @
188 .macro movw_pc, reg
189 mov pc, \reg
190 nop
191 .endm
Catalin Marinasb86040a2009-07-24 12:32:54 +0100192#endif /* !CONFIG_THUMB2_KERNEL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194/*
195 * These are the registers used in the syscall handler, and allow us to
196 * have in theory up to 7 arguments to a function - r0 to r6.
197 *
198 * r7 is reserved for the system call number for thumb mode.
199 *
200 * Note that tbl == why is intentional.
201 *
202 * We must set at least "tsk" and "why" when calling ret_with_reschedule.
203 */
204scno .req r7 @ syscall number
205tbl .req r8 @ syscall table pointer
206why .req r8 @ Linux syscall (!= 0)
207tsk .req r9 @ current thread_info