entry.S 22 KB

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