entry.S 21 KB

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