Russell King | bce495d | 2005-04-26 15:21:02 +0100 | [diff] [blame] | 1 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #include <linux/linkage.h> |
| 3 | |
| 4 | #include <asm/assembler.h> |
Sam Ravnborg | e6ae744 | 2005-09-09 21:08:59 +0200 | [diff] [blame] | 5 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <asm/errno.h> |
Russell King | bce495d | 2005-04-26 15:21:02 +0100 | [diff] [blame] | 7 | #include <asm/thread_info.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | @ |
Russell King | 925c8a1 | 2005-04-26 15:18:59 +0100 | [diff] [blame] | 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. |
Nicolas Pitre | 2dede2d | 2006-01-14 16:18:08 +0000 | [diff] [blame] | 21 | @ This _must_ remain a multiple of 8 for EABI. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | @ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #define S_OFF 8 |
| 24 | |
Russell King | 925c8a1 | 2005-04-26 15:18:59 +0100 | [diff] [blame] | 25 | /* |
| 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 King | bce495d | 2005-04-26 15:21:02 +0100 | [diff] [blame] | 33 | .macro zero_fp |
| 34 | #ifdef CONFIG_FRAME_POINTER |
| 35 | mov fp, #0 |
| 36 | #endif |
| 37 | .endm |
| 38 | |
Russell King | 49f680e | 2005-05-31 18:02:00 +0100 | [diff] [blame] | 39 | .macro alignment_trap, rtemp |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #ifdef CONFIG_ALIGNMENT_TRAP |
Russell King | 49f680e | 2005-05-31 18:02:00 +0100 | [diff] [blame] | 41 | ldr \rtemp, .LCcralign |
| 42 | ldr \rtemp, [\rtemp] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | mcr p15, 0, \rtemp, c1, c0 |
| 44 | #endif |
| 45 | .endm |
| 46 | |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 47 | @ |
| 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 King | 9b56feb | 2013-03-28 12:57:40 +0000 | [diff] [blame] | 77 | .macro svc_exit, rpsr, irq = 0 |
| 78 | .if \irq != 0 |
Russell King | f8f02ec | 2013-03-28 14:36:05 +0000 | [diff] [blame^] | 79 | @ IRQs already off |
Russell King | 9b56feb | 2013-03-28 12:57:40 +0000 | [diff] [blame] | 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. |
| 83 | bl trace_hardirqs_on |
| 84 | #endif |
| 85 | .else |
Russell King | f8f02ec | 2013-03-28 14:36:05 +0000 | [diff] [blame^] | 86 | @ IRQs off again before pulling preserved data off the stack |
| 87 | disable_irq_notrace |
Russell King | 9b56feb | 2013-03-28 12:57:40 +0000 | [diff] [blame] | 88 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 89 | tst \rpsr, #PSR_I_BIT |
| 90 | bleq trace_hardirqs_on |
| 91 | tst \rpsr, #PSR_I_BIT |
| 92 | blne trace_hardirqs_off |
| 93 | #endif |
| 94 | .endif |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 95 | msr spsr_cxsf, \rpsr |
Russell King | 7db44c7 | 2011-01-17 15:35:37 +0000 | [diff] [blame] | 96 | #if defined(CONFIG_CPU_V6) |
Catalin Marinas | 200b812 | 2009-09-18 23:27:05 +0100 | [diff] [blame] | 97 | ldr r0, [sp] |
| 98 | strex r1, r2, [sp] @ clear the exclusive monitor |
| 99 | ldmib sp, {r1 - pc}^ @ load r1 - pc, cpsr |
Russell King | 7db44c7 | 2011-01-17 15:35:37 +0000 | [diff] [blame] | 100 | #elif defined(CONFIG_CPU_32v6K) |
| 101 | clrex @ clear the exclusive monitor |
| 102 | ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr |
Nicolas Pitre | 9e6ec39 | 2009-09-25 16:28:02 -0400 | [diff] [blame] | 103 | #else |
| 104 | ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr |
Catalin Marinas | 200b812 | 2009-09-18 23:27:05 +0100 | [diff] [blame] | 105 | #endif |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 106 | .endm |
| 107 | |
| 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 |
Russell King | 7db44c7 | 2011-01-17 15:35:37 +0000 | [diff] [blame] | 112 | #if defined(CONFIG_CPU_V6) |
Catalin Marinas | 200b812 | 2009-09-18 23:27:05 +0100 | [diff] [blame] | 113 | strex r1, r2, [sp] @ clear the exclusive monitor |
Russell King | 7db44c7 | 2011-01-17 15:35:37 +0000 | [diff] [blame] | 114 | #elif defined(CONFIG_CPU_32v6K) |
| 115 | clrex @ clear the exclusive monitor |
Catalin Marinas | 200b812 | 2009-09-18 23:27:05 +0100 | [diff] [blame] | 116 | #endif |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 117 | .if \fast |
| 118 | ldmdb sp, {r1 - lr}^ @ get calling r1 - lr |
| 119 | .else |
| 120 | ldmdb sp, {r0 - lr}^ @ get calling r0 - lr |
| 121 | .endif |
Anders Grafström | 8e4971f | 2010-03-15 16:04:14 +0100 | [diff] [blame] | 122 | mov r0, r0 @ ARMv5T and earlier require a nop |
| 123 | @ after ldm {}^ |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 124 | add sp, sp, #S_FRAME_SIZE - S_PC |
| 125 | movs pc, lr @ return & move spsr_svc into cpsr |
| 126 | .endm |
| 127 | |
| 128 | .macro get_thread_info, rd |
| 129 | mov \rd, sp, lsr #13 |
| 130 | mov \rd, \rd, lsl #13 |
| 131 | .endm |
Catalin Marinas | a771fe6 | 2009-10-12 17:31:20 +0100 | [diff] [blame] | 132 | |
| 133 | @ |
| 134 | @ 32-bit wide "mov pc, reg" |
| 135 | @ |
| 136 | .macro movw_pc, reg |
| 137 | mov pc, \reg |
| 138 | .endm |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 139 | #else /* CONFIG_THUMB2_KERNEL */ |
Russell King | 9b56feb | 2013-03-28 12:57:40 +0000 | [diff] [blame] | 140 | .macro svc_exit, rpsr, irq = 0 |
| 141 | .if \irq != 0 |
Russell King | f8f02ec | 2013-03-28 14:36:05 +0000 | [diff] [blame^] | 142 | @ IRQs already off |
Russell King | 9b56feb | 2013-03-28 12:57:40 +0000 | [diff] [blame] | 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. |
| 146 | bl trace_hardirqs_on |
| 147 | #endif |
| 148 | .else |
Russell King | f8f02ec | 2013-03-28 14:36:05 +0000 | [diff] [blame^] | 149 | @ IRQs off again before pulling preserved data off the stack |
| 150 | disable_irq_notrace |
Russell King | 9b56feb | 2013-03-28 12:57:40 +0000 | [diff] [blame] | 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 |
| 156 | #endif |
| 157 | .endif |
Jon Medhurst | 5948106 | 2011-03-18 17:32:44 +0000 | [diff] [blame] | 158 | ldr lr, [sp, #S_SP] @ top of the stack |
| 159 | ldrd r0, r1, [sp, #S_LR] @ calling lr and pc |
Catalin Marinas | 200b812 | 2009-09-18 23:27:05 +0100 | [diff] [blame] | 160 | clrex @ clear the exclusive monitor |
Jon Medhurst | 5948106 | 2011-03-18 17:32:44 +0000 | [diff] [blame] | 161 | stmdb lr!, {r0, r1, \rpsr} @ calling lr and rfe context |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 162 | ldmia sp, {r0 - r12} |
Jon Medhurst | 5948106 | 2011-03-18 17:32:44 +0000 | [diff] [blame] | 163 | mov sp, lr |
| 164 | ldr lr, [sp], #4 |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 165 | rfeia sp! |
| 166 | .endm |
| 167 | |
| 168 | .macro restore_user_regs, fast = 0, offset = 0 |
Catalin Marinas | 200b812 | 2009-09-18 23:27:05 +0100 | [diff] [blame] | 169 | clrex @ clear the exclusive monitor |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 170 | mov r2, sp |
| 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 |
| 176 | .if \fast |
| 177 | ldmdb sp, {r1 - r12} @ get calling r1 - r12 |
| 178 | .else |
| 179 | ldmdb sp, {r0 - r12} @ get calling r0 - r12 |
| 180 | .endif |
| 181 | add sp, sp, #S_FRAME_SIZE - S_SP |
| 182 | movs pc, lr @ return & move spsr_svc into cpsr |
| 183 | .endm |
| 184 | |
| 185 | .macro get_thread_info, rd |
| 186 | mov \rd, sp |
| 187 | lsr \rd, \rd, #13 |
| 188 | mov \rd, \rd, lsl #13 |
| 189 | .endm |
Catalin Marinas | a771fe6 | 2009-10-12 17:31:20 +0100 | [diff] [blame] | 190 | |
| 191 | @ |
| 192 | @ 32-bit wide "mov pc, reg" |
| 193 | @ |
| 194 | .macro movw_pc, reg |
| 195 | mov pc, \reg |
| 196 | nop |
| 197 | .endm |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 198 | #endif /* !CONFIG_THUMB2_KERNEL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | /* |
| 201 | * These are the registers used in the syscall handler, and allow us to |
| 202 | * have in theory up to 7 arguments to a function - r0 to r6. |
| 203 | * |
| 204 | * r7 is reserved for the system call number for thumb mode. |
| 205 | * |
| 206 | * Note that tbl == why is intentional. |
| 207 | * |
| 208 | * We must set at least "tsk" and "why" when calling ret_with_reschedule. |
| 209 | */ |
| 210 | scno .req r7 @ syscall number |
| 211 | tbl .req r8 @ syscall table pointer |
| 212 | why .req r8 @ Linux syscall (!= 0) |
| 213 | tsk .req r9 @ current thread_info |