entry.S 22 KB

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