blob: e33a0bf45589089707e9e715cfdfe40f5b805f95 [file] [log] [blame]
Vineet Gupta9d42c842013-01-18 15:12:18 +05301/*
2 * Low Level Interrupts/Traps/Exceptions(non-TLB) Handling for ARC
3 *
4 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
Vineet Gupta547f1122013-01-18 15:12:22 +053010 * vineetg: Feb 2011 (ptrace low level code fixes)
11 * -traced syscall return code (r0) was not saved into pt_regs for restoring
12 * into user reg-file when traded task rets to user space.
13 * -syscalls needing arch-wrappers (mainly for passing sp as pt_regs)
14 * were not invoking post-syscall trace hook (jumping directly into
15 * ret_from_system_call)
16 *
Vineet Gupta9d42c842013-01-18 15:12:18 +053017 * vineetg: Nov 2010:
18 * -Vector table jumps (@8 bytes) converted into branches (@4 bytes)
19 * -To maintain the slot size of 8 bytes/vector, added nop, which is
20 * not executed at runtime.
21 *
22 * vineetg: Nov 2009 (Everything needed for TIF_RESTORE_SIGMASK)
23 * -do_signal()invoked upon TIF_RESTORE_SIGMASK as well
24 * -Wrappers for sys_{,rt_}sigsuspend() nolonger needed as they don't
25 * need ptregs anymore
26 *
27 * Vineetg: Oct 2009
28 * -In a rare scenario, Process gets a Priv-V exception and gets scheduled
29 * out. Since we don't do FAKE RTIE for Priv-V, CPU excpetion state remains
30 * active (AE bit enabled). This causes a double fault for a subseq valid
31 * exception. Thus FAKE RTIE needed in low level Priv-Violation handler.
32 * Instr Error could also cause similar scenario, so same there as well.
33 *
Vineet Gupta4788a592013-01-18 15:12:22 +053034 * Vineetg: March 2009 (Supporting 2 levels of Interrupts)
35 *
Vineet Gupta9d42c842013-01-18 15:12:18 +053036 * Vineetg: Aug 28th 2008: Bug #94984
37 * -Zero Overhead Loop Context shd be cleared when entering IRQ/EXcp/Trap
38 * Normally CPU does this automatically, however when doing FAKE rtie,
39 * we need to explicitly do this. The problem in macros
40 * FAKE_RET_FROM_EXCPN and FAKE_RET_FROM_EXCPN_LOCK_IRQ was that this bit
41 * was being "CLEARED" rather then "SET". Since it is Loop INHIBIT Bit,
42 * setting it and not clearing it clears ZOL context
43 *
Vineet Gupta080c3742013-02-11 19:52:57 +053044 * Vineetg: May 16th, 2008
45 * - r25 now contains the Current Task when in kernel
46 *
Vineet Gupta9d42c842013-01-18 15:12:18 +053047 * Vineetg: Dec 22, 2007
48 * Minor Surgery of Low Level ISR to make it SMP safe
49 * - MMU_SCRATCH0 Reg used for freeing up r9 in Level 1 ISR
50 * - _current_task is made an array of NR_CPUS
51 * - Access of _current_task wrapped inside a macro so that if hardware
52 * team agrees for a dedicated reg, no other code is touched
53 *
54 * Amit Bhor, Rahul Trivedi, Kanika Nema, Sameer Dhavale : Codito Tech 2004
55 */
56
57/*------------------------------------------------------------------
58 * Function ABI
59 *------------------------------------------------------------------
60 *
61 * Arguments r0 - r7
62 * Caller Saved Registers r0 - r12
63 * Callee Saved Registers r13- r25
64 * Global Pointer (gp) r26
65 * Frame Pointer (fp) r27
66 * Stack Pointer (sp) r28
67 * Interrupt link register (ilink1) r29
68 * Interrupt link register (ilink2) r30
69 * Branch link register (blink) r31
70 *------------------------------------------------------------------
71 */
72
73 .cpu A7
74
75;############################ Vector Table #################################
76
77.macro VECTOR lbl
78#if 1 /* Just in case, build breaks */
79 j \lbl
80#else
81 b \lbl
82 nop
83#endif
84.endm
85
86 .section .vector, "ax",@progbits
87 .align 4
88
89/* Each entry in the vector table must occupy 2 words. Since it is a jump
90 * across sections (.vector to .text) we are gauranteed that 'j somewhere'
91 * will use the 'j limm' form of the intrsuction as long as somewhere is in
92 * a section other than .vector.
93 */
94
95; ********* Critical System Events **********************
96VECTOR res_service ; 0x0, Restart Vector (0x0)
97VECTOR mem_service ; 0x8, Mem exception (0x1)
98VECTOR instr_service ; 0x10, Instrn Error (0x2)
99
100; ******************** Device ISRs **********************
Vineet Gupta4788a592013-01-18 15:12:22 +0530101#ifdef CONFIG_ARC_IRQ3_LV2
102VECTOR handle_interrupt_level2
103#else
Vineet Gupta9d42c842013-01-18 15:12:18 +0530104VECTOR handle_interrupt_level1
Vineet Gupta4788a592013-01-18 15:12:22 +0530105#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530106
107VECTOR handle_interrupt_level1
108
Vineet Gupta4788a592013-01-18 15:12:22 +0530109#ifdef CONFIG_ARC_IRQ5_LV2
110VECTOR handle_interrupt_level2
111#else
Vineet Gupta9d42c842013-01-18 15:12:18 +0530112VECTOR handle_interrupt_level1
Vineet Gupta4788a592013-01-18 15:12:22 +0530113#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530114
Vineet Gupta4788a592013-01-18 15:12:22 +0530115#ifdef CONFIG_ARC_IRQ6_LV2
116VECTOR handle_interrupt_level2
117#else
Vineet Gupta9d42c842013-01-18 15:12:18 +0530118VECTOR handle_interrupt_level1
Vineet Gupta4788a592013-01-18 15:12:22 +0530119#endif
Vineet Gupta9d42c842013-01-18 15:12:18 +0530120
121.rept 25
122VECTOR handle_interrupt_level1 ; Other devices
123.endr
124
125/* FOR ARC600: timer = 0x3, uart = 0x8, emac = 0x10 */
126
127; ******************** Exceptions **********************
128VECTOR EV_MachineCheck ; 0x100, Fatal Machine check (0x20)
129VECTOR EV_TLBMissI ; 0x108, Intruction TLB miss (0x21)
130VECTOR EV_TLBMissD ; 0x110, Data TLB miss (0x22)
131VECTOR EV_TLBProtV ; 0x118, Protection Violation (0x23)
132 ; or Misaligned Access
133VECTOR EV_PrivilegeV ; 0x120, Privilege Violation (0x24)
134VECTOR EV_Trap ; 0x128, Trap exception (0x25)
135VECTOR EV_Extension ; 0x130, Extn Intruction Excp (0x26)
136
137.rept 24
138VECTOR reserved ; Reserved Exceptions
139.endr
140
141#include <linux/linkage.h> /* ARC_{EXTRY,EXIT} */
142#include <asm/entry.h> /* SAVE_ALL_{INT1,INT2,TRAP...} */
143#include <asm/errno.h>
144#include <asm/arcregs.h>
145#include <asm/irqflags.h>
146
147;##################### Scratch Mem for IRQ stack switching #############
148
149 .section .data ; NOT .global
150 .align 32
151 .type int1_saved_reg, @object
152 .size int1_saved_reg, 4
153int1_saved_reg:
154 .zero 4
155
Vineet Gupta4788a592013-01-18 15:12:22 +0530156/* Each Interrupt level needs it's own scratch */
157#ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
158
159 .section .data ; NOT .global
160 .type int2_saved_reg, @object
161 .size int2_saved_reg, 4
162int2_saved_reg:
163 .zero 4
164
165#endif
166
Vineet Gupta9d42c842013-01-18 15:12:18 +0530167; ---------------------------------------------
168 .section .text, "ax",@progbits
169
170res_service: ; processor restart
171 flag 0x1 ; not implemented
172 nop
173 nop
174
175reserved: ; processor restart
176 rtie ; jump to processor initializations
177
178;##################### Interrupt Handling ##############################
179
Vineet Gupta4788a592013-01-18 15:12:22 +0530180#ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
181; ---------------------------------------------
182; Level 2 ISR: Can interrupt a Level 1 ISR
183; ---------------------------------------------
184ARC_ENTRY handle_interrupt_level2
185
186 ; TODO-vineetg for SMP this wont work
187 ; free up r9 as scratchpad
188 st r9, [@int2_saved_reg]
189
190 ;Which mode (user/kernel) was the system in when intr occured
191 lr r9, [status32_l2]
192
193 SWITCH_TO_KERNEL_STK
194 SAVE_ALL_INT2
195
196 ;------------------------------------------------------
197 ; if L2 IRQ interrupted a L1 ISR, disable preemption
198 ;------------------------------------------------------
199
200 ld r9, [sp, PT_status32] ; get statu32_l2 (saved in pt_regs)
201 bbit0 r9, STATUS_A1_BIT, 1f ; L1 not active when L2 IRQ, so normal
202
203 ; A1 is set in status32_l2
204 ; bump thread_info->preempt_count (Disable preemption)
205 GET_CURR_THR_INFO_FROM_SP r10
206 ld r9, [r10, THREAD_INFO_PREEMPT_COUNT]
207 add r9, r9, 1
208 st r9, [r10, THREAD_INFO_PREEMPT_COUNT]
209
2101:
211 ;------------------------------------------------------
212 ; setup params for Linux common ISR and invoke it
213 ;------------------------------------------------------
214 lr r0, [icause2]
215 and r0, r0, 0x1f
216
217 bl.d @arch_do_IRQ
218 mov r1, sp
219
220 mov r8,0x2
221 sr r8, [AUX_IRQ_LV12] ; clear bit in Sticky Status Reg
222
223 b ret_from_exception
224
225ARC_EXIT handle_interrupt_level2
226
227#endif
228
Vineet Gupta9d42c842013-01-18 15:12:18 +0530229; ---------------------------------------------
230; Level 1 ISR
231; ---------------------------------------------
232ARC_ENTRY handle_interrupt_level1
233
234 /* free up r9 as scratchpad */
235 st r9, [@int1_saved_reg]
236
237 ;Which mode (user/kernel) was the system in when intr occured
238 lr r9, [status32_l1]
239
240 SWITCH_TO_KERNEL_STK
241 SAVE_ALL_INT1
242
243 lr r0, [icause1]
244 and r0, r0, 0x1f
245
246 bl.d @arch_do_IRQ
247 mov r1, sp
248
249 mov r8,0x1
250 sr r8, [AUX_IRQ_LV12] ; clear bit in Sticky Status Reg
251
252 b ret_from_exception
253ARC_EXIT handle_interrupt_level1
254
255;################### Non TLB Exception Handling #############################
256
257; ---------------------------------------------
258; Instruction Error Exception Handler
259; ---------------------------------------------
260
261ARC_ENTRY instr_service
262
263 EXCPN_PROLOG_FREEUP_REG r9
264
265 lr r9, [erstatus]
266
267 SWITCH_TO_KERNEL_STK
268 SAVE_ALL_SYS
269
270 lr r0, [ecr]
271 lr r1, [efa]
272
273 mov r2, sp
274
275 FAKE_RET_FROM_EXCPN r9
276
277 bl do_insterror_or_kprobe
278 b ret_from_exception
279ARC_EXIT instr_service
280
281; ---------------------------------------------
282; Memory Error Exception Handler
283; ---------------------------------------------
284
285ARC_ENTRY mem_service
286
287 EXCPN_PROLOG_FREEUP_REG r9
288
289 lr r9, [erstatus]
290
291 SWITCH_TO_KERNEL_STK
292 SAVE_ALL_SYS
293
294 lr r0, [ecr]
295 lr r1, [efa]
296 mov r2, sp
297 bl do_memory_error
298 b ret_from_exception
299ARC_EXIT mem_service
300
301; ---------------------------------------------
302; Machine Check Exception Handler
303; ---------------------------------------------
304
305ARC_ENTRY EV_MachineCheck
306
307 EXCPN_PROLOG_FREEUP_REG r9
308 lr r9, [erstatus]
309
310 SWITCH_TO_KERNEL_STK
311 SAVE_ALL_SYS
312
313 lr r0, [ecr]
314 lr r1, [efa]
315 mov r2, sp
316
317 brne r0, 0x200100, 1f
318 bl do_tlb_overlap_fault
319 b ret_from_exception
320
3211:
322 ; DEAD END: can't do much, display Regs and HALT
323 SAVE_CALLEE_SAVED_USER
324
325 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
326 st sp, [r10, THREAD_CALLEE_REG]
327
328 j do_machine_check_fault
329
330ARC_EXIT EV_MachineCheck
331
332; ---------------------------------------------
333; Protection Violation Exception Handler
334; ---------------------------------------------
335
336ARC_ENTRY EV_TLBProtV
337
338 EXCPN_PROLOG_FREEUP_REG r9
339
340 ;Which mode (user/kernel) was the system in when Exception occured
341 lr r9, [erstatus]
342
343 SWITCH_TO_KERNEL_STK
344 SAVE_ALL_SYS
345
346 ;---------(3) Save some more regs-----------------
347 ; vineetg: Mar 6th: Random Seg Fault issue #1
348 ; ecr and efa were not saved in case an Intr sneaks in
349 ; after fake rtie
350 ;
351 lr r3, [ecr]
352 lr r4, [efa]
353
354 ; --------(4) Return from CPU Exception Mode ---------
355 ; Fake a rtie, but rtie to next label
356 ; That way, subsequently, do_page_fault ( ) executes in pure kernel
357 ; mode with further Exceptions enabled
358
359 FAKE_RET_FROM_EXCPN r9
360
361 ;------ (5) Type of Protection Violation? ----------
362 ;
363 ; ProtV Hardware Exception is triggered for Access Faults of 2 types
364 ; -Access Violaton (WRITE to READ ONLY Page) - for linux COW
365 ; -Unaligned Access (READ/WRITE on odd boundary)
366 ;
367 cmp r3, 0x230400 ; Misaligned data access ?
368 beq 4f
369
370 ;========= (6a) Access Violation Processing ========
371 cmp r3, 0x230100
372 mov r1, 0x0 ; if LD exception ? write = 0
373 mov.ne r1, 0x1 ; else write = 1
374
375 mov r2, r4 ; faulting address
376 mov r0, sp ; pt_regs
377 bl do_page_fault
378 b ret_from_exception
379
380 ;========== (6b) Non aligned access ============
3814:
382 mov r0, r3 ; cause code
383 mov r1, r4 ; faulting address
384 mov r2, sp ; pt_regs
385
386 bl do_misaligned_access
387 b ret_from_exception
388
389ARC_EXIT EV_TLBProtV
390
391; ---------------------------------------------
392; Privilege Violation Exception Handler
393; ---------------------------------------------
394ARC_ENTRY EV_PrivilegeV
395
396 EXCPN_PROLOG_FREEUP_REG r9
397
398 lr r9, [erstatus]
399
400 SWITCH_TO_KERNEL_STK
401 SAVE_ALL_SYS
402
403 lr r0, [ecr]
404 lr r1, [efa]
405 mov r2, sp
406
407 FAKE_RET_FROM_EXCPN r9
408
409 bl do_privilege_fault
410 b ret_from_exception
411ARC_EXIT EV_PrivilegeV
412
413; ---------------------------------------------
414; Extension Instruction Exception Handler
415; ---------------------------------------------
416ARC_ENTRY EV_Extension
417
418 EXCPN_PROLOG_FREEUP_REG r9
419 lr r9, [erstatus]
420
421 SWITCH_TO_KERNEL_STK
422 SAVE_ALL_SYS
423
424 lr r0, [ecr]
425 lr r1, [efa]
426 mov r2, sp
427 bl do_extension_fault
428 b ret_from_exception
429ARC_EXIT EV_Extension
430
Vineet Gupta547f1122013-01-18 15:12:22 +0530431;######################### System Call Tracing #########################
432
433tracesys:
434 ; save EFA in case tracer wants the PC of traced task
435 ; using ERET won't work since next-PC has already committed
436 lr r12, [efa]
437 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r11
438 st r12, [r11, THREAD_FAULT_ADDR]
439
440 ; PRE Sys Call Ptrace hook
441 mov r0, sp ; pt_regs needed
442 bl @syscall_trace_entry
443
444 ; Tracing code now returns the syscall num (orig or modif)
445 mov r8, r0
446
447 ; Do the Sys Call as we normally would.
448 ; Validate the Sys Call number
449 cmp r8, NR_syscalls
450 mov.hi r0, -ENOSYS
451 bhi tracesys_exit
452
453 ; Restore the sys-call args. Mere invocation of the hook abv could have
454 ; clobbered them (since they are in scratch regs). The tracer could also
455 ; have deliberately changed the syscall args: r0-r7
456 ld r0, [sp, PT_r0]
457 ld r1, [sp, PT_r1]
458 ld r2, [sp, PT_r2]
459 ld r3, [sp, PT_r3]
460 ld r4, [sp, PT_r4]
461 ld r5, [sp, PT_r5]
462 ld r6, [sp, PT_r6]
463 ld r7, [sp, PT_r7]
464 ld.as r9, [sys_call_table, r8]
465 jl [r9] ; Entry into Sys Call Handler
466
467tracesys_exit:
468 st r0, [sp, PT_r0] ; sys call return value in pt_regs
469
470 ;POST Sys Call Ptrace Hook
471 bl @syscall_trace_exit
472 b ret_from_exception ; NOT ret_from_system_call at is saves r0 which
473 ; we'd done before calling post hook above
474
Vineet Gupta9d42c842013-01-18 15:12:18 +0530475;################### Break Point TRAP ##########################
476
477 ; ======= (5b) Trap is due to Break-Point =========
478
479trap_with_param:
480
Vineet Gupta5c39c0a2013-02-11 20:01:24 +0530481 ; stop_pc info by gdb needs this info
482 st orig_r8_IS_BRKPT, [sp, PT_orig_r8]
Vineet Gupta9d42c842013-01-18 15:12:18 +0530483
484 mov r0, r12
485 lr r1, [efa]
486 mov r2, sp
487
488 ; Now that we have read EFA, its safe to do "fake" rtie
489 ; and get out of CPU exception mode
490 FAKE_RET_FROM_EXCPN r11
491
492 ; Save callee regs in case gdb wants to have a look
493 ; SP will grow up by size of CALLEE Reg-File
494 ; NOTE: clobbers r12
495 SAVE_CALLEE_SAVED_USER
496
497 ; save location of saved Callee Regs @ thread_struct->pc
498 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
499 st sp, [r10, THREAD_CALLEE_REG]
500
501 ; Call the trap handler
502 bl do_non_swi_trap
503
504 ; unwind stack to discard Callee saved Regs
505 DISCARD_CALLEE_SAVED_USER
506
507 b ret_from_exception
508
509;##################### Trap Handling ##############################
510;
511; EV_Trap caused by TRAP_S and TRAP0 instructions.
512;------------------------------------------------------------------
513; (1) System Calls
514; :parameters in r0-r7.
515; :r8 has the system call number
516; (2) Break Points
517;------------------------------------------------------------------
518
519ARC_ENTRY EV_Trap
520
521 ; Need at least 1 reg to code the early exception prolog
522 EXCPN_PROLOG_FREEUP_REG r9
523
524 ;Which mode (user/kernel) was the system in when intr occured
525 lr r9, [erstatus]
526
527 SWITCH_TO_KERNEL_STK
528 SAVE_ALL_TRAP
529
530 ;------- (4) What caused the Trap --------------
531 lr r12, [ecr]
532 and.f 0, r12, ECR_PARAM_MASK
533 bnz trap_with_param
534
535 ; ======= (5a) Trap is due to System Call ========
536
537 ; Before doing anything, return from CPU Exception Mode
538 FAKE_RET_FROM_EXCPN r11
539
Vineet Gupta547f1122013-01-18 15:12:22 +0530540 ; If syscall tracing ongoing, invoke pre-pos-hooks
541 GET_CURR_THR_INFO_FLAGS r10
542 btst r10, TIF_SYSCALL_TRACE
543 bnz tracesys ; this never comes back
544
Vineet Gupta9d42c842013-01-18 15:12:18 +0530545 ;============ This is normal System Call case ==========
546 ; Sys-call num shd not exceed the total system calls avail
547 cmp r8, NR_syscalls
548 mov.hi r0, -ENOSYS
549 bhi ret_from_system_call
550
551 ; Offset into the syscall_table and call handler
552 ld.as r9,[sys_call_table, r8]
553 jl [r9] ; Entry into Sys Call Handler
554
555 ; fall through to ret_from_system_call
556ARC_EXIT EV_Trap
557
558ARC_ENTRY ret_from_system_call
559
560 st r0, [sp, PT_r0] ; sys call return value in pt_regs
561
562 ; fall through yet again to ret_from_exception
563
564;############# Return from Intr/Excp/Trap (Linux Specifics) ##############
565;
566; If ret to user mode do we need to handle signals, schedule() et al.
567
568ARC_ENTRY ret_from_exception
569
570 ; Pre-{IRQ,Trap,Exception} K/U mode from pt_regs->status32
571 ld r8, [sp, PT_status32] ; returning to User/Kernel Mode
572
573#ifdef CONFIG_PREEMPT
574 bbit0 r8, STATUS_U_BIT, resume_kernel_mode
575#else
576 bbit0 r8, STATUS_U_BIT, restore_regs
577#endif
578
579 ; Before returning to User mode check-for-and-complete any pending work
580 ; such as rescheduling/signal-delivery etc.
581resume_user_mode_begin:
582
583 ; Disable IRQs to ensures that chk for pending work itself is atomic
584 ; (and we don't end up missing a NEED_RESCHED/SIGPENDING due to an
585 ; interim IRQ).
586 IRQ_DISABLE r10
587
588 ; Fast Path return to user mode if no pending work
589 GET_CURR_THR_INFO_FLAGS r9
590 and.f 0, r9, _TIF_WORK_MASK
591 bz restore_regs
592
593 ; --- (Slow Path #1) task preemption ---
594 bbit0 r9, TIF_NEED_RESCHED, .Lchk_pend_signals
595 mov blink, resume_user_mode_begin ; tail-call to U mode ret chks
596 b @schedule ; BTST+Bnz causes relo error in link
597
598.Lchk_pend_signals:
599 IRQ_ENABLE r10
600
601 ; --- (Slow Path #2) pending signal ---
602 mov r0, sp ; pt_regs for arg to do_signal()/do_notify_resume()
603
604 bbit0 r9, TIF_SIGPENDING, .Lchk_notify_resume
605
Vineet Guptac3581032013-01-18 15:12:19 +0530606 ; Normal Trap/IRQ entry only saves Scratch (caller-saved) regs
607 ; in pt_reg since the "C" ABI (kernel code) will automatically
608 ; save/restore callee-saved regs.
609 ;
610 ; However, here we need to explicitly save callee regs because
Vineet Gupta9d42c842013-01-18 15:12:18 +0530611 ; (i) If this signal causes coredump - full regfile needed
612 ; (ii) If signal is SIGTRAP/SIGSTOP, task is being traced thus
613 ; tracer might call PEEKUSR(CALLEE reg)
614 ;
615 ; NOTE: SP will grow up by size of CALLEE Reg-File
616 SAVE_CALLEE_SAVED_USER ; clobbers r12
617
618 ; save location of saved Callee Regs @ thread_struct->callee
619 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
620 st sp, [r10, THREAD_CALLEE_REG]
621
622 bl @do_signal
623
Vineet Guptac3581032013-01-18 15:12:19 +0530624 ; Ideally we want to discard the Callee reg above, however if this was
625 ; a tracing signal, tracer could have done a POKEUSR(CALLEE reg)
626 RESTORE_CALLEE_SAVED_USER
Vineet Gupta9d42c842013-01-18 15:12:18 +0530627
628 b resume_user_mode_begin ; loop back to start of U mode ret
629
630 ; --- (Slow Path #3) notify_resume ---
631.Lchk_notify_resume:
632 btst r9, TIF_NOTIFY_RESUME
633 blnz @do_notify_resume
634 b resume_user_mode_begin ; unconditionally back to U mode ret chks
635 ; for single exit point from this block
636
637#ifdef CONFIG_PREEMPT
638
639resume_kernel_mode:
640
641 ; Can't preempt if preemption disabled
642 GET_CURR_THR_INFO_FROM_SP r10
643 ld r8, [r10, THREAD_INFO_PREEMPT_COUNT]
644 brne r8, 0, restore_regs
645
646 ; check if this task's NEED_RESCHED flag set
647 ld r9, [r10, THREAD_INFO_FLAGS]
648 bbit0 r9, TIF_NEED_RESCHED, restore_regs
649
650 IRQ_DISABLE r9
651
652 ; Invoke PREEMPTION
653 bl preempt_schedule_irq
654
655 ; preempt_schedule_irq() always returns with IRQ disabled
656#endif
657
658 ; fall through
659
660;############# Return from Intr/Excp/Trap (ARC Specifics) ##############
661;
662; Restore the saved sys context (common exit-path for EXCPN/IRQ/Trap)
663; IRQ shd definitely not happen between now and rtie
664
665restore_regs :
666
667 ; Disable Interrupts while restoring reg-file back
668 ; XXX can this be optimised out
669 IRQ_DISABLE_SAVE r9, r10 ;@r10 has prisitine (pre-disable) copy
670
Vineet Gupta080c3742013-02-11 19:52:57 +0530671#ifdef CONFIG_ARC_CURR_IN_REG
672 ; Restore User R25
673 ; Earlier this used to be only for returning to user mode
674 ; However with 2 levels of IRQ this can also happen even if
675 ; in kernel mode
676 ld r9, [sp, PT_sp]
677 brhs r9, VMALLOC_START, 8f
678 RESTORE_USER_R25
6798:
680#endif
681
Vineet Gupta9d42c842013-01-18 15:12:18 +0530682 ; Restore REG File. In case multiple Events outstanding,
683 ; use the same priorty as rtie: EXCPN, L2 IRQ, L1 IRQ, None
684 ; Note that we use realtime STATUS32 (not pt_regs->status32) to
685 ; decide that.
686
687 ; if Returning from Exception
688 bbit0 r10, STATUS_AE_BIT, not_exception
689 RESTORE_ALL_SYS
690 rtie
691
692 ; Not Exception so maybe Interrupts (Level 1 or 2)
693
694not_exception:
695
Vineet Gupta4788a592013-01-18 15:12:22 +0530696#ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
697
698 bbit0 r10, STATUS_A2_BIT, not_level2_interrupt
699
700 ;------------------------------------------------------------------
701 ; if L2 IRQ interrupted a L1 ISR, we'd disbaled preemption earlier
702 ; so that sched doesnt move to new task, causing L1 to be delayed
703 ; undeterministically. Now that we've achieved that, lets reset
704 ; things to what they were, before returning from L2 context
705 ;----------------------------------------------------------------
706
707 ld r9, [sp, PT_orig_r8] ; get orig_r8 to make sure it is
708 brne r9, orig_r8_IS_IRQ2, 149f ; infact a L2 ISR ret path
709
710 ld r9, [sp, PT_status32] ; get statu32_l2 (saved in pt_regs)
711 bbit0 r9, STATUS_A1_BIT, 149f ; L1 not active when L2 IRQ, so normal
712
713 ; A1 is set in status32_l2
714 ; decrement thread_info->preempt_count (re-enable preemption)
715 GET_CURR_THR_INFO_FROM_SP r10
716 ld r9, [r10, THREAD_INFO_PREEMPT_COUNT]
717
718 ; paranoid check, given A1 was active when A2 happened, preempt count
719 ; must not be 0 beccause we would have incremented it.
720 ; If this does happen we simply HALT as it means a BUG !!!
721 cmp r9, 0
722 bnz 2f
723 flag 1
724
7252:
726 sub r9, r9, 1
727 st r9, [r10, THREAD_INFO_PREEMPT_COUNT]
728
729149:
730 ;return from level 2
731 RESTORE_ALL_INT2
732debug_marker_l2:
733 rtie
734
735not_level2_interrupt:
736
737#endif
738
Vineet Gupta9d42c842013-01-18 15:12:18 +0530739 bbit0 r10, STATUS_A1_BIT, not_level1_interrupt
740
741 ;return from level 1
742
743 RESTORE_ALL_INT1
744debug_marker_l1:
745 rtie
746
747not_level1_interrupt:
748
749 ;this case is for syscalls or Exceptions (with fake rtie)
750
751 RESTORE_ALL_SYS
752debug_marker_syscall:
753 rtie
754
755ARC_EXIT ret_from_exception
756
757ARC_ENTRY ret_from_fork
758 ; when the forked child comes here from the __switch_to function
759 ; r0 has the last task pointer.
760 ; put last task in scheduler queue
Vineet Guptabf90e1e2013-01-18 15:12:18 +0530761 bl @schedule_tail
762
763 ; If kernel thread, jump to it's entry-point
764 ld r9, [sp, PT_status32]
765 brne r9, 0, 1f
766
767 jl.d [r14]
768 mov r0, r13 ; arg to payload
769
7701:
771 ; special case of kernel_thread entry point returning back due to
772 ; kernel_execve() - pretend return from syscall to ret to userland
773 b ret_from_exception
Vineet Gupta9d42c842013-01-18 15:12:18 +0530774ARC_EXIT ret_from_fork
Vineet Gupta4adeefe2013-01-18 15:12:18 +0530775
776;################### Special Sys Call Wrappers ##########################
777
778; TBD: call do_fork directly from here
779ARC_ENTRY sys_fork_wrapper
780 SAVE_CALLEE_SAVED_USER
781 bl @sys_fork
782 DISCARD_CALLEE_SAVED_USER
783
Vineet Gupta547f1122013-01-18 15:12:22 +0530784 GET_CURR_THR_INFO_FLAGS r10
785 btst r10, TIF_SYSCALL_TRACE
786 bnz tracesys_exit
787
Vineet Gupta4adeefe2013-01-18 15:12:18 +0530788 b ret_from_system_call
789ARC_EXIT sys_fork_wrapper
790
791ARC_ENTRY sys_vfork_wrapper
792 SAVE_CALLEE_SAVED_USER
793 bl @sys_vfork
794 DISCARD_CALLEE_SAVED_USER
795
Vineet Gupta547f1122013-01-18 15:12:22 +0530796 GET_CURR_THR_INFO_FLAGS r10
797 btst r10, TIF_SYSCALL_TRACE
798 bnz tracesys_exit
799
Vineet Gupta4adeefe2013-01-18 15:12:18 +0530800 b ret_from_system_call
801ARC_EXIT sys_vfork_wrapper
802
803ARC_ENTRY sys_clone_wrapper
804 SAVE_CALLEE_SAVED_USER
805 bl @sys_clone
806 DISCARD_CALLEE_SAVED_USER
807
Vineet Gupta547f1122013-01-18 15:12:22 +0530808 GET_CURR_THR_INFO_FLAGS r10
809 btst r10, TIF_SYSCALL_TRACE
810 bnz tracesys_exit
811
Vineet Gupta4adeefe2013-01-18 15:12:18 +0530812 b ret_from_system_call
813ARC_EXIT sys_clone_wrapper