entry.S 22 KB

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