2005-04-26 22:21:02 +08:00
|
|
|
#include <linux/init.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/linkage.h>
|
|
|
|
|
|
|
|
#include <asm/assembler.h>
|
2005-09-10 03:08:59 +08:00
|
|
|
#include <asm/asm-offsets.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/errno.h>
|
2005-04-26 22:21:02 +08:00
|
|
|
#include <asm/thread_info.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
@ Bad Abort numbers
|
|
|
|
@ -----------------
|
|
|
|
@
|
|
|
|
#define BAD_PREFETCH 0
|
|
|
|
#define BAD_DATA 1
|
|
|
|
#define BAD_ADDREXCPTN 2
|
|
|
|
#define BAD_IRQ 3
|
|
|
|
#define BAD_UNDEFINSTR 4
|
|
|
|
|
|
|
|
@
|
2005-04-26 22:18:59 +08:00
|
|
|
@ Most of the stack format comes from struct pt_regs, but with
|
|
|
|
@ the addition of 8 bytes for storing syscall args 5 and 6.
|
2006-01-15 00:18:08 +08:00
|
|
|
@ This _must_ remain a multiple of 8 for EABI.
|
2005-04-17 06:20:36 +08:00
|
|
|
@
|
|
|
|
#define S_OFF 8
|
|
|
|
|
2005-04-26 22:18:59 +08:00
|
|
|
/*
|
|
|
|
* The SWI code relies on the fact that R0 is at the bottom of the stack
|
|
|
|
* (due to slow/fast restore user regs).
|
|
|
|
*/
|
|
|
|
#if S_R0 != 0
|
|
|
|
#error "Please fix"
|
|
|
|
#endif
|
|
|
|
|
2005-04-26 22:21:02 +08:00
|
|
|
.macro zero_fp
|
|
|
|
#ifdef CONFIG_FRAME_POINTER
|
|
|
|
mov fp, #0
|
|
|
|
#endif
|
|
|
|
.endm
|
|
|
|
|
2005-06-01 01:02:00 +08:00
|
|
|
.macro alignment_trap, rtemp
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_ALIGNMENT_TRAP
|
2005-06-01 01:02:00 +08:00
|
|
|
ldr \rtemp, .LCcralign
|
|
|
|
ldr \rtemp, [\rtemp]
|
2005-04-17 06:20:36 +08:00
|
|
|
mcr p15, 0, \rtemp, c1, c0
|
|
|
|
#endif
|
|
|
|
.endm
|
|
|
|
|
2009-07-24 19:32:54 +08:00
|
|
|
@
|
|
|
|
@ Store/load the USER SP and LR registers by switching to the SYS
|
|
|
|
@ mode. Useful in Thumb-2 mode where "stm/ldm rd, {sp, lr}^" is not
|
|
|
|
@ available. Should only be called from SVC mode
|
|
|
|
@
|
|
|
|
.macro store_user_sp_lr, rd, rtemp, offset = 0
|
|
|
|
mrs \rtemp, cpsr
|
|
|
|
eor \rtemp, \rtemp, #(SVC_MODE ^ SYSTEM_MODE)
|
|
|
|
msr cpsr_c, \rtemp @ switch to the SYS mode
|
|
|
|
|
|
|
|
str sp, [\rd, #\offset] @ save sp_usr
|
|
|
|
str lr, [\rd, #\offset + 4] @ save lr_usr
|
|
|
|
|
|
|
|
eor \rtemp, \rtemp, #(SVC_MODE ^ SYSTEM_MODE)
|
|
|
|
msr cpsr_c, \rtemp @ switch back to the SVC mode
|
|
|
|
.endm
|
|
|
|
|
|
|
|
.macro load_user_sp_lr, rd, rtemp, offset = 0
|
|
|
|
mrs \rtemp, cpsr
|
|
|
|
eor \rtemp, \rtemp, #(SVC_MODE ^ SYSTEM_MODE)
|
|
|
|
msr cpsr_c, \rtemp @ switch to the SYS mode
|
|
|
|
|
|
|
|
ldr sp, [\rd, #\offset] @ load sp_usr
|
|
|
|
ldr lr, [\rd, #\offset + 4] @ load lr_usr
|
|
|
|
|
|
|
|
eor \rtemp, \rtemp, #(SVC_MODE ^ SYSTEM_MODE)
|
|
|
|
msr cpsr_c, \rtemp @ switch back to the SVC mode
|
|
|
|
.endm
|
|
|
|
|
|
|
|
#ifndef CONFIG_THUMB2_KERNEL
|
|
|
|
.macro svc_exit, rpsr
|
|
|
|
msr spsr_cxsf, \rpsr
|
2011-01-17 23:35:37 +08:00
|
|
|
#if defined(CONFIG_CPU_V6)
|
2009-09-19 06:27:05 +08:00
|
|
|
ldr r0, [sp]
|
|
|
|
strex r1, r2, [sp] @ clear the exclusive monitor
|
|
|
|
ldmib sp, {r1 - pc}^ @ load r1 - pc, cpsr
|
2011-01-17 23:35:37 +08:00
|
|
|
#elif defined(CONFIG_CPU_32v6K)
|
|
|
|
clrex @ clear the exclusive monitor
|
|
|
|
ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
|
2009-09-26 04:28:02 +08:00
|
|
|
#else
|
|
|
|
ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
|
2009-09-19 06:27:05 +08:00
|
|
|
#endif
|
2009-07-24 19:32:54 +08:00
|
|
|
.endm
|
|
|
|
|
|
|
|
.macro restore_user_regs, fast = 0, offset = 0
|
|
|
|
ldr r1, [sp, #\offset + S_PSR] @ get calling cpsr
|
|
|
|
ldr lr, [sp, #\offset + S_PC]! @ get pc
|
|
|
|
msr spsr_cxsf, r1 @ save in spsr_svc
|
2011-01-17 23:35:37 +08:00
|
|
|
#if defined(CONFIG_CPU_V6)
|
2009-09-19 06:27:05 +08:00
|
|
|
strex r1, r2, [sp] @ clear the exclusive monitor
|
2011-01-17 23:35:37 +08:00
|
|
|
#elif defined(CONFIG_CPU_32v6K)
|
|
|
|
clrex @ clear the exclusive monitor
|
2009-09-19 06:27:05 +08:00
|
|
|
#endif
|
2009-07-24 19:32:54 +08:00
|
|
|
.if \fast
|
|
|
|
ldmdb sp, {r1 - lr}^ @ get calling r1 - lr
|
|
|
|
.else
|
|
|
|
ldmdb sp, {r0 - lr}^ @ get calling r0 - lr
|
|
|
|
.endif
|
2010-03-15 23:04:14 +08:00
|
|
|
mov r0, r0 @ ARMv5T and earlier require a nop
|
|
|
|
@ after ldm {}^
|
2009-07-24 19:32:54 +08:00
|
|
|
add sp, sp, #S_FRAME_SIZE - S_PC
|
|
|
|
movs pc, lr @ return & move spsr_svc into cpsr
|
|
|
|
.endm
|
|
|
|
|
|
|
|
.macro get_thread_info, rd
|
|
|
|
mov \rd, sp, lsr #13
|
|
|
|
mov \rd, \rd, lsl #13
|
|
|
|
.endm
|
2009-10-13 00:31:20 +08:00
|
|
|
|
|
|
|
@
|
|
|
|
@ 32-bit wide "mov pc, reg"
|
|
|
|
@
|
|
|
|
.macro movw_pc, reg
|
|
|
|
mov pc, \reg
|
|
|
|
.endm
|
2009-07-24 19:32:54 +08:00
|
|
|
#else /* CONFIG_THUMB2_KERNEL */
|
|
|
|
.macro svc_exit, rpsr
|
2009-09-19 06:27:05 +08:00
|
|
|
clrex @ clear the exclusive monitor
|
2009-07-24 19:32:54 +08:00
|
|
|
ldr r0, [sp, #S_SP] @ top of the stack
|
|
|
|
ldr r1, [sp, #S_PC] @ return address
|
|
|
|
tst r0, #4 @ orig stack 8-byte aligned?
|
|
|
|
stmdb r0, {r1, \rpsr} @ rfe context
|
|
|
|
ldmia sp, {r0 - r12}
|
|
|
|
ldr lr, [sp, #S_LR]
|
|
|
|
addeq sp, sp, #S_FRAME_SIZE - 8 @ aligned
|
|
|
|
addne sp, sp, #S_FRAME_SIZE - 4 @ not aligned
|
|
|
|
rfeia sp!
|
|
|
|
.endm
|
|
|
|
|
|
|
|
.macro restore_user_regs, fast = 0, offset = 0
|
2009-09-19 06:27:05 +08:00
|
|
|
clrex @ clear the exclusive monitor
|
2009-07-24 19:32:54 +08:00
|
|
|
mov r2, sp
|
|
|
|
load_user_sp_lr r2, r3, \offset + S_SP @ calling sp, lr
|
|
|
|
ldr r1, [sp, #\offset + S_PSR] @ get calling cpsr
|
|
|
|
ldr lr, [sp, #\offset + S_PC] @ get pc
|
|
|
|
add sp, sp, #\offset + S_SP
|
|
|
|
msr spsr_cxsf, r1 @ save in spsr_svc
|
|
|
|
.if \fast
|
|
|
|
ldmdb sp, {r1 - r12} @ get calling r1 - r12
|
|
|
|
.else
|
|
|
|
ldmdb sp, {r0 - r12} @ get calling r0 - r12
|
|
|
|
.endif
|
|
|
|
add sp, sp, #S_FRAME_SIZE - S_SP
|
|
|
|
movs pc, lr @ return & move spsr_svc into cpsr
|
|
|
|
.endm
|
|
|
|
|
|
|
|
.macro get_thread_info, rd
|
|
|
|
mov \rd, sp
|
|
|
|
lsr \rd, \rd, #13
|
|
|
|
mov \rd, \rd, lsl #13
|
|
|
|
.endm
|
2009-10-13 00:31:20 +08:00
|
|
|
|
|
|
|
@
|
|
|
|
@ 32-bit wide "mov pc, reg"
|
|
|
|
@
|
|
|
|
.macro movw_pc, reg
|
|
|
|
mov pc, \reg
|
|
|
|
nop
|
|
|
|
.endm
|
2009-07-24 19:32:54 +08:00
|
|
|
#endif /* !CONFIG_THUMB2_KERNEL */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-11-28 22:57:24 +08:00
|
|
|
@
|
|
|
|
@ Debug exceptions are taken as prefetch or data aborts.
|
|
|
|
@ We must disable preemption during the handler so that
|
|
|
|
@ we can access the debug registers safely.
|
|
|
|
@
|
|
|
|
.macro debug_entry, fsr
|
|
|
|
#if defined(CONFIG_HAVE_HW_BREAKPOINT) && defined(CONFIG_PREEMPT)
|
|
|
|
ldr r4, =0x40f @ mask out fsr.fs
|
|
|
|
and r5, r4, \fsr
|
|
|
|
cmp r5, #2 @ debug exception
|
|
|
|
bne 1f
|
|
|
|
get_thread_info r10
|
|
|
|
ldr r6, [r10, #TI_PREEMPT] @ get preempt count
|
|
|
|
add r11, r6, #1 @ increment it
|
|
|
|
str r11, [r10, #TI_PREEMPT]
|
|
|
|
1:
|
|
|
|
#endif
|
|
|
|
.endm
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* These are the registers used in the syscall handler, and allow us to
|
|
|
|
* have in theory up to 7 arguments to a function - r0 to r6.
|
|
|
|
*
|
|
|
|
* r7 is reserved for the system call number for thumb mode.
|
|
|
|
*
|
|
|
|
* Note that tbl == why is intentional.
|
|
|
|
*
|
|
|
|
* We must set at least "tsk" and "why" when calling ret_with_reschedule.
|
|
|
|
*/
|
|
|
|
scno .req r7 @ syscall number
|
|
|
|
tbl .req r8 @ syscall table pointer
|
|
|
|
why .req r8 @ Linux syscall (!= 0)
|
|
|
|
tsk .req r9 @ current thread_info
|