entry.S 45 KB

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