entry.S 46 KB

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