entry.S 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939
  1. /*
  2. * arch/xtensa/kernel/entry.S
  3. *
  4. * Low-level exception handling
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. *
  10. * Copyright (C) 2004 - 2008 by Tensilica Inc.
  11. *
  12. * Chris Zankel <chris@zankel.net>
  13. *
  14. */
  15. #include <linux/linkage.h>
  16. #include <asm/asm-offsets.h>
  17. #include <asm/processor.h>
  18. #include <asm/coprocessor.h>
  19. #include <asm/thread_info.h>
  20. #include <asm/uaccess.h>
  21. #include <asm/unistd.h>
  22. #include <asm/ptrace.h>
  23. #include <asm/current.h>
  24. #include <asm/pgtable.h>
  25. #include <asm/page.h>
  26. #include <asm/signal.h>
  27. #include <asm/tlbflush.h>
  28. #include <variant/tie-asm.h>
  29. /* Unimplemented features. */
  30. #undef KERNEL_STACK_OVERFLOW_CHECK
  31. /* Not well tested.
  32. *
  33. * - fast_coprocessor
  34. */
  35. /*
  36. * Macro to find first bit set in WINDOWBASE from the left + 1
  37. *
  38. * 100....0 -> 1
  39. * 010....0 -> 2
  40. * 000....1 -> WSBITS
  41. */
  42. .macro ffs_ws bit mask
  43. #if XCHAL_HAVE_NSA
  44. nsau \bit, \mask # 32-WSBITS ... 31 (32 iff 0)
  45. addi \bit, \bit, WSBITS - 32 + 1 # uppest bit set -> return 1
  46. #else
  47. movi \bit, WSBITS
  48. #if WSBITS > 16
  49. _bltui \mask, 0x10000, 99f
  50. addi \bit, \bit, -16
  51. extui \mask, \mask, 16, 16
  52. #endif
  53. #if WSBITS > 8
  54. 99: _bltui \mask, 0x100, 99f
  55. addi \bit, \bit, -8
  56. srli \mask, \mask, 8
  57. #endif
  58. 99: _bltui \mask, 0x10, 99f
  59. addi \bit, \bit, -4
  60. srli \mask, \mask, 4
  61. 99: _bltui \mask, 0x4, 99f
  62. addi \bit, \bit, -2
  63. srli \mask, \mask, 2
  64. 99: _bltui \mask, 0x2, 99f
  65. addi \bit, \bit, -1
  66. 99:
  67. #endif
  68. .endm
  69. /* ----------------- DEFAULT FIRST LEVEL EXCEPTION HANDLERS ----------------- */
  70. /*
  71. * First-level exception handler for user exceptions.
  72. * Save some special registers, extra states and all registers in the AR
  73. * register file that were in use in the user task, and jump to the common
  74. * exception code.
  75. * We save SAR (used to calculate WMASK), and WB and WS (we don't have to
  76. * save them for kernel exceptions).
  77. *
  78. * Entry condition for user_exception:
  79. *
  80. * a0: trashed, original value saved on stack (PT_AREG0)
  81. * a1: a1
  82. * a2: new stack pointer, original value in depc
  83. * a3: a3
  84. * depc: a2, original value saved on stack (PT_DEPC)
  85. * excsave1: dispatch table
  86. *
  87. * PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception, DEPC
  88. * < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception
  89. *
  90. * Entry condition for _user_exception:
  91. *
  92. * a0-a3 and depc have been saved to PT_AREG0...PT_AREG3 and PT_DEPC
  93. * excsave has been restored, and
  94. * stack pointer (a1) has been set.
  95. *
  96. * Note: _user_exception might be at an odd address. Don't use call0..call12
  97. */
  98. ENTRY(user_exception)
  99. /* Save a1, a2, a3, and set SP. */
  100. rsr a0, depc
  101. s32i a1, a2, PT_AREG1
  102. s32i a0, a2, PT_AREG2
  103. s32i a3, a2, PT_AREG3
  104. mov a1, a2
  105. .globl _user_exception
  106. _user_exception:
  107. /* Save SAR and turn off single stepping */
  108. movi a2, 0
  109. rsr a3, sar
  110. xsr a2, icountlevel
  111. s32i a3, a1, PT_SAR
  112. s32i a2, a1, PT_ICOUNTLEVEL
  113. #if XCHAL_HAVE_THREADPTR
  114. rur a2, threadptr
  115. s32i a2, a1, PT_THREADPTR
  116. #endif
  117. /* Rotate ws so that the current windowbase is at bit0. */
  118. /* Assume ws = xxwww1yyyy. Rotate ws right, so that a2 = yyyyxxwww1 */
  119. rsr a2, windowbase
  120. rsr a3, windowstart
  121. ssr a2
  122. s32i a2, a1, PT_WINDOWBASE
  123. s32i a3, a1, PT_WINDOWSTART
  124. slli a2, a3, 32-WSBITS
  125. src a2, a3, a2
  126. srli a2, a2, 32-WSBITS
  127. s32i a2, a1, PT_WMASK # needed for restoring registers
  128. /* Save only live registers. */
  129. _bbsi.l a2, 1, 1f
  130. s32i a4, a1, PT_AREG4
  131. s32i a5, a1, PT_AREG5
  132. s32i a6, a1, PT_AREG6
  133. s32i a7, a1, PT_AREG7
  134. _bbsi.l a2, 2, 1f
  135. s32i a8, a1, PT_AREG8
  136. s32i a9, a1, PT_AREG9
  137. s32i a10, a1, PT_AREG10
  138. s32i a11, a1, PT_AREG11
  139. _bbsi.l a2, 3, 1f
  140. s32i a12, a1, PT_AREG12
  141. s32i a13, a1, PT_AREG13
  142. s32i a14, a1, PT_AREG14
  143. s32i a15, a1, PT_AREG15
  144. _bnei a2, 1, 1f # only one valid frame?
  145. /* Only one valid frame, skip saving regs. */
  146. j 2f
  147. /* Save the remaining registers.
  148. * We have to save all registers up to the first '1' from
  149. * the right, except the current frame (bit 0).
  150. * Assume a2 is: 001001000110001
  151. * All register frames starting from the top field to the marked '1'
  152. * must be saved.
  153. */
  154. 1: addi a3, a2, -1 # eliminate '1' in bit 0: yyyyxxww0
  155. neg a3, a3 # yyyyxxww0 -> YYYYXXWW1+1
  156. and a3, a3, a2 # max. only one bit is set
  157. /* Find number of frames to save */
  158. ffs_ws a0, a3 # number of frames to the '1' from left
  159. /* Store information into WMASK:
  160. * bits 0..3: xxx1 masked lower 4 bits of the rotated windowstart,
  161. * bits 4...: number of valid 4-register frames
  162. */
  163. slli a3, a0, 4 # number of frames to save in bits 8..4
  164. extui a2, a2, 0, 4 # mask for the first 16 registers
  165. or a2, a3, a2
  166. s32i a2, a1, PT_WMASK # needed when we restore the reg-file
  167. /* Save 4 registers at a time */
  168. 1: rotw -1
  169. s32i a0, a5, PT_AREG_END - 16
  170. s32i a1, a5, PT_AREG_END - 12
  171. s32i a2, a5, PT_AREG_END - 8
  172. s32i a3, a5, PT_AREG_END - 4
  173. addi a0, a4, -1
  174. addi a1, a5, -16
  175. _bnez a0, 1b
  176. /* WINDOWBASE still in SAR! */
  177. rsr a2, sar # original WINDOWBASE
  178. movi a3, 1
  179. ssl a2
  180. sll a3, a3
  181. wsr a3, windowstart # set corresponding WINDOWSTART bit
  182. wsr a2, windowbase # and WINDOWSTART
  183. rsync
  184. /* We are back to the original stack pointer (a1) */
  185. 2: /* Now, jump to the common exception handler. */
  186. j common_exception
  187. ENDPROC(user_exception)
  188. /*
  189. * First-level exit handler for kernel exceptions
  190. * Save special registers and the live window frame.
  191. * Note: Even though we changes the stack pointer, we don't have to do a
  192. * MOVSP here, as we do that when we return from the exception.
  193. * (See comment in the kernel exception exit code)
  194. *
  195. * Entry condition for kernel_exception:
  196. *
  197. * a0: trashed, original value saved on stack (PT_AREG0)
  198. * a1: a1
  199. * a2: new stack pointer, original in DEPC
  200. * a3: a3
  201. * depc: a2, original value saved on stack (PT_DEPC)
  202. * excsave_1: dispatch table
  203. *
  204. * PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception, DEPC
  205. * < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception
  206. *
  207. * Entry condition for _kernel_exception:
  208. *
  209. * a0-a3 and depc have been saved to PT_AREG0...PT_AREG3 and PT_DEPC
  210. * excsave has been restored, and
  211. * stack pointer (a1) has been set.
  212. *
  213. * Note: _kernel_exception might be at an odd address. Don't use call0..call12
  214. */
  215. ENTRY(kernel_exception)
  216. /* Save a1, a2, a3, and set SP. */
  217. rsr a0, depc # get a2
  218. s32i a1, a2, PT_AREG1
  219. s32i a0, a2, PT_AREG2
  220. s32i a3, a2, PT_AREG3
  221. mov a1, a2
  222. .globl _kernel_exception
  223. _kernel_exception:
  224. /* Save SAR and turn off single stepping */
  225. movi a2, 0
  226. rsr a3, sar
  227. xsr a2, icountlevel
  228. s32i a3, a1, PT_SAR
  229. s32i a2, a1, PT_ICOUNTLEVEL
  230. /* Rotate ws so that the current windowbase is at bit0. */
  231. /* Assume ws = xxwww1yyyy. Rotate ws right, so that a2 = yyyyxxwww1 */
  232. rsr a2, windowbase # don't need to save these, we only
  233. rsr a3, windowstart # need shifted windowstart: windowmask
  234. ssr a2
  235. slli a2, a3, 32-WSBITS
  236. src a2, a3, a2
  237. srli a2, a2, 32-WSBITS
  238. s32i a2, a1, PT_WMASK # needed for kernel_exception_exit
  239. /* Save only the live window-frame */
  240. _bbsi.l a2, 1, 1f
  241. s32i a4, a1, PT_AREG4
  242. s32i a5, a1, PT_AREG5
  243. s32i a6, a1, PT_AREG6
  244. s32i a7, a1, PT_AREG7
  245. _bbsi.l a2, 2, 1f
  246. s32i a8, a1, PT_AREG8
  247. s32i a9, a1, PT_AREG9
  248. s32i a10, a1, PT_AREG10
  249. s32i a11, a1, PT_AREG11
  250. _bbsi.l a2, 3, 1f
  251. s32i a12, a1, PT_AREG12
  252. s32i a13, a1, PT_AREG13
  253. s32i a14, a1, PT_AREG14
  254. s32i a15, a1, PT_AREG15
  255. 1:
  256. #ifdef KERNEL_STACK_OVERFLOW_CHECK
  257. /* Stack overflow check, for debugging */
  258. extui a2, a1, TASK_SIZE_BITS,XX
  259. movi a3, SIZE??
  260. _bge a2, a3, out_of_stack_panic
  261. #endif
  262. /*
  263. * This is the common exception handler.
  264. * We get here from the user exception handler or simply by falling through
  265. * from the kernel exception handler.
  266. * Save the remaining special registers, switch to kernel mode, and jump
  267. * to the second-level exception handler.
  268. *
  269. */
  270. common_exception:
  271. /* Save some registers, disable loops and clear the syscall flag. */
  272. rsr a2, debugcause
  273. rsr a3, epc1
  274. s32i a2, a1, PT_DEBUGCAUSE
  275. s32i a3, a1, PT_PC
  276. movi a2, -1
  277. rsr a3, excvaddr
  278. s32i a2, a1, PT_SYSCALL
  279. movi a2, 0
  280. s32i a3, a1, PT_EXCVADDR
  281. xsr a2, lcount
  282. s32i a2, a1, PT_LCOUNT
  283. /* It is now save to restore the EXC_TABLE_FIXUP variable. */
  284. rsr a0, exccause
  285. movi a3, 0
  286. rsr a2, excsave1
  287. s32i a0, a1, PT_EXCCAUSE
  288. s32i a3, a2, EXC_TABLE_FIXUP
  289. /* All unrecoverable states are saved on stack, now, and a1 is valid,
  290. * so we can allow exceptions and interrupts (*) again.
  291. * Set PS(EXCM = 0, UM = 0, RING = 0, OWB = 0, WOE = 1, INTLEVEL = X)
  292. *
  293. * (*) We only allow interrupts if they were previously enabled and
  294. * we're not handling an IRQ
  295. */
  296. rsr a3, ps
  297. addi a0, a0, -EXCCAUSE_LEVEL1_INTERRUPT
  298. movi a2, LOCKLEVEL
  299. extui a3, a3, PS_INTLEVEL_SHIFT, PS_INTLEVEL_WIDTH
  300. # a3 = PS.INTLEVEL
  301. moveqz a3, a2, a0 # a3 = LOCKLEVEL iff interrupt
  302. movi a2, 1 << PS_WOE_BIT
  303. or a3, a3, a2
  304. rsr a0, exccause
  305. xsr a3, ps
  306. s32i a3, a1, PT_PS # save ps
  307. /* Save lbeg, lend */
  308. rsr a2, lbeg
  309. rsr a3, lend
  310. s32i a2, a1, PT_LBEG
  311. s32i a3, a1, PT_LEND
  312. /* Save SCOMPARE1 */
  313. #if XCHAL_HAVE_S32C1I
  314. rsr a2, scompare1
  315. s32i a2, a1, PT_SCOMPARE1
  316. #endif
  317. /* Save optional registers. */
  318. save_xtregs_opt a1 a2 a4 a5 a6 a7 PT_XTREGS_OPT
  319. #ifdef CONFIG_TRACE_IRQFLAGS
  320. l32i a4, a1, PT_DEPC
  321. /* Double exception means we came here with an exception
  322. * while PS.EXCM was set, i.e. interrupts disabled.
  323. */
  324. bgeui a4, VALID_DOUBLE_EXCEPTION_ADDRESS, 1f
  325. l32i a4, a1, PT_EXCCAUSE
  326. bnei a4, EXCCAUSE_LEVEL1_INTERRUPT, 1f
  327. /* We came here with an interrupt means interrupts were enabled
  328. * and we've just disabled them.
  329. */
  330. movi a4, trace_hardirqs_off
  331. callx4 a4
  332. 1:
  333. #endif
  334. /* Go to second-level dispatcher. Set up parameters to pass to the
  335. * exception handler and call the exception handler.
  336. */
  337. rsr a4, excsave1
  338. mov a6, a1 # pass stack frame
  339. mov a7, a0 # pass EXCCAUSE
  340. addx4 a4, a0, a4
  341. l32i a4, a4, EXC_TABLE_DEFAULT # load handler
  342. /* Call the second-level handler */
  343. callx4 a4
  344. /* Jump here for exception exit */
  345. .global common_exception_return
  346. common_exception_return:
  347. 1:
  348. rsil a2, LOCKLEVEL
  349. /* Jump if we are returning from kernel exceptions. */
  350. l32i a3, a1, PT_PS
  351. GET_THREAD_INFO(a2, a1)
  352. l32i a4, a2, TI_FLAGS
  353. _bbci.l a3, PS_UM_BIT, 6f
  354. /* Specific to a user exception exit:
  355. * We need to check some flags for signal handling and rescheduling,
  356. * and have to restore WB and WS, extra states, and all registers
  357. * in the register file that were in use in the user task.
  358. * Note that we don't disable interrupts here.
  359. */
  360. _bbsi.l a4, TIF_NEED_RESCHED, 3f
  361. _bbsi.l a4, TIF_NOTIFY_RESUME, 2f
  362. _bbci.l a4, TIF_SIGPENDING, 5f
  363. 2: l32i a4, a1, PT_DEPC
  364. bgeui a4, VALID_DOUBLE_EXCEPTION_ADDRESS, 4f
  365. /* Call do_signal() */
  366. rsil a2, 0
  367. movi a4, do_notify_resume # int do_notify_resume(struct pt_regs*)
  368. mov a6, a1
  369. callx4 a4
  370. j 1b
  371. 3: /* Reschedule */
  372. rsil a2, 0
  373. movi a4, schedule # void schedule (void)
  374. callx4 a4
  375. j 1b
  376. #ifdef CONFIG_PREEMPT
  377. 6:
  378. _bbci.l a4, TIF_NEED_RESCHED, 4f
  379. /* Check current_thread_info->preempt_count */
  380. l32i a4, a2, TI_PRE_COUNT
  381. bnez a4, 4f
  382. movi a4, preempt_schedule_irq
  383. callx4 a4
  384. j 1b
  385. #endif
  386. 5:
  387. #ifdef CONFIG_DEBUG_TLB_SANITY
  388. l32i a4, a1, PT_DEPC
  389. bgeui a4, VALID_DOUBLE_EXCEPTION_ADDRESS, 4f
  390. movi a4, check_tlb_sanity
  391. callx4 a4
  392. #endif
  393. 6:
  394. 4:
  395. #ifdef CONFIG_TRACE_IRQFLAGS
  396. l32i a4, a1, PT_DEPC
  397. /* Double exception means we came here with an exception
  398. * while PS.EXCM was set, i.e. interrupts disabled.
  399. */
  400. bgeui a4, VALID_DOUBLE_EXCEPTION_ADDRESS, 1f
  401. l32i a4, a1, PT_EXCCAUSE
  402. bnei a4, EXCCAUSE_LEVEL1_INTERRUPT, 1f
  403. /* We came here with an interrupt means interrupts were enabled
  404. * and we'll reenable them on return.
  405. */
  406. movi a4, trace_hardirqs_on
  407. callx4 a4
  408. 1:
  409. #endif
  410. /* Restore optional registers. */
  411. load_xtregs_opt a1 a2 a4 a5 a6 a7 PT_XTREGS_OPT
  412. /* Restore SCOMPARE1 */
  413. #if XCHAL_HAVE_S32C1I
  414. l32i a2, a1, PT_SCOMPARE1
  415. wsr a2, scompare1
  416. #endif
  417. wsr a3, ps /* disable interrupts */
  418. _bbci.l a3, PS_UM_BIT, kernel_exception_exit
  419. user_exception_exit:
  420. /* Restore the state of the task and return from the exception. */
  421. /* Switch to the user thread WINDOWBASE. Save SP temporarily in DEPC */
  422. l32i a2, a1, PT_WINDOWBASE
  423. l32i a3, a1, PT_WINDOWSTART
  424. wsr a1, depc # use DEPC as temp storage
  425. wsr a3, windowstart # restore WINDOWSTART
  426. ssr a2 # preserve user's WB in the SAR
  427. wsr a2, windowbase # switch to user's saved WB
  428. rsync
  429. rsr a1, depc # restore stack pointer
  430. l32i a2, a1, PT_WMASK # register frames saved (in bits 4...9)
  431. rotw -1 # we restore a4..a7
  432. _bltui a6, 16, 1f # only have to restore current window?
  433. /* The working registers are a0 and a3. We are restoring to
  434. * a4..a7. Be careful not to destroy what we have just restored.
  435. * Note: wmask has the format YYYYM:
  436. * Y: number of registers saved in groups of 4
  437. * M: 4 bit mask of first 16 registers
  438. */
  439. mov a2, a6
  440. mov a3, a5
  441. 2: rotw -1 # a0..a3 become a4..a7
  442. addi a3, a7, -4*4 # next iteration
  443. addi a2, a6, -16 # decrementing Y in WMASK
  444. l32i a4, a3, PT_AREG_END + 0
  445. l32i a5, a3, PT_AREG_END + 4
  446. l32i a6, a3, PT_AREG_END + 8
  447. l32i a7, a3, PT_AREG_END + 12
  448. _bgeui a2, 16, 2b
  449. /* Clear unrestored registers (don't leak anything to user-land */
  450. 1: rsr a0, windowbase
  451. rsr a3, sar
  452. sub a3, a0, a3
  453. beqz a3, 2f
  454. extui a3, a3, 0, WBBITS
  455. 1: rotw -1
  456. addi a3, a7, -1
  457. movi a4, 0
  458. movi a5, 0
  459. movi a6, 0
  460. movi a7, 0
  461. bgei a3, 1, 1b
  462. /* We are back were we were when we started.
  463. * Note: a2 still contains WMASK (if we've returned to the original
  464. * frame where we had loaded a2), or at least the lower 4 bits
  465. * (if we have restored WSBITS-1 frames).
  466. */
  467. #if XCHAL_HAVE_THREADPTR
  468. l32i a3, a1, PT_THREADPTR
  469. wur a3, threadptr
  470. #endif
  471. 2: j common_exception_exit
  472. /* This is the kernel exception exit.
  473. * We avoided to do a MOVSP when we entered the exception, but we
  474. * have to do it here.
  475. */
  476. kernel_exception_exit:
  477. /* Check if we have to do a movsp.
  478. *
  479. * We only have to do a movsp if the previous window-frame has
  480. * been spilled to the *temporary* exception stack instead of the
  481. * task's stack. This is the case if the corresponding bit in
  482. * WINDOWSTART for the previous window-frame was set before
  483. * (not spilled) but is zero now (spilled).
  484. * If this bit is zero, all other bits except the one for the
  485. * current window frame are also zero. So, we can use a simple test:
  486. * 'and' WINDOWSTART and WINDOWSTART-1:
  487. *
  488. * (XXXXXX1[0]* - 1) AND XXXXXX1[0]* = XXXXXX0[0]*
  489. *
  490. * The result is zero only if one bit was set.
  491. *
  492. * (Note: We might have gone through several task switches before
  493. * we come back to the current task, so WINDOWBASE might be
  494. * different from the time the exception occurred.)
  495. */
  496. /* Test WINDOWSTART before and after the exception.
  497. * We actually have WMASK, so we only have to test if it is 1 or not.
  498. */
  499. l32i a2, a1, PT_WMASK
  500. _beqi a2, 1, common_exception_exit # Spilled before exception,jump
  501. /* Test WINDOWSTART now. If spilled, do the movsp */
  502. rsr a3, windowstart
  503. addi a0, a3, -1
  504. and a3, a3, a0
  505. _bnez a3, common_exception_exit
  506. /* Do a movsp (we returned from a call4, so we have at least a0..a7) */
  507. addi a0, a1, -16
  508. l32i a3, a0, 0
  509. l32i a4, a0, 4
  510. s32i a3, a1, PT_SIZE+0
  511. s32i a4, a1, PT_SIZE+4
  512. l32i a3, a0, 8
  513. l32i a4, a0, 12
  514. s32i a3, a1, PT_SIZE+8
  515. s32i a4, a1, PT_SIZE+12
  516. /* Common exception exit.
  517. * We restore the special register and the current window frame, and
  518. * return from the exception.
  519. *
  520. * Note: We expect a2 to hold PT_WMASK
  521. */
  522. common_exception_exit:
  523. /* Restore address registers. */
  524. _bbsi.l a2, 1, 1f
  525. l32i a4, a1, PT_AREG4
  526. l32i a5, a1, PT_AREG5
  527. l32i a6, a1, PT_AREG6
  528. l32i a7, a1, PT_AREG7
  529. _bbsi.l a2, 2, 1f
  530. l32i a8, a1, PT_AREG8
  531. l32i a9, a1, PT_AREG9
  532. l32i a10, a1, PT_AREG10
  533. l32i a11, a1, PT_AREG11
  534. _bbsi.l a2, 3, 1f
  535. l32i a12, a1, PT_AREG12
  536. l32i a13, a1, PT_AREG13
  537. l32i a14, a1, PT_AREG14
  538. l32i a15, a1, PT_AREG15
  539. /* Restore PC, SAR */
  540. 1: l32i a2, a1, PT_PC
  541. l32i a3, a1, PT_SAR
  542. wsr a2, epc1
  543. wsr a3, sar
  544. /* Restore LBEG, LEND, LCOUNT */
  545. l32i a2, a1, PT_LBEG
  546. l32i a3, a1, PT_LEND
  547. wsr a2, lbeg
  548. l32i a2, a1, PT_LCOUNT
  549. wsr a3, lend
  550. wsr a2, lcount
  551. /* We control single stepping through the ICOUNTLEVEL register. */
  552. l32i a2, a1, PT_ICOUNTLEVEL
  553. movi a3, -2
  554. wsr a2, icountlevel
  555. wsr a3, icount
  556. /* Check if it was double exception. */
  557. l32i a0, a1, PT_DEPC
  558. l32i a3, a1, PT_AREG3
  559. l32i a2, a1, PT_AREG2
  560. _bgeui a0, VALID_DOUBLE_EXCEPTION_ADDRESS, 1f
  561. /* Restore a0...a3 and return */
  562. l32i a0, a1, PT_AREG0
  563. l32i a1, a1, PT_AREG1
  564. rfe
  565. 1: wsr a0, depc
  566. l32i a0, a1, PT_AREG0
  567. l32i a1, a1, PT_AREG1
  568. rfde
  569. ENDPROC(kernel_exception)
  570. /*
  571. * Debug exception handler.
  572. *
  573. * Currently, we don't support KGDB, so only user application can be debugged.
  574. *
  575. * When we get here, a0 is trashed and saved to excsave[debuglevel]
  576. */
  577. ENTRY(debug_exception)
  578. rsr a0, SREG_EPS + XCHAL_DEBUGLEVEL
  579. bbsi.l a0, PS_EXCM_BIT, 1f # exception mode
  580. /* Set EPC1 and EXCCAUSE */
  581. wsr a2, depc # save a2 temporarily
  582. rsr a2, SREG_EPC + XCHAL_DEBUGLEVEL
  583. wsr a2, epc1
  584. movi a2, EXCCAUSE_MAPPED_DEBUG
  585. wsr a2, exccause
  586. /* Restore PS to the value before the debug exc but with PS.EXCM set.*/
  587. movi a2, 1 << PS_EXCM_BIT
  588. or a2, a0, a2
  589. movi a0, debug_exception # restore a3, debug jump vector
  590. wsr a2, ps
  591. xsr a0, SREG_EXCSAVE + XCHAL_DEBUGLEVEL
  592. /* Switch to kernel/user stack, restore jump vector, and save a0 */
  593. bbsi.l a2, PS_UM_BIT, 2f # jump if user mode
  594. addi a2, a1, -16-PT_SIZE # assume kernel stack
  595. s32i a0, a2, PT_AREG0
  596. movi a0, 0
  597. s32i a1, a2, PT_AREG1
  598. s32i a0, a2, PT_DEPC # mark it as a regular exception
  599. xsr a0, depc
  600. s32i a3, a2, PT_AREG3
  601. s32i a0, a2, PT_AREG2
  602. mov a1, a2
  603. j _kernel_exception
  604. 2: rsr a2, excsave1
  605. l32i a2, a2, EXC_TABLE_KSTK # load kernel stack pointer
  606. s32i a0, a2, PT_AREG0
  607. movi a0, 0
  608. s32i a1, a2, PT_AREG1
  609. s32i a0, a2, PT_DEPC
  610. xsr a0, depc
  611. s32i a3, a2, PT_AREG3
  612. s32i a0, a2, PT_AREG2
  613. mov a1, a2
  614. j _user_exception
  615. /* Debug exception while in exception mode. */
  616. 1: j 1b // FIXME!!
  617. ENDPROC(debug_exception)
  618. /*
  619. * We get here in case of an unrecoverable exception.
  620. * The only thing we can do is to be nice and print a panic message.
  621. * We only produce a single stack frame for panic, so ???
  622. *
  623. *
  624. * Entry conditions:
  625. *
  626. * - a0 contains the caller address; original value saved in excsave1.
  627. * - the original a0 contains a valid return address (backtrace) or 0.
  628. * - a2 contains a valid stackpointer
  629. *
  630. * Notes:
  631. *
  632. * - If the stack pointer could be invalid, the caller has to setup a
  633. * dummy stack pointer (e.g. the stack of the init_task)
  634. *
  635. * - If the return address could be invalid, the caller has to set it
  636. * to 0, so the backtrace would stop.
  637. *
  638. */
  639. .align 4
  640. unrecoverable_text:
  641. .ascii "Unrecoverable error in exception handler\0"
  642. ENTRY(unrecoverable_exception)
  643. movi a0, 1
  644. movi a1, 0
  645. wsr a0, windowstart
  646. wsr a1, windowbase
  647. rsync
  648. movi a1, (1 << PS_WOE_BIT) | LOCKLEVEL
  649. wsr a1, ps
  650. rsync
  651. movi a1, init_task
  652. movi a0, 0
  653. addi a1, a1, PT_REGS_OFFSET
  654. movi a4, panic
  655. movi a6, unrecoverable_text
  656. callx4 a4
  657. 1: j 1b
  658. ENDPROC(unrecoverable_exception)
  659. /* -------------------------- FAST EXCEPTION HANDLERS ----------------------- */
  660. /*
  661. * Fast-handler for alloca exceptions
  662. *
  663. * The ALLOCA handler is entered when user code executes the MOVSP
  664. * instruction and the caller's frame is not in the register file.
  665. *
  666. * This algorithm was taken from the Ross Morley's RTOS Porting Layer:
  667. *
  668. * /home/ross/rtos/porting/XtensaRTOS-PortingLayer-20090507/xtensa_vectors.S
  669. *
  670. * It leverages the existing window spill/fill routines and their support for
  671. * double exceptions. The 'movsp' instruction will only cause an exception if
  672. * the next window needs to be loaded. In fact this ALLOCA exception may be
  673. * replaced at some point by changing the hardware to do a underflow exception
  674. * of the proper size instead.
  675. *
  676. * This algorithm simply backs out the register changes started by the user
  677. * excpetion handler, makes it appear that we have started a window underflow
  678. * by rotating the window back and then setting the old window base (OWB) in
  679. * the 'ps' register with the rolled back window base. The 'movsp' instruction
  680. * will be re-executed and this time since the next window frames is in the
  681. * active AR registers it won't cause an exception.
  682. *
  683. * If the WindowUnderflow code gets a TLB miss the page will get mapped
  684. * the the partial windeowUnderflow will be handeled in the double exception
  685. * handler.
  686. *
  687. * Entry condition:
  688. *
  689. * a0: trashed, original value saved on stack (PT_AREG0)
  690. * a1: a1
  691. * a2: new stack pointer, original in DEPC
  692. * a3: a3
  693. * depc: a2, original value saved on stack (PT_DEPC)
  694. * excsave_1: dispatch table
  695. *
  696. * PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception, DEPC
  697. * < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception
  698. */
  699. ENTRY(fast_alloca)
  700. rsr a0, windowbase
  701. rotw -1
  702. rsr a2, ps
  703. extui a3, a2, PS_OWB_SHIFT, PS_OWB_WIDTH
  704. xor a3, a3, a4
  705. l32i a4, a6, PT_AREG0
  706. l32i a1, a6, PT_DEPC
  707. rsr a6, depc
  708. wsr a1, depc
  709. slli a3, a3, PS_OWB_SHIFT
  710. xor a2, a2, a3
  711. wsr a2, ps
  712. rsync
  713. _bbci.l a4, 31, 4f
  714. rotw -1
  715. _bbci.l a8, 30, 8f
  716. rotw -1
  717. j _WindowUnderflow12
  718. 8: j _WindowUnderflow8
  719. 4: j _WindowUnderflow4
  720. ENDPROC(fast_alloca)
  721. /*
  722. * fast system calls.
  723. *
  724. * WARNING: The kernel doesn't save the entire user context before
  725. * handling a fast system call. These functions are small and short,
  726. * usually offering some functionality not available to user tasks.
  727. *
  728. * BE CAREFUL TO PRESERVE THE USER'S CONTEXT.
  729. *
  730. * Entry condition:
  731. *
  732. * a0: trashed, original value saved on stack (PT_AREG0)
  733. * a1: a1
  734. * a2: new stack pointer, original in DEPC
  735. * a3: a3
  736. * depc: a2, original value saved on stack (PT_DEPC)
  737. * excsave_1: dispatch table
  738. */
  739. ENTRY(fast_syscall_kernel)
  740. /* Skip syscall. */
  741. rsr a0, epc1
  742. addi a0, a0, 3
  743. wsr a0, epc1
  744. l32i a0, a2, PT_DEPC
  745. bgeui a0, VALID_DOUBLE_EXCEPTION_ADDRESS, fast_syscall_unrecoverable
  746. rsr a0, depc # get syscall-nr
  747. _beqz a0, fast_syscall_spill_registers
  748. _beqi a0, __NR_xtensa, fast_syscall_xtensa
  749. j kernel_exception
  750. ENDPROC(fast_syscall_kernel)
  751. ENTRY(fast_syscall_user)
  752. /* Skip syscall. */
  753. rsr a0, epc1
  754. addi a0, a0, 3
  755. wsr a0, epc1
  756. l32i a0, a2, PT_DEPC
  757. bgeui a0, VALID_DOUBLE_EXCEPTION_ADDRESS, fast_syscall_unrecoverable
  758. rsr a0, depc # get syscall-nr
  759. _beqz a0, fast_syscall_spill_registers
  760. _beqi a0, __NR_xtensa, fast_syscall_xtensa
  761. j user_exception
  762. ENDPROC(fast_syscall_user)
  763. ENTRY(fast_syscall_unrecoverable)
  764. /* Restore all states. */
  765. l32i a0, a2, PT_AREG0 # restore a0
  766. xsr a2, depc # restore a2, depc
  767. wsr a0, excsave1
  768. movi a0, unrecoverable_exception
  769. callx0 a0
  770. ENDPROC(fast_syscall_unrecoverable)
  771. /*
  772. * sysxtensa syscall handler
  773. *
  774. * int sysxtensa (SYS_XTENSA_ATOMIC_SET, ptr, val, unused);
  775. * int sysxtensa (SYS_XTENSA_ATOMIC_ADD, ptr, val, unused);
  776. * int sysxtensa (SYS_XTENSA_ATOMIC_EXG_ADD, ptr, val, unused);
  777. * int sysxtensa (SYS_XTENSA_ATOMIC_CMP_SWP, ptr, oldval, newval);
  778. * a2 a6 a3 a4 a5
  779. *
  780. * Entry condition:
  781. *
  782. * a0: a2 (syscall-nr), original value saved on stack (PT_AREG0)
  783. * a1: a1
  784. * a2: new stack pointer, original in a0 and DEPC
  785. * a3: a3
  786. * a4..a15: unchanged
  787. * depc: a2, original value saved on stack (PT_DEPC)
  788. * excsave_1: dispatch table
  789. *
  790. * PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception, DEPC
  791. * < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception
  792. *
  793. * Note: we don't have to save a2; a2 holds the return value
  794. *
  795. * We use the two macros TRY and CATCH:
  796. *
  797. * TRY adds an entry to the __ex_table fixup table for the immediately
  798. * following instruction.
  799. *
  800. * CATCH catches any exception that occurred at one of the preceding TRY
  801. * statements and continues from there
  802. *
  803. * Usage TRY l32i a0, a1, 0
  804. * <other code>
  805. * done: rfe
  806. * CATCH <set return code>
  807. * j done
  808. */
  809. #ifdef CONFIG_FAST_SYSCALL_XTENSA
  810. #define TRY \
  811. .section __ex_table, "a"; \
  812. .word 66f, 67f; \
  813. .text; \
  814. 66:
  815. #define CATCH \
  816. 67:
  817. ENTRY(fast_syscall_xtensa)
  818. s32i a7, a2, PT_AREG7 # we need an additional register
  819. movi a7, 4 # sizeof(unsigned int)
  820. access_ok a3, a7, a0, a2, .Leac # a0: scratch reg, a2: sp
  821. _bgeui a6, SYS_XTENSA_COUNT, .Lill
  822. _bnei a6, SYS_XTENSA_ATOMIC_CMP_SWP, .Lnswp
  823. /* Fall through for ATOMIC_CMP_SWP. */
  824. .Lswp: /* Atomic compare and swap */
  825. TRY l32i a0, a3, 0 # read old value
  826. bne a0, a4, 1f # same as old value? jump
  827. TRY s32i a5, a3, 0 # different, modify value
  828. l32i a7, a2, PT_AREG7 # restore a7
  829. l32i a0, a2, PT_AREG0 # restore a0
  830. movi a2, 1 # and return 1
  831. rfe
  832. 1: l32i a7, a2, PT_AREG7 # restore a7
  833. l32i a0, a2, PT_AREG0 # restore a0
  834. movi a2, 0 # return 0 (note that we cannot set
  835. rfe
  836. .Lnswp: /* Atomic set, add, and exg_add. */
  837. TRY l32i a7, a3, 0 # orig
  838. addi a6, a6, -SYS_XTENSA_ATOMIC_SET
  839. add a0, a4, a7 # + arg
  840. moveqz a0, a4, a6 # set
  841. addi a6, a6, SYS_XTENSA_ATOMIC_SET
  842. TRY s32i a0, a3, 0 # write new value
  843. mov a0, a2
  844. mov a2, a7
  845. l32i a7, a0, PT_AREG7 # restore a7
  846. l32i a0, a0, PT_AREG0 # restore a0
  847. rfe
  848. CATCH
  849. .Leac: l32i a7, a2, PT_AREG7 # restore a7
  850. l32i a0, a2, PT_AREG0 # restore a0
  851. movi a2, -EFAULT
  852. rfe
  853. .Lill: l32i a7, a2, PT_AREG7 # restore a7
  854. l32i a0, a2, PT_AREG0 # restore a0
  855. movi a2, -EINVAL
  856. rfe
  857. ENDPROC(fast_syscall_xtensa)
  858. #else /* CONFIG_FAST_SYSCALL_XTENSA */
  859. ENTRY(fast_syscall_xtensa)
  860. l32i a0, a2, PT_AREG0 # restore a0
  861. movi a2, -ENOSYS
  862. rfe
  863. ENDPROC(fast_syscall_xtensa)
  864. #endif /* CONFIG_FAST_SYSCALL_XTENSA */
  865. /* fast_syscall_spill_registers.
  866. *
  867. * Entry condition:
  868. *
  869. * a0: trashed, original value saved on stack (PT_AREG0)
  870. * a1: a1
  871. * a2: new stack pointer, original in DEPC
  872. * a3: a3
  873. * depc: a2, original value saved on stack (PT_DEPC)
  874. * excsave_1: dispatch table
  875. *
  876. * Note: We assume the stack pointer is EXC_TABLE_KSTK in the fixup handler.
  877. */
  878. #ifdef CONFIG_FAST_SYSCALL_SPILL_REGISTERS
  879. ENTRY(fast_syscall_spill_registers)
  880. /* Register a FIXUP handler (pass current wb as a parameter) */
  881. xsr a3, excsave1
  882. movi a0, fast_syscall_spill_registers_fixup
  883. s32i a0, a3, EXC_TABLE_FIXUP
  884. rsr a0, windowbase
  885. s32i a0, a3, EXC_TABLE_PARAM
  886. xsr a3, excsave1 # restore a3 and excsave_1
  887. /* Save a3, a4 and SAR on stack. */
  888. rsr a0, sar
  889. s32i a3, a2, PT_AREG3
  890. s32i a0, a2, PT_SAR
  891. /* The spill routine might clobber a4, a7, a8, a11, a12, and a15. */
  892. s32i a4, a2, PT_AREG4
  893. s32i a7, a2, PT_AREG7
  894. s32i a8, a2, PT_AREG8
  895. s32i a11, a2, PT_AREG11
  896. s32i a12, a2, PT_AREG12
  897. s32i a15, a2, PT_AREG15
  898. /*
  899. * Rotate ws so that the current windowbase is at bit 0.
  900. * Assume ws = xxxwww1yy (www1 current window frame).
  901. * Rotate ws right so that a4 = yyxxxwww1.
  902. */
  903. rsr a0, windowbase
  904. rsr a3, windowstart # a3 = xxxwww1yy
  905. ssr a0 # holds WB
  906. slli a0, a3, WSBITS
  907. or a3, a3, a0 # a3 = xxxwww1yyxxxwww1yy
  908. srl a3, a3 # a3 = 00xxxwww1yyxxxwww1
  909. /* We are done if there are no more than the current register frame. */
  910. extui a3, a3, 1, WSBITS-1 # a3 = 0yyxxxwww
  911. movi a0, (1 << (WSBITS-1))
  912. _beqz a3, .Lnospill # only one active frame? jump
  913. /* We want 1 at the top, so that we return to the current windowbase */
  914. or a3, a3, a0 # 1yyxxxwww
  915. /* Skip empty frames - get 'oldest' WINDOWSTART-bit. */
  916. wsr a3, windowstart # save shifted windowstart
  917. neg a0, a3
  918. and a3, a0, a3 # first bit set from right: 000010000
  919. ffs_ws a0, a3 # a0: shifts to skip empty frames
  920. movi a3, WSBITS
  921. sub a0, a3, a0 # WSBITS-a0:number of 0-bits from right
  922. ssr a0 # save in SAR for later.
  923. rsr a3, windowbase
  924. add a3, a3, a0
  925. wsr a3, windowbase
  926. rsync
  927. rsr a3, windowstart
  928. srl a3, a3 # shift windowstart
  929. /* WB is now just one frame below the oldest frame in the register
  930. window. WS is shifted so the oldest frame is in bit 0, thus, WB
  931. and WS differ by one 4-register frame. */
  932. /* Save frames. Depending what call was used (call4, call8, call12),
  933. * we have to save 4,8. or 12 registers.
  934. */
  935. .Lloop: _bbsi.l a3, 1, .Lc4
  936. _bbci.l a3, 2, .Lc12
  937. .Lc8: s32e a4, a13, -16
  938. l32e a4, a5, -12
  939. s32e a8, a4, -32
  940. s32e a5, a13, -12
  941. s32e a6, a13, -8
  942. s32e a7, a13, -4
  943. s32e a9, a4, -28
  944. s32e a10, a4, -24
  945. s32e a11, a4, -20
  946. srli a11, a3, 2 # shift windowbase by 2
  947. rotw 2
  948. _bnei a3, 1, .Lloop
  949. j .Lexit
  950. .Lc4: s32e a4, a9, -16
  951. s32e a5, a9, -12
  952. s32e a6, a9, -8
  953. s32e a7, a9, -4
  954. srli a7, a3, 1
  955. rotw 1
  956. _bnei a3, 1, .Lloop
  957. j .Lexit
  958. .Lc12: _bbci.l a3, 3, .Linvalid_mask # bit 2 shouldn't be zero!
  959. /* 12-register frame (call12) */
  960. l32e a0, a5, -12
  961. s32e a8, a0, -48
  962. mov a8, a0
  963. s32e a9, a8, -44
  964. s32e a10, a8, -40
  965. s32e a11, a8, -36
  966. s32e a12, a8, -32
  967. s32e a13, a8, -28
  968. s32e a14, a8, -24
  969. s32e a15, a8, -20
  970. srli a15, a3, 3
  971. /* The stack pointer for a4..a7 is out of reach, so we rotate the
  972. * window, grab the stackpointer, and rotate back.
  973. * Alternatively, we could also use the following approach, but that
  974. * makes the fixup routine much more complicated:
  975. * rotw 1
  976. * s32e a0, a13, -16
  977. * ...
  978. * rotw 2
  979. */
  980. rotw 1
  981. mov a4, a13
  982. rotw -1
  983. s32e a4, a8, -16
  984. s32e a5, a8, -12
  985. s32e a6, a8, -8
  986. s32e a7, a8, -4
  987. rotw 3
  988. _beqi a3, 1, .Lexit
  989. j .Lloop
  990. .Lexit:
  991. /* Done. Do the final rotation and set WS */
  992. rotw 1
  993. rsr a3, windowbase
  994. ssl a3
  995. movi a3, 1
  996. sll a3, a3
  997. wsr a3, windowstart
  998. .Lnospill:
  999. /* Advance PC, restore registers and SAR, and return from exception. */
  1000. l32i a3, a2, PT_SAR
  1001. l32i a0, a2, PT_AREG0
  1002. wsr a3, sar
  1003. l32i a3, a2, PT_AREG3
  1004. /* Restore clobbered registers. */
  1005. l32i a4, a2, PT_AREG4
  1006. l32i a7, a2, PT_AREG7
  1007. l32i a8, a2, PT_AREG8
  1008. l32i a11, a2, PT_AREG11
  1009. l32i a12, a2, PT_AREG12
  1010. l32i a15, a2, PT_AREG15
  1011. movi a2, 0
  1012. rfe
  1013. .Linvalid_mask:
  1014. /* We get here because of an unrecoverable error in the window
  1015. * registers, so set up a dummy frame and kill the user application.
  1016. * Note: We assume EXC_TABLE_KSTK contains a valid stack pointer.
  1017. */
  1018. movi a0, 1
  1019. movi a1, 0
  1020. wsr a0, windowstart
  1021. wsr a1, windowbase
  1022. rsync
  1023. movi a0, 0
  1024. rsr a3, excsave1
  1025. l32i a1, a3, EXC_TABLE_KSTK
  1026. movi a4, (1 << PS_WOE_BIT) | LOCKLEVEL
  1027. wsr a4, ps
  1028. rsync
  1029. movi a6, SIGSEGV
  1030. movi a4, do_exit
  1031. callx4 a4
  1032. /* shouldn't return, so panic */
  1033. wsr a0, excsave1
  1034. movi a0, unrecoverable_exception
  1035. callx0 a0 # should not return
  1036. 1: j 1b
  1037. ENDPROC(fast_syscall_spill_registers)
  1038. /* Fixup handler.
  1039. *
  1040. * We get here if the spill routine causes an exception, e.g. tlb miss.
  1041. * We basically restore WINDOWBASE and WINDOWSTART to the condition when
  1042. * we entered the spill routine and jump to the user exception handler.
  1043. *
  1044. * Note that we only need to restore the bits in windowstart that have not
  1045. * been spilled yet by the _spill_register routine. Luckily, a3 contains a
  1046. * rotated windowstart with only those bits set for frames that haven't been
  1047. * spilled yet. Because a3 is rotated such that bit 0 represents the register
  1048. * frame for the current windowbase - 1, we need to rotate a3 left by the
  1049. * value of the current windowbase + 1 and move it to windowstart.
  1050. *
  1051. * a0: value of depc, original value in depc
  1052. * a2: trashed, original value in EXC_TABLE_DOUBLE_SAVE
  1053. * a3: exctable, original value in excsave1
  1054. */
  1055. ENTRY(fast_syscall_spill_registers_fixup)
  1056. rsr a2, windowbase # get current windowbase (a2 is saved)
  1057. xsr a0, depc # restore depc and a0
  1058. ssl a2 # set shift (32 - WB)
  1059. /* We need to make sure the current registers (a0-a3) are preserved.
  1060. * To do this, we simply set the bit for the current window frame
  1061. * in WS, so that the exception handlers save them to the task stack.
  1062. *
  1063. * Note: we use a3 to set the windowbase, so we take a special care
  1064. * of it, saving it in the original _spill_registers frame across
  1065. * the exception handler call.
  1066. */
  1067. xsr a3, excsave1 # get spill-mask
  1068. slli a3, a3, 1 # shift left by one
  1069. addi a3, a3, 1 # set the bit for the current window frame
  1070. slli a2, a3, 32-WSBITS
  1071. src a2, a3, a2 # a2 = xxwww1yyxxxwww1yy......
  1072. wsr a2, windowstart # set corrected windowstart
  1073. srli a3, a3, 1
  1074. rsr a2, excsave1
  1075. l32i a2, a2, EXC_TABLE_DOUBLE_SAVE # restore a2
  1076. xsr a2, excsave1
  1077. s32i a3, a2, EXC_TABLE_DOUBLE_SAVE # save a3
  1078. l32i a3, a2, EXC_TABLE_PARAM # original WB (in user task)
  1079. xsr a2, excsave1
  1080. /* Return to the original (user task) WINDOWBASE.
  1081. * We leave the following frame behind:
  1082. * a0, a1, a2 same
  1083. * a3: trashed (saved in EXC_TABLE_DOUBLE_SAVE)
  1084. * depc: depc (we have to return to that address)
  1085. * excsave_1: exctable
  1086. */
  1087. wsr a3, windowbase
  1088. rsync
  1089. /* We are now in the original frame when we entered _spill_registers:
  1090. * a0: return address
  1091. * a1: used, stack pointer
  1092. * a2: kernel stack pointer
  1093. * a3: available
  1094. * depc: exception address
  1095. * excsave: exctable
  1096. * Note: This frame might be the same as above.
  1097. */
  1098. /* Setup stack pointer. */
  1099. addi a2, a2, -PT_USER_SIZE
  1100. s32i a0, a2, PT_AREG0
  1101. /* Make sure we return to this fixup handler. */
  1102. movi a3, fast_syscall_spill_registers_fixup_return
  1103. s32i a3, a2, PT_DEPC # setup depc
  1104. /* Jump to the exception handler. */
  1105. rsr a3, excsave1
  1106. rsr a0, exccause
  1107. addx4 a0, a0, a3 # find entry in table
  1108. l32i a0, a0, EXC_TABLE_FAST_USER # load handler
  1109. l32i a3, a3, EXC_TABLE_DOUBLE_SAVE
  1110. jx a0
  1111. ENDPROC(fast_syscall_spill_registers_fixup)
  1112. ENTRY(fast_syscall_spill_registers_fixup_return)
  1113. /* When we return here, all registers have been restored (a2: DEPC) */
  1114. wsr a2, depc # exception address
  1115. /* Restore fixup handler. */
  1116. rsr a2, excsave1
  1117. s32i a3, a2, EXC_TABLE_DOUBLE_SAVE
  1118. movi a3, fast_syscall_spill_registers_fixup
  1119. s32i a3, a2, EXC_TABLE_FIXUP
  1120. rsr a3, windowbase
  1121. s32i a3, a2, EXC_TABLE_PARAM
  1122. l32i a2, a2, EXC_TABLE_KSTK
  1123. /* Load WB at the time the exception occurred. */
  1124. rsr a3, sar # WB is still in SAR
  1125. neg a3, a3
  1126. wsr a3, windowbase
  1127. rsync
  1128. rsr a3, excsave1
  1129. l32i a3, a3, EXC_TABLE_DOUBLE_SAVE
  1130. rfde
  1131. ENDPROC(fast_syscall_spill_registers_fixup_return)
  1132. #else /* CONFIG_FAST_SYSCALL_SPILL_REGISTERS */
  1133. ENTRY(fast_syscall_spill_registers)
  1134. l32i a0, a2, PT_AREG0 # restore a0
  1135. movi a2, -ENOSYS
  1136. rfe
  1137. ENDPROC(fast_syscall_spill_registers)
  1138. #endif /* CONFIG_FAST_SYSCALL_SPILL_REGISTERS */
  1139. #ifdef CONFIG_MMU
  1140. /*
  1141. * We should never get here. Bail out!
  1142. */
  1143. ENTRY(fast_second_level_miss_double_kernel)
  1144. 1: movi a0, unrecoverable_exception
  1145. callx0 a0 # should not return
  1146. 1: j 1b
  1147. ENDPROC(fast_second_level_miss_double_kernel)
  1148. /* First-level entry handler for user, kernel, and double 2nd-level
  1149. * TLB miss exceptions. Note that for now, user and kernel miss
  1150. * exceptions share the same entry point and are handled identically.
  1151. *
  1152. * An old, less-efficient C version of this function used to exist.
  1153. * We include it below, interleaved as comments, for reference.
  1154. *
  1155. * Entry condition:
  1156. *
  1157. * a0: trashed, original value saved on stack (PT_AREG0)
  1158. * a1: a1
  1159. * a2: new stack pointer, original in DEPC
  1160. * a3: a3
  1161. * depc: a2, original value saved on stack (PT_DEPC)
  1162. * excsave_1: dispatch table
  1163. *
  1164. * PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception, DEPC
  1165. * < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception
  1166. */
  1167. ENTRY(fast_second_level_miss)
  1168. /* Save a1 and a3. Note: we don't expect a double exception. */
  1169. s32i a1, a2, PT_AREG1
  1170. s32i a3, a2, PT_AREG3
  1171. /* We need to map the page of PTEs for the user task. Find
  1172. * the pointer to that page. Also, it's possible for tsk->mm
  1173. * to be NULL while tsk->active_mm is nonzero if we faulted on
  1174. * a vmalloc address. In that rare case, we must use
  1175. * active_mm instead to avoid a fault in this handler. See
  1176. *
  1177. * http://mail.nl.linux.org/linux-mm/2002-08/msg00258.html
  1178. * (or search Internet on "mm vs. active_mm")
  1179. *
  1180. * if (!mm)
  1181. * mm = tsk->active_mm;
  1182. * pgd = pgd_offset (mm, regs->excvaddr);
  1183. * pmd = pmd_offset (pgd, regs->excvaddr);
  1184. * pmdval = *pmd;
  1185. */
  1186. GET_CURRENT(a1,a2)
  1187. l32i a0, a1, TASK_MM # tsk->mm
  1188. beqz a0, 9f
  1189. 8: rsr a3, excvaddr # fault address
  1190. _PGD_OFFSET(a0, a3, a1)
  1191. l32i a0, a0, 0 # read pmdval
  1192. beqz a0, 2f
  1193. /* Read ptevaddr and convert to top of page-table page.
  1194. *
  1195. * vpnval = read_ptevaddr_register() & PAGE_MASK;
  1196. * vpnval += DTLB_WAY_PGTABLE;
  1197. * pteval = mk_pte (virt_to_page(pmd_val(pmdval)), PAGE_KERNEL);
  1198. * write_dtlb_entry (pteval, vpnval);
  1199. *
  1200. * The messy computation for 'pteval' above really simplifies
  1201. * into the following:
  1202. *
  1203. * pteval = ((pmdval - PAGE_OFFSET) & PAGE_MASK) | PAGE_DIRECTORY
  1204. */
  1205. movi a1, (-PAGE_OFFSET) & 0xffffffff
  1206. add a0, a0, a1 # pmdval - PAGE_OFFSET
  1207. extui a1, a0, 0, PAGE_SHIFT # ... & PAGE_MASK
  1208. xor a0, a0, a1
  1209. movi a1, _PAGE_DIRECTORY
  1210. or a0, a0, a1 # ... | PAGE_DIRECTORY
  1211. /*
  1212. * We utilize all three wired-ways (7-9) to hold pmd translations.
  1213. * Memory regions are mapped to the DTLBs according to bits 28 and 29.
  1214. * This allows to map the three most common regions to three different
  1215. * DTLBs:
  1216. * 0,1 -> way 7 program (0040.0000) and virtual (c000.0000)
  1217. * 2 -> way 8 shared libaries (2000.0000)
  1218. * 3 -> way 0 stack (3000.0000)
  1219. */
  1220. extui a3, a3, 28, 2 # addr. bit 28 and 29 0,1,2,3
  1221. rsr a1, ptevaddr
  1222. addx2 a3, a3, a3 # -> 0,3,6,9
  1223. srli a1, a1, PAGE_SHIFT
  1224. extui a3, a3, 2, 2 # -> 0,0,1,2
  1225. slli a1, a1, PAGE_SHIFT # ptevaddr & PAGE_MASK
  1226. addi a3, a3, DTLB_WAY_PGD
  1227. add a1, a1, a3 # ... + way_number
  1228. 3: wdtlb a0, a1
  1229. dsync
  1230. /* Exit critical section. */
  1231. 4: rsr a3, excsave1
  1232. movi a0, 0
  1233. s32i a0, a3, EXC_TABLE_FIXUP
  1234. /* Restore the working registers, and return. */
  1235. l32i a0, a2, PT_AREG0
  1236. l32i a1, a2, PT_AREG1
  1237. l32i a3, a2, PT_AREG3
  1238. l32i a2, a2, PT_DEPC
  1239. bgeui a2, VALID_DOUBLE_EXCEPTION_ADDRESS, 1f
  1240. /* Restore excsave1 and return. */
  1241. rsr a2, depc
  1242. rfe
  1243. /* Return from double exception. */
  1244. 1: xsr a2, depc
  1245. esync
  1246. rfde
  1247. 9: l32i a0, a1, TASK_ACTIVE_MM # unlikely case mm == 0
  1248. j 8b
  1249. #if (DCACHE_WAY_SIZE > PAGE_SIZE)
  1250. 2: /* Special case for cache aliasing.
  1251. * We (should) only get here if a clear_user_page, copy_user_page
  1252. * or the aliased cache flush functions got preemptively interrupted
  1253. * by another task. Re-establish temporary mapping to the
  1254. * TLBTEMP_BASE areas.
  1255. */
  1256. /* We shouldn't be in a double exception */
  1257. l32i a0, a2, PT_DEPC
  1258. bgeui a0, VALID_DOUBLE_EXCEPTION_ADDRESS, 2f
  1259. /* Make sure the exception originated in the special functions */
  1260. movi a0, __tlbtemp_mapping_start
  1261. rsr a3, epc1
  1262. bltu a3, a0, 2f
  1263. movi a0, __tlbtemp_mapping_end
  1264. bgeu a3, a0, 2f
  1265. /* Check if excvaddr was in one of the TLBTEMP_BASE areas. */
  1266. movi a3, TLBTEMP_BASE_1
  1267. rsr a0, excvaddr
  1268. bltu a0, a3, 2f
  1269. addi a1, a0, -TLBTEMP_SIZE
  1270. bgeu a1, a3, 2f
  1271. /* Check if we have to restore an ITLB mapping. */
  1272. movi a1, __tlbtemp_mapping_itlb
  1273. rsr a3, epc1
  1274. sub a3, a3, a1
  1275. /* Calculate VPN */
  1276. movi a1, PAGE_MASK
  1277. and a1, a1, a0
  1278. /* Jump for ITLB entry */
  1279. bgez a3, 1f
  1280. /* We can use up to two TLBTEMP areas, one for src and one for dst. */
  1281. extui a3, a0, PAGE_SHIFT + DCACHE_ALIAS_ORDER, 1
  1282. add a1, a3, a1
  1283. /* PPN is in a6 for the first TLBTEMP area and in a7 for the second. */
  1284. mov a0, a6
  1285. movnez a0, a7, a3
  1286. j 3b
  1287. /* ITLB entry. We only use dst in a6. */
  1288. 1: witlb a6, a1
  1289. isync
  1290. j 4b
  1291. #endif // DCACHE_WAY_SIZE > PAGE_SIZE
  1292. 2: /* Invalid PGD, default exception handling */
  1293. rsr a1, depc
  1294. s32i a1, a2, PT_AREG2
  1295. mov a1, a2
  1296. rsr a2, ps
  1297. bbsi.l a2, PS_UM_BIT, 1f
  1298. j _kernel_exception
  1299. 1: j _user_exception
  1300. ENDPROC(fast_second_level_miss)
  1301. /*
  1302. * StoreProhibitedException
  1303. *
  1304. * Update the pte and invalidate the itlb mapping for this pte.
  1305. *
  1306. * Entry condition:
  1307. *
  1308. * a0: trashed, original value saved on stack (PT_AREG0)
  1309. * a1: a1
  1310. * a2: new stack pointer, original in DEPC
  1311. * a3: a3
  1312. * depc: a2, original value saved on stack (PT_DEPC)
  1313. * excsave_1: dispatch table
  1314. *
  1315. * PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception, DEPC
  1316. * < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception
  1317. */
  1318. ENTRY(fast_store_prohibited)
  1319. /* Save a1 and a3. */
  1320. s32i a1, a2, PT_AREG1
  1321. s32i a3, a2, PT_AREG3
  1322. GET_CURRENT(a1,a2)
  1323. l32i a0, a1, TASK_MM # tsk->mm
  1324. beqz a0, 9f
  1325. 8: rsr a1, excvaddr # fault address
  1326. _PGD_OFFSET(a0, a1, a3)
  1327. l32i a0, a0, 0
  1328. beqz a0, 2f
  1329. /*
  1330. * Note that we test _PAGE_WRITABLE_BIT only if PTE is present
  1331. * and is not PAGE_NONE. See pgtable.h for possible PTE layouts.
  1332. */
  1333. _PTE_OFFSET(a0, a1, a3)
  1334. l32i a3, a0, 0 # read pteval
  1335. movi a1, _PAGE_CA_INVALID
  1336. ball a3, a1, 2f
  1337. bbci.l a3, _PAGE_WRITABLE_BIT, 2f
  1338. movi a1, _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_HW_WRITE
  1339. or a3, a3, a1
  1340. rsr a1, excvaddr
  1341. s32i a3, a0, 0
  1342. /* We need to flush the cache if we have page coloring. */
  1343. #if (DCACHE_WAY_SIZE > PAGE_SIZE) && XCHAL_DCACHE_IS_WRITEBACK
  1344. dhwb a0, 0
  1345. #endif
  1346. pdtlb a0, a1
  1347. wdtlb a3, a0
  1348. /* Exit critical section. */
  1349. movi a0, 0
  1350. rsr a3, excsave1
  1351. s32i a0, a3, EXC_TABLE_FIXUP
  1352. /* Restore the working registers, and return. */
  1353. l32i a3, a2, PT_AREG3
  1354. l32i a1, a2, PT_AREG1
  1355. l32i a0, a2, PT_AREG0
  1356. l32i a2, a2, PT_DEPC
  1357. bgeui a2, VALID_DOUBLE_EXCEPTION_ADDRESS, 1f
  1358. rsr a2, depc
  1359. rfe
  1360. /* Double exception. Restore FIXUP handler and return. */
  1361. 1: xsr a2, depc
  1362. esync
  1363. rfde
  1364. 9: l32i a0, a1, TASK_ACTIVE_MM # unlikely case mm == 0
  1365. j 8b
  1366. 2: /* If there was a problem, handle fault in C */
  1367. rsr a3, depc # still holds a2
  1368. s32i a3, a2, PT_AREG2
  1369. mov a1, a2
  1370. rsr a2, ps
  1371. bbsi.l a2, PS_UM_BIT, 1f
  1372. j _kernel_exception
  1373. 1: j _user_exception
  1374. ENDPROC(fast_store_prohibited)
  1375. #endif /* CONFIG_MMU */
  1376. /*
  1377. * System Calls.
  1378. *
  1379. * void system_call (struct pt_regs* regs, int exccause)
  1380. * a2 a3
  1381. */
  1382. ENTRY(system_call)
  1383. entry a1, 32
  1384. /* regs->syscall = regs->areg[2] */
  1385. l32i a3, a2, PT_AREG2
  1386. mov a6, a2
  1387. movi a4, do_syscall_trace_enter
  1388. s32i a3, a2, PT_SYSCALL
  1389. callx4 a4
  1390. /* syscall = sys_call_table[syscall_nr] */
  1391. movi a4, sys_call_table;
  1392. movi a5, __NR_syscall_count
  1393. movi a6, -ENOSYS
  1394. bgeu a3, a5, 1f
  1395. addx4 a4, a3, a4
  1396. l32i a4, a4, 0
  1397. movi a5, sys_ni_syscall;
  1398. beq a4, a5, 1f
  1399. /* Load args: arg0 - arg5 are passed via regs. */
  1400. l32i a6, a2, PT_AREG6
  1401. l32i a7, a2, PT_AREG3
  1402. l32i a8, a2, PT_AREG4
  1403. l32i a9, a2, PT_AREG5
  1404. l32i a10, a2, PT_AREG8
  1405. l32i a11, a2, PT_AREG9
  1406. /* Pass one additional argument to the syscall: pt_regs (on stack) */
  1407. s32i a2, a1, 0
  1408. callx4 a4
  1409. 1: /* regs->areg[2] = return_value */
  1410. s32i a6, a2, PT_AREG2
  1411. movi a4, do_syscall_trace_leave
  1412. mov a6, a2
  1413. callx4 a4
  1414. retw
  1415. ENDPROC(system_call)
  1416. /*
  1417. * Spill live registers on the kernel stack macro.
  1418. *
  1419. * Entry condition: ps.woe is set, ps.excm is cleared
  1420. * Exit condition: windowstart has single bit set
  1421. * May clobber: a12, a13
  1422. */
  1423. .macro spill_registers_kernel
  1424. #if XCHAL_NUM_AREGS > 16
  1425. call12 1f
  1426. _j 2f
  1427. retw
  1428. .align 4
  1429. 1:
  1430. _entry a1, 48
  1431. addi a12, a0, 3
  1432. #if XCHAL_NUM_AREGS > 32
  1433. .rept (XCHAL_NUM_AREGS - 32) / 12
  1434. _entry a1, 48
  1435. mov a12, a0
  1436. .endr
  1437. #endif
  1438. _entry a1, 48
  1439. #if XCHAL_NUM_AREGS % 12 == 0
  1440. mov a8, a8
  1441. #elif XCHAL_NUM_AREGS % 12 == 4
  1442. mov a12, a12
  1443. #elif XCHAL_NUM_AREGS % 12 == 8
  1444. mov a4, a4
  1445. #endif
  1446. retw
  1447. 2:
  1448. #else
  1449. mov a12, a12
  1450. #endif
  1451. .endm
  1452. /*
  1453. * Task switch.
  1454. *
  1455. * struct task* _switch_to (struct task* prev, struct task* next)
  1456. * a2 a2 a3
  1457. */
  1458. ENTRY(_switch_to)
  1459. entry a1, 16
  1460. mov a11, a3 # and 'next' (a3)
  1461. l32i a4, a2, TASK_THREAD_INFO
  1462. l32i a5, a3, TASK_THREAD_INFO
  1463. save_xtregs_user a4 a6 a8 a9 a12 a13 THREAD_XTREGS_USER
  1464. #if THREAD_RA > 1020 || THREAD_SP > 1020
  1465. addi a10, a2, TASK_THREAD
  1466. s32i a0, a10, THREAD_RA - TASK_THREAD # save return address
  1467. s32i a1, a10, THREAD_SP - TASK_THREAD # save stack pointer
  1468. #else
  1469. s32i a0, a2, THREAD_RA # save return address
  1470. s32i a1, a2, THREAD_SP # save stack pointer
  1471. #endif
  1472. /* Disable ints while we manipulate the stack pointer. */
  1473. rsil a14, LOCKLEVEL
  1474. rsr a3, excsave1
  1475. rsync
  1476. s32i a3, a3, EXC_TABLE_FIXUP /* enter critical section */
  1477. /* Switch CPENABLE */
  1478. #if (XTENSA_HAVE_COPROCESSORS || XTENSA_HAVE_IO_PORTS)
  1479. l32i a3, a5, THREAD_CPENABLE
  1480. xsr a3, cpenable
  1481. s32i a3, a4, THREAD_CPENABLE
  1482. #endif
  1483. /* Flush register file. */
  1484. spill_registers_kernel
  1485. /* Set kernel stack (and leave critical section)
  1486. * Note: It's save to set it here. The stack will not be overwritten
  1487. * because the kernel stack will only be loaded again after
  1488. * we return from kernel space.
  1489. */
  1490. rsr a3, excsave1 # exc_table
  1491. movi a6, 0
  1492. addi a7, a5, PT_REGS_OFFSET
  1493. s32i a6, a3, EXC_TABLE_FIXUP
  1494. s32i a7, a3, EXC_TABLE_KSTK
  1495. /* restore context of the task 'next' */
  1496. l32i a0, a11, THREAD_RA # restore return address
  1497. l32i a1, a11, THREAD_SP # restore stack pointer
  1498. load_xtregs_user a5 a6 a8 a9 a12 a13 THREAD_XTREGS_USER
  1499. wsr a14, ps
  1500. rsync
  1501. retw
  1502. ENDPROC(_switch_to)
  1503. ENTRY(ret_from_fork)
  1504. /* void schedule_tail (struct task_struct *prev)
  1505. * Note: prev is still in a6 (return value from fake call4 frame)
  1506. */
  1507. movi a4, schedule_tail
  1508. callx4 a4
  1509. movi a4, do_syscall_trace_leave
  1510. mov a6, a1
  1511. callx4 a4
  1512. j common_exception_return
  1513. ENDPROC(ret_from_fork)
  1514. /*
  1515. * Kernel thread creation helper
  1516. * On entry, set up by copy_thread: a2 = thread_fn, a3 = thread_fn arg
  1517. * left from _switch_to: a6 = prev
  1518. */
  1519. ENTRY(ret_from_kernel_thread)
  1520. call4 schedule_tail
  1521. mov a6, a3
  1522. callx4 a2
  1523. j common_exception_return
  1524. ENDPROC(ret_from_kernel_thread)