entry.S 45 KB

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