entry.S 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  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. EXCPN_PROLOG_FREEUP_REG r9
  221. lr r9, [erstatus]
  222. SWITCH_TO_KERNEL_STK
  223. SAVE_ALL_SYS
  224. lr r0, [efa]
  225. mov r1, sp
  226. FAKE_RET_FROM_EXCPN r9
  227. bl do_insterror_or_kprobe
  228. b ret_from_exception
  229. ARC_EXIT instr_service
  230. ; ---------------------------------------------
  231. ; Memory Error Exception Handler
  232. ; ---------------------------------------------
  233. ARC_ENTRY mem_service
  234. EXCPN_PROLOG_FREEUP_REG r9
  235. lr r9, [erstatus]
  236. SWITCH_TO_KERNEL_STK
  237. SAVE_ALL_SYS
  238. lr r0, [efa]
  239. mov r1, sp
  240. bl do_memory_error
  241. b ret_from_exception
  242. ARC_EXIT mem_service
  243. ; ---------------------------------------------
  244. ; Machine Check Exception Handler
  245. ; ---------------------------------------------
  246. ARC_ENTRY EV_MachineCheck
  247. EXCPN_PROLOG_FREEUP_REG r9
  248. lr r9, [erstatus]
  249. SWITCH_TO_KERNEL_STK
  250. SAVE_ALL_SYS
  251. lr r2, [ecr]
  252. lr r0, [efa]
  253. mov r1, sp
  254. lsr r3, r2, 8
  255. bmsk r3, r3, 7
  256. brne r3, ECR_C_MCHK_DUP_TLB, 1f
  257. bl do_tlb_overlap_fault
  258. b ret_from_exception
  259. 1:
  260. ; DEAD END: can't do much, display Regs and HALT
  261. SAVE_CALLEE_SAVED_USER
  262. GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
  263. st sp, [r10, THREAD_CALLEE_REG]
  264. j do_machine_check_fault
  265. ARC_EXIT EV_MachineCheck
  266. ; ---------------------------------------------
  267. ; Protection Violation Exception Handler
  268. ; ---------------------------------------------
  269. ARC_ENTRY EV_TLBProtV
  270. EXCPN_PROLOG_FREEUP_REG r9
  271. ;Which mode (user/kernel) was the system in when Exception occured
  272. lr r9, [erstatus]
  273. SWITCH_TO_KERNEL_STK
  274. SAVE_ALL_SYS
  275. ;---------(3) Save some more regs-----------------
  276. ; vineetg: Mar 6th: Random Seg Fault issue #1
  277. ; ecr and efa were not saved in case an Intr sneaks in
  278. ; after fake rtie
  279. ;
  280. lr r2, [ecr]
  281. lr r1, [efa] ; Faulting Data address
  282. ; --------(4) Return from CPU Exception Mode ---------
  283. ; Fake a rtie, but rtie to next label
  284. ; That way, subsequently, do_page_fault ( ) executes in pure kernel
  285. ; mode with further Exceptions enabled
  286. FAKE_RET_FROM_EXCPN r9
  287. ;------ (5) Type of Protection Violation? ----------
  288. ;
  289. ; ProtV Hardware Exception is triggered for Access Faults of 2 types
  290. ; -Access Violaton : 00_23_(00|01|02|03)_00
  291. ; x r w r+w
  292. ; -Unaligned Access : 00_23_04_00
  293. ;
  294. bbit1 r2, ECR_C_BIT_PROTV_MISALIG_DATA, 4f
  295. ;========= (6a) Access Violation Processing ========
  296. mov r0, sp ; pt_regs
  297. bl do_page_fault
  298. b ret_from_exception
  299. ;========== (6b) Non aligned access ============
  300. 4:
  301. mov r0, r1
  302. mov r1, sp ; pt_regs
  303. #ifdef CONFIG_ARC_MISALIGN_ACCESS
  304. SAVE_CALLEE_SAVED_USER
  305. mov r2, sp ; callee_regs
  306. bl do_misaligned_access
  307. ; TBD: optimize - do this only if a callee reg was involved
  308. ; either a dst of emulated LD/ST or src with address-writeback
  309. RESTORE_CALLEE_SAVED_USER
  310. #else
  311. bl do_misaligned_error
  312. #endif
  313. b ret_from_exception
  314. ARC_EXIT EV_TLBProtV
  315. ; ---------------------------------------------
  316. ; Privilege Violation Exception Handler
  317. ; ---------------------------------------------
  318. ARC_ENTRY EV_PrivilegeV
  319. EXCPN_PROLOG_FREEUP_REG r9
  320. lr r9, [erstatus]
  321. SWITCH_TO_KERNEL_STK
  322. SAVE_ALL_SYS
  323. lr r0, [efa]
  324. mov r1, sp
  325. FAKE_RET_FROM_EXCPN r9
  326. bl do_privilege_fault
  327. b ret_from_exception
  328. ARC_EXIT EV_PrivilegeV
  329. ; ---------------------------------------------
  330. ; Extension Instruction Exception Handler
  331. ; ---------------------------------------------
  332. ARC_ENTRY EV_Extension
  333. EXCPN_PROLOG_FREEUP_REG r9
  334. lr r9, [erstatus]
  335. SWITCH_TO_KERNEL_STK
  336. SAVE_ALL_SYS
  337. lr r0, [efa]
  338. mov r1, sp
  339. bl do_extension_fault
  340. b ret_from_exception
  341. ARC_EXIT EV_Extension
  342. ;######################### System Call Tracing #########################
  343. tracesys:
  344. ; save EFA in case tracer wants the PC of traced task
  345. ; using ERET won't work since next-PC has already committed
  346. lr r12, [efa]
  347. GET_CURR_TASK_FIELD_PTR TASK_THREAD, r11
  348. st r12, [r11, THREAD_FAULT_ADDR] ; thread.fault_address
  349. ; PRE Sys Call Ptrace hook
  350. mov r0, sp ; pt_regs needed
  351. bl @syscall_trace_entry
  352. ; Tracing code now returns the syscall num (orig or modif)
  353. mov r8, r0
  354. ; Do the Sys Call as we normally would.
  355. ; Validate the Sys Call number
  356. cmp r8, NR_syscalls
  357. mov.hi r0, -ENOSYS
  358. bhi tracesys_exit
  359. ; Restore the sys-call args. Mere invocation of the hook abv could have
  360. ; clobbered them (since they are in scratch regs). The tracer could also
  361. ; have deliberately changed the syscall args: r0-r7
  362. ld r0, [sp, PT_r0]
  363. ld r1, [sp, PT_r1]
  364. ld r2, [sp, PT_r2]
  365. ld r3, [sp, PT_r3]
  366. ld r4, [sp, PT_r4]
  367. ld r5, [sp, PT_r5]
  368. ld r6, [sp, PT_r6]
  369. ld r7, [sp, PT_r7]
  370. ld.as r9, [sys_call_table, r8]
  371. jl [r9] ; Entry into Sys Call Handler
  372. tracesys_exit:
  373. st r0, [sp, PT_r0] ; sys call return value in pt_regs
  374. ;POST Sys Call Ptrace Hook
  375. bl @syscall_trace_exit
  376. b ret_from_exception ; NOT ret_from_system_call at is saves r0 which
  377. ; we'd done before calling post hook above
  378. ;################### Break Point TRAP ##########################
  379. ; ======= (5b) Trap is due to Break-Point =========
  380. trap_with_param:
  381. ; stop_pc info by gdb needs this info
  382. lr r0, [efa]
  383. mov r1, sp
  384. ; Now that we have read EFA, its safe to do "fake" rtie
  385. ; and get out of CPU exception mode
  386. FAKE_RET_FROM_EXCPN r11
  387. ; Save callee regs in case gdb wants to have a look
  388. ; SP will grow up by size of CALLEE Reg-File
  389. ; NOTE: clobbers r12
  390. SAVE_CALLEE_SAVED_USER
  391. ; save location of saved Callee Regs @ thread_struct->pc
  392. GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
  393. st sp, [r10, THREAD_CALLEE_REG]
  394. ; Call the trap handler
  395. bl do_non_swi_trap
  396. ; unwind stack to discard Callee saved Regs
  397. DISCARD_CALLEE_SAVED_USER
  398. b ret_from_exception
  399. ;##################### Trap Handling ##############################
  400. ;
  401. ; EV_Trap caused by TRAP_S and TRAP0 instructions.
  402. ;------------------------------------------------------------------
  403. ; (1) System Calls
  404. ; :parameters in r0-r7.
  405. ; :r8 has the system call number
  406. ; (2) Break Points
  407. ;------------------------------------------------------------------
  408. ARC_ENTRY EV_Trap
  409. ; Need at least 1 reg to code the early exception prolog
  410. EXCPN_PROLOG_FREEUP_REG r9
  411. ;Which mode (user/kernel) was the system in when intr occured
  412. lr r9, [erstatus]
  413. SWITCH_TO_KERNEL_STK
  414. SAVE_ALL_SYS
  415. ;------- (4) What caused the Trap --------------
  416. lr r12, [ecr]
  417. bmsk.f 0, r12, 7
  418. bnz trap_with_param
  419. ; ======= (5a) Trap is due to System Call ========
  420. ; Before doing anything, return from CPU Exception Mode
  421. FAKE_RET_FROM_EXCPN r11
  422. ; If syscall tracing ongoing, invoke pre-pos-hooks
  423. GET_CURR_THR_INFO_FLAGS r10
  424. btst r10, TIF_SYSCALL_TRACE
  425. bnz tracesys ; this never comes back
  426. ;============ This is normal System Call case ==========
  427. ; Sys-call num shd not exceed the total system calls avail
  428. cmp r8, NR_syscalls
  429. mov.hi r0, -ENOSYS
  430. bhi ret_from_system_call
  431. ; Offset into the syscall_table and call handler
  432. ld.as r9,[sys_call_table, r8]
  433. jl [r9] ; Entry into Sys Call Handler
  434. ; fall through to ret_from_system_call
  435. ARC_EXIT EV_Trap
  436. ARC_ENTRY ret_from_system_call
  437. st r0, [sp, PT_r0] ; sys call return value in pt_regs
  438. ; fall through yet again to ret_from_exception
  439. ;############# Return from Intr/Excp/Trap (Linux Specifics) ##############
  440. ;
  441. ; If ret to user mode do we need to handle signals, schedule() et al.
  442. ARC_ENTRY ret_from_exception
  443. ; Pre-{IRQ,Trap,Exception} K/U mode from pt_regs->status32
  444. ld r8, [sp, PT_status32] ; returning to User/Kernel Mode
  445. bbit0 r8, STATUS_U_BIT, resume_kernel_mode
  446. ; Before returning to User mode check-for-and-complete any pending work
  447. ; such as rescheduling/signal-delivery etc.
  448. resume_user_mode_begin:
  449. ; Disable IRQs to ensures that chk for pending work itself is atomic
  450. ; (and we don't end up missing a NEED_RESCHED/SIGPENDING due to an
  451. ; interim IRQ).
  452. IRQ_DISABLE r10
  453. ; Fast Path return to user mode if no pending work
  454. GET_CURR_THR_INFO_FLAGS r9
  455. and.f 0, r9, _TIF_WORK_MASK
  456. bz restore_regs
  457. ; --- (Slow Path #1) task preemption ---
  458. bbit0 r9, TIF_NEED_RESCHED, .Lchk_pend_signals
  459. mov blink, resume_user_mode_begin ; tail-call to U mode ret chks
  460. b @schedule ; BTST+Bnz causes relo error in link
  461. .Lchk_pend_signals:
  462. IRQ_ENABLE r10
  463. ; --- (Slow Path #2) pending signal ---
  464. mov r0, sp ; pt_regs for arg to do_signal()/do_notify_resume()
  465. bbit0 r9, TIF_SIGPENDING, .Lchk_notify_resume
  466. ; Normal Trap/IRQ entry only saves Scratch (caller-saved) regs
  467. ; in pt_reg since the "C" ABI (kernel code) will automatically
  468. ; save/restore callee-saved regs.
  469. ;
  470. ; However, here we need to explicitly save callee regs because
  471. ; (i) If this signal causes coredump - full regfile needed
  472. ; (ii) If signal is SIGTRAP/SIGSTOP, task is being traced thus
  473. ; tracer might call PEEKUSR(CALLEE reg)
  474. ;
  475. ; NOTE: SP will grow up by size of CALLEE Reg-File
  476. SAVE_CALLEE_SAVED_USER ; clobbers r12
  477. ; save location of saved Callee Regs @ thread_struct->callee
  478. GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
  479. st sp, [r10, THREAD_CALLEE_REG]
  480. bl @do_signal
  481. ; Ideally we want to discard the Callee reg above, however if this was
  482. ; a tracing signal, tracer could have done a POKEUSR(CALLEE reg)
  483. RESTORE_CALLEE_SAVED_USER
  484. b resume_user_mode_begin ; loop back to start of U mode ret
  485. ; --- (Slow Path #3) notify_resume ---
  486. .Lchk_notify_resume:
  487. btst r9, TIF_NOTIFY_RESUME
  488. blnz @do_notify_resume
  489. b resume_user_mode_begin ; unconditionally back to U mode ret chks
  490. ; for single exit point from this block
  491. resume_kernel_mode:
  492. #ifdef CONFIG_PREEMPT
  493. ; Can't preempt if preemption disabled
  494. GET_CURR_THR_INFO_FROM_SP r10
  495. ld r8, [r10, THREAD_INFO_PREEMPT_COUNT]
  496. brne r8, 0, restore_regs
  497. ; check if this task's NEED_RESCHED flag set
  498. ld r9, [r10, THREAD_INFO_FLAGS]
  499. bbit0 r9, TIF_NEED_RESCHED, restore_regs
  500. IRQ_DISABLE r9
  501. ; Invoke PREEMPTION
  502. bl preempt_schedule_irq
  503. ; preempt_schedule_irq() always returns with IRQ disabled
  504. #endif
  505. ; fall through
  506. ;############# Return from Intr/Excp/Trap (ARC Specifics) ##############
  507. ;
  508. ; Restore the saved sys context (common exit-path for EXCPN/IRQ/Trap)
  509. ; IRQ shd definitely not happen between now and rtie
  510. restore_regs :
  511. ; Disable Interrupts while restoring reg-file back
  512. ; XXX can this be optimised out
  513. IRQ_DISABLE_SAVE r9, r10 ;@r10 has prisitine (pre-disable) copy
  514. ; Restore REG File. In case multiple Events outstanding,
  515. ; use the same priorty as rtie: EXCPN, L2 IRQ, L1 IRQ, None
  516. ; Note that we use realtime STATUS32 (not pt_regs->status32) to
  517. ; decide that.
  518. ; if Returning from Exception
  519. bbit0 r10, STATUS_AE_BIT, not_exception
  520. RESTORE_ALL_SYS
  521. rtie
  522. ; Not Exception so maybe Interrupts (Level 1 or 2)
  523. not_exception:
  524. #ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
  525. ; Level 2 interrupt return Path - from hardware standpoint
  526. bbit0 r10, STATUS_A2_BIT, not_level2_interrupt
  527. ;------------------------------------------------------------------
  528. ; However the context returning might not have taken L2 intr itself
  529. ; e.g. Task'A' user-code -> L2 intr -> schedule -> 'B' user-code ret
  530. ; Special considerations needed for the context which took L2 intr
  531. ld r9, [sp, PT_event] ; Ensure this is L2 intr context
  532. brne r9, event_IRQ2, 149f
  533. ;------------------------------------------------------------------
  534. ; if L2 IRQ interrupted a L1 ISR, we'd disbaled preemption earlier
  535. ; so that sched doesnt move to new task, causing L1 to be delayed
  536. ; undeterministically. Now that we've achieved that, lets reset
  537. ; things to what they were, before returning from L2 context
  538. ;----------------------------------------------------------------
  539. ld r9, [sp, PT_status32] ; get statu32_l2 (saved in pt_regs)
  540. bbit0 r9, STATUS_A1_BIT, 149f ; L1 not active when L2 IRQ, so normal
  541. ; decrement thread_info->preempt_count (re-enable preemption)
  542. GET_CURR_THR_INFO_FROM_SP r10
  543. ld r9, [r10, THREAD_INFO_PREEMPT_COUNT]
  544. ; paranoid check, given A1 was active when A2 happened, preempt count
  545. ; must not be 0 because we would have incremented it.
  546. ; If this does happen we simply HALT as it means a BUG !!!
  547. cmp r9, 0
  548. bnz 2f
  549. flag 1
  550. 2:
  551. sub r9, r9, 1
  552. st r9, [r10, THREAD_INFO_PREEMPT_COUNT]
  553. 149:
  554. ;return from level 2
  555. RESTORE_ALL_INT2
  556. debug_marker_l2:
  557. rtie
  558. not_level2_interrupt:
  559. #endif
  560. bbit0 r10, STATUS_A1_BIT, not_level1_interrupt
  561. ;return from level 1
  562. RESTORE_ALL_INT1
  563. debug_marker_l1:
  564. rtie
  565. not_level1_interrupt:
  566. ;this case is for syscalls or Exceptions (with fake rtie)
  567. RESTORE_ALL_SYS
  568. debug_marker_syscall:
  569. rtie
  570. ARC_EXIT ret_from_exception
  571. ARC_ENTRY ret_from_fork
  572. ; when the forked child comes here from the __switch_to function
  573. ; r0 has the last task pointer.
  574. ; put last task in scheduler queue
  575. bl @schedule_tail
  576. ; If kernel thread, jump to it's entry-point
  577. ld r9, [sp, PT_status32]
  578. brne r9, 0, 1f
  579. jl.d [r14]
  580. mov r0, r13 ; arg to payload
  581. 1:
  582. ; special case of kernel_thread entry point returning back due to
  583. ; kernel_execve() - pretend return from syscall to ret to userland
  584. b ret_from_exception
  585. ARC_EXIT ret_from_fork
  586. ;################### Special Sys Call Wrappers ##########################
  587. ARC_ENTRY sys_clone_wrapper
  588. SAVE_CALLEE_SAVED_USER
  589. bl @sys_clone
  590. DISCARD_CALLEE_SAVED_USER
  591. GET_CURR_THR_INFO_FLAGS r10
  592. btst r10, TIF_SYSCALL_TRACE
  593. bnz tracesys_exit
  594. b ret_from_system_call
  595. ARC_EXIT sys_clone_wrapper
  596. #ifdef CONFIG_ARC_DW2_UNWIND
  597. ; Workaround for bug 94179 (STAR ):
  598. ; Despite -fasynchronous-unwind-tables, linker is not making dwarf2 unwinder
  599. ; section (.debug_frame) as loadable. So we force it here.
  600. ; This also fixes STAR 9000487933 where the prev-workaround (objcopy --setflag)
  601. ; would not work after a clean build due to kernel build system dependencies.
  602. .section .debug_frame, "wa",@progbits
  603. #endif