blob: 69d0d376e28b598c7799a8db70416becaad1327c [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 *
10 * vineetg: Nov 2010:
11 * -Vector table jumps (@8 bytes) converted into branches (@4 bytes)
12 * -To maintain the slot size of 8 bytes/vector, added nop, which is
13 * not executed at runtime.
14 *
15 * vineetg: Nov 2009 (Everything needed for TIF_RESTORE_SIGMASK)
16 * -do_signal()invoked upon TIF_RESTORE_SIGMASK as well
17 * -Wrappers for sys_{,rt_}sigsuspend() nolonger needed as they don't
18 * need ptregs anymore
19 *
20 * Vineetg: Oct 2009
21 * -In a rare scenario, Process gets a Priv-V exception and gets scheduled
22 * out. Since we don't do FAKE RTIE for Priv-V, CPU excpetion state remains
23 * active (AE bit enabled). This causes a double fault for a subseq valid
24 * exception. Thus FAKE RTIE needed in low level Priv-Violation handler.
25 * Instr Error could also cause similar scenario, so same there as well.
26 *
27 * Vineetg: Aug 28th 2008: Bug #94984
28 * -Zero Overhead Loop Context shd be cleared when entering IRQ/EXcp/Trap
29 * Normally CPU does this automatically, however when doing FAKE rtie,
30 * we need to explicitly do this. The problem in macros
31 * FAKE_RET_FROM_EXCPN and FAKE_RET_FROM_EXCPN_LOCK_IRQ was that this bit
32 * was being "CLEARED" rather then "SET". Since it is Loop INHIBIT Bit,
33 * setting it and not clearing it clears ZOL context
34 *
Vineet Gupta080c3742013-02-11 19:52:57 +053035 * Vineetg: May 16th, 2008
36 * - r25 now contains the Current Task when in kernel
37 *
Vineet Gupta9d42c842013-01-18 15:12:18 +053038 * Vineetg: Dec 22, 2007
39 * Minor Surgery of Low Level ISR to make it SMP safe
40 * - MMU_SCRATCH0 Reg used for freeing up r9 in Level 1 ISR
41 * - _current_task is made an array of NR_CPUS
42 * - Access of _current_task wrapped inside a macro so that if hardware
43 * team agrees for a dedicated reg, no other code is touched
44 *
45 * Amit Bhor, Rahul Trivedi, Kanika Nema, Sameer Dhavale : Codito Tech 2004
46 */
47
48/*------------------------------------------------------------------
49 * Function ABI
50 *------------------------------------------------------------------
51 *
52 * Arguments r0 - r7
53 * Caller Saved Registers r0 - r12
54 * Callee Saved Registers r13- r25
55 * Global Pointer (gp) r26
56 * Frame Pointer (fp) r27
57 * Stack Pointer (sp) r28
58 * Interrupt link register (ilink1) r29
59 * Interrupt link register (ilink2) r30
60 * Branch link register (blink) r31
61 *------------------------------------------------------------------
62 */
63
64 .cpu A7
65
66;############################ Vector Table #################################
67
68.macro VECTOR lbl
69#if 1 /* Just in case, build breaks */
70 j \lbl
71#else
72 b \lbl
73 nop
74#endif
75.endm
76
77 .section .vector, "ax",@progbits
78 .align 4
79
80/* Each entry in the vector table must occupy 2 words. Since it is a jump
81 * across sections (.vector to .text) we are gauranteed that 'j somewhere'
82 * will use the 'j limm' form of the intrsuction as long as somewhere is in
83 * a section other than .vector.
84 */
85
86; ********* Critical System Events **********************
87VECTOR res_service ; 0x0, Restart Vector (0x0)
88VECTOR mem_service ; 0x8, Mem exception (0x1)
89VECTOR instr_service ; 0x10, Instrn Error (0x2)
90
91; ******************** Device ISRs **********************
92VECTOR handle_interrupt_level1
93
94VECTOR handle_interrupt_level1
95
96VECTOR handle_interrupt_level1
97
98VECTOR handle_interrupt_level1
99
100.rept 25
101VECTOR handle_interrupt_level1 ; Other devices
102.endr
103
104/* FOR ARC600: timer = 0x3, uart = 0x8, emac = 0x10 */
105
106; ******************** Exceptions **********************
107VECTOR EV_MachineCheck ; 0x100, Fatal Machine check (0x20)
108VECTOR EV_TLBMissI ; 0x108, Intruction TLB miss (0x21)
109VECTOR EV_TLBMissD ; 0x110, Data TLB miss (0x22)
110VECTOR EV_TLBProtV ; 0x118, Protection Violation (0x23)
111 ; or Misaligned Access
112VECTOR EV_PrivilegeV ; 0x120, Privilege Violation (0x24)
113VECTOR EV_Trap ; 0x128, Trap exception (0x25)
114VECTOR EV_Extension ; 0x130, Extn Intruction Excp (0x26)
115
116.rept 24
117VECTOR reserved ; Reserved Exceptions
118.endr
119
120#include <linux/linkage.h> /* ARC_{EXTRY,EXIT} */
121#include <asm/entry.h> /* SAVE_ALL_{INT1,INT2,TRAP...} */
122#include <asm/errno.h>
123#include <asm/arcregs.h>
124#include <asm/irqflags.h>
125
126;##################### Scratch Mem for IRQ stack switching #############
127
128 .section .data ; NOT .global
129 .align 32
130 .type int1_saved_reg, @object
131 .size int1_saved_reg, 4
132int1_saved_reg:
133 .zero 4
134
135; ---------------------------------------------
136 .section .text, "ax",@progbits
137
138res_service: ; processor restart
139 flag 0x1 ; not implemented
140 nop
141 nop
142
143reserved: ; processor restart
144 rtie ; jump to processor initializations
145
146;##################### Interrupt Handling ##############################
147
148; ---------------------------------------------
149; Level 1 ISR
150; ---------------------------------------------
151ARC_ENTRY handle_interrupt_level1
152
153 /* free up r9 as scratchpad */
154 st r9, [@int1_saved_reg]
155
156 ;Which mode (user/kernel) was the system in when intr occured
157 lr r9, [status32_l1]
158
159 SWITCH_TO_KERNEL_STK
160 SAVE_ALL_INT1
161
162 lr r0, [icause1]
163 and r0, r0, 0x1f
164
165 bl.d @arch_do_IRQ
166 mov r1, sp
167
168 mov r8,0x1
169 sr r8, [AUX_IRQ_LV12] ; clear bit in Sticky Status Reg
170
171 b ret_from_exception
172ARC_EXIT handle_interrupt_level1
173
174;################### Non TLB Exception Handling #############################
175
176; ---------------------------------------------
177; Instruction Error Exception Handler
178; ---------------------------------------------
179
180ARC_ENTRY instr_service
181
182 EXCPN_PROLOG_FREEUP_REG r9
183
184 lr r9, [erstatus]
185
186 SWITCH_TO_KERNEL_STK
187 SAVE_ALL_SYS
188
189 lr r0, [ecr]
190 lr r1, [efa]
191
192 mov r2, sp
193
194 FAKE_RET_FROM_EXCPN r9
195
196 bl do_insterror_or_kprobe
197 b ret_from_exception
198ARC_EXIT instr_service
199
200; ---------------------------------------------
201; Memory Error Exception Handler
202; ---------------------------------------------
203
204ARC_ENTRY mem_service
205
206 EXCPN_PROLOG_FREEUP_REG r9
207
208 lr r9, [erstatus]
209
210 SWITCH_TO_KERNEL_STK
211 SAVE_ALL_SYS
212
213 lr r0, [ecr]
214 lr r1, [efa]
215 mov r2, sp
216 bl do_memory_error
217 b ret_from_exception
218ARC_EXIT mem_service
219
220; ---------------------------------------------
221; Machine Check Exception Handler
222; ---------------------------------------------
223
224ARC_ENTRY EV_MachineCheck
225
226 EXCPN_PROLOG_FREEUP_REG r9
227 lr r9, [erstatus]
228
229 SWITCH_TO_KERNEL_STK
230 SAVE_ALL_SYS
231
232 lr r0, [ecr]
233 lr r1, [efa]
234 mov r2, sp
235
236 brne r0, 0x200100, 1f
237 bl do_tlb_overlap_fault
238 b ret_from_exception
239
2401:
241 ; DEAD END: can't do much, display Regs and HALT
242 SAVE_CALLEE_SAVED_USER
243
244 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
245 st sp, [r10, THREAD_CALLEE_REG]
246
247 j do_machine_check_fault
248
249ARC_EXIT EV_MachineCheck
250
251; ---------------------------------------------
252; Protection Violation Exception Handler
253; ---------------------------------------------
254
255ARC_ENTRY EV_TLBProtV
256
257 EXCPN_PROLOG_FREEUP_REG r9
258
259 ;Which mode (user/kernel) was the system in when Exception occured
260 lr r9, [erstatus]
261
262 SWITCH_TO_KERNEL_STK
263 SAVE_ALL_SYS
264
265 ;---------(3) Save some more regs-----------------
266 ; vineetg: Mar 6th: Random Seg Fault issue #1
267 ; ecr and efa were not saved in case an Intr sneaks in
268 ; after fake rtie
269 ;
270 lr r3, [ecr]
271 lr r4, [efa]
272
273 ; --------(4) Return from CPU Exception Mode ---------
274 ; Fake a rtie, but rtie to next label
275 ; That way, subsequently, do_page_fault ( ) executes in pure kernel
276 ; mode with further Exceptions enabled
277
278 FAKE_RET_FROM_EXCPN r9
279
280 ;------ (5) Type of Protection Violation? ----------
281 ;
282 ; ProtV Hardware Exception is triggered for Access Faults of 2 types
283 ; -Access Violaton (WRITE to READ ONLY Page) - for linux COW
284 ; -Unaligned Access (READ/WRITE on odd boundary)
285 ;
286 cmp r3, 0x230400 ; Misaligned data access ?
287 beq 4f
288
289 ;========= (6a) Access Violation Processing ========
290 cmp r3, 0x230100
291 mov r1, 0x0 ; if LD exception ? write = 0
292 mov.ne r1, 0x1 ; else write = 1
293
294 mov r2, r4 ; faulting address
295 mov r0, sp ; pt_regs
296 bl do_page_fault
297 b ret_from_exception
298
299 ;========== (6b) Non aligned access ============
3004:
301 mov r0, r3 ; cause code
302 mov r1, r4 ; faulting address
303 mov r2, sp ; pt_regs
304
305 bl do_misaligned_access
306 b ret_from_exception
307
308ARC_EXIT EV_TLBProtV
309
310; ---------------------------------------------
311; Privilege Violation Exception Handler
312; ---------------------------------------------
313ARC_ENTRY EV_PrivilegeV
314
315 EXCPN_PROLOG_FREEUP_REG r9
316
317 lr r9, [erstatus]
318
319 SWITCH_TO_KERNEL_STK
320 SAVE_ALL_SYS
321
322 lr r0, [ecr]
323 lr r1, [efa]
324 mov r2, sp
325
326 FAKE_RET_FROM_EXCPN r9
327
328 bl do_privilege_fault
329 b ret_from_exception
330ARC_EXIT EV_PrivilegeV
331
332; ---------------------------------------------
333; Extension Instruction Exception Handler
334; ---------------------------------------------
335ARC_ENTRY EV_Extension
336
337 EXCPN_PROLOG_FREEUP_REG r9
338 lr r9, [erstatus]
339
340 SWITCH_TO_KERNEL_STK
341 SAVE_ALL_SYS
342
343 lr r0, [ecr]
344 lr r1, [efa]
345 mov r2, sp
346 bl do_extension_fault
347 b ret_from_exception
348ARC_EXIT EV_Extension
349
350;################### Break Point TRAP ##########################
351
352 ; ======= (5b) Trap is due to Break-Point =========
353
354trap_with_param:
355
Vineet Gupta5c39c0a2013-02-11 20:01:24 +0530356 ; stop_pc info by gdb needs this info
357 st orig_r8_IS_BRKPT, [sp, PT_orig_r8]
Vineet Gupta9d42c842013-01-18 15:12:18 +0530358
359 mov r0, r12
360 lr r1, [efa]
361 mov r2, sp
362
363 ; Now that we have read EFA, its safe to do "fake" rtie
364 ; and get out of CPU exception mode
365 FAKE_RET_FROM_EXCPN r11
366
367 ; Save callee regs in case gdb wants to have a look
368 ; SP will grow up by size of CALLEE Reg-File
369 ; NOTE: clobbers r12
370 SAVE_CALLEE_SAVED_USER
371
372 ; save location of saved Callee Regs @ thread_struct->pc
373 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
374 st sp, [r10, THREAD_CALLEE_REG]
375
376 ; Call the trap handler
377 bl do_non_swi_trap
378
379 ; unwind stack to discard Callee saved Regs
380 DISCARD_CALLEE_SAVED_USER
381
382 b ret_from_exception
383
384;##################### Trap Handling ##############################
385;
386; EV_Trap caused by TRAP_S and TRAP0 instructions.
387;------------------------------------------------------------------
388; (1) System Calls
389; :parameters in r0-r7.
390; :r8 has the system call number
391; (2) Break Points
392;------------------------------------------------------------------
393
394ARC_ENTRY EV_Trap
395
396 ; Need at least 1 reg to code the early exception prolog
397 EXCPN_PROLOG_FREEUP_REG r9
398
399 ;Which mode (user/kernel) was the system in when intr occured
400 lr r9, [erstatus]
401
402 SWITCH_TO_KERNEL_STK
403 SAVE_ALL_TRAP
404
405 ;------- (4) What caused the Trap --------------
406 lr r12, [ecr]
407 and.f 0, r12, ECR_PARAM_MASK
408 bnz trap_with_param
409
410 ; ======= (5a) Trap is due to System Call ========
411
412 ; Before doing anything, return from CPU Exception Mode
413 FAKE_RET_FROM_EXCPN r11
414
415 ;============ This is normal System Call case ==========
416 ; Sys-call num shd not exceed the total system calls avail
417 cmp r8, NR_syscalls
418 mov.hi r0, -ENOSYS
419 bhi ret_from_system_call
420
421 ; Offset into the syscall_table and call handler
422 ld.as r9,[sys_call_table, r8]
423 jl [r9] ; Entry into Sys Call Handler
424
425 ; fall through to ret_from_system_call
426ARC_EXIT EV_Trap
427
428ARC_ENTRY ret_from_system_call
429
430 st r0, [sp, PT_r0] ; sys call return value in pt_regs
431
432 ; fall through yet again to ret_from_exception
433
434;############# Return from Intr/Excp/Trap (Linux Specifics) ##############
435;
436; If ret to user mode do we need to handle signals, schedule() et al.
437
438ARC_ENTRY ret_from_exception
439
440 ; Pre-{IRQ,Trap,Exception} K/U mode from pt_regs->status32
441 ld r8, [sp, PT_status32] ; returning to User/Kernel Mode
442
443#ifdef CONFIG_PREEMPT
444 bbit0 r8, STATUS_U_BIT, resume_kernel_mode
445#else
446 bbit0 r8, STATUS_U_BIT, restore_regs
447#endif
448
449 ; Before returning to User mode check-for-and-complete any pending work
450 ; such as rescheduling/signal-delivery etc.
451resume_user_mode_begin:
452
453 ; Disable IRQs to ensures that chk for pending work itself is atomic
454 ; (and we don't end up missing a NEED_RESCHED/SIGPENDING due to an
455 ; interim IRQ).
456 IRQ_DISABLE r10
457
458 ; Fast Path return to user mode if no pending work
459 GET_CURR_THR_INFO_FLAGS r9
460 and.f 0, r9, _TIF_WORK_MASK
461 bz restore_regs
462
463 ; --- (Slow Path #1) task preemption ---
464 bbit0 r9, TIF_NEED_RESCHED, .Lchk_pend_signals
465 mov blink, resume_user_mode_begin ; tail-call to U mode ret chks
466 b @schedule ; BTST+Bnz causes relo error in link
467
468.Lchk_pend_signals:
469 IRQ_ENABLE r10
470
471 ; --- (Slow Path #2) pending signal ---
472 mov r0, sp ; pt_regs for arg to do_signal()/do_notify_resume()
473
474 bbit0 r9, TIF_SIGPENDING, .Lchk_notify_resume
475
Vineet Guptac3581032013-01-18 15:12:19 +0530476 ; Normal Trap/IRQ entry only saves Scratch (caller-saved) regs
477 ; in pt_reg since the "C" ABI (kernel code) will automatically
478 ; save/restore callee-saved regs.
479 ;
480 ; However, here we need to explicitly save callee regs because
Vineet Gupta9d42c842013-01-18 15:12:18 +0530481 ; (i) If this signal causes coredump - full regfile needed
482 ; (ii) If signal is SIGTRAP/SIGSTOP, task is being traced thus
483 ; tracer might call PEEKUSR(CALLEE reg)
484 ;
485 ; NOTE: SP will grow up by size of CALLEE Reg-File
486 SAVE_CALLEE_SAVED_USER ; clobbers r12
487
488 ; save location of saved Callee Regs @ thread_struct->callee
489 GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
490 st sp, [r10, THREAD_CALLEE_REG]
491
492 bl @do_signal
493
Vineet Guptac3581032013-01-18 15:12:19 +0530494 ; Ideally we want to discard the Callee reg above, however if this was
495 ; a tracing signal, tracer could have done a POKEUSR(CALLEE reg)
496 RESTORE_CALLEE_SAVED_USER
Vineet Gupta9d42c842013-01-18 15:12:18 +0530497
498 b resume_user_mode_begin ; loop back to start of U mode ret
499
500 ; --- (Slow Path #3) notify_resume ---
501.Lchk_notify_resume:
502 btst r9, TIF_NOTIFY_RESUME
503 blnz @do_notify_resume
504 b resume_user_mode_begin ; unconditionally back to U mode ret chks
505 ; for single exit point from this block
506
507#ifdef CONFIG_PREEMPT
508
509resume_kernel_mode:
510
511 ; Can't preempt if preemption disabled
512 GET_CURR_THR_INFO_FROM_SP r10
513 ld r8, [r10, THREAD_INFO_PREEMPT_COUNT]
514 brne r8, 0, restore_regs
515
516 ; check if this task's NEED_RESCHED flag set
517 ld r9, [r10, THREAD_INFO_FLAGS]
518 bbit0 r9, TIF_NEED_RESCHED, restore_regs
519
520 IRQ_DISABLE r9
521
522 ; Invoke PREEMPTION
523 bl preempt_schedule_irq
524
525 ; preempt_schedule_irq() always returns with IRQ disabled
526#endif
527
528 ; fall through
529
530;############# Return from Intr/Excp/Trap (ARC Specifics) ##############
531;
532; Restore the saved sys context (common exit-path for EXCPN/IRQ/Trap)
533; IRQ shd definitely not happen between now and rtie
534
535restore_regs :
536
537 ; Disable Interrupts while restoring reg-file back
538 ; XXX can this be optimised out
539 IRQ_DISABLE_SAVE r9, r10 ;@r10 has prisitine (pre-disable) copy
540
Vineet Gupta080c3742013-02-11 19:52:57 +0530541#ifdef CONFIG_ARC_CURR_IN_REG
542 ; Restore User R25
543 ; Earlier this used to be only for returning to user mode
544 ; However with 2 levels of IRQ this can also happen even if
545 ; in kernel mode
546 ld r9, [sp, PT_sp]
547 brhs r9, VMALLOC_START, 8f
548 RESTORE_USER_R25
5498:
550#endif
551
Vineet Gupta9d42c842013-01-18 15:12:18 +0530552 ; Restore REG File. In case multiple Events outstanding,
553 ; use the same priorty as rtie: EXCPN, L2 IRQ, L1 IRQ, None
554 ; Note that we use realtime STATUS32 (not pt_regs->status32) to
555 ; decide that.
556
557 ; if Returning from Exception
558 bbit0 r10, STATUS_AE_BIT, not_exception
559 RESTORE_ALL_SYS
560 rtie
561
562 ; Not Exception so maybe Interrupts (Level 1 or 2)
563
564not_exception:
565
566 bbit0 r10, STATUS_A1_BIT, not_level1_interrupt
567
568 ;return from level 1
569
570 RESTORE_ALL_INT1
571debug_marker_l1:
572 rtie
573
574not_level1_interrupt:
575
576 ;this case is for syscalls or Exceptions (with fake rtie)
577
578 RESTORE_ALL_SYS
579debug_marker_syscall:
580 rtie
581
582ARC_EXIT ret_from_exception
583
584ARC_ENTRY ret_from_fork
585 ; when the forked child comes here from the __switch_to function
586 ; r0 has the last task pointer.
587 ; put last task in scheduler queue
Vineet Guptabf90e1e2013-01-18 15:12:18 +0530588 bl @schedule_tail
589
590 ; If kernel thread, jump to it's entry-point
591 ld r9, [sp, PT_status32]
592 brne r9, 0, 1f
593
594 jl.d [r14]
595 mov r0, r13 ; arg to payload
596
5971:
598 ; special case of kernel_thread entry point returning back due to
599 ; kernel_execve() - pretend return from syscall to ret to userland
600 b ret_from_exception
Vineet Gupta9d42c842013-01-18 15:12:18 +0530601ARC_EXIT ret_from_fork
Vineet Gupta4adeefe2013-01-18 15:12:18 +0530602
603;################### Special Sys Call Wrappers ##########################
604
605; TBD: call do_fork directly from here
606ARC_ENTRY sys_fork_wrapper
607 SAVE_CALLEE_SAVED_USER
608 bl @sys_fork
609 DISCARD_CALLEE_SAVED_USER
610
611 b ret_from_system_call
612ARC_EXIT sys_fork_wrapper
613
614ARC_ENTRY sys_vfork_wrapper
615 SAVE_CALLEE_SAVED_USER
616 bl @sys_vfork
617 DISCARD_CALLEE_SAVED_USER
618
619 b ret_from_system_call
620ARC_EXIT sys_vfork_wrapper
621
622ARC_ENTRY sys_clone_wrapper
623 SAVE_CALLEE_SAVED_USER
624 bl @sys_clone
625 DISCARD_CALLEE_SAVED_USER
626
627 b ret_from_system_call
628ARC_EXIT sys_clone_wrapper