vectors.S 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. /*
  2. * arch/xtensa/kernel/vectors.S
  3. *
  4. * This file contains all exception vectors (user, kernel, and double),
  5. * as well as the window vectors (overflow and underflow), and the debug
  6. * vector. These are the primary vectors executed by the processor if an
  7. * exception occurs.
  8. *
  9. * This file is subject to the terms and conditions of the GNU General
  10. * Public License. See the file "COPYING" in the main directory of
  11. * this archive for more details.
  12. *
  13. * Copyright (C) 2005 - 2008 Tensilica, Inc.
  14. *
  15. * Chris Zankel <[email protected]>
  16. *
  17. */
  18. /*
  19. * We use a two-level table approach. The user and kernel exception vectors
  20. * use a first-level dispatch table to dispatch the exception to a registered
  21. * fast handler or the default handler, if no fast handler was registered.
  22. * The default handler sets up a C-stack and dispatches the exception to a
  23. * registerd C handler in the second-level dispatch table.
  24. *
  25. * Fast handler entry condition:
  26. *
  27. * a0: trashed, original value saved on stack (PT_AREG0)
  28. * a1: a1
  29. * a2: new stack pointer, original value in depc
  30. * a3: dispatch table
  31. * depc: a2, original value saved on stack (PT_DEPC)
  32. * excsave_1: a3
  33. *
  34. * The value for PT_DEPC saved to stack also functions as a boolean to
  35. * indicate that the exception is either a double or a regular exception:
  36. *
  37. * PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception
  38. * < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception
  39. *
  40. * Note: Neither the kernel nor the user exception handler generate literals.
  41. *
  42. */
  43. #include <linux/linkage.h>
  44. #include <linux/pgtable.h>
  45. #include <asm/asmmacro.h>
  46. #include <asm/ptrace.h>
  47. #include <asm/current.h>
  48. #include <asm/asm-offsets.h>
  49. #include <asm/processor.h>
  50. #include <asm/page.h>
  51. #include <asm/thread_info.h>
  52. #include <asm/vectors.h>
  53. #define WINDOW_VECTORS_SIZE 0x180
  54. /*
  55. * User exception vector. (Exceptions with PS.UM == 1, PS.EXCM == 0)
  56. *
  57. * We get here when an exception occurred while we were in userland.
  58. * We switch to the kernel stack and jump to the first level handler
  59. * associated to the exception cause.
  60. *
  61. * Note: the saved kernel stack pointer (EXC_TABLE_KSTK) is already
  62. * decremented by PT_USER_SIZE.
  63. */
  64. .section .UserExceptionVector.text, "ax"
  65. ENTRY(_UserExceptionVector)
  66. xsr a3, excsave1 # save a3 and get dispatch table
  67. wsr a2, depc # save a2
  68. l32i a2, a3, EXC_TABLE_KSTK # load kernel stack to a2
  69. s32i a0, a2, PT_AREG0 # save a0 to ESF
  70. rsr a0, exccause # retrieve exception cause
  71. s32i a0, a2, PT_DEPC # mark it as a regular exception
  72. addx4 a0, a0, a3 # find entry in table
  73. l32i a0, a0, EXC_TABLE_FAST_USER # load handler
  74. xsr a3, excsave1 # restore a3 and dispatch table
  75. jx a0
  76. ENDPROC(_UserExceptionVector)
  77. /*
  78. * Kernel exception vector. (Exceptions with PS.UM == 0, PS.EXCM == 0)
  79. *
  80. * We get this exception when we were already in kernel space.
  81. * We decrement the current stack pointer (kernel) by PT_KERNEL_SIZE and
  82. * jump to the first-level handler associated with the exception cause.
  83. *
  84. * Note: we need to preserve space for the spill region.
  85. */
  86. .section .KernelExceptionVector.text, "ax"
  87. ENTRY(_KernelExceptionVector)
  88. xsr a3, excsave1 # save a3, and get dispatch table
  89. wsr a2, depc # save a2
  90. addi a2, a1, -16 - PT_KERNEL_SIZE # adjust stack pointer
  91. s32i a0, a2, PT_AREG0 # save a0 to ESF
  92. rsr a0, exccause # retrieve exception cause
  93. s32i a0, a2, PT_DEPC # mark it as a regular exception
  94. addx4 a0, a0, a3 # find entry in table
  95. l32i a0, a0, EXC_TABLE_FAST_KERNEL # load handler address
  96. xsr a3, excsave1 # restore a3 and dispatch table
  97. jx a0
  98. ENDPROC(_KernelExceptionVector)
  99. /*
  100. * Double exception vector (Exceptions with PS.EXCM == 1)
  101. * We get this exception when another exception occurs while were are
  102. * already in an exception, such as window overflow/underflow exception,
  103. * or 'expected' exceptions, for example memory exception when we were trying
  104. * to read data from an invalid address in user space.
  105. *
  106. * Note that this vector is never invoked for level-1 interrupts, because such
  107. * interrupts are disabled (masked) when PS.EXCM is set.
  108. *
  109. * We decode the exception and take the appropriate action. However, the
  110. * double exception vector is much more careful, because a lot more error
  111. * cases go through the double exception vector than through the user and
  112. * kernel exception vectors.
  113. *
  114. * Occasionally, the kernel expects a double exception to occur. This usually
  115. * happens when accessing user-space memory with the user's permissions
  116. * (l32e/s32e instructions). The kernel state, though, is not always suitable
  117. * for immediate transfer of control to handle_double, where "normal" exception
  118. * processing occurs. Also in kernel mode, TLB misses can occur if accessing
  119. * vmalloc memory, possibly requiring repair in a double exception handler.
  120. *
  121. * The variable at TABLE_FIXUP offset from the pointer in EXCSAVE_1 doubles as
  122. * a boolean variable and a pointer to a fixup routine. If the variable
  123. * EXC_TABLE_FIXUP is non-zero, this handler jumps to that address. A value of
  124. * zero indicates to use the default kernel/user exception handler.
  125. * There is only one exception, when the value is identical to the exc_table
  126. * label, the kernel is in trouble. This mechanism is used to protect critical
  127. * sections, mainly when the handler writes to the stack to assert the stack
  128. * pointer is valid. Once the fixup/default handler leaves that area, the
  129. * EXC_TABLE_FIXUP variable is reset to the fixup handler or zero.
  130. *
  131. * Procedures wishing to use this mechanism should set EXC_TABLE_FIXUP to the
  132. * nonzero address of a fixup routine before it could cause a double exception
  133. * and reset it before it returns.
  134. *
  135. * Some other things to take care of when a fast exception handler doesn't
  136. * specify a particular fixup handler but wants to use the default handlers:
  137. *
  138. * - The original stack pointer (in a1) must not be modified. The fast
  139. * exception handler should only use a2 as the stack pointer.
  140. *
  141. * - If the fast handler manipulates the stack pointer (in a2), it has to
  142. * register a valid fixup handler and cannot use the default handlers.
  143. *
  144. * - The handler can use any other generic register from a3 to a15, but it
  145. * must save the content of these registers to stack (PT_AREG3...PT_AREGx)
  146. *
  147. * - These registers must be saved before a double exception can occur.
  148. *
  149. * - If we ever implement handling signals while in double exceptions, the
  150. * number of registers a fast handler has saved (excluding a0 and a1) must
  151. * be written to PT_AREG1. (1 if only a3 is used, 2 for a3 and a4, etc. )
  152. *
  153. * The fixup handlers are special handlers:
  154. *
  155. * - Fixup entry conditions differ from regular exceptions:
  156. *
  157. * a0: DEPC
  158. * a1: a1
  159. * a2: trashed, original value in EXC_TABLE_DOUBLE_SAVE
  160. * a3: exctable
  161. * depc: a0
  162. * excsave_1: a3
  163. *
  164. * - When the kernel enters the fixup handler, it still assumes it is in a
  165. * critical section, so EXC_TABLE_FIXUP variable is set to exc_table.
  166. * The fixup handler, therefore, has to re-register itself as the fixup
  167. * handler before it returns from the double exception.
  168. *
  169. * - Fixup handler can share the same exception frame with the fast handler.
  170. * The kernel stack pointer is not changed when entering the fixup handler.
  171. *
  172. * - Fixup handlers can jump to the default kernel and user exception
  173. * handlers. Before it jumps, though, it has to setup a exception frame
  174. * on stack. Because the default handler resets the register fixup handler
  175. * the fixup handler must make sure that the default handler returns to
  176. * it instead of the exception address, so it can re-register itself as
  177. * the fixup handler.
  178. *
  179. * In case of a critical condition where the kernel cannot recover, we jump
  180. * to unrecoverable_exception with the following entry conditions.
  181. * All registers a0...a15 are unchanged from the last exception, except:
  182. *
  183. * a0: last address before we jumped to the unrecoverable_exception.
  184. * excsave_1: a0
  185. *
  186. *
  187. * See the handle_alloca_user and spill_registers routines for example clients.
  188. *
  189. * FIXME: Note: we currently don't allow signal handling coming from a double
  190. * exception, so the item markt with (*) is not required.
  191. */
  192. .section .DoubleExceptionVector.text, "ax"
  193. ENTRY(_DoubleExceptionVector)
  194. xsr a3, excsave1
  195. s32i a2, a3, EXC_TABLE_DOUBLE_SAVE
  196. /* Check for kernel double exception (usually fatal). */
  197. rsr a2, ps
  198. _bbsi.l a2, PS_UM_BIT, 1f
  199. j .Lksp
  200. .align 4
  201. .literal_position
  202. 1:
  203. /* Check if we are currently handling a window exception. */
  204. /* Note: We don't need to indicate that we enter a critical section. */
  205. xsr a0, depc # get DEPC, save a0
  206. #ifdef SUPPORT_WINDOWED
  207. movi a2, WINDOW_VECTORS_VADDR
  208. _bltu a0, a2, .Lfixup
  209. addi a2, a2, WINDOW_VECTORS_SIZE
  210. _bgeu a0, a2, .Lfixup
  211. /* Window overflow/underflow exception. Get stack pointer. */
  212. l32i a2, a3, EXC_TABLE_KSTK
  213. /* Check for overflow/underflow exception, jump if overflow. */
  214. bbci.l a0, 6, _DoubleExceptionVector_WindowOverflow
  215. /*
  216. * Restart window underflow exception.
  217. * Currently:
  218. * depc = orig a0,
  219. * a0 = orig DEPC,
  220. * a2 = new sp based on KSTK from exc_table
  221. * a3 = excsave_1
  222. * excsave_1 = orig a3
  223. *
  224. * We return to the instruction in user space that caused the window
  225. * underflow exception. Therefore, we change window base to the value
  226. * before we entered the window underflow exception and prepare the
  227. * registers to return as if we were coming from a regular exception
  228. * by changing depc (in a0).
  229. * Note: We can trash the current window frame (a0...a3) and depc!
  230. */
  231. _DoubleExceptionVector_WindowUnderflow:
  232. xsr a3, excsave1
  233. wsr a2, depc # save stack pointer temporarily
  234. rsr a0, ps
  235. extui a0, a0, PS_OWB_SHIFT, PS_OWB_WIDTH
  236. wsr a0, windowbase
  237. rsync
  238. /* We are now in the previous window frame. Save registers again. */
  239. xsr a2, depc # save a2 and get stack pointer
  240. s32i a0, a2, PT_AREG0
  241. xsr a3, excsave1
  242. rsr a0, exccause
  243. s32i a0, a2, PT_DEPC # mark it as a regular exception
  244. addx4 a0, a0, a3
  245. xsr a3, excsave1
  246. l32i a0, a0, EXC_TABLE_FAST_USER
  247. jx a0
  248. #else
  249. j .Lfixup
  250. #endif
  251. /*
  252. * We only allow the ITLB miss exception if we are in kernel space.
  253. * All other exceptions are unexpected and thus unrecoverable!
  254. */
  255. #ifdef CONFIG_MMU
  256. .extern fast_second_level_miss_double_kernel
  257. .Lksp: /* a0: a0, a1: a1, a2: a2, a3: trashed, depc: depc, excsave: a3 */
  258. rsr a3, exccause
  259. beqi a3, EXCCAUSE_ITLB_MISS, 1f
  260. addi a3, a3, -EXCCAUSE_DTLB_MISS
  261. bnez a3, .Lunrecoverable
  262. 1: movi a3, fast_second_level_miss_double_kernel
  263. jx a3
  264. #else
  265. .equ .Lksp, .Lunrecoverable
  266. #endif
  267. /* Critical! We can't handle this situation. PANIC! */
  268. .extern unrecoverable_exception
  269. .Lunrecoverable_fixup:
  270. l32i a2, a3, EXC_TABLE_DOUBLE_SAVE
  271. xsr a0, depc
  272. .Lunrecoverable:
  273. rsr a3, excsave1
  274. wsr a0, excsave1
  275. call0 unrecoverable_exception
  276. .Lfixup:/* Check for a fixup handler or if we were in a critical section. */
  277. /* a0: depc, a1: a1, a2: trash, a3: exctable, depc: a0, excsave1: a3 */
  278. /* Enter critical section. */
  279. l32i a2, a3, EXC_TABLE_FIXUP
  280. s32i a3, a3, EXC_TABLE_FIXUP
  281. beq a2, a3, .Lunrecoverable_fixup # critical section
  282. beqz a2, .Ldflt # no handler was registered
  283. /* a0: depc, a1: a1, a2: trash, a3: exctable, depc: a0, excsave: a3 */
  284. jx a2
  285. .Ldflt: /* Get stack pointer. */
  286. l32i a2, a3, EXC_TABLE_DOUBLE_SAVE
  287. addi a2, a2, -PT_USER_SIZE
  288. /* a0: depc, a1: a1, a2: kstk, a3: exctable, depc: a0, excsave: a3 */
  289. s32i a0, a2, PT_DEPC
  290. l32i a0, a3, EXC_TABLE_DOUBLE_SAVE
  291. xsr a0, depc
  292. s32i a0, a2, PT_AREG0
  293. /* a0: avail, a1: a1, a2: kstk, a3: exctable, depc: a2, excsave: a3 */
  294. rsr a0, exccause
  295. addx4 a0, a0, a3
  296. xsr a3, excsave1
  297. l32i a0, a0, EXC_TABLE_FAST_USER
  298. jx a0
  299. #ifdef SUPPORT_WINDOWED
  300. /*
  301. * Restart window OVERFLOW exception.
  302. * Currently:
  303. * depc = orig a0,
  304. * a0 = orig DEPC,
  305. * a2 = new sp based on KSTK from exc_table
  306. * a3 = EXCSAVE_1
  307. * excsave_1 = orig a3
  308. *
  309. * We return to the instruction in user space that caused the window
  310. * overflow exception. Therefore, we change window base to the value
  311. * before we entered the window overflow exception and prepare the
  312. * registers to return as if we were coming from a regular exception
  313. * by changing DEPC (in a0).
  314. *
  315. * NOTE: We CANNOT trash the current window frame (a0...a3), but we
  316. * can clobber depc.
  317. *
  318. * The tricky part here is that overflow8 and overflow12 handlers
  319. * save a0, then clobber a0. To restart the handler, we have to restore
  320. * a0 if the double exception was past the point where a0 was clobbered.
  321. *
  322. * To keep things simple, we take advantage of the fact all overflow
  323. * handlers save a0 in their very first instruction. If DEPC was past
  324. * that instruction, we can safely restore a0 from where it was saved
  325. * on the stack.
  326. *
  327. * a0: depc, a1: a1, a2: kstk, a3: exc_table, depc: a0, excsave1: a3
  328. */
  329. _DoubleExceptionVector_WindowOverflow:
  330. extui a2, a0, 0, 6 # get offset into 64-byte vector handler
  331. beqz a2, 1f # if at start of vector, don't restore
  332. addi a0, a0, -128
  333. bbsi.l a0, 8, 1f # don't restore except for overflow 8 and 12
  334. /*
  335. * This fixup handler is for the extremely unlikely case where the
  336. * overflow handler's reference thru a0 gets a hardware TLB refill
  337. * that bumps out the (distinct, aliasing) TLB entry that mapped its
  338. * prior references thru a9/a13, and where our reference now thru
  339. * a9/a13 gets a 2nd-level miss exception (not hardware TLB refill).
  340. */
  341. movi a2, window_overflow_restore_a0_fixup
  342. s32i a2, a3, EXC_TABLE_FIXUP
  343. l32i a2, a3, EXC_TABLE_DOUBLE_SAVE
  344. xsr a3, excsave1
  345. bbsi.l a0, 7, 2f
  346. /*
  347. * Restore a0 as saved by _WindowOverflow8().
  348. */
  349. l32e a0, a9, -16
  350. wsr a0, depc # replace the saved a0
  351. j 3f
  352. 2:
  353. /*
  354. * Restore a0 as saved by _WindowOverflow12().
  355. */
  356. l32e a0, a13, -16
  357. wsr a0, depc # replace the saved a0
  358. 3:
  359. xsr a3, excsave1
  360. movi a0, 0
  361. s32i a0, a3, EXC_TABLE_FIXUP
  362. s32i a2, a3, EXC_TABLE_DOUBLE_SAVE
  363. 1:
  364. /*
  365. * Restore WindowBase while leaving all address registers restored.
  366. * We have to use ROTW for this, because WSR.WINDOWBASE requires
  367. * an address register (which would prevent restore).
  368. *
  369. * Window Base goes from 0 ... 7 (Module 8)
  370. * Window Start is 8 bits; Ex: (0b1010 1010):0x55 from series of call4s
  371. */
  372. rsr a0, ps
  373. extui a0, a0, PS_OWB_SHIFT, PS_OWB_WIDTH
  374. rsr a2, windowbase
  375. sub a0, a2, a0
  376. extui a0, a0, 0, 3
  377. l32i a2, a3, EXC_TABLE_DOUBLE_SAVE
  378. xsr a3, excsave1
  379. beqi a0, 1, .L1pane
  380. beqi a0, 3, .L3pane
  381. rsr a0, depc
  382. rotw -2
  383. /*
  384. * We are now in the user code's original window frame.
  385. * Process the exception as a user exception as if it was
  386. * taken by the user code.
  387. *
  388. * This is similar to the user exception vector,
  389. * except that PT_DEPC isn't set to EXCCAUSE.
  390. */
  391. 1:
  392. xsr a3, excsave1
  393. wsr a2, depc
  394. l32i a2, a3, EXC_TABLE_KSTK
  395. s32i a0, a2, PT_AREG0
  396. rsr a0, exccause
  397. s32i a0, a2, PT_DEPC
  398. _DoubleExceptionVector_handle_exception:
  399. addi a0, a0, -EXCCAUSE_UNALIGNED
  400. beqz a0, 2f
  401. addx4 a0, a0, a3
  402. l32i a0, a0, EXC_TABLE_FAST_USER + 4 * EXCCAUSE_UNALIGNED
  403. xsr a3, excsave1
  404. jx a0
  405. 2:
  406. movi a0, user_exception
  407. xsr a3, excsave1
  408. jx a0
  409. .L1pane:
  410. rsr a0, depc
  411. rotw -1
  412. j 1b
  413. .L3pane:
  414. rsr a0, depc
  415. rotw -3
  416. j 1b
  417. #endif
  418. ENDPROC(_DoubleExceptionVector)
  419. #ifdef SUPPORT_WINDOWED
  420. /*
  421. * Fixup handler for TLB miss in double exception handler for window owerflow.
  422. * We get here with windowbase set to the window that was being spilled and
  423. * a0 trashed. a0 bit 7 determines if this is a call8 (bit clear) or call12
  424. * (bit set) window.
  425. *
  426. * We do the following here:
  427. * - go to the original window retaining a0 value;
  428. * - set up exception stack to return back to appropriate a0 restore code
  429. * (we'll need to rotate window back and there's no place to save this
  430. * information, use different return address for that);
  431. * - handle the exception;
  432. * - go to the window that was being spilled;
  433. * - set up window_overflow_restore_a0_fixup as a fixup routine;
  434. * - reload a0;
  435. * - restore the original window;
  436. * - reset the default fixup routine;
  437. * - return to user. By the time we get to this fixup handler all information
  438. * about the conditions of the original double exception that happened in
  439. * the window overflow handler is lost, so we just return to userspace to
  440. * retry overflow from start.
  441. *
  442. * a0: value of depc, original value in depc
  443. * a2: trashed, original value in EXC_TABLE_DOUBLE_SAVE
  444. * a3: exctable, original value in excsave1
  445. */
  446. __XTENSA_HANDLER
  447. .literal_position
  448. ENTRY(window_overflow_restore_a0_fixup)
  449. rsr a0, ps
  450. extui a0, a0, PS_OWB_SHIFT, PS_OWB_WIDTH
  451. rsr a2, windowbase
  452. sub a0, a2, a0
  453. extui a0, a0, 0, 3
  454. l32i a2, a3, EXC_TABLE_DOUBLE_SAVE
  455. xsr a3, excsave1
  456. _beqi a0, 1, .Lhandle_1
  457. _beqi a0, 3, .Lhandle_3
  458. .macro overflow_fixup_handle_exception_pane n
  459. rsr a0, depc
  460. rotw -\n
  461. xsr a3, excsave1
  462. wsr a2, depc
  463. l32i a2, a3, EXC_TABLE_KSTK
  464. s32i a0, a2, PT_AREG0
  465. movi a0, .Lrestore_\n
  466. s32i a0, a2, PT_DEPC
  467. rsr a0, exccause
  468. j _DoubleExceptionVector_handle_exception
  469. .endm
  470. overflow_fixup_handle_exception_pane 2
  471. .Lhandle_1:
  472. overflow_fixup_handle_exception_pane 1
  473. .Lhandle_3:
  474. overflow_fixup_handle_exception_pane 3
  475. .macro overflow_fixup_restore_a0_pane n
  476. rotw \n
  477. /* Need to preserve a0 value here to be able to handle exception
  478. * that may occur on a0 reload from stack. It may occur because
  479. * TLB miss handler may not be atomic and pointer to page table
  480. * may be lost before we get here. There are no free registers,
  481. * so we need to use EXC_TABLE_DOUBLE_SAVE area.
  482. */
  483. xsr a3, excsave1
  484. s32i a2, a3, EXC_TABLE_DOUBLE_SAVE
  485. movi a2, window_overflow_restore_a0_fixup
  486. s32i a2, a3, EXC_TABLE_FIXUP
  487. l32i a2, a3, EXC_TABLE_DOUBLE_SAVE
  488. xsr a3, excsave1
  489. bbsi.l a0, 7, 1f
  490. l32e a0, a9, -16
  491. j 2f
  492. 1:
  493. l32e a0, a13, -16
  494. 2:
  495. rotw -\n
  496. .endm
  497. .Lrestore_2:
  498. overflow_fixup_restore_a0_pane 2
  499. .Lset_default_fixup:
  500. xsr a3, excsave1
  501. s32i a2, a3, EXC_TABLE_DOUBLE_SAVE
  502. movi a2, 0
  503. s32i a2, a3, EXC_TABLE_FIXUP
  504. l32i a2, a3, EXC_TABLE_DOUBLE_SAVE
  505. xsr a3, excsave1
  506. rfe
  507. .Lrestore_1:
  508. overflow_fixup_restore_a0_pane 1
  509. j .Lset_default_fixup
  510. .Lrestore_3:
  511. overflow_fixup_restore_a0_pane 3
  512. j .Lset_default_fixup
  513. ENDPROC(window_overflow_restore_a0_fixup)
  514. #endif
  515. /*
  516. * Debug interrupt vector
  517. *
  518. * There is not much space here, so simply jump to another handler.
  519. * EXCSAVE[DEBUGLEVEL] has been set to that handler.
  520. */
  521. .section .DebugInterruptVector.text, "ax"
  522. ENTRY(_DebugInterruptVector)
  523. xsr a3, SREG_EXCSAVE + XCHAL_DEBUGLEVEL
  524. s32i a0, a3, DT_DEBUG_SAVE
  525. l32i a0, a3, DT_DEBUG_EXCEPTION
  526. jx a0
  527. ENDPROC(_DebugInterruptVector)
  528. /*
  529. * Medium priority level interrupt vectors
  530. *
  531. * Each takes less than 16 (0x10) bytes, no literals, by placing
  532. * the extra 8 bytes that would otherwise be required in the window
  533. * vectors area where there is space. With relocatable vectors,
  534. * all vectors are within ~ 4 kB range of each other, so we can
  535. * simply jump (J) to another vector without having to use JX.
  536. *
  537. * common_exception code gets current IRQ level in PS.INTLEVEL
  538. * and preserves it for the IRQ handling time.
  539. */
  540. .macro irq_entry_level level
  541. .if XCHAL_EXCM_LEVEL >= \level
  542. .section .Level\level\()InterruptVector.text, "ax"
  543. ENTRY(_Level\level\()InterruptVector)
  544. wsr a0, excsave2
  545. rsr a0, epc\level
  546. wsr a0, epc1
  547. .if \level <= LOCKLEVEL
  548. movi a0, EXCCAUSE_LEVEL1_INTERRUPT
  549. .else
  550. movi a0, EXCCAUSE_MAPPED_NMI
  551. .endif
  552. wsr a0, exccause
  553. rsr a0, eps\level
  554. # branch to user or kernel vector
  555. j _SimulateUserKernelVectorException
  556. .endif
  557. .endm
  558. irq_entry_level 2
  559. irq_entry_level 3
  560. irq_entry_level 4
  561. irq_entry_level 5
  562. irq_entry_level 6
  563. #if XCHAL_EXCM_LEVEL >= 2
  564. /*
  565. * Continuation of medium priority interrupt dispatch code.
  566. * On entry here, a0 contains PS, and EPC2 contains saved a0:
  567. */
  568. __XTENSA_HANDLER
  569. .align 4
  570. _SimulateUserKernelVectorException:
  571. addi a0, a0, (1 << PS_EXCM_BIT)
  572. #if !XTENSA_FAKE_NMI
  573. wsr a0, ps
  574. #endif
  575. bbsi.l a0, PS_UM_BIT, 1f # branch if user mode
  576. xsr a0, excsave2 # restore a0
  577. j _KernelExceptionVector # simulate kernel vector exception
  578. 1: xsr a0, excsave2 # restore a0
  579. j _UserExceptionVector # simulate user vector exception
  580. #endif
  581. /* Window overflow and underflow handlers.
  582. * The handlers must be 64 bytes apart, first starting with the underflow
  583. * handlers underflow-4 to underflow-12, then the overflow handlers
  584. * overflow-4 to overflow-12.
  585. *
  586. * Note: We rerun the underflow handlers if we hit an exception, so
  587. * we try to access any page that would cause a page fault early.
  588. */
  589. #define ENTRY_ALIGN64(name) \
  590. .globl name; \
  591. .align 64; \
  592. name:
  593. .section .WindowVectors.text, "ax"
  594. #ifdef SUPPORT_WINDOWED
  595. /* 4-Register Window Overflow Vector (Handler) */
  596. ENTRY_ALIGN64(_WindowOverflow4)
  597. s32e a0, a5, -16
  598. s32e a1, a5, -12
  599. s32e a2, a5, -8
  600. s32e a3, a5, -4
  601. rfwo
  602. ENDPROC(_WindowOverflow4)
  603. /* 4-Register Window Underflow Vector (Handler) */
  604. ENTRY_ALIGN64(_WindowUnderflow4)
  605. l32e a0, a5, -16
  606. l32e a1, a5, -12
  607. l32e a2, a5, -8
  608. l32e a3, a5, -4
  609. rfwu
  610. ENDPROC(_WindowUnderflow4)
  611. /* 8-Register Window Overflow Vector (Handler) */
  612. ENTRY_ALIGN64(_WindowOverflow8)
  613. s32e a0, a9, -16
  614. l32e a0, a1, -12
  615. s32e a2, a9, -8
  616. s32e a1, a9, -12
  617. s32e a3, a9, -4
  618. s32e a4, a0, -32
  619. s32e a5, a0, -28
  620. s32e a6, a0, -24
  621. s32e a7, a0, -20
  622. rfwo
  623. ENDPROC(_WindowOverflow8)
  624. /* 8-Register Window Underflow Vector (Handler) */
  625. ENTRY_ALIGN64(_WindowUnderflow8)
  626. l32e a1, a9, -12
  627. l32e a0, a9, -16
  628. l32e a7, a1, -12
  629. l32e a2, a9, -8
  630. l32e a4, a7, -32
  631. l32e a3, a9, -4
  632. l32e a5, a7, -28
  633. l32e a6, a7, -24
  634. l32e a7, a7, -20
  635. rfwu
  636. ENDPROC(_WindowUnderflow8)
  637. /* 12-Register Window Overflow Vector (Handler) */
  638. ENTRY_ALIGN64(_WindowOverflow12)
  639. s32e a0, a13, -16
  640. l32e a0, a1, -12
  641. s32e a1, a13, -12
  642. s32e a2, a13, -8
  643. s32e a3, a13, -4
  644. s32e a4, a0, -48
  645. s32e a5, a0, -44
  646. s32e a6, a0, -40
  647. s32e a7, a0, -36
  648. s32e a8, a0, -32
  649. s32e a9, a0, -28
  650. s32e a10, a0, -24
  651. s32e a11, a0, -20
  652. rfwo
  653. ENDPROC(_WindowOverflow12)
  654. /* 12-Register Window Underflow Vector (Handler) */
  655. ENTRY_ALIGN64(_WindowUnderflow12)
  656. l32e a1, a13, -12
  657. l32e a0, a13, -16
  658. l32e a11, a1, -12
  659. l32e a2, a13, -8
  660. l32e a4, a11, -48
  661. l32e a8, a11, -32
  662. l32e a3, a13, -4
  663. l32e a5, a11, -44
  664. l32e a6, a11, -40
  665. l32e a7, a11, -36
  666. l32e a9, a11, -28
  667. l32e a10, a11, -24
  668. l32e a11, a11, -20
  669. rfwu
  670. ENDPROC(_WindowUnderflow12)
  671. #endif
  672. .text