entry.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /*
  2. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * Vineetg: March 2009 (Supporting 2 levels of Interrupts)
  9. * Stack switching code can no longer reliably rely on the fact that
  10. * if we are NOT in user mode, stack is switched to kernel mode.
  11. * e.g. L2 IRQ interrupted a L1 ISR which had not yet completed
  12. * it's prologue including stack switching from user mode
  13. *
  14. * Vineetg: Aug 28th 2008: Bug #94984
  15. * -Zero Overhead Loop Context shd be cleared when entering IRQ/EXcp/Trap
  16. * Normally CPU does this automatically, however when doing FAKE rtie,
  17. * we also need to explicitly do this. The problem in macros
  18. * FAKE_RET_FROM_EXCPN and FAKE_RET_FROM_EXCPN_LOCK_IRQ was that this bit
  19. * was being "CLEARED" rather then "SET". Actually "SET" clears ZOL context
  20. *
  21. * Vineetg: May 5th 2008
  22. * -Modified CALLEE_REG save/restore macros to handle the fact that
  23. * r25 contains the kernel current task ptr
  24. * - Defined Stack Switching Macro to be reused in all intr/excp hdlrs
  25. * - Shaved off 11 instructions from RESTORE_ALL_INT1 by using the
  26. * address Write back load ld.ab instead of seperate ld/add instn
  27. *
  28. * Amit Bhor, Sameer Dhavale: Codito Technologies 2004
  29. */
  30. #ifndef __ASM_ARC_ENTRY_H
  31. #define __ASM_ARC_ENTRY_H
  32. #ifdef __ASSEMBLY__
  33. #include <asm/unistd.h> /* For NR_syscalls defination */
  34. #include <asm/asm-offsets.h>
  35. #include <asm/arcregs.h>
  36. #include <asm/ptrace.h>
  37. #include <asm/processor.h> /* For VMALLOC_START */
  38. #include <asm/thread_info.h> /* For THREAD_SIZE */
  39. /* Note on the LD/ST addr modes with addr reg wback
  40. *
  41. * LD.a same as LD.aw
  42. *
  43. * LD.a reg1, [reg2, x] => Pre Incr
  44. * Eff Addr for load = [reg2 + x]
  45. *
  46. * LD.ab reg1, [reg2, x] => Post Incr
  47. * Eff Addr for load = [reg2]
  48. */
  49. /*--------------------------------------------------------------
  50. * Save caller saved registers (scratch registers) ( r0 - r12 )
  51. * Registers are pushed / popped in the order defined in struct ptregs
  52. * in asm/ptrace.h
  53. *-------------------------------------------------------------*/
  54. .macro SAVE_CALLER_SAVED
  55. st.a r0, [sp, -4]
  56. st.a r1, [sp, -4]
  57. st.a r2, [sp, -4]
  58. st.a r3, [sp, -4]
  59. st.a r4, [sp, -4]
  60. st.a r5, [sp, -4]
  61. st.a r6, [sp, -4]
  62. st.a r7, [sp, -4]
  63. st.a r8, [sp, -4]
  64. st.a r9, [sp, -4]
  65. st.a r10, [sp, -4]
  66. st.a r11, [sp, -4]
  67. st.a r12, [sp, -4]
  68. .endm
  69. /*--------------------------------------------------------------
  70. * Restore caller saved registers (scratch registers)
  71. *-------------------------------------------------------------*/
  72. .macro RESTORE_CALLER_SAVED
  73. ld.ab r12, [sp, 4]
  74. ld.ab r11, [sp, 4]
  75. ld.ab r10, [sp, 4]
  76. ld.ab r9, [sp, 4]
  77. ld.ab r8, [sp, 4]
  78. ld.ab r7, [sp, 4]
  79. ld.ab r6, [sp, 4]
  80. ld.ab r5, [sp, 4]
  81. ld.ab r4, [sp, 4]
  82. ld.ab r3, [sp, 4]
  83. ld.ab r2, [sp, 4]
  84. ld.ab r1, [sp, 4]
  85. ld.ab r0, [sp, 4]
  86. .endm
  87. /*--------------------------------------------------------------
  88. * Save callee saved registers (non scratch registers) ( r13 - r25 )
  89. * on kernel stack.
  90. * User mode callee regs need to be saved in case of
  91. * -fork and friends for replicating from parent to child
  92. * -before going into do_signal( ) for ptrace/core-dump
  93. * Special case handling is required for r25 in case it is used by kernel
  94. * for caching task ptr. Low level exception/ISR save user mode r25
  95. * into task->thread.user_r25. So it needs to be retrieved from there and
  96. * saved into kernel stack with rest of callee reg-file
  97. *-------------------------------------------------------------*/
  98. .macro SAVE_CALLEE_SAVED_USER
  99. st.a r13, [sp, -4]
  100. st.a r14, [sp, -4]
  101. st.a r15, [sp, -4]
  102. st.a r16, [sp, -4]
  103. st.a r17, [sp, -4]
  104. st.a r18, [sp, -4]
  105. st.a r19, [sp, -4]
  106. st.a r20, [sp, -4]
  107. st.a r21, [sp, -4]
  108. st.a r22, [sp, -4]
  109. st.a r23, [sp, -4]
  110. st.a r24, [sp, -4]
  111. #ifdef CONFIG_ARC_CURR_IN_REG
  112. ; Retrieve orig r25 and save it on stack
  113. ld r12, [r25, TASK_THREAD + THREAD_USER_R25]
  114. st.a r12, [sp, -4]
  115. #else
  116. st.a r25, [sp, -4]
  117. #endif
  118. /* move up by 1 word to "create" callee_regs->"stack_place_holder" */
  119. sub sp, sp, 4
  120. .endm
  121. /*--------------------------------------------------------------
  122. * Save callee saved registers (non scratch registers) ( r13 - r25 )
  123. * kernel mode callee regs needed to be saved in case of context switch
  124. * If r25 is used for caching task pointer then that need not be saved
  125. * as it can be re-created from current task global
  126. *-------------------------------------------------------------*/
  127. .macro SAVE_CALLEE_SAVED_KERNEL
  128. st.a r13, [sp, -4]
  129. st.a r14, [sp, -4]
  130. st.a r15, [sp, -4]
  131. st.a r16, [sp, -4]
  132. st.a r17, [sp, -4]
  133. st.a r18, [sp, -4]
  134. st.a r19, [sp, -4]
  135. st.a r20, [sp, -4]
  136. st.a r21, [sp, -4]
  137. st.a r22, [sp, -4]
  138. st.a r23, [sp, -4]
  139. st.a r24, [sp, -4]
  140. #ifdef CONFIG_ARC_CURR_IN_REG
  141. sub sp, sp, 8
  142. #else
  143. st.a r25, [sp, -4]
  144. sub sp, sp, 4
  145. #endif
  146. .endm
  147. /*--------------------------------------------------------------
  148. * RESTORE_CALLEE_SAVED_KERNEL:
  149. * Loads callee (non scratch) Reg File by popping from Kernel mode stack.
  150. * This is reverse of SAVE_CALLEE_SAVED,
  151. *
  152. * NOTE:
  153. * Ideally this shd only be called in switch_to for loading
  154. * switched-IN task's CALLEE Reg File.
  155. * For all other cases RESTORE_CALLEE_SAVED_FAST must be used
  156. * which simply pops the stack w/o touching regs.
  157. *-------------------------------------------------------------*/
  158. .macro RESTORE_CALLEE_SAVED_KERNEL
  159. #ifdef CONFIG_ARC_CURR_IN_REG
  160. add sp, sp, 8 /* skip callee_reg gutter and user r25 placeholder */
  161. #else
  162. add sp, sp, 4 /* skip "callee_regs->stack_place_holder" */
  163. ld.ab r25, [sp, 4]
  164. #endif
  165. ld.ab r24, [sp, 4]
  166. ld.ab r23, [sp, 4]
  167. ld.ab r22, [sp, 4]
  168. ld.ab r21, [sp, 4]
  169. ld.ab r20, [sp, 4]
  170. ld.ab r19, [sp, 4]
  171. ld.ab r18, [sp, 4]
  172. ld.ab r17, [sp, 4]
  173. ld.ab r16, [sp, 4]
  174. ld.ab r15, [sp, 4]
  175. ld.ab r14, [sp, 4]
  176. ld.ab r13, [sp, 4]
  177. .endm
  178. /*--------------------------------------------------------------
  179. * RESTORE_CALLEE_SAVED_USER:
  180. * This is called after do_signal where tracer might have changed callee regs
  181. * thus we need to restore the reg file.
  182. * Special case handling is required for r25 in case it is used by kernel
  183. * for caching task ptr. Ptrace would have modified on-kernel-stack value of
  184. * r25, which needs to be shoved back into task->thread.user_r25 where from
  185. * Low level exception/ISR return code will retrieve to populate with rest of
  186. * callee reg-file.
  187. *-------------------------------------------------------------*/
  188. .macro RESTORE_CALLEE_SAVED_USER
  189. add sp, sp, 4 /* skip "callee_regs->stack_place_holder" */
  190. #ifdef CONFIG_ARC_CURR_IN_REG
  191. ld.ab r12, [sp, 4]
  192. st r12, [r25, TASK_THREAD + THREAD_USER_R25]
  193. #else
  194. ld.ab r25, [sp, 4]
  195. #endif
  196. ld.ab r24, [sp, 4]
  197. ld.ab r23, [sp, 4]
  198. ld.ab r22, [sp, 4]
  199. ld.ab r21, [sp, 4]
  200. ld.ab r20, [sp, 4]
  201. ld.ab r19, [sp, 4]
  202. ld.ab r18, [sp, 4]
  203. ld.ab r17, [sp, 4]
  204. ld.ab r16, [sp, 4]
  205. ld.ab r15, [sp, 4]
  206. ld.ab r14, [sp, 4]
  207. ld.ab r13, [sp, 4]
  208. .endm
  209. /*--------------------------------------------------------------
  210. * Super FAST Restore callee saved regs by simply re-adjusting SP
  211. *-------------------------------------------------------------*/
  212. .macro DISCARD_CALLEE_SAVED_USER
  213. add sp, sp, 14 * 4
  214. .endm
  215. /*--------------------------------------------------------------
  216. * Restore User mode r25 saved in task_struct->thread.user_r25
  217. *-------------------------------------------------------------*/
  218. .macro RESTORE_USER_R25
  219. ld r25, [r25, TASK_THREAD + THREAD_USER_R25]
  220. .endm
  221. /*-------------------------------------------------------------
  222. * given a tsk struct, get to the base of it's kernel mode stack
  223. * tsk->thread_info is really a PAGE, whose bottom hoists stack
  224. * which grows upwards towards thread_info
  225. *------------------------------------------------------------*/
  226. .macro GET_TSK_STACK_BASE tsk, out
  227. /* Get task->thread_info (this is essentially start of a PAGE) */
  228. ld \out, [\tsk, TASK_THREAD_INFO]
  229. /* Go to end of page where stack begins (grows upwards) */
  230. add2 \out, \out, (THREAD_SIZE)/4
  231. .endm
  232. /*--------------------------------------------------------------
  233. * Switch to Kernel Mode stack if SP points to User Mode stack
  234. *
  235. * Entry : r9 contains pre-IRQ/exception/trap status32
  236. * Exit : SP is set to kernel mode stack pointer
  237. * If CURR_IN_REG, r25 set to "current" task pointer
  238. * Clobbers: r9
  239. *-------------------------------------------------------------*/
  240. .macro SWITCH_TO_KERNEL_STK
  241. /* User Mode when this happened ? Yes: Proceed to switch stack */
  242. bbit1 r9, STATUS_U_BIT, 88f
  243. /* OK we were already in kernel mode when this event happened, thus can
  244. * assume SP is kernel mode SP. _NO_ need to do any stack switching
  245. */
  246. #ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
  247. /* However....
  248. * If Level 2 Interrupts enabled, we may end up with a corner case:
  249. * 1. User Task executing
  250. * 2. L1 IRQ taken, ISR starts (CPU auto-switched to KERNEL mode)
  251. * 3. But before it could switch SP from USER to KERNEL stack
  252. * a L2 IRQ "Interrupts" L1
  253. * Thay way although L2 IRQ happened in Kernel mode, stack is still
  254. * not switched.
  255. * To handle this, we may need to switch stack even if in kernel mode
  256. * provided SP has values in range of USER mode stack ( < 0x7000_0000 )
  257. */
  258. brlo sp, VMALLOC_START, 88f
  259. /* TODO: vineetg:
  260. * We need to be a bit more cautious here. What if a kernel bug in
  261. * L1 ISR, caused SP to go whaco (some small value which looks like
  262. * USER stk) and then we take L2 ISR.
  263. * Above brlo alone would treat it as a valid L1-L2 sceanrio
  264. * instead of shouting alound
  265. * The only feasible way is to make sure this L2 happened in
  266. * L1 prelogue ONLY i.e. ilink2 is less than a pre-set marker in
  267. * L1 ISR before it switches stack
  268. */
  269. #endif
  270. /* Save Pre Intr/Exception KERNEL MODE SP on kernel stack
  271. * safe-keeping not really needed, but it keeps the epilogue code
  272. * (SP restore) simpler/uniform.
  273. */
  274. b.d 77f
  275. st.a sp, [sp, -12] ; Make room for orig_r0 and orig_r8
  276. 88: /*------Intr/Ecxp happened in user mode, "switch" stack ------ */
  277. GET_CURR_TASK_ON_CPU r9
  278. #ifdef CONFIG_ARC_CURR_IN_REG
  279. /* If current task pointer cached in r25, time to
  280. * -safekeep USER r25 in task->thread_struct->user_r25
  281. * -load r25 with current task ptr
  282. */
  283. st.as r25, [r9, (TASK_THREAD + THREAD_USER_R25)/4]
  284. mov r25, r9
  285. #endif
  286. /* With current tsk in r9, get it's kernel mode stack base */
  287. GET_TSK_STACK_BASE r9, r9
  288. /* Save Pre Intr/Exception User SP on kernel stack */
  289. st.a sp, [r9, -12] ; Make room for orig_r0 and orig_r8
  290. /* CAUTION:
  291. * SP should be set at the very end when we are done with everything
  292. * In case of 2 levels of interrupt we depend on value of SP to assume
  293. * that everything else is done (loading r25 etc)
  294. */
  295. /* set SP to point to kernel mode stack */
  296. mov sp, r9
  297. 77: /* ----- Stack Switched to kernel Mode, Now save REG FILE ----- */
  298. .endm
  299. /*------------------------------------------------------------
  300. * "FAKE" a rtie to return from CPU Exception context
  301. * This is to re-enable Exceptions within exception
  302. * Look at EV_ProtV to see how this is actually used
  303. *-------------------------------------------------------------*/
  304. .macro FAKE_RET_FROM_EXCPN reg
  305. ld \reg, [sp, PT_status32]
  306. bic \reg, \reg, (STATUS_U_MASK|STATUS_DE_MASK)
  307. bset \reg, \reg, STATUS_L_BIT
  308. sr \reg, [erstatus]
  309. mov \reg, 55f
  310. sr \reg, [eret]
  311. rtie
  312. 55:
  313. .endm
  314. /*
  315. * @reg [OUT] &thread_info of "current"
  316. */
  317. .macro GET_CURR_THR_INFO_FROM_SP reg
  318. and \reg, sp, ~(THREAD_SIZE - 1)
  319. .endm
  320. /*
  321. * @reg [OUT] thread_info->flags of "current"
  322. */
  323. .macro GET_CURR_THR_INFO_FLAGS reg
  324. GET_CURR_THR_INFO_FROM_SP \reg
  325. ld \reg, [\reg, THREAD_INFO_FLAGS]
  326. .endm
  327. /*--------------------------------------------------------------
  328. * For early Exception Prologue, a core reg is temporarily needed to
  329. * code the rest of prolog (stack switching). This is done by stashing
  330. * it to memory (non-SMP case) or SCRATCH0 Aux Reg (SMP).
  331. *
  332. * Before saving the full regfile - this reg is restored back, only
  333. * to be saved again on kernel mode stack, as part of ptregs.
  334. *-------------------------------------------------------------*/
  335. .macro EXCPN_PROLOG_FREEUP_REG reg
  336. #ifdef CONFIG_SMP
  337. sr \reg, [ARC_REG_SCRATCH_DATA0]
  338. #else
  339. st \reg, [@ex_saved_reg1]
  340. #endif
  341. .endm
  342. .macro EXCPN_PROLOG_RESTORE_REG reg
  343. #ifdef CONFIG_SMP
  344. lr \reg, [ARC_REG_SCRATCH_DATA0]
  345. #else
  346. ld \reg, [@ex_saved_reg1]
  347. #endif
  348. .endm
  349. /*--------------------------------------------------------------
  350. * Save all registers used by Exceptions (TLB Miss, Prot-V, Mem err etc)
  351. * Requires SP to be already switched to kernel mode Stack
  352. * sp points to the next free element on the stack at exit of this macro.
  353. * Registers are pushed / popped in the order defined in struct ptregs
  354. * in asm/ptrace.h
  355. * Note that syscalls are implemented via TRAP which is also a exception
  356. * from CPU's point of view
  357. *-------------------------------------------------------------*/
  358. .macro SAVE_ALL_EXCEPTION marker
  359. st \marker, [sp, 8] /* orig_r8 */
  360. st r0, [sp, 4] /* orig_r0, needed only for sys calls */
  361. /* Restore r9 used to code the early prologue */
  362. EXCPN_PROLOG_RESTORE_REG r9
  363. SAVE_CALLER_SAVED
  364. st.a r26, [sp, -4] /* gp */
  365. st.a fp, [sp, -4]
  366. st.a blink, [sp, -4]
  367. lr r9, [eret]
  368. st.a r9, [sp, -4]
  369. lr r9, [erstatus]
  370. st.a r9, [sp, -4]
  371. st.a lp_count, [sp, -4]
  372. lr r9, [lp_end]
  373. st.a r9, [sp, -4]
  374. lr r9, [lp_start]
  375. st.a r9, [sp, -4]
  376. lr r9, [erbta]
  377. st.a r9, [sp, -4]
  378. .endm
  379. /*--------------------------------------------------------------
  380. * Save scratch regs for exceptions
  381. *-------------------------------------------------------------*/
  382. .macro SAVE_ALL_SYS
  383. SAVE_ALL_EXCEPTION orig_r8_IS_EXCPN
  384. .endm
  385. /*--------------------------------------------------------------
  386. * Save scratch regs for sys calls
  387. *-------------------------------------------------------------*/
  388. .macro SAVE_ALL_TRAP
  389. /*
  390. * Setup pt_regs->orig_r8.
  391. * Encode syscall number (r8) in upper short word of event type (r9)
  392. * N.B. #1: This is already endian safe (see ptrace.h)
  393. * #2: Only r9 can be used as scratch as it is already clobbered
  394. * and it's contents are no longer needed by the latter part
  395. * of exception prologue
  396. */
  397. lsl r9, r8, 16
  398. or r9, r9, orig_r8_IS_SCALL
  399. SAVE_ALL_EXCEPTION r9
  400. .endm
  401. /*--------------------------------------------------------------
  402. * Restore all registers used by system call or Exceptions
  403. * SP should always be pointing to the next free stack element
  404. * when entering this macro.
  405. *
  406. * NOTE:
  407. *
  408. * It is recommended that lp_count/ilink1/ilink2 not be used as a dest reg
  409. * for memory load operations. If used in that way interrupts are deffered
  410. * by hardware and that is not good.
  411. *-------------------------------------------------------------*/
  412. .macro RESTORE_ALL_SYS
  413. ld.ab r9, [sp, 4]
  414. sr r9, [erbta]
  415. ld.ab r9, [sp, 4]
  416. sr r9, [lp_start]
  417. ld.ab r9, [sp, 4]
  418. sr r9, [lp_end]
  419. ld.ab r9, [sp, 4]
  420. mov lp_count, r9
  421. ld.ab r9, [sp, 4]
  422. sr r9, [erstatus]
  423. ld.ab r9, [sp, 4]
  424. sr r9, [eret]
  425. ld.ab blink, [sp, 4]
  426. ld.ab fp, [sp, 4]
  427. ld.ab r26, [sp, 4] /* gp */
  428. RESTORE_CALLER_SAVED
  429. ld sp, [sp] /* restore original sp */
  430. /* orig_r0 and orig_r8 skipped automatically */
  431. .endm
  432. /*--------------------------------------------------------------
  433. * Save all registers used by interrupt handlers.
  434. *-------------------------------------------------------------*/
  435. .macro SAVE_ALL_INT1
  436. /* restore original r9 , saved in int1_saved_reg
  437. * It will be saved on stack in macro: SAVE_CALLER_SAVED
  438. */
  439. #ifdef CONFIG_SMP
  440. lr r9, [ARC_REG_SCRATCH_DATA0]
  441. #else
  442. ld r9, [@int1_saved_reg]
  443. #endif
  444. /* now we are ready to save the remaining context :) */
  445. st orig_r8_IS_IRQ1, [sp, 8] /* Event Type */
  446. st 0, [sp, 4] /* orig_r0 , N/A for IRQ */
  447. SAVE_CALLER_SAVED
  448. st.a r26, [sp, -4] /* gp */
  449. st.a fp, [sp, -4]
  450. st.a blink, [sp, -4]
  451. st.a ilink1, [sp, -4]
  452. lr r9, [status32_l1]
  453. st.a r9, [sp, -4]
  454. st.a lp_count, [sp, -4]
  455. lr r9, [lp_end]
  456. st.a r9, [sp, -4]
  457. lr r9, [lp_start]
  458. st.a r9, [sp, -4]
  459. lr r9, [bta_l1]
  460. st.a r9, [sp, -4]
  461. .endm
  462. .macro SAVE_ALL_INT2
  463. /* TODO-vineetg: SMP we can't use global nor can we use
  464. * SCRATCH0 as we do for int1 because while int1 is using
  465. * it, int2 can come
  466. */
  467. /* retsore original r9 , saved in sys_saved_r9 */
  468. ld r9, [@int2_saved_reg]
  469. /* now we are ready to save the remaining context :) */
  470. st orig_r8_IS_IRQ2, [sp, 8] /* Event Type */
  471. st 0, [sp, 4] /* orig_r0 , N/A for IRQ */
  472. SAVE_CALLER_SAVED
  473. st.a r26, [sp, -4] /* gp */
  474. st.a fp, [sp, -4]
  475. st.a blink, [sp, -4]
  476. st.a ilink2, [sp, -4]
  477. lr r9, [status32_l2]
  478. st.a r9, [sp, -4]
  479. st.a lp_count, [sp, -4]
  480. lr r9, [lp_end]
  481. st.a r9, [sp, -4]
  482. lr r9, [lp_start]
  483. st.a r9, [sp, -4]
  484. lr r9, [bta_l2]
  485. st.a r9, [sp, -4]
  486. .endm
  487. /*--------------------------------------------------------------
  488. * Restore all registers used by interrupt handlers.
  489. *
  490. * NOTE:
  491. *
  492. * It is recommended that lp_count/ilink1/ilink2 not be used as a dest reg
  493. * for memory load operations. If used in that way interrupts are deffered
  494. * by hardware and that is not good.
  495. *-------------------------------------------------------------*/
  496. .macro RESTORE_ALL_INT1
  497. ld.ab r9, [sp, 4] /* Actual reg file */
  498. sr r9, [bta_l1]
  499. ld.ab r9, [sp, 4]
  500. sr r9, [lp_start]
  501. ld.ab r9, [sp, 4]
  502. sr r9, [lp_end]
  503. ld.ab r9, [sp, 4]
  504. mov lp_count, r9
  505. ld.ab r9, [sp, 4]
  506. sr r9, [status32_l1]
  507. ld.ab r9, [sp, 4]
  508. mov ilink1, r9
  509. ld.ab blink, [sp, 4]
  510. ld.ab fp, [sp, 4]
  511. ld.ab r26, [sp, 4] /* gp */
  512. RESTORE_CALLER_SAVED
  513. ld sp, [sp] /* restore original sp */
  514. /* orig_r0 and orig_r8 skipped automatically */
  515. .endm
  516. .macro RESTORE_ALL_INT2
  517. ld.ab r9, [sp, 4]
  518. sr r9, [bta_l2]
  519. ld.ab r9, [sp, 4]
  520. sr r9, [lp_start]
  521. ld.ab r9, [sp, 4]
  522. sr r9, [lp_end]
  523. ld.ab r9, [sp, 4]
  524. mov lp_count, r9
  525. ld.ab r9, [sp, 4]
  526. sr r9, [status32_l2]
  527. ld.ab r9, [sp, 4]
  528. mov ilink2, r9
  529. ld.ab blink, [sp, 4]
  530. ld.ab fp, [sp, 4]
  531. ld.ab r26, [sp, 4] /* gp */
  532. RESTORE_CALLER_SAVED
  533. ld sp, [sp] /* restore original sp */
  534. /* orig_r0 and orig_r8 skipped automatically */
  535. .endm
  536. /* Get CPU-ID of this core */
  537. .macro GET_CPU_ID reg
  538. lr \reg, [identity]
  539. lsr \reg, \reg, 8
  540. bmsk \reg, \reg, 7
  541. .endm
  542. #ifdef CONFIG_SMP
  543. /*-------------------------------------------------
  544. * Retrieve the current running task on this CPU
  545. * 1. Determine curr CPU id.
  546. * 2. Use it to index into _current_task[ ]
  547. */
  548. .macro GET_CURR_TASK_ON_CPU reg
  549. GET_CPU_ID \reg
  550. ld.as \reg, [@_current_task, \reg]
  551. .endm
  552. /*-------------------------------------------------
  553. * Save a new task as the "current" task on this CPU
  554. * 1. Determine curr CPU id.
  555. * 2. Use it to index into _current_task[ ]
  556. *
  557. * Coded differently than GET_CURR_TASK_ON_CPU (which uses LD.AS)
  558. * because ST r0, [r1, offset] can ONLY have s9 @offset
  559. * while LD can take s9 (4 byte insn) or LIMM (8 byte insn)
  560. */
  561. .macro SET_CURR_TASK_ON_CPU tsk, tmp
  562. GET_CPU_ID \tmp
  563. add2 \tmp, @_current_task, \tmp
  564. st \tsk, [\tmp]
  565. #ifdef CONFIG_ARC_CURR_IN_REG
  566. mov r25, \tsk
  567. #endif
  568. .endm
  569. #else /* Uniprocessor implementation of macros */
  570. .macro GET_CURR_TASK_ON_CPU reg
  571. ld \reg, [@_current_task]
  572. .endm
  573. .macro SET_CURR_TASK_ON_CPU tsk, tmp
  574. st \tsk, [@_current_task]
  575. #ifdef CONFIG_ARC_CURR_IN_REG
  576. mov r25, \tsk
  577. #endif
  578. .endm
  579. #endif /* SMP / UNI */
  580. /* ------------------------------------------------------------------
  581. * Get the ptr to some field of Current Task at @off in task struct
  582. * -Uses r25 for Current task ptr if that is enabled
  583. */
  584. #ifdef CONFIG_ARC_CURR_IN_REG
  585. .macro GET_CURR_TASK_FIELD_PTR off, reg
  586. add \reg, r25, \off
  587. .endm
  588. #else
  589. .macro GET_CURR_TASK_FIELD_PTR off, reg
  590. GET_CURR_TASK_ON_CPU \reg
  591. add \reg, \reg, \off
  592. .endm
  593. #endif /* CONFIG_ARC_CURR_IN_REG */
  594. #endif /* __ASSEMBLY__ */
  595. #endif /* __ASM_ARC_ENTRY_H */