entry.S 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /*
  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. *
  35. * Vineetg: Dec 22, 2007
  36. * Minor Surgery of Low Level ISR to make it SMP safe
  37. * - MMU_SCRATCH0 Reg used for freeing up r9 in Level 1 ISR
  38. * - _current_task is made an array of NR_CPUS
  39. * - Access of _current_task wrapped inside a macro so that if hardware
  40. * team agrees for a dedicated reg, no other code is touched
  41. *
  42. * Amit Bhor, Rahul Trivedi, Kanika Nema, Sameer Dhavale : Codito Tech 2004
  43. */
  44. /*------------------------------------------------------------------
  45. * Function ABI
  46. *------------------------------------------------------------------
  47. *
  48. * Arguments r0 - r7
  49. * Caller Saved Registers r0 - r12
  50. * Callee Saved Registers r13- r25
  51. * Global Pointer (gp) r26
  52. * Frame Pointer (fp) r27
  53. * Stack Pointer (sp) r28
  54. * Interrupt link register (ilink1) r29
  55. * Interrupt link register (ilink2) r30
  56. * Branch link register (blink) r31
  57. *------------------------------------------------------------------
  58. */
  59. .cpu A7
  60. ;############################ Vector Table #################################
  61. .macro VECTOR lbl
  62. #if 1 /* Just in case, build breaks */
  63. j \lbl
  64. #else
  65. b \lbl
  66. nop
  67. #endif
  68. .endm
  69. .section .vector, "ax",@progbits
  70. .align 4
  71. /* Each entry in the vector table must occupy 2 words. Since it is a jump
  72. * across sections (.vector to .text) we are gauranteed that 'j somewhere'
  73. * will use the 'j limm' form of the intrsuction as long as somewhere is in
  74. * a section other than .vector.
  75. */
  76. ; ********* Critical System Events **********************
  77. VECTOR res_service ; 0x0, Restart Vector (0x0)
  78. VECTOR mem_service ; 0x8, Mem exception (0x1)
  79. VECTOR instr_service ; 0x10, Instrn Error (0x2)
  80. ; ******************** Device ISRs **********************
  81. VECTOR handle_interrupt_level1
  82. VECTOR handle_interrupt_level1
  83. VECTOR handle_interrupt_level1
  84. VECTOR handle_interrupt_level1
  85. .rept 25
  86. VECTOR handle_interrupt_level1 ; Other devices
  87. .endr
  88. /* FOR ARC600: timer = 0x3, uart = 0x8, emac = 0x10 */
  89. ; ******************** Exceptions **********************
  90. VECTOR EV_MachineCheck ; 0x100, Fatal Machine check (0x20)
  91. VECTOR EV_TLBMissI ; 0x108, Intruction TLB miss (0x21)
  92. VECTOR EV_TLBMissD ; 0x110, Data TLB miss (0x22)
  93. VECTOR EV_TLBProtV ; 0x118, Protection Violation (0x23)
  94. ; or Misaligned Access
  95. VECTOR EV_PrivilegeV ; 0x120, Privilege Violation (0x24)
  96. VECTOR EV_Trap ; 0x128, Trap exception (0x25)
  97. VECTOR EV_Extension ; 0x130, Extn Intruction Excp (0x26)
  98. .rept 24
  99. VECTOR reserved ; Reserved Exceptions
  100. .endr
  101. #include <linux/linkage.h> /* ARC_{EXTRY,EXIT} */
  102. #include <asm/entry.h> /* SAVE_ALL_{INT1,INT2,TRAP...} */
  103. #include <asm/errno.h>
  104. #include <asm/arcregs.h>
  105. #include <asm/irqflags.h>
  106. ;##################### Scratch Mem for IRQ stack switching #############
  107. .section .data ; NOT .global
  108. .align 32
  109. .type int1_saved_reg, @object
  110. .size int1_saved_reg, 4
  111. int1_saved_reg:
  112. .zero 4
  113. ; ---------------------------------------------
  114. .section .text, "ax",@progbits
  115. res_service: ; processor restart
  116. flag 0x1 ; not implemented
  117. nop
  118. nop
  119. reserved: ; processor restart
  120. rtie ; jump to processor initializations
  121. ;##################### Interrupt Handling ##############################
  122. ; ---------------------------------------------
  123. ; Level 1 ISR
  124. ; ---------------------------------------------
  125. ARC_ENTRY handle_interrupt_level1
  126. /* free up r9 as scratchpad */
  127. st r9, [@int1_saved_reg]
  128. ;Which mode (user/kernel) was the system in when intr occured
  129. lr r9, [status32_l1]
  130. SWITCH_TO_KERNEL_STK
  131. SAVE_ALL_INT1
  132. lr r0, [icause1]
  133. and r0, r0, 0x1f
  134. bl.d @arch_do_IRQ
  135. mov r1, sp
  136. mov r8,0x1
  137. sr r8, [AUX_IRQ_LV12] ; clear bit in Sticky Status Reg
  138. b ret_from_exception
  139. ARC_EXIT handle_interrupt_level1
  140. ;################### Non TLB Exception Handling #############################
  141. ; ---------------------------------------------
  142. ; Instruction Error Exception Handler
  143. ; ---------------------------------------------
  144. ARC_ENTRY instr_service
  145. EXCPN_PROLOG_FREEUP_REG r9
  146. lr r9, [erstatus]
  147. SWITCH_TO_KERNEL_STK
  148. SAVE_ALL_SYS
  149. lr r0, [ecr]
  150. lr r1, [efa]
  151. mov r2, sp
  152. FAKE_RET_FROM_EXCPN r9
  153. bl do_insterror_or_kprobe
  154. b ret_from_exception
  155. ARC_EXIT instr_service
  156. ; ---------------------------------------------
  157. ; Memory Error Exception Handler
  158. ; ---------------------------------------------
  159. ARC_ENTRY mem_service
  160. EXCPN_PROLOG_FREEUP_REG r9
  161. lr r9, [erstatus]
  162. SWITCH_TO_KERNEL_STK
  163. SAVE_ALL_SYS
  164. lr r0, [ecr]
  165. lr r1, [efa]
  166. mov r2, sp
  167. bl do_memory_error
  168. b ret_from_exception
  169. ARC_EXIT mem_service
  170. ; ---------------------------------------------
  171. ; Machine Check Exception Handler
  172. ; ---------------------------------------------
  173. ARC_ENTRY EV_MachineCheck
  174. EXCPN_PROLOG_FREEUP_REG r9
  175. lr r9, [erstatus]
  176. SWITCH_TO_KERNEL_STK
  177. SAVE_ALL_SYS
  178. lr r0, [ecr]
  179. lr r1, [efa]
  180. mov r2, sp
  181. brne r0, 0x200100, 1f
  182. bl do_tlb_overlap_fault
  183. b ret_from_exception
  184. 1:
  185. ; DEAD END: can't do much, display Regs and HALT
  186. SAVE_CALLEE_SAVED_USER
  187. GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
  188. st sp, [r10, THREAD_CALLEE_REG]
  189. j do_machine_check_fault
  190. ARC_EXIT EV_MachineCheck
  191. ; ---------------------------------------------
  192. ; Protection Violation Exception Handler
  193. ; ---------------------------------------------
  194. ARC_ENTRY EV_TLBProtV
  195. EXCPN_PROLOG_FREEUP_REG r9
  196. ;Which mode (user/kernel) was the system in when Exception occured
  197. lr r9, [erstatus]
  198. SWITCH_TO_KERNEL_STK
  199. SAVE_ALL_SYS
  200. ;---------(3) Save some more regs-----------------
  201. ; vineetg: Mar 6th: Random Seg Fault issue #1
  202. ; ecr and efa were not saved in case an Intr sneaks in
  203. ; after fake rtie
  204. ;
  205. lr r3, [ecr]
  206. lr r4, [efa]
  207. ; --------(4) Return from CPU Exception Mode ---------
  208. ; Fake a rtie, but rtie to next label
  209. ; That way, subsequently, do_page_fault ( ) executes in pure kernel
  210. ; mode with further Exceptions enabled
  211. FAKE_RET_FROM_EXCPN r9
  212. ;------ (5) Type of Protection Violation? ----------
  213. ;
  214. ; ProtV Hardware Exception is triggered for Access Faults of 2 types
  215. ; -Access Violaton (WRITE to READ ONLY Page) - for linux COW
  216. ; -Unaligned Access (READ/WRITE on odd boundary)
  217. ;
  218. cmp r3, 0x230400 ; Misaligned data access ?
  219. beq 4f
  220. ;========= (6a) Access Violation Processing ========
  221. cmp r3, 0x230100
  222. mov r1, 0x0 ; if LD exception ? write = 0
  223. mov.ne r1, 0x1 ; else write = 1
  224. mov r2, r4 ; faulting address
  225. mov r0, sp ; pt_regs
  226. bl do_page_fault
  227. b ret_from_exception
  228. ;========== (6b) Non aligned access ============
  229. 4:
  230. mov r0, r3 ; cause code
  231. mov r1, r4 ; faulting address
  232. mov r2, sp ; pt_regs
  233. bl do_misaligned_access
  234. b ret_from_exception
  235. ARC_EXIT EV_TLBProtV
  236. ; ---------------------------------------------
  237. ; Privilege Violation Exception Handler
  238. ; ---------------------------------------------
  239. ARC_ENTRY EV_PrivilegeV
  240. EXCPN_PROLOG_FREEUP_REG r9
  241. lr r9, [erstatus]
  242. SWITCH_TO_KERNEL_STK
  243. SAVE_ALL_SYS
  244. lr r0, [ecr]
  245. lr r1, [efa]
  246. mov r2, sp
  247. FAKE_RET_FROM_EXCPN r9
  248. bl do_privilege_fault
  249. b ret_from_exception
  250. ARC_EXIT EV_PrivilegeV
  251. ; ---------------------------------------------
  252. ; Extension Instruction Exception Handler
  253. ; ---------------------------------------------
  254. ARC_ENTRY EV_Extension
  255. EXCPN_PROLOG_FREEUP_REG r9
  256. lr r9, [erstatus]
  257. SWITCH_TO_KERNEL_STK
  258. SAVE_ALL_SYS
  259. lr r0, [ecr]
  260. lr r1, [efa]
  261. mov r2, sp
  262. bl do_extension_fault
  263. b ret_from_exception
  264. ARC_EXIT EV_Extension
  265. ;################### Break Point TRAP ##########################
  266. ; ======= (5b) Trap is due to Break-Point =========
  267. trap_with_param:
  268. ;make sure orig_r8 is a positive value
  269. st NR_syscalls + 2, [sp, PT_orig_r8]
  270. mov r0, r12
  271. lr r1, [efa]
  272. mov r2, sp
  273. ; Now that we have read EFA, its safe to do "fake" rtie
  274. ; and get out of CPU exception mode
  275. FAKE_RET_FROM_EXCPN r11
  276. ; Save callee regs in case gdb wants to have a look
  277. ; SP will grow up by size of CALLEE Reg-File
  278. ; NOTE: clobbers r12
  279. SAVE_CALLEE_SAVED_USER
  280. ; save location of saved Callee Regs @ thread_struct->pc
  281. GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
  282. st sp, [r10, THREAD_CALLEE_REG]
  283. ; Call the trap handler
  284. bl do_non_swi_trap
  285. ; unwind stack to discard Callee saved Regs
  286. DISCARD_CALLEE_SAVED_USER
  287. b ret_from_exception
  288. ;##################### Trap Handling ##############################
  289. ;
  290. ; EV_Trap caused by TRAP_S and TRAP0 instructions.
  291. ;------------------------------------------------------------------
  292. ; (1) System Calls
  293. ; :parameters in r0-r7.
  294. ; :r8 has the system call number
  295. ; (2) Break Points
  296. ;------------------------------------------------------------------
  297. ARC_ENTRY EV_Trap
  298. ; Need at least 1 reg to code the early exception prolog
  299. EXCPN_PROLOG_FREEUP_REG r9
  300. ;Which mode (user/kernel) was the system in when intr occured
  301. lr r9, [erstatus]
  302. SWITCH_TO_KERNEL_STK
  303. SAVE_ALL_TRAP
  304. ;------- (4) What caused the Trap --------------
  305. lr r12, [ecr]
  306. and.f 0, r12, ECR_PARAM_MASK
  307. bnz trap_with_param
  308. ; ======= (5a) Trap is due to System Call ========
  309. ; Before doing anything, return from CPU Exception Mode
  310. FAKE_RET_FROM_EXCPN r11
  311. ;============ This is normal System Call case ==========
  312. ; Sys-call num shd not exceed the total system calls avail
  313. cmp r8, NR_syscalls
  314. mov.hi r0, -ENOSYS
  315. bhi ret_from_system_call
  316. ; Offset into the syscall_table and call handler
  317. ld.as r9,[sys_call_table, r8]
  318. jl [r9] ; Entry into Sys Call Handler
  319. ; fall through to ret_from_system_call
  320. ARC_EXIT EV_Trap
  321. ARC_ENTRY ret_from_system_call
  322. st r0, [sp, PT_r0] ; sys call return value in pt_regs
  323. ; fall through yet again to ret_from_exception
  324. ;############# Return from Intr/Excp/Trap (Linux Specifics) ##############
  325. ;
  326. ; If ret to user mode do we need to handle signals, schedule() et al.
  327. ARC_ENTRY ret_from_exception
  328. ; Pre-{IRQ,Trap,Exception} K/U mode from pt_regs->status32
  329. ld r8, [sp, PT_status32] ; returning to User/Kernel Mode
  330. #ifdef CONFIG_PREEMPT
  331. bbit0 r8, STATUS_U_BIT, resume_kernel_mode
  332. #else
  333. bbit0 r8, STATUS_U_BIT, restore_regs
  334. #endif
  335. ; Before returning to User mode check-for-and-complete any pending work
  336. ; such as rescheduling/signal-delivery etc.
  337. resume_user_mode_begin:
  338. ; Disable IRQs to ensures that chk for pending work itself is atomic
  339. ; (and we don't end up missing a NEED_RESCHED/SIGPENDING due to an
  340. ; interim IRQ).
  341. IRQ_DISABLE r10
  342. ; Fast Path return to user mode if no pending work
  343. GET_CURR_THR_INFO_FLAGS r9
  344. and.f 0, r9, _TIF_WORK_MASK
  345. bz restore_regs
  346. ; --- (Slow Path #1) task preemption ---
  347. bbit0 r9, TIF_NEED_RESCHED, .Lchk_pend_signals
  348. mov blink, resume_user_mode_begin ; tail-call to U mode ret chks
  349. b @schedule ; BTST+Bnz causes relo error in link
  350. .Lchk_pend_signals:
  351. IRQ_ENABLE r10
  352. ; --- (Slow Path #2) pending signal ---
  353. mov r0, sp ; pt_regs for arg to do_signal()/do_notify_resume()
  354. bbit0 r9, TIF_SIGPENDING, .Lchk_notify_resume
  355. ; save CALLEE Regs.
  356. ; (i) If this signal causes coredump - full regfile needed
  357. ; (ii) If signal is SIGTRAP/SIGSTOP, task is being traced thus
  358. ; tracer might call PEEKUSR(CALLEE reg)
  359. ;
  360. ; NOTE: SP will grow up by size of CALLEE Reg-File
  361. SAVE_CALLEE_SAVED_USER ; clobbers r12
  362. ; save location of saved Callee Regs @ thread_struct->callee
  363. GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
  364. st sp, [r10, THREAD_CALLEE_REG]
  365. bl @do_signal
  366. ; unwind SP for cheap discard of Callee saved Regs
  367. DISCARD_CALLEE_SAVED_USER
  368. b resume_user_mode_begin ; loop back to start of U mode ret
  369. ; --- (Slow Path #3) notify_resume ---
  370. .Lchk_notify_resume:
  371. btst r9, TIF_NOTIFY_RESUME
  372. blnz @do_notify_resume
  373. b resume_user_mode_begin ; unconditionally back to U mode ret chks
  374. ; for single exit point from this block
  375. #ifdef CONFIG_PREEMPT
  376. resume_kernel_mode:
  377. ; Can't preempt if preemption disabled
  378. GET_CURR_THR_INFO_FROM_SP r10
  379. ld r8, [r10, THREAD_INFO_PREEMPT_COUNT]
  380. brne r8, 0, restore_regs
  381. ; check if this task's NEED_RESCHED flag set
  382. ld r9, [r10, THREAD_INFO_FLAGS]
  383. bbit0 r9, TIF_NEED_RESCHED, restore_regs
  384. IRQ_DISABLE r9
  385. ; Invoke PREEMPTION
  386. bl preempt_schedule_irq
  387. ; preempt_schedule_irq() always returns with IRQ disabled
  388. #endif
  389. ; fall through
  390. ;############# Return from Intr/Excp/Trap (ARC Specifics) ##############
  391. ;
  392. ; Restore the saved sys context (common exit-path for EXCPN/IRQ/Trap)
  393. ; IRQ shd definitely not happen between now and rtie
  394. restore_regs :
  395. ; Disable Interrupts while restoring reg-file back
  396. ; XXX can this be optimised out
  397. IRQ_DISABLE_SAVE r9, r10 ;@r10 has prisitine (pre-disable) copy
  398. ; Restore REG File. In case multiple Events outstanding,
  399. ; use the same priorty as rtie: EXCPN, L2 IRQ, L1 IRQ, None
  400. ; Note that we use realtime STATUS32 (not pt_regs->status32) to
  401. ; decide that.
  402. ; if Returning from Exception
  403. bbit0 r10, STATUS_AE_BIT, not_exception
  404. RESTORE_ALL_SYS
  405. rtie
  406. ; Not Exception so maybe Interrupts (Level 1 or 2)
  407. not_exception:
  408. bbit0 r10, STATUS_A1_BIT, not_level1_interrupt
  409. ;return from level 1
  410. RESTORE_ALL_INT1
  411. debug_marker_l1:
  412. rtie
  413. not_level1_interrupt:
  414. ;this case is for syscalls or Exceptions (with fake rtie)
  415. RESTORE_ALL_SYS
  416. debug_marker_syscall:
  417. rtie
  418. ARC_EXIT ret_from_exception
  419. ARC_ENTRY ret_from_fork
  420. ; when the forked child comes here from the __switch_to function
  421. ; r0 has the last task pointer.
  422. ; put last task in scheduler queue
  423. bl @schedule_tail
  424. b @ret_from_exception
  425. ARC_EXIT ret_from_fork