1 #include <linux/init.h>
2 #include <linux/linkage.h>
4 #include <asm/assembler.h>
5 #include <asm/asm-offsets.h>
7 #include <asm/thread_info.h>
12 #define BAD_PREFETCH 0
14 #define BAD_ADDREXCPTN 2
16 #define BAD_UNDEFINSTR 4
19 @ 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.
21 @ This _must_ remain a multiple of 8 for EABI.
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).
34 #ifdef CONFIG_FRAME_POINTER
39 .macro alignment_trap, rtemp
40 #ifdef CONFIG_ALIGNMENT_TRAP
41 ldr \rtemp, .LCcralign
43 mcr p15, 0, \rtemp, c1, c0
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
52 .macro store_user_sp_lr, rd, rtemp, offset = 0
54 eor \rtemp, \rtemp, #(SVC_MODE ^ SYSTEM_MODE)
55 msr cpsr_c, \rtemp @ switch to the SYS mode
57 str sp, [\rd, #\offset] @ save sp_usr
58 str lr, [\rd, #\offset + 4] @ save lr_usr
60 eor \rtemp, \rtemp, #(SVC_MODE ^ SYSTEM_MODE)
61 msr cpsr_c, \rtemp @ switch back to the SVC mode
64 .macro load_user_sp_lr, rd, rtemp, offset = 0
66 eor \rtemp, \rtemp, #(SVC_MODE ^ SYSTEM_MODE)
67 msr cpsr_c, \rtemp @ switch to the SYS mode
69 ldr sp, [\rd, #\offset] @ load sp_usr
70 ldr lr, [\rd, #\offset + 4] @ load lr_usr
72 eor \rtemp, \rtemp, #(SVC_MODE ^ SYSTEM_MODE)
73 msr cpsr_c, \rtemp @ switch back to the SVC mode
76 #ifndef CONFIG_THUMB2_KERNEL
77 .macro svc_exit, rpsr, irq = 0
80 #ifdef CONFIG_TRACE_IRQFLAGS
81 @ The parent context IRQs must have been enabled to get here in
82 @ the first place, so there's no point checking the PSR I bit.
86 @ IRQs off again before pulling preserved data off the stack
88 #ifdef CONFIG_TRACE_IRQFLAGS
90 bleq trace_hardirqs_on
92 blne trace_hardirqs_off
96 #if defined(CONFIG_CPU_V6)
98 strex r1, r2, [sp] @ clear the exclusive monitor
99 ldmib sp, {r1 - pc}^ @ load r1 - pc, cpsr
100 #elif defined(CONFIG_CPU_32v6K)
101 clrex @ clear the exclusive monitor
102 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
104 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
108 .macro restore_user_regs, fast = 0, offset = 0
109 ldr r1, [sp, #\offset + S_PSR] @ get calling cpsr
110 ldr lr, [sp, #\offset + S_PC]! @ get pc
111 msr spsr_cxsf, r1 @ save in spsr_svc
112 #if defined(CONFIG_CPU_V6)
113 strex r1, r2, [sp] @ clear the exclusive monitor
114 #elif defined(CONFIG_CPU_32v6K)
115 clrex @ clear the exclusive monitor
118 ldmdb sp, {r1 - lr}^ @ get calling r1 - lr
120 ldmdb sp, {r0 - lr}^ @ get calling r0 - lr
122 mov r0, r0 @ ARMv5T and earlier require a nop
124 add sp, sp, #S_FRAME_SIZE - S_PC
125 movs pc, lr @ return & move spsr_svc into cpsr
128 .macro get_thread_info, rd
130 mov \rd, \rd, lsl #13
134 @ 32-bit wide "mov pc, reg"
139 #else /* CONFIG_THUMB2_KERNEL */
140 .macro svc_exit, rpsr, irq = 0
143 #ifdef CONFIG_TRACE_IRQFLAGS
144 @ The parent context IRQs must have been enabled to get here in
145 @ the first place, so there's no point checking the PSR I bit.
149 @ IRQs off again before pulling preserved data off the stack
151 #ifdef CONFIG_TRACE_IRQFLAGS
152 tst \rpsr, #PSR_I_BIT
153 bleq trace_hardirqs_on
154 tst \rpsr, #PSR_I_BIT
155 blne trace_hardirqs_off
158 ldr lr, [sp, #S_SP] @ top of the stack
159 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
160 clrex @ clear the exclusive monitor
161 stmdb lr!, {r0, r1, \rpsr} @ calling lr and rfe context
168 .macro restore_user_regs, fast = 0, offset = 0
169 clrex @ clear the exclusive monitor
171 load_user_sp_lr r2, r3, \offset + S_SP @ calling sp, lr
172 ldr r1, [sp, #\offset + S_PSR] @ get calling cpsr
173 ldr lr, [sp, #\offset + S_PC] @ get pc
174 add sp, sp, #\offset + S_SP
175 msr spsr_cxsf, r1 @ save in spsr_svc
177 ldmdb sp, {r1 - r12} @ get calling r1 - r12
179 ldmdb sp, {r0 - r12} @ get calling r0 - r12
181 add sp, sp, #S_FRAME_SIZE - S_SP
182 movs pc, lr @ return & move spsr_svc into cpsr
185 .macro get_thread_info, rd
188 mov \rd, \rd, lsl #13
192 @ 32-bit wide "mov pc, reg"
198 #endif /* !CONFIG_THUMB2_KERNEL */
201 * Context tracking subsystem. Used to instrument transitions
202 * between user and kernel mode.
204 .macro ct_user_exit, save = 1
205 #ifdef CONFIG_CONTEXT_TRACKING
207 stmdb sp!, {r0-r3, ip, lr}
209 ldmia sp!, {r0-r3, ip, lr}
216 .macro ct_user_enter, save = 1
217 #ifdef CONFIG_CONTEXT_TRACKING
219 stmdb sp!, {r0-r3, ip, lr}
221 ldmia sp!, {r0-r3, ip, lr}
229 * These are the registers used in the syscall handler, and allow us to
230 * have in theory up to 7 arguments to a function - r0 to r6.
232 * r7 is reserved for the system call number for thumb mode.
234 * Note that tbl == why is intentional.
236 * We must set at least "tsk" and "why" when calling ret_with_reschedule.
238 scno .req r7 @ syscall number
239 tbl .req r8 @ syscall table pointer
240 why .req r8 @ Linux syscall (!= 0)
241 tsk .req r9 @ current thread_info