blob: 820202af21a5f3512d5417f3d88b77ce581d5056 [file] [log] [blame]
Vineet Gupta9d42c842013-01-18 15:12:18 +05301/*
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 Gupta4788a592013-01-18 15:12:22 +05308 * 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 Gupta9d42c842013-01-18 15:12:18 +053014 * 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 Gupta080c3742013-02-11 19:52:57 +053022 * -Modified CALLEE_REG save/restore macros to handle the fact that
23 * r25 contains the kernel current task ptr
Vineet Gupta9d42c842013-01-18 15:12:18 +053024 * - 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 Gupta080c3742013-02-11 19:52:57 +053039#include <asm/processor.h> /* For VMALLOC_START */
Vineet Gupta9d42c842013-01-18 15:12:18 +053040#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
53/*--------------------------------------------------------------
54 * Save caller saved registers (scratch registers) ( r0 - r12 )
55 * Registers are pushed / popped in the order defined in struct ptregs
56 * in asm/ptrace.h
57 *-------------------------------------------------------------*/
58.macro SAVE_CALLER_SAVED
59 st.a r0, [sp, -4]
60 st.a r1, [sp, -4]
61 st.a r2, [sp, -4]
62 st.a r3, [sp, -4]
63 st.a r4, [sp, -4]
64 st.a r5, [sp, -4]
65 st.a r6, [sp, -4]
66 st.a r7, [sp, -4]
67 st.a r8, [sp, -4]
68 st.a r9, [sp, -4]
69 st.a r10, [sp, -4]
70 st.a r11, [sp, -4]
71 st.a r12, [sp, -4]
72.endm
73
74/*--------------------------------------------------------------
75 * Restore caller saved registers (scratch registers)
76 *-------------------------------------------------------------*/
77.macro RESTORE_CALLER_SAVED
78 ld.ab r12, [sp, 4]
79 ld.ab r11, [sp, 4]
80 ld.ab r10, [sp, 4]
81 ld.ab r9, [sp, 4]
82 ld.ab r8, [sp, 4]
83 ld.ab r7, [sp, 4]
84 ld.ab r6, [sp, 4]
85 ld.ab r5, [sp, 4]
86 ld.ab r4, [sp, 4]
87 ld.ab r3, [sp, 4]
88 ld.ab r2, [sp, 4]
89 ld.ab r1, [sp, 4]
90 ld.ab r0, [sp, 4]
91.endm
92
93
94/*--------------------------------------------------------------
95 * Save callee saved registers (non scratch registers) ( r13 - r25 )
96 * on kernel stack.
97 * User mode callee regs need to be saved in case of
98 * -fork and friends for replicating from parent to child
99 * -before going into do_signal( ) for ptrace/core-dump
100 * Special case handling is required for r25 in case it is used by kernel
101 * for caching task ptr. Low level exception/ISR save user mode r25
102 * into task->thread.user_r25. So it needs to be retrieved from there and
103 * saved into kernel stack with rest of callee reg-file
104 *-------------------------------------------------------------*/
105.macro SAVE_CALLEE_SAVED_USER
106 st.a r13, [sp, -4]
107 st.a r14, [sp, -4]
108 st.a r15, [sp, -4]
109 st.a r16, [sp, -4]
110 st.a r17, [sp, -4]
111 st.a r18, [sp, -4]
112 st.a r19, [sp, -4]
113 st.a r20, [sp, -4]
114 st.a r21, [sp, -4]
115 st.a r22, [sp, -4]
116 st.a r23, [sp, -4]
117 st.a r24, [sp, -4]
Vineet Gupta080c3742013-02-11 19:52:57 +0530118
119#ifdef CONFIG_ARC_CURR_IN_REG
120 ; Retrieve orig r25 and save it on stack
121 ld r12, [r25, TASK_THREAD + THREAD_USER_R25]
122 st.a r12, [sp, -4]
123#else
Vineet Gupta9d42c842013-01-18 15:12:18 +0530124 st.a r25, [sp, -4]
Vineet Gupta080c3742013-02-11 19:52:57 +0530125#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530126
Vineet Gupta9d42c842013-01-18 15:12:18 +0530127.endm
128
129/*--------------------------------------------------------------
130 * Save callee saved registers (non scratch registers) ( r13 - r25 )
131 * kernel mode callee regs needed to be saved in case of context switch
132 * If r25 is used for caching task pointer then that need not be saved
133 * as it can be re-created from current task global
134 *-------------------------------------------------------------*/
135.macro SAVE_CALLEE_SAVED_KERNEL
136 st.a r13, [sp, -4]
137 st.a r14, [sp, -4]
138 st.a r15, [sp, -4]
139 st.a r16, [sp, -4]
140 st.a r17, [sp, -4]
141 st.a r18, [sp, -4]
142 st.a r19, [sp, -4]
143 st.a r20, [sp, -4]
144 st.a r21, [sp, -4]
145 st.a r22, [sp, -4]
146 st.a r23, [sp, -4]
147 st.a r24, [sp, -4]
Vineet Gupta080c3742013-02-11 19:52:57 +0530148#ifdef CONFIG_ARC_CURR_IN_REG
Vineet Gupta16f9afe2013-05-27 21:43:41 +0530149 sub sp, sp, 4
Vineet Gupta080c3742013-02-11 19:52:57 +0530150#else
Vineet Gupta9d42c842013-01-18 15:12:18 +0530151 st.a r25, [sp, -4]
Vineet Gupta080c3742013-02-11 19:52:57 +0530152#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530153.endm
154
155/*--------------------------------------------------------------
156 * RESTORE_CALLEE_SAVED_KERNEL:
157 * Loads callee (non scratch) Reg File by popping from Kernel mode stack.
158 * This is reverse of SAVE_CALLEE_SAVED,
159 *
160 * NOTE:
161 * Ideally this shd only be called in switch_to for loading
162 * switched-IN task's CALLEE Reg File.
163 * For all other cases RESTORE_CALLEE_SAVED_FAST must be used
164 * which simply pops the stack w/o touching regs.
165 *-------------------------------------------------------------*/
166.macro RESTORE_CALLEE_SAVED_KERNEL
167
Vineet Gupta080c3742013-02-11 19:52:57 +0530168#ifdef CONFIG_ARC_CURR_IN_REG
Vineet Gupta16f9afe2013-05-27 21:43:41 +0530169 add sp, sp, 4 /* skip usual r25 placeholder */
Vineet Gupta080c3742013-02-11 19:52:57 +0530170#else
Vineet Gupta9d42c842013-01-18 15:12:18 +0530171 ld.ab r25, [sp, 4]
Vineet Gupta080c3742013-02-11 19:52:57 +0530172#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530173 ld.ab r24, [sp, 4]
174 ld.ab r23, [sp, 4]
175 ld.ab r22, [sp, 4]
176 ld.ab r21, [sp, 4]
177 ld.ab r20, [sp, 4]
178 ld.ab r19, [sp, 4]
179 ld.ab r18, [sp, 4]
180 ld.ab r17, [sp, 4]
181 ld.ab r16, [sp, 4]
182 ld.ab r15, [sp, 4]
183 ld.ab r14, [sp, 4]
184 ld.ab r13, [sp, 4]
185
186.endm
187
188/*--------------------------------------------------------------
Vineet Guptac3581032013-01-18 15:12:19 +0530189 * RESTORE_CALLEE_SAVED_USER:
190 * This is called after do_signal where tracer might have changed callee regs
191 * thus we need to restore the reg file.
192 * Special case handling is required for r25 in case it is used by kernel
193 * for caching task ptr. Ptrace would have modified on-kernel-stack value of
194 * r25, which needs to be shoved back into task->thread.user_r25 where from
195 * Low level exception/ISR return code will retrieve to populate with rest of
196 * callee reg-file.
197 *-------------------------------------------------------------*/
198.macro RESTORE_CALLEE_SAVED_USER
199
Vineet Guptac3581032013-01-18 15:12:19 +0530200#ifdef CONFIG_ARC_CURR_IN_REG
201 ld.ab r12, [sp, 4]
202 st r12, [r25, TASK_THREAD + THREAD_USER_R25]
203#else
204 ld.ab r25, [sp, 4]
205#endif
206
207 ld.ab r24, [sp, 4]
208 ld.ab r23, [sp, 4]
209 ld.ab r22, [sp, 4]
210 ld.ab r21, [sp, 4]
211 ld.ab r20, [sp, 4]
212 ld.ab r19, [sp, 4]
213 ld.ab r18, [sp, 4]
214 ld.ab r17, [sp, 4]
215 ld.ab r16, [sp, 4]
216 ld.ab r15, [sp, 4]
217 ld.ab r14, [sp, 4]
218 ld.ab r13, [sp, 4]
219.endm
220
221/*--------------------------------------------------------------
Vineet Gupta9d42c842013-01-18 15:12:18 +0530222 * Super FAST Restore callee saved regs by simply re-adjusting SP
223 *-------------------------------------------------------------*/
224.macro DISCARD_CALLEE_SAVED_USER
Vineet Gupta16f9afe2013-05-27 21:43:41 +0530225 add sp, sp, SZ_CALLEE_REGS
Vineet Gupta9d42c842013-01-18 15:12:18 +0530226.endm
227
228/*--------------------------------------------------------------
229 * Restore User mode r25 saved in task_struct->thread.user_r25
230 *-------------------------------------------------------------*/
231.macro RESTORE_USER_R25
232 ld r25, [r25, TASK_THREAD + THREAD_USER_R25]
233.endm
234
235/*-------------------------------------------------------------
236 * given a tsk struct, get to the base of it's kernel mode stack
237 * tsk->thread_info is really a PAGE, whose bottom hoists stack
238 * which grows upwards towards thread_info
239 *------------------------------------------------------------*/
240
241.macro GET_TSK_STACK_BASE tsk, out
242
243 /* Get task->thread_info (this is essentially start of a PAGE) */
244 ld \out, [\tsk, TASK_THREAD_INFO]
245
246 /* Go to end of page where stack begins (grows upwards) */
Vineet Gupta283237a2013-05-28 09:34:45 +0530247 add2 \out, \out, (THREAD_SIZE)/4
Vineet Gupta9d42c842013-01-18 15:12:18 +0530248
249.endm
250
251/*--------------------------------------------------------------
252 * Switch to Kernel Mode stack if SP points to User Mode stack
253 *
254 * Entry : r9 contains pre-IRQ/exception/trap status32
255 * Exit : SP is set to kernel mode stack pointer
Vineet Gupta080c3742013-02-11 19:52:57 +0530256 * If CURR_IN_REG, r25 set to "current" task pointer
Vineet Gupta9d42c842013-01-18 15:12:18 +0530257 * Clobbers: r9
258 *-------------------------------------------------------------*/
259
260.macro SWITCH_TO_KERNEL_STK
261
262 /* User Mode when this happened ? Yes: Proceed to switch stack */
263 bbit1 r9, STATUS_U_BIT, 88f
264
265 /* OK we were already in kernel mode when this event happened, thus can
266 * assume SP is kernel mode SP. _NO_ need to do any stack switching
267 */
268
Vineet Gupta4788a592013-01-18 15:12:22 +0530269#ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
270 /* However....
271 * If Level 2 Interrupts enabled, we may end up with a corner case:
272 * 1. User Task executing
273 * 2. L1 IRQ taken, ISR starts (CPU auto-switched to KERNEL mode)
274 * 3. But before it could switch SP from USER to KERNEL stack
275 * a L2 IRQ "Interrupts" L1
276 * Thay way although L2 IRQ happened in Kernel mode, stack is still
277 * not switched.
278 * To handle this, we may need to switch stack even if in kernel mode
279 * provided SP has values in range of USER mode stack ( < 0x7000_0000 )
280 */
281 brlo sp, VMALLOC_START, 88f
282
283 /* TODO: vineetg:
284 * We need to be a bit more cautious here. What if a kernel bug in
285 * L1 ISR, caused SP to go whaco (some small value which looks like
286 * USER stk) and then we take L2 ISR.
287 * Above brlo alone would treat it as a valid L1-L2 sceanrio
288 * instead of shouting alound
289 * The only feasible way is to make sure this L2 happened in
290 * L1 prelogue ONLY i.e. ilink2 is less than a pre-set marker in
291 * L1 ISR before it switches stack
292 */
293
294#endif
295
Vineet Gupta9d42c842013-01-18 15:12:18 +0530296 /* Save Pre Intr/Exception KERNEL MODE SP on kernel stack
297 * safe-keeping not really needed, but it keeps the epilogue code
298 * (SP restore) simpler/uniform.
299 */
300 b.d 77f
301
302 st.a sp, [sp, -12] ; Make room for orig_r0 and orig_r8
303
30488: /*------Intr/Ecxp happened in user mode, "switch" stack ------ */
305
306 GET_CURR_TASK_ON_CPU r9
307
Vineet Gupta080c3742013-02-11 19:52:57 +0530308#ifdef CONFIG_ARC_CURR_IN_REG
309
310 /* If current task pointer cached in r25, time to
311 * -safekeep USER r25 in task->thread_struct->user_r25
312 * -load r25 with current task ptr
313 */
314 st.as r25, [r9, (TASK_THREAD + THREAD_USER_R25)/4]
315 mov r25, r9
316#endif
317
Vineet Gupta9d42c842013-01-18 15:12:18 +0530318 /* With current tsk in r9, get it's kernel mode stack base */
319 GET_TSK_STACK_BASE r9, r9
320
Vineet Gupta9d42c842013-01-18 15:12:18 +0530321 /* Save Pre Intr/Exception User SP on kernel stack */
322 st.a sp, [r9, -12] ; Make room for orig_r0 and orig_r8
323
324 /* CAUTION:
325 * SP should be set at the very end when we are done with everything
326 * In case of 2 levels of interrupt we depend on value of SP to assume
327 * that everything else is done (loading r25 etc)
328 */
329
330 /* set SP to point to kernel mode stack */
331 mov sp, r9
332
33377: /* ----- Stack Switched to kernel Mode, Now save REG FILE ----- */
334
335.endm
336
337/*------------------------------------------------------------
338 * "FAKE" a rtie to return from CPU Exception context
339 * This is to re-enable Exceptions within exception
340 * Look at EV_ProtV to see how this is actually used
341 *-------------------------------------------------------------*/
342
343.macro FAKE_RET_FROM_EXCPN reg
344
345 ld \reg, [sp, PT_status32]
346 bic \reg, \reg, (STATUS_U_MASK|STATUS_DE_MASK)
347 bset \reg, \reg, STATUS_L_BIT
348 sr \reg, [erstatus]
349 mov \reg, 55f
350 sr \reg, [eret]
351
352 rtie
35355:
354.endm
355
356/*
357 * @reg [OUT] &thread_info of "current"
358 */
359.macro GET_CURR_THR_INFO_FROM_SP reg
360 and \reg, sp, ~(THREAD_SIZE - 1)
361.endm
362
363/*
364 * @reg [OUT] thread_info->flags of "current"
365 */
366.macro GET_CURR_THR_INFO_FLAGS reg
367 GET_CURR_THR_INFO_FROM_SP \reg
368 ld \reg, [\reg, THREAD_INFO_FLAGS]
369.endm
370
371/*--------------------------------------------------------------
372 * For early Exception Prologue, a core reg is temporarily needed to
373 * code the rest of prolog (stack switching). This is done by stashing
374 * it to memory (non-SMP case) or SCRATCH0 Aux Reg (SMP).
375 *
376 * Before saving the full regfile - this reg is restored back, only
377 * to be saved again on kernel mode stack, as part of ptregs.
378 *-------------------------------------------------------------*/
379.macro EXCPN_PROLOG_FREEUP_REG reg
Vineet Gupta41195d22013-01-18 15:12:23 +0530380#ifdef CONFIG_SMP
381 sr \reg, [ARC_REG_SCRATCH_DATA0]
382#else
Vineet Gupta9d42c842013-01-18 15:12:18 +0530383 st \reg, [@ex_saved_reg1]
Vineet Gupta41195d22013-01-18 15:12:23 +0530384#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530385.endm
386
387.macro EXCPN_PROLOG_RESTORE_REG reg
Vineet Gupta41195d22013-01-18 15:12:23 +0530388#ifdef CONFIG_SMP
389 lr \reg, [ARC_REG_SCRATCH_DATA0]
390#else
Vineet Gupta9d42c842013-01-18 15:12:18 +0530391 ld \reg, [@ex_saved_reg1]
Vineet Gupta41195d22013-01-18 15:12:23 +0530392#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530393.endm
394
395/*--------------------------------------------------------------
396 * Save all registers used by Exceptions (TLB Miss, Prot-V, Mem err etc)
397 * Requires SP to be already switched to kernel mode Stack
398 * sp points to the next free element on the stack at exit of this macro.
399 * Registers are pushed / popped in the order defined in struct ptregs
400 * in asm/ptrace.h
401 * Note that syscalls are implemented via TRAP which is also a exception
402 * from CPU's point of view
403 *-------------------------------------------------------------*/
404.macro SAVE_ALL_EXCEPTION marker
405
Vineet Gupta367f3fc2013-03-20 16:53:14 +0530406 st \marker, [sp, 8] /* orig_r8 */
Vineet Gupta5c39c0a2013-02-11 20:01:24 +0530407 st r0, [sp, 4] /* orig_r0, needed only for sys calls */
408
Vineet Gupta9d42c842013-01-18 15:12:18 +0530409 /* Restore r9 used to code the early prologue */
410 EXCPN_PROLOG_RESTORE_REG r9
411
Vineet Gupta9d42c842013-01-18 15:12:18 +0530412 SAVE_CALLER_SAVED
413 st.a r26, [sp, -4] /* gp */
414 st.a fp, [sp, -4]
415 st.a blink, [sp, -4]
416 lr r9, [eret]
417 st.a r9, [sp, -4]
418 lr r9, [erstatus]
419 st.a r9, [sp, -4]
420 st.a lp_count, [sp, -4]
421 lr r9, [lp_end]
422 st.a r9, [sp, -4]
423 lr r9, [lp_start]
424 st.a r9, [sp, -4]
425 lr r9, [erbta]
426 st.a r9, [sp, -4]
Vineet Gupta9d42c842013-01-18 15:12:18 +0530427.endm
428
429/*--------------------------------------------------------------
430 * Save scratch regs for exceptions
431 *-------------------------------------------------------------*/
432.macro SAVE_ALL_SYS
Vineet Gupta5c39c0a2013-02-11 20:01:24 +0530433 SAVE_ALL_EXCEPTION orig_r8_IS_EXCPN
Vineet Gupta9d42c842013-01-18 15:12:18 +0530434.endm
435
436/*--------------------------------------------------------------
437 * Save scratch regs for sys calls
438 *-------------------------------------------------------------*/
439.macro SAVE_ALL_TRAP
Vineet Gupta5c39c0a2013-02-11 20:01:24 +0530440 /*
441 * Setup pt_regs->orig_r8.
442 * Encode syscall number (r8) in upper short word of event type (r9)
443 * N.B. #1: This is already endian safe (see ptrace.h)
444 * #2: Only r9 can be used as scratch as it is already clobbered
445 * and it's contents are no longer needed by the latter part
446 * of exception prologue
447 */
448 lsl r9, r8, 16
449 or r9, r9, orig_r8_IS_SCALL
450
451 SAVE_ALL_EXCEPTION r9
Vineet Gupta9d42c842013-01-18 15:12:18 +0530452.endm
453
454/*--------------------------------------------------------------
455 * Restore all registers used by system call or Exceptions
456 * SP should always be pointing to the next free stack element
457 * when entering this macro.
458 *
459 * NOTE:
460 *
461 * It is recommended that lp_count/ilink1/ilink2 not be used as a dest reg
462 * for memory load operations. If used in that way interrupts are deffered
463 * by hardware and that is not good.
464 *-------------------------------------------------------------*/
465.macro RESTORE_ALL_SYS
Vineet Gupta9d42c842013-01-18 15:12:18 +0530466 ld.ab r9, [sp, 4]
467 sr r9, [erbta]
468 ld.ab r9, [sp, 4]
469 sr r9, [lp_start]
470 ld.ab r9, [sp, 4]
471 sr r9, [lp_end]
472 ld.ab r9, [sp, 4]
473 mov lp_count, r9
474 ld.ab r9, [sp, 4]
475 sr r9, [erstatus]
476 ld.ab r9, [sp, 4]
477 sr r9, [eret]
478 ld.ab blink, [sp, 4]
479 ld.ab fp, [sp, 4]
480 ld.ab r26, [sp, 4] /* gp */
481 RESTORE_CALLER_SAVED
482
483 ld sp, [sp] /* restore original sp */
484 /* orig_r0 and orig_r8 skipped automatically */
485.endm
486
487
488/*--------------------------------------------------------------
489 * Save all registers used by interrupt handlers.
490 *-------------------------------------------------------------*/
491.macro SAVE_ALL_INT1
492
493 /* restore original r9 , saved in int1_saved_reg
494 * It will be saved on stack in macro: SAVE_CALLER_SAVED
495 */
Vineet Gupta41195d22013-01-18 15:12:23 +0530496#ifdef CONFIG_SMP
497 lr r9, [ARC_REG_SCRATCH_DATA0]
498#else
Vineet Gupta9d42c842013-01-18 15:12:18 +0530499 ld r9, [@int1_saved_reg]
Vineet Gupta41195d22013-01-18 15:12:23 +0530500#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530501
502 /* now we are ready to save the remaining context :) */
Vineet Gupta5c39c0a2013-02-11 20:01:24 +0530503 st orig_r8_IS_IRQ1, [sp, 8] /* Event Type */
Vineet Gupta9d42c842013-01-18 15:12:18 +0530504 st 0, [sp, 4] /* orig_r0 , N/A for IRQ */
505 SAVE_CALLER_SAVED
506 st.a r26, [sp, -4] /* gp */
507 st.a fp, [sp, -4]
508 st.a blink, [sp, -4]
509 st.a ilink1, [sp, -4]
510 lr r9, [status32_l1]
511 st.a r9, [sp, -4]
512 st.a lp_count, [sp, -4]
513 lr r9, [lp_end]
514 st.a r9, [sp, -4]
515 lr r9, [lp_start]
516 st.a r9, [sp, -4]
517 lr r9, [bta_l1]
518 st.a r9, [sp, -4]
Vineet Gupta9d42c842013-01-18 15:12:18 +0530519.endm
520
Vineet Gupta4788a592013-01-18 15:12:22 +0530521.macro SAVE_ALL_INT2
522
523 /* TODO-vineetg: SMP we can't use global nor can we use
524 * SCRATCH0 as we do for int1 because while int1 is using
525 * it, int2 can come
526 */
527 /* retsore original r9 , saved in sys_saved_r9 */
528 ld r9, [@int2_saved_reg]
529
530 /* now we are ready to save the remaining context :) */
531 st orig_r8_IS_IRQ2, [sp, 8] /* Event Type */
532 st 0, [sp, 4] /* orig_r0 , N/A for IRQ */
533 SAVE_CALLER_SAVED
534 st.a r26, [sp, -4] /* gp */
535 st.a fp, [sp, -4]
536 st.a blink, [sp, -4]
537 st.a ilink2, [sp, -4]
538 lr r9, [status32_l2]
539 st.a r9, [sp, -4]
540 st.a lp_count, [sp, -4]
541 lr r9, [lp_end]
542 st.a r9, [sp, -4]
543 lr r9, [lp_start]
544 st.a r9, [sp, -4]
545 lr r9, [bta_l2]
546 st.a r9, [sp, -4]
Vineet Gupta4788a592013-01-18 15:12:22 +0530547.endm
548
Vineet Gupta9d42c842013-01-18 15:12:18 +0530549/*--------------------------------------------------------------
550 * Restore all registers used by interrupt handlers.
551 *
552 * NOTE:
553 *
554 * It is recommended that lp_count/ilink1/ilink2 not be used as a dest reg
555 * for memory load operations. If used in that way interrupts are deffered
556 * by hardware and that is not good.
557 *-------------------------------------------------------------*/
558
559.macro RESTORE_ALL_INT1
Vineet Gupta9d42c842013-01-18 15:12:18 +0530560 ld.ab r9, [sp, 4] /* Actual reg file */
561 sr r9, [bta_l1]
562 ld.ab r9, [sp, 4]
563 sr r9, [lp_start]
564 ld.ab r9, [sp, 4]
565 sr r9, [lp_end]
566 ld.ab r9, [sp, 4]
567 mov lp_count, r9
568 ld.ab r9, [sp, 4]
569 sr r9, [status32_l1]
570 ld.ab r9, [sp, 4]
571 mov ilink1, r9
572 ld.ab blink, [sp, 4]
573 ld.ab fp, [sp, 4]
574 ld.ab r26, [sp, 4] /* gp */
575 RESTORE_CALLER_SAVED
576
577 ld sp, [sp] /* restore original sp */
578 /* orig_r0 and orig_r8 skipped automatically */
579.endm
580
Vineet Gupta4788a592013-01-18 15:12:22 +0530581.macro RESTORE_ALL_INT2
Vineet Gupta4788a592013-01-18 15:12:22 +0530582 ld.ab r9, [sp, 4]
583 sr r9, [bta_l2]
584 ld.ab r9, [sp, 4]
585 sr r9, [lp_start]
586 ld.ab r9, [sp, 4]
587 sr r9, [lp_end]
588 ld.ab r9, [sp, 4]
589 mov lp_count, r9
590 ld.ab r9, [sp, 4]
591 sr r9, [status32_l2]
592 ld.ab r9, [sp, 4]
593 mov ilink2, r9
594 ld.ab blink, [sp, 4]
595 ld.ab fp, [sp, 4]
596 ld.ab r26, [sp, 4] /* gp */
597 RESTORE_CALLER_SAVED
598
599 ld sp, [sp] /* restore original sp */
600 /* orig_r0 and orig_r8 skipped automatically */
601
602.endm
603
604
Vineet Gupta9d42c842013-01-18 15:12:18 +0530605/* Get CPU-ID of this core */
606.macro GET_CPU_ID reg
607 lr \reg, [identity]
608 lsr \reg, \reg, 8
609 bmsk \reg, \reg, 7
610.endm
611
Vineet Gupta41195d22013-01-18 15:12:23 +0530612#ifdef CONFIG_SMP
613
614/*-------------------------------------------------
615 * Retrieve the current running task on this CPU
616 * 1. Determine curr CPU id.
617 * 2. Use it to index into _current_task[ ]
618 */
619.macro GET_CURR_TASK_ON_CPU reg
620 GET_CPU_ID \reg
621 ld.as \reg, [@_current_task, \reg]
622.endm
623
624/*-------------------------------------------------
625 * Save a new task as the "current" task on this CPU
626 * 1. Determine curr CPU id.
627 * 2. Use it to index into _current_task[ ]
628 *
629 * Coded differently than GET_CURR_TASK_ON_CPU (which uses LD.AS)
630 * because ST r0, [r1, offset] can ONLY have s9 @offset
631 * while LD can take s9 (4 byte insn) or LIMM (8 byte insn)
632 */
633
634.macro SET_CURR_TASK_ON_CPU tsk, tmp
635 GET_CPU_ID \tmp
636 add2 \tmp, @_current_task, \tmp
637 st \tsk, [\tmp]
638#ifdef CONFIG_ARC_CURR_IN_REG
639 mov r25, \tsk
640#endif
641
642.endm
643
644
645#else /* Uniprocessor implementation of macros */
646
Vineet Gupta9d42c842013-01-18 15:12:18 +0530647.macro GET_CURR_TASK_ON_CPU reg
648 ld \reg, [@_current_task]
649.endm
650
651.macro SET_CURR_TASK_ON_CPU tsk, tmp
652 st \tsk, [@_current_task]
Vineet Gupta080c3742013-02-11 19:52:57 +0530653#ifdef CONFIG_ARC_CURR_IN_REG
654 mov r25, \tsk
655#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530656.endm
657
Vineet Gupta41195d22013-01-18 15:12:23 +0530658#endif /* SMP / UNI */
659
Vineet Gupta9d42c842013-01-18 15:12:18 +0530660/* ------------------------------------------------------------------
661 * Get the ptr to some field of Current Task at @off in task struct
Vineet Gupta080c3742013-02-11 19:52:57 +0530662 * -Uses r25 for Current task ptr if that is enabled
Vineet Gupta9d42c842013-01-18 15:12:18 +0530663 */
664
Vineet Gupta080c3742013-02-11 19:52:57 +0530665#ifdef CONFIG_ARC_CURR_IN_REG
666
667.macro GET_CURR_TASK_FIELD_PTR off, reg
668 add \reg, r25, \off
669.endm
670
671#else
672
Vineet Gupta9d42c842013-01-18 15:12:18 +0530673.macro GET_CURR_TASK_FIELD_PTR off, reg
674 GET_CURR_TASK_ON_CPU \reg
675 add \reg, \reg, \off
676.endm
677
Vineet Gupta080c3742013-02-11 19:52:57 +0530678#endif /* CONFIG_ARC_CURR_IN_REG */
679
Vineet Gupta9d42c842013-01-18 15:12:18 +0530680#endif /* __ASSEMBLY__ */
681
682#endif /* __ASM_ARC_ENTRY_H */