Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com) |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
Vineet Gupta | 4788a59 | 2013-01-18 15:12:22 +0530 | [diff] [blame] | 8 | * Vineetg: March 2009 (Supporting 2 levels of Interrupts) |
| 9 | * Stack switching code can no longer reliably rely on the fact that |
| 10 | * if we are NOT in user mode, stack is switched to kernel mode. |
| 11 | * e.g. L2 IRQ interrupted a L1 ISR which had not yet completed |
| 12 | * it's prologue including stack switching from user mode |
| 13 | * |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 14 | * Vineetg: Aug 28th 2008: Bug #94984 |
| 15 | * -Zero Overhead Loop Context shd be cleared when entering IRQ/EXcp/Trap |
| 16 | * Normally CPU does this automatically, however when doing FAKE rtie, |
| 17 | * we also need to explicitly do this. The problem in macros |
| 18 | * FAKE_RET_FROM_EXCPN and FAKE_RET_FROM_EXCPN_LOCK_IRQ was that this bit |
| 19 | * was being "CLEARED" rather then "SET". Actually "SET" clears ZOL context |
| 20 | * |
| 21 | * Vineetg: May 5th 2008 |
Vineet Gupta | 080c374 | 2013-02-11 19:52:57 +0530 | [diff] [blame] | 22 | * -Modified CALLEE_REG save/restore macros to handle the fact that |
| 23 | * r25 contains the kernel current task ptr |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 24 | * - Defined Stack Switching Macro to be reused in all intr/excp hdlrs |
| 25 | * - Shaved off 11 instructions from RESTORE_ALL_INT1 by using the |
| 26 | * address Write back load ld.ab instead of seperate ld/add instn |
| 27 | * |
| 28 | * Amit Bhor, Sameer Dhavale: Codito Technologies 2004 |
| 29 | */ |
| 30 | |
| 31 | #ifndef __ASM_ARC_ENTRY_H |
| 32 | #define __ASM_ARC_ENTRY_H |
| 33 | |
| 34 | #ifdef __ASSEMBLY__ |
| 35 | #include <asm/unistd.h> /* For NR_syscalls defination */ |
| 36 | #include <asm/asm-offsets.h> |
| 37 | #include <asm/arcregs.h> |
| 38 | #include <asm/ptrace.h> |
Vineet Gupta | 080c374 | 2013-02-11 19:52:57 +0530 | [diff] [blame] | 39 | #include <asm/processor.h> /* For VMALLOC_START */ |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 40 | #include <asm/thread_info.h> /* For THREAD_SIZE */ |
| 41 | |
| 42 | /* Note on the LD/ST addr modes with addr reg wback |
| 43 | * |
| 44 | * LD.a same as LD.aw |
| 45 | * |
| 46 | * LD.a reg1, [reg2, x] => Pre Incr |
| 47 | * Eff Addr for load = [reg2 + x] |
| 48 | * |
| 49 | * LD.ab reg1, [reg2, x] => Post Incr |
| 50 | * Eff Addr for load = [reg2] |
| 51 | */ |
| 52 | |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 53 | .macro PUSH reg |
| 54 | st.a \reg, [sp, -4] |
| 55 | .endm |
| 56 | |
| 57 | .macro PUSHAX aux |
| 58 | lr r9, [\aux] |
| 59 | PUSH r9 |
| 60 | .endm |
| 61 | |
| 62 | .macro POP reg |
| 63 | ld.ab \reg, [sp, 4] |
| 64 | .endm |
| 65 | |
| 66 | .macro POPAX aux |
| 67 | POP r9 |
| 68 | sr r9, [\aux] |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 69 | .endm |
| 70 | |
| 71 | /*-------------------------------------------------------------- |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 72 | * Helpers to save/restore Scratch Regs: |
| 73 | * used by Interrupt/Exception Prologue/Epilogue |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 74 | *-------------------------------------------------------------*/ |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 75 | .macro SAVE_R0_TO_R12 |
| 76 | PUSH r0 |
| 77 | PUSH r1 |
| 78 | PUSH r2 |
| 79 | PUSH r3 |
| 80 | PUSH r4 |
| 81 | PUSH r5 |
| 82 | PUSH r6 |
| 83 | PUSH r7 |
| 84 | PUSH r8 |
| 85 | PUSH r9 |
| 86 | PUSH r10 |
| 87 | PUSH r11 |
| 88 | PUSH r12 |
| 89 | .endm |
| 90 | |
| 91 | .macro RESTORE_R12_TO_R0 |
| 92 | POP r12 |
| 93 | POP r11 |
| 94 | POP r10 |
| 95 | POP r9 |
| 96 | POP r8 |
| 97 | POP r7 |
| 98 | POP r6 |
| 99 | POP r5 |
| 100 | POP r4 |
| 101 | POP r3 |
| 102 | POP r2 |
| 103 | POP r1 |
| 104 | POP r0 |
Vineet Gupta | 359105b | 2013-05-28 13:50:41 +0530 | [diff] [blame] | 105 | |
| 106 | #ifdef CONFIG_ARC_CURR_IN_REG |
| 107 | ld r25, [sp, 12] |
| 108 | #endif |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 109 | .endm |
| 110 | |
| 111 | /*-------------------------------------------------------------- |
| 112 | * Helpers to save/restore callee-saved regs: |
| 113 | * used by several macros below |
| 114 | *-------------------------------------------------------------*/ |
| 115 | .macro SAVE_R13_TO_R24 |
| 116 | PUSH r13 |
| 117 | PUSH r14 |
| 118 | PUSH r15 |
| 119 | PUSH r16 |
| 120 | PUSH r17 |
| 121 | PUSH r18 |
| 122 | PUSH r19 |
| 123 | PUSH r20 |
| 124 | PUSH r21 |
| 125 | PUSH r22 |
| 126 | PUSH r23 |
| 127 | PUSH r24 |
| 128 | .endm |
| 129 | |
| 130 | .macro RESTORE_R24_TO_R13 |
| 131 | POP r24 |
| 132 | POP r23 |
| 133 | POP r22 |
| 134 | POP r21 |
| 135 | POP r20 |
| 136 | POP r19 |
| 137 | POP r18 |
| 138 | POP r17 |
| 139 | POP r16 |
| 140 | POP r15 |
| 141 | POP r14 |
| 142 | POP r13 |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 143 | .endm |
| 144 | |
Vineet Gupta | 359105b | 2013-05-28 13:50:41 +0530 | [diff] [blame] | 145 | #define OFF_USER_R25_FROM_R24 (SZ_CALLEE_REGS + SZ_PT_REGS - 8)/4 |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 146 | |
| 147 | /*-------------------------------------------------------------- |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 148 | * Collect User Mode callee regs as struct callee_regs - needed by |
| 149 | * fork/do_signal/unaligned-access-emulation. |
| 150 | * (By default only scratch regs are saved on entry to kernel) |
| 151 | * |
| 152 | * Special handling for r25 if used for caching Task Pointer. |
| 153 | * It would have been saved in task->thread.user_r25 already, but to keep |
| 154 | * the interface same it is copied into regular r25 placeholder in |
| 155 | * struct callee_regs. |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 156 | *-------------------------------------------------------------*/ |
| 157 | .macro SAVE_CALLEE_SAVED_USER |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 158 | |
| 159 | SAVE_R13_TO_R24 |
Vineet Gupta | 080c374 | 2013-02-11 19:52:57 +0530 | [diff] [blame] | 160 | |
| 161 | #ifdef CONFIG_ARC_CURR_IN_REG |
| 162 | ; Retrieve orig r25 and save it on stack |
Vineet Gupta | 359105b | 2013-05-28 13:50:41 +0530 | [diff] [blame] | 163 | ld.as r12, [sp, OFF_USER_R25_FROM_R24] |
Vineet Gupta | 080c374 | 2013-02-11 19:52:57 +0530 | [diff] [blame] | 164 | st.a r12, [sp, -4] |
| 165 | #else |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 166 | PUSH r25 |
Vineet Gupta | 080c374 | 2013-02-11 19:52:57 +0530 | [diff] [blame] | 167 | #endif |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 168 | |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 169 | .endm |
| 170 | |
| 171 | /*-------------------------------------------------------------- |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 172 | * Save kernel Mode callee regs at the time of Contect Switch. |
| 173 | * |
| 174 | * Special handling for r25 if used for caching Task Pointer. |
| 175 | * Kernel simply skips saving it since it will be loaded with |
| 176 | * incoming task pointer anyways |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 177 | *-------------------------------------------------------------*/ |
| 178 | .macro SAVE_CALLEE_SAVED_KERNEL |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 179 | |
| 180 | SAVE_R13_TO_R24 |
| 181 | |
Vineet Gupta | 080c374 | 2013-02-11 19:52:57 +0530 | [diff] [blame] | 182 | #ifdef CONFIG_ARC_CURR_IN_REG |
Vineet Gupta | 16f9afe | 2013-05-27 21:43:41 +0530 | [diff] [blame] | 183 | sub sp, sp, 4 |
Vineet Gupta | 080c374 | 2013-02-11 19:52:57 +0530 | [diff] [blame] | 184 | #else |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 185 | PUSH r25 |
Vineet Gupta | 080c374 | 2013-02-11 19:52:57 +0530 | [diff] [blame] | 186 | #endif |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 187 | .endm |
| 188 | |
| 189 | /*-------------------------------------------------------------- |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 190 | * Opposite of SAVE_CALLEE_SAVED_KERNEL |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 191 | *-------------------------------------------------------------*/ |
| 192 | .macro RESTORE_CALLEE_SAVED_KERNEL |
| 193 | |
Vineet Gupta | 080c374 | 2013-02-11 19:52:57 +0530 | [diff] [blame] | 194 | #ifdef CONFIG_ARC_CURR_IN_REG |
Vineet Gupta | 16f9afe | 2013-05-27 21:43:41 +0530 | [diff] [blame] | 195 | add sp, sp, 4 /* skip usual r25 placeholder */ |
Vineet Gupta | 080c374 | 2013-02-11 19:52:57 +0530 | [diff] [blame] | 196 | #else |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 197 | POP r25 |
Vineet Gupta | 080c374 | 2013-02-11 19:52:57 +0530 | [diff] [blame] | 198 | #endif |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 199 | RESTORE_R24_TO_R13 |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 200 | .endm |
| 201 | |
| 202 | /*-------------------------------------------------------------- |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 203 | * Opposite of SAVE_CALLEE_SAVED_USER |
| 204 | * |
| 205 | * ptrace tracer or unaligned-access fixup might have changed a user mode |
| 206 | * callee reg which is saved back to usual r25 storage location |
Vineet Gupta | c358103 | 2013-01-18 15:12:19 +0530 | [diff] [blame] | 207 | *-------------------------------------------------------------*/ |
| 208 | .macro RESTORE_CALLEE_SAVED_USER |
| 209 | |
Vineet Gupta | c358103 | 2013-01-18 15:12:19 +0530 | [diff] [blame] | 210 | #ifdef CONFIG_ARC_CURR_IN_REG |
| 211 | ld.ab r12, [sp, 4] |
Vineet Gupta | 359105b | 2013-05-28 13:50:41 +0530 | [diff] [blame] | 212 | st.as r12, [sp, OFF_USER_R25_FROM_R24] |
Vineet Gupta | c358103 | 2013-01-18 15:12:19 +0530 | [diff] [blame] | 213 | #else |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 214 | POP r25 |
Vineet Gupta | c358103 | 2013-01-18 15:12:19 +0530 | [diff] [blame] | 215 | #endif |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 216 | RESTORE_R24_TO_R13 |
Vineet Gupta | c358103 | 2013-01-18 15:12:19 +0530 | [diff] [blame] | 217 | .endm |
| 218 | |
| 219 | /*-------------------------------------------------------------- |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 220 | * Super FAST Restore callee saved regs by simply re-adjusting SP |
| 221 | *-------------------------------------------------------------*/ |
| 222 | .macro DISCARD_CALLEE_SAVED_USER |
Vineet Gupta | 16f9afe | 2013-05-27 21:43:41 +0530 | [diff] [blame] | 223 | add sp, sp, SZ_CALLEE_REGS |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 224 | .endm |
| 225 | |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 226 | /*------------------------------------------------------------- |
| 227 | * given a tsk struct, get to the base of it's kernel mode stack |
| 228 | * tsk->thread_info is really a PAGE, whose bottom hoists stack |
| 229 | * which grows upwards towards thread_info |
| 230 | *------------------------------------------------------------*/ |
| 231 | |
| 232 | .macro GET_TSK_STACK_BASE tsk, out |
| 233 | |
| 234 | /* Get task->thread_info (this is essentially start of a PAGE) */ |
| 235 | ld \out, [\tsk, TASK_THREAD_INFO] |
| 236 | |
| 237 | /* Go to end of page where stack begins (grows upwards) */ |
Vineet Gupta | 283237a | 2013-05-28 09:34:45 +0530 | [diff] [blame] | 238 | add2 \out, \out, (THREAD_SIZE)/4 |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 239 | |
| 240 | .endm |
| 241 | |
| 242 | /*-------------------------------------------------------------- |
| 243 | * Switch to Kernel Mode stack if SP points to User Mode stack |
| 244 | * |
| 245 | * Entry : r9 contains pre-IRQ/exception/trap status32 |
| 246 | * Exit : SP is set to kernel mode stack pointer |
Vineet Gupta | 080c374 | 2013-02-11 19:52:57 +0530 | [diff] [blame] | 247 | * If CURR_IN_REG, r25 set to "current" task pointer |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 248 | * Clobbers: r9 |
| 249 | *-------------------------------------------------------------*/ |
| 250 | |
| 251 | .macro SWITCH_TO_KERNEL_STK |
| 252 | |
| 253 | /* User Mode when this happened ? Yes: Proceed to switch stack */ |
| 254 | bbit1 r9, STATUS_U_BIT, 88f |
| 255 | |
| 256 | /* OK we were already in kernel mode when this event happened, thus can |
| 257 | * assume SP is kernel mode SP. _NO_ need to do any stack switching |
| 258 | */ |
| 259 | |
Vineet Gupta | 4788a59 | 2013-01-18 15:12:22 +0530 | [diff] [blame] | 260 | #ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS |
| 261 | /* However.... |
| 262 | * If Level 2 Interrupts enabled, we may end up with a corner case: |
| 263 | * 1. User Task executing |
| 264 | * 2. L1 IRQ taken, ISR starts (CPU auto-switched to KERNEL mode) |
| 265 | * 3. But before it could switch SP from USER to KERNEL stack |
| 266 | * a L2 IRQ "Interrupts" L1 |
| 267 | * Thay way although L2 IRQ happened in Kernel mode, stack is still |
| 268 | * not switched. |
| 269 | * To handle this, we may need to switch stack even if in kernel mode |
| 270 | * provided SP has values in range of USER mode stack ( < 0x7000_0000 ) |
| 271 | */ |
| 272 | brlo sp, VMALLOC_START, 88f |
| 273 | |
| 274 | /* TODO: vineetg: |
| 275 | * We need to be a bit more cautious here. What if a kernel bug in |
| 276 | * L1 ISR, caused SP to go whaco (some small value which looks like |
| 277 | * USER stk) and then we take L2 ISR. |
| 278 | * Above brlo alone would treat it as a valid L1-L2 sceanrio |
| 279 | * instead of shouting alound |
| 280 | * The only feasible way is to make sure this L2 happened in |
| 281 | * L1 prelogue ONLY i.e. ilink2 is less than a pre-set marker in |
| 282 | * L1 ISR before it switches stack |
| 283 | */ |
| 284 | |
| 285 | #endif |
| 286 | |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 287 | /* Save Pre Intr/Exception KERNEL MODE SP on kernel stack |
| 288 | * safe-keeping not really needed, but it keeps the epilogue code |
| 289 | * (SP restore) simpler/uniform. |
| 290 | */ |
Vineet Gupta | ba3558c | 2013-05-27 18:51:27 +0530 | [diff] [blame] | 291 | b.d 66f |
| 292 | mov r9, sp |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 293 | |
| 294 | 88: /*------Intr/Ecxp happened in user mode, "switch" stack ------ */ |
| 295 | |
| 296 | GET_CURR_TASK_ON_CPU r9 |
| 297 | |
| 298 | /* With current tsk in r9, get it's kernel mode stack base */ |
| 299 | GET_TSK_STACK_BASE r9, r9 |
| 300 | |
Vineet Gupta | ba3558c | 2013-05-27 18:51:27 +0530 | [diff] [blame] | 301 | 66: |
Vineet Gupta | 359105b | 2013-05-28 13:50:41 +0530 | [diff] [blame] | 302 | #ifdef CONFIG_ARC_CURR_IN_REG |
| 303 | /* |
| 304 | * Treat r25 as scratch reg, save it on stack first |
| 305 | * Load it with current task pointer |
| 306 | */ |
| 307 | st r25, [r9, -4] |
| 308 | GET_CURR_TASK_ON_CPU r25 |
| 309 | #endif |
| 310 | |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 311 | /* Save Pre Intr/Exception User SP on kernel stack */ |
Vineet Gupta | 359105b | 2013-05-28 13:50:41 +0530 | [diff] [blame] | 312 | st.a sp, [r9, -16] ; Make room for orig_r0, orig_r8, user_r25 |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 313 | |
| 314 | /* CAUTION: |
| 315 | * SP should be set at the very end when we are done with everything |
| 316 | * In case of 2 levels of interrupt we depend on value of SP to assume |
| 317 | * that everything else is done (loading r25 etc) |
| 318 | */ |
| 319 | |
| 320 | /* set SP to point to kernel mode stack */ |
| 321 | mov sp, r9 |
| 322 | |
Vineet Gupta | ba3558c | 2013-05-27 18:51:27 +0530 | [diff] [blame] | 323 | /* ----- Stack Switched to kernel Mode, Now save REG FILE ----- */ |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 324 | |
| 325 | .endm |
| 326 | |
| 327 | /*------------------------------------------------------------ |
| 328 | * "FAKE" a rtie to return from CPU Exception context |
| 329 | * This is to re-enable Exceptions within exception |
| 330 | * Look at EV_ProtV to see how this is actually used |
| 331 | *-------------------------------------------------------------*/ |
| 332 | |
| 333 | .macro FAKE_RET_FROM_EXCPN reg |
| 334 | |
| 335 | ld \reg, [sp, PT_status32] |
| 336 | bic \reg, \reg, (STATUS_U_MASK|STATUS_DE_MASK) |
| 337 | bset \reg, \reg, STATUS_L_BIT |
| 338 | sr \reg, [erstatus] |
| 339 | mov \reg, 55f |
| 340 | sr \reg, [eret] |
| 341 | |
| 342 | rtie |
| 343 | 55: |
| 344 | .endm |
| 345 | |
| 346 | /* |
| 347 | * @reg [OUT] &thread_info of "current" |
| 348 | */ |
| 349 | .macro GET_CURR_THR_INFO_FROM_SP reg |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 350 | bic \reg, sp, (THREAD_SIZE - 1) |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 351 | .endm |
| 352 | |
| 353 | /* |
| 354 | * @reg [OUT] thread_info->flags of "current" |
| 355 | */ |
| 356 | .macro GET_CURR_THR_INFO_FLAGS reg |
| 357 | GET_CURR_THR_INFO_FROM_SP \reg |
| 358 | ld \reg, [\reg, THREAD_INFO_FLAGS] |
| 359 | .endm |
| 360 | |
| 361 | /*-------------------------------------------------------------- |
| 362 | * For early Exception Prologue, a core reg is temporarily needed to |
| 363 | * code the rest of prolog (stack switching). This is done by stashing |
| 364 | * it to memory (non-SMP case) or SCRATCH0 Aux Reg (SMP). |
| 365 | * |
| 366 | * Before saving the full regfile - this reg is restored back, only |
| 367 | * to be saved again on kernel mode stack, as part of ptregs. |
| 368 | *-------------------------------------------------------------*/ |
| 369 | .macro EXCPN_PROLOG_FREEUP_REG reg |
Vineet Gupta | 41195d2 | 2013-01-18 15:12:23 +0530 | [diff] [blame] | 370 | #ifdef CONFIG_SMP |
| 371 | sr \reg, [ARC_REG_SCRATCH_DATA0] |
| 372 | #else |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 373 | st \reg, [@ex_saved_reg1] |
Vineet Gupta | 41195d2 | 2013-01-18 15:12:23 +0530 | [diff] [blame] | 374 | #endif |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 375 | .endm |
| 376 | |
| 377 | .macro EXCPN_PROLOG_RESTORE_REG reg |
Vineet Gupta | 41195d2 | 2013-01-18 15:12:23 +0530 | [diff] [blame] | 378 | #ifdef CONFIG_SMP |
| 379 | lr \reg, [ARC_REG_SCRATCH_DATA0] |
| 380 | #else |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 381 | ld \reg, [@ex_saved_reg1] |
Vineet Gupta | 41195d2 | 2013-01-18 15:12:23 +0530 | [diff] [blame] | 382 | #endif |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 383 | .endm |
| 384 | |
| 385 | /*-------------------------------------------------------------- |
| 386 | * Save all registers used by Exceptions (TLB Miss, Prot-V, Mem err etc) |
| 387 | * Requires SP to be already switched to kernel mode Stack |
| 388 | * sp points to the next free element on the stack at exit of this macro. |
| 389 | * Registers are pushed / popped in the order defined in struct ptregs |
| 390 | * in asm/ptrace.h |
| 391 | * Note that syscalls are implemented via TRAP which is also a exception |
| 392 | * from CPU's point of view |
| 393 | *-------------------------------------------------------------*/ |
| 394 | .macro SAVE_ALL_EXCEPTION marker |
| 395 | |
Vineet Gupta | 367f3fc | 2013-03-20 16:53:14 +0530 | [diff] [blame] | 396 | st \marker, [sp, 8] /* orig_r8 */ |
Vineet Gupta | 5c39c0a | 2013-02-11 20:01:24 +0530 | [diff] [blame] | 397 | st r0, [sp, 4] /* orig_r0, needed only for sys calls */ |
| 398 | |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 399 | /* Restore r9 used to code the early prologue */ |
| 400 | EXCPN_PROLOG_RESTORE_REG r9 |
| 401 | |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 402 | SAVE_R0_TO_R12 |
| 403 | PUSH gp |
| 404 | PUSH fp |
| 405 | PUSH blink |
| 406 | PUSHAX eret |
| 407 | PUSHAX erstatus |
| 408 | PUSH lp_count |
| 409 | PUSHAX lp_end |
| 410 | PUSHAX lp_start |
| 411 | PUSHAX erbta |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 412 | .endm |
| 413 | |
| 414 | /*-------------------------------------------------------------- |
| 415 | * Save scratch regs for exceptions |
| 416 | *-------------------------------------------------------------*/ |
| 417 | .macro SAVE_ALL_SYS |
Vineet Gupta | 5c39c0a | 2013-02-11 20:01:24 +0530 | [diff] [blame] | 418 | SAVE_ALL_EXCEPTION orig_r8_IS_EXCPN |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 419 | .endm |
| 420 | |
| 421 | /*-------------------------------------------------------------- |
| 422 | * Save scratch regs for sys calls |
| 423 | *-------------------------------------------------------------*/ |
| 424 | .macro SAVE_ALL_TRAP |
Vineet Gupta | 352c1d9 | 2013-06-22 12:38:59 +0530 | [diff] [blame^] | 425 | SAVE_ALL_EXCEPTION orig_r8_IS_SCALL |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 426 | .endm |
| 427 | |
| 428 | /*-------------------------------------------------------------- |
| 429 | * Restore all registers used by system call or Exceptions |
| 430 | * SP should always be pointing to the next free stack element |
| 431 | * when entering this macro. |
| 432 | * |
| 433 | * NOTE: |
| 434 | * |
| 435 | * It is recommended that lp_count/ilink1/ilink2 not be used as a dest reg |
| 436 | * for memory load operations. If used in that way interrupts are deffered |
| 437 | * by hardware and that is not good. |
| 438 | *-------------------------------------------------------------*/ |
| 439 | .macro RESTORE_ALL_SYS |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 440 | POPAX erbta |
| 441 | POPAX lp_start |
| 442 | POPAX lp_end |
| 443 | |
| 444 | POP r9 |
| 445 | mov lp_count, r9 ;LD to lp_count is not allowed |
| 446 | |
| 447 | POPAX erstatus |
| 448 | POPAX eret |
| 449 | POP blink |
| 450 | POP fp |
| 451 | POP gp |
| 452 | RESTORE_R12_TO_R0 |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 453 | |
| 454 | ld sp, [sp] /* restore original sp */ |
Vineet Gupta | 359105b | 2013-05-28 13:50:41 +0530 | [diff] [blame] | 455 | /* orig_r0, orig_r8, user_r25 skipped automatically */ |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 456 | .endm |
| 457 | |
| 458 | |
| 459 | /*-------------------------------------------------------------- |
| 460 | * Save all registers used by interrupt handlers. |
| 461 | *-------------------------------------------------------------*/ |
| 462 | .macro SAVE_ALL_INT1 |
| 463 | |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 464 | /* restore original r9 to be saved as part of reg-file */ |
Vineet Gupta | 41195d2 | 2013-01-18 15:12:23 +0530 | [diff] [blame] | 465 | #ifdef CONFIG_SMP |
| 466 | lr r9, [ARC_REG_SCRATCH_DATA0] |
| 467 | #else |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 468 | ld r9, [@int1_saved_reg] |
Vineet Gupta | 41195d2 | 2013-01-18 15:12:23 +0530 | [diff] [blame] | 469 | #endif |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 470 | |
| 471 | /* now we are ready to save the remaining context :) */ |
Vineet Gupta | 5c39c0a | 2013-02-11 20:01:24 +0530 | [diff] [blame] | 472 | st orig_r8_IS_IRQ1, [sp, 8] /* Event Type */ |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 473 | st 0, [sp, 4] /* orig_r0 , N/A for IRQ */ |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 474 | |
| 475 | SAVE_R0_TO_R12 |
| 476 | PUSH gp |
| 477 | PUSH fp |
| 478 | PUSH blink |
| 479 | PUSH ilink1 |
| 480 | PUSHAX status32_l1 |
| 481 | PUSH lp_count |
| 482 | PUSHAX lp_end |
| 483 | PUSHAX lp_start |
| 484 | PUSHAX bta_l1 |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 485 | .endm |
| 486 | |
Vineet Gupta | 4788a59 | 2013-01-18 15:12:22 +0530 | [diff] [blame] | 487 | .macro SAVE_ALL_INT2 |
| 488 | |
| 489 | /* TODO-vineetg: SMP we can't use global nor can we use |
| 490 | * SCRATCH0 as we do for int1 because while int1 is using |
| 491 | * it, int2 can come |
| 492 | */ |
| 493 | /* retsore original r9 , saved in sys_saved_r9 */ |
| 494 | ld r9, [@int2_saved_reg] |
| 495 | |
| 496 | /* now we are ready to save the remaining context :) */ |
| 497 | st orig_r8_IS_IRQ2, [sp, 8] /* Event Type */ |
| 498 | st 0, [sp, 4] /* orig_r0 , N/A for IRQ */ |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 499 | |
| 500 | SAVE_R0_TO_R12 |
| 501 | PUSH gp |
| 502 | PUSH fp |
| 503 | PUSH blink |
| 504 | PUSH ilink2 |
| 505 | PUSHAX status32_l2 |
| 506 | PUSH lp_count |
| 507 | PUSHAX lp_end |
| 508 | PUSHAX lp_start |
| 509 | PUSHAX bta_l2 |
Vineet Gupta | 4788a59 | 2013-01-18 15:12:22 +0530 | [diff] [blame] | 510 | .endm |
| 511 | |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 512 | /*-------------------------------------------------------------- |
| 513 | * Restore all registers used by interrupt handlers. |
| 514 | * |
| 515 | * NOTE: |
| 516 | * |
| 517 | * It is recommended that lp_count/ilink1/ilink2 not be used as a dest reg |
| 518 | * for memory load operations. If used in that way interrupts are deffered |
| 519 | * by hardware and that is not good. |
| 520 | *-------------------------------------------------------------*/ |
| 521 | |
| 522 | .macro RESTORE_ALL_INT1 |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 523 | POPAX bta_l1 |
| 524 | POPAX lp_start |
| 525 | POPAX lp_end |
| 526 | |
| 527 | POP r9 |
| 528 | mov lp_count, r9 ;LD to lp_count is not allowed |
| 529 | |
| 530 | POPAX status32_l1 |
| 531 | POP ilink1 |
| 532 | POP blink |
| 533 | POP fp |
| 534 | POP gp |
| 535 | RESTORE_R12_TO_R0 |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 536 | |
| 537 | ld sp, [sp] /* restore original sp */ |
Vineet Gupta | 359105b | 2013-05-28 13:50:41 +0530 | [diff] [blame] | 538 | /* orig_r0, orig_r8, user_r25 skipped automatically */ |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 539 | .endm |
| 540 | |
Vineet Gupta | 4788a59 | 2013-01-18 15:12:22 +0530 | [diff] [blame] | 541 | .macro RESTORE_ALL_INT2 |
Vineet Gupta | 3ebedbb | 2013-05-28 13:24:43 +0530 | [diff] [blame] | 542 | POPAX bta_l2 |
| 543 | POPAX lp_start |
| 544 | POPAX lp_end |
| 545 | |
| 546 | POP r9 |
| 547 | mov lp_count, r9 ;LD to lp_count is not allowed |
| 548 | |
| 549 | POPAX status32_l2 |
| 550 | POP ilink2 |
| 551 | POP blink |
| 552 | POP fp |
| 553 | POP gp |
| 554 | RESTORE_R12_TO_R0 |
Vineet Gupta | 4788a59 | 2013-01-18 15:12:22 +0530 | [diff] [blame] | 555 | |
| 556 | ld sp, [sp] /* restore original sp */ |
Vineet Gupta | 359105b | 2013-05-28 13:50:41 +0530 | [diff] [blame] | 557 | /* orig_r0, orig_r8, user_r25 skipped automatically */ |
Vineet Gupta | 4788a59 | 2013-01-18 15:12:22 +0530 | [diff] [blame] | 558 | .endm |
| 559 | |
| 560 | |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 561 | /* Get CPU-ID of this core */ |
| 562 | .macro GET_CPU_ID reg |
| 563 | lr \reg, [identity] |
| 564 | lsr \reg, \reg, 8 |
| 565 | bmsk \reg, \reg, 7 |
| 566 | .endm |
| 567 | |
Vineet Gupta | 41195d2 | 2013-01-18 15:12:23 +0530 | [diff] [blame] | 568 | #ifdef CONFIG_SMP |
| 569 | |
| 570 | /*------------------------------------------------- |
| 571 | * Retrieve the current running task on this CPU |
| 572 | * 1. Determine curr CPU id. |
| 573 | * 2. Use it to index into _current_task[ ] |
| 574 | */ |
| 575 | .macro GET_CURR_TASK_ON_CPU reg |
| 576 | GET_CPU_ID \reg |
| 577 | ld.as \reg, [@_current_task, \reg] |
| 578 | .endm |
| 579 | |
| 580 | /*------------------------------------------------- |
| 581 | * Save a new task as the "current" task on this CPU |
| 582 | * 1. Determine curr CPU id. |
| 583 | * 2. Use it to index into _current_task[ ] |
| 584 | * |
| 585 | * Coded differently than GET_CURR_TASK_ON_CPU (which uses LD.AS) |
| 586 | * because ST r0, [r1, offset] can ONLY have s9 @offset |
| 587 | * while LD can take s9 (4 byte insn) or LIMM (8 byte insn) |
| 588 | */ |
| 589 | |
| 590 | .macro SET_CURR_TASK_ON_CPU tsk, tmp |
| 591 | GET_CPU_ID \tmp |
| 592 | add2 \tmp, @_current_task, \tmp |
| 593 | st \tsk, [\tmp] |
| 594 | #ifdef CONFIG_ARC_CURR_IN_REG |
| 595 | mov r25, \tsk |
| 596 | #endif |
| 597 | |
| 598 | .endm |
| 599 | |
| 600 | |
| 601 | #else /* Uniprocessor implementation of macros */ |
| 602 | |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 603 | .macro GET_CURR_TASK_ON_CPU reg |
| 604 | ld \reg, [@_current_task] |
| 605 | .endm |
| 606 | |
| 607 | .macro SET_CURR_TASK_ON_CPU tsk, tmp |
| 608 | st \tsk, [@_current_task] |
Vineet Gupta | 080c374 | 2013-02-11 19:52:57 +0530 | [diff] [blame] | 609 | #ifdef CONFIG_ARC_CURR_IN_REG |
| 610 | mov r25, \tsk |
| 611 | #endif |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 612 | .endm |
| 613 | |
Vineet Gupta | 41195d2 | 2013-01-18 15:12:23 +0530 | [diff] [blame] | 614 | #endif /* SMP / UNI */ |
| 615 | |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 616 | /* ------------------------------------------------------------------ |
| 617 | * Get the ptr to some field of Current Task at @off in task struct |
Vineet Gupta | 080c374 | 2013-02-11 19:52:57 +0530 | [diff] [blame] | 618 | * -Uses r25 for Current task ptr if that is enabled |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 619 | */ |
| 620 | |
Vineet Gupta | 080c374 | 2013-02-11 19:52:57 +0530 | [diff] [blame] | 621 | #ifdef CONFIG_ARC_CURR_IN_REG |
| 622 | |
| 623 | .macro GET_CURR_TASK_FIELD_PTR off, reg |
| 624 | add \reg, r25, \off |
| 625 | .endm |
| 626 | |
| 627 | #else |
| 628 | |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 629 | .macro GET_CURR_TASK_FIELD_PTR off, reg |
| 630 | GET_CURR_TASK_ON_CPU \reg |
| 631 | add \reg, \reg, \off |
| 632 | .endm |
| 633 | |
Vineet Gupta | 080c374 | 2013-02-11 19:52:57 +0530 | [diff] [blame] | 634 | #endif /* CONFIG_ARC_CURR_IN_REG */ |
| 635 | |
Vineet Gupta | 9d42c84 | 2013-01-18 15:12:18 +0530 | [diff] [blame] | 636 | #endif /* __ASSEMBLY__ */ |
| 637 | |
| 638 | #endif /* __ASM_ARC_ENTRY_H */ |