entry.S 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780
  1. /* $Id: entry.S,v 1.144 2002/02/09 19:49:30 davem Exp $
  2. * arch/sparc64/kernel/entry.S: Sparc64 trap low-level entry points.
  3. *
  4. * Copyright (C) 1995,1997 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
  6. * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
  7. * Copyright (C) 1996,98,99 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  8. */
  9. #include <linux/config.h>
  10. #include <linux/errno.h>
  11. #include <asm/head.h>
  12. #include <asm/asi.h>
  13. #include <asm/smp.h>
  14. #include <asm/ptrace.h>
  15. #include <asm/page.h>
  16. #include <asm/signal.h>
  17. #include <asm/pgtable.h>
  18. #include <asm/processor.h>
  19. #include <asm/visasm.h>
  20. #include <asm/estate.h>
  21. #include <asm/auxio.h>
  22. #include <asm/sfafsr.h>
  23. #define curptr g6
  24. #define NR_SYSCALLS 300 /* Each OS is different... */
  25. .text
  26. .align 32
  27. /* This is trivial with the new code... */
  28. .globl do_fpdis
  29. do_fpdis:
  30. sethi %hi(TSTATE_PEF), %g4
  31. rdpr %tstate, %g5
  32. andcc %g5, %g4, %g0
  33. be,pt %xcc, 1f
  34. nop
  35. rd %fprs, %g5
  36. andcc %g5, FPRS_FEF, %g0
  37. be,pt %xcc, 1f
  38. nop
  39. /* Legal state when DCR_IFPOE is set in Cheetah %dcr. */
  40. sethi %hi(109f), %g7
  41. ba,pt %xcc, etrap
  42. 109: or %g7, %lo(109b), %g7
  43. add %g0, %g0, %g0
  44. ba,a,pt %xcc, rtrap_clr_l6
  45. 1: TRAP_LOAD_THREAD_REG
  46. ldub [%g6 + TI_FPSAVED], %g5
  47. wr %g0, FPRS_FEF, %fprs
  48. andcc %g5, FPRS_FEF, %g0
  49. be,a,pt %icc, 1f
  50. clr %g7
  51. ldx [%g6 + TI_GSR], %g7
  52. 1: andcc %g5, FPRS_DL, %g0
  53. bne,pn %icc, 2f
  54. fzero %f0
  55. andcc %g5, FPRS_DU, %g0
  56. bne,pn %icc, 1f
  57. fzero %f2
  58. faddd %f0, %f2, %f4
  59. fmuld %f0, %f2, %f6
  60. faddd %f0, %f2, %f8
  61. fmuld %f0, %f2, %f10
  62. faddd %f0, %f2, %f12
  63. fmuld %f0, %f2, %f14
  64. faddd %f0, %f2, %f16
  65. fmuld %f0, %f2, %f18
  66. faddd %f0, %f2, %f20
  67. fmuld %f0, %f2, %f22
  68. faddd %f0, %f2, %f24
  69. fmuld %f0, %f2, %f26
  70. faddd %f0, %f2, %f28
  71. fmuld %f0, %f2, %f30
  72. faddd %f0, %f2, %f32
  73. fmuld %f0, %f2, %f34
  74. faddd %f0, %f2, %f36
  75. fmuld %f0, %f2, %f38
  76. faddd %f0, %f2, %f40
  77. fmuld %f0, %f2, %f42
  78. faddd %f0, %f2, %f44
  79. fmuld %f0, %f2, %f46
  80. faddd %f0, %f2, %f48
  81. fmuld %f0, %f2, %f50
  82. faddd %f0, %f2, %f52
  83. fmuld %f0, %f2, %f54
  84. faddd %f0, %f2, %f56
  85. fmuld %f0, %f2, %f58
  86. b,pt %xcc, fpdis_exit2
  87. faddd %f0, %f2, %f60
  88. 1: mov SECONDARY_CONTEXT, %g3
  89. add %g6, TI_FPREGS + 0x80, %g1
  90. faddd %f0, %f2, %f4
  91. fmuld %f0, %f2, %f6
  92. ldxa [%g3] ASI_DMMU, %g5
  93. sethi %hi(sparc64_kern_sec_context), %g2
  94. ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
  95. stxa %g2, [%g3] ASI_DMMU
  96. membar #Sync
  97. add %g6, TI_FPREGS + 0xc0, %g2
  98. faddd %f0, %f2, %f8
  99. fmuld %f0, %f2, %f10
  100. membar #Sync
  101. ldda [%g1] ASI_BLK_S, %f32
  102. ldda [%g2] ASI_BLK_S, %f48
  103. membar #Sync
  104. faddd %f0, %f2, %f12
  105. fmuld %f0, %f2, %f14
  106. faddd %f0, %f2, %f16
  107. fmuld %f0, %f2, %f18
  108. faddd %f0, %f2, %f20
  109. fmuld %f0, %f2, %f22
  110. faddd %f0, %f2, %f24
  111. fmuld %f0, %f2, %f26
  112. faddd %f0, %f2, %f28
  113. fmuld %f0, %f2, %f30
  114. b,pt %xcc, fpdis_exit
  115. nop
  116. 2: andcc %g5, FPRS_DU, %g0
  117. bne,pt %icc, 3f
  118. fzero %f32
  119. mov SECONDARY_CONTEXT, %g3
  120. fzero %f34
  121. ldxa [%g3] ASI_DMMU, %g5
  122. add %g6, TI_FPREGS, %g1
  123. sethi %hi(sparc64_kern_sec_context), %g2
  124. ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
  125. stxa %g2, [%g3] ASI_DMMU
  126. membar #Sync
  127. add %g6, TI_FPREGS + 0x40, %g2
  128. faddd %f32, %f34, %f36
  129. fmuld %f32, %f34, %f38
  130. membar #Sync
  131. ldda [%g1] ASI_BLK_S, %f0
  132. ldda [%g2] ASI_BLK_S, %f16
  133. membar #Sync
  134. faddd %f32, %f34, %f40
  135. fmuld %f32, %f34, %f42
  136. faddd %f32, %f34, %f44
  137. fmuld %f32, %f34, %f46
  138. faddd %f32, %f34, %f48
  139. fmuld %f32, %f34, %f50
  140. faddd %f32, %f34, %f52
  141. fmuld %f32, %f34, %f54
  142. faddd %f32, %f34, %f56
  143. fmuld %f32, %f34, %f58
  144. faddd %f32, %f34, %f60
  145. fmuld %f32, %f34, %f62
  146. ba,pt %xcc, fpdis_exit
  147. nop
  148. 3: mov SECONDARY_CONTEXT, %g3
  149. add %g6, TI_FPREGS, %g1
  150. ldxa [%g3] ASI_DMMU, %g5
  151. sethi %hi(sparc64_kern_sec_context), %g2
  152. ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
  153. stxa %g2, [%g3] ASI_DMMU
  154. membar #Sync
  155. mov 0x40, %g2
  156. membar #Sync
  157. ldda [%g1] ASI_BLK_S, %f0
  158. ldda [%g1 + %g2] ASI_BLK_S, %f16
  159. add %g1, 0x80, %g1
  160. ldda [%g1] ASI_BLK_S, %f32
  161. ldda [%g1 + %g2] ASI_BLK_S, %f48
  162. membar #Sync
  163. fpdis_exit:
  164. stxa %g5, [%g3] ASI_DMMU
  165. membar #Sync
  166. fpdis_exit2:
  167. wr %g7, 0, %gsr
  168. ldx [%g6 + TI_XFSR], %fsr
  169. rdpr %tstate, %g3
  170. or %g3, %g4, %g3 ! anal...
  171. wrpr %g3, %tstate
  172. wr %g0, FPRS_FEF, %fprs ! clean DU/DL bits
  173. retry
  174. .align 32
  175. fp_other_bounce:
  176. call do_fpother
  177. add %sp, PTREGS_OFF, %o0
  178. ba,pt %xcc, rtrap
  179. clr %l6
  180. .globl do_fpother_check_fitos
  181. .align 32
  182. do_fpother_check_fitos:
  183. TRAP_LOAD_THREAD_REG
  184. sethi %hi(fp_other_bounce - 4), %g7
  185. or %g7, %lo(fp_other_bounce - 4), %g7
  186. /* NOTE: Need to preserve %g7 until we fully commit
  187. * to the fitos fixup.
  188. */
  189. stx %fsr, [%g6 + TI_XFSR]
  190. rdpr %tstate, %g3
  191. andcc %g3, TSTATE_PRIV, %g0
  192. bne,pn %xcc, do_fptrap_after_fsr
  193. nop
  194. ldx [%g6 + TI_XFSR], %g3
  195. srlx %g3, 14, %g1
  196. and %g1, 7, %g1
  197. cmp %g1, 2 ! Unfinished FP-OP
  198. bne,pn %xcc, do_fptrap_after_fsr
  199. sethi %hi(1 << 23), %g1 ! Inexact
  200. andcc %g3, %g1, %g0
  201. bne,pn %xcc, do_fptrap_after_fsr
  202. rdpr %tpc, %g1
  203. lduwa [%g1] ASI_AIUP, %g3 ! This cannot ever fail
  204. #define FITOS_MASK 0xc1f83fe0
  205. #define FITOS_COMPARE 0x81a01880
  206. sethi %hi(FITOS_MASK), %g1
  207. or %g1, %lo(FITOS_MASK), %g1
  208. and %g3, %g1, %g1
  209. sethi %hi(FITOS_COMPARE), %g2
  210. or %g2, %lo(FITOS_COMPARE), %g2
  211. cmp %g1, %g2
  212. bne,pn %xcc, do_fptrap_after_fsr
  213. nop
  214. std %f62, [%g6 + TI_FPREGS + (62 * 4)]
  215. sethi %hi(fitos_table_1), %g1
  216. and %g3, 0x1f, %g2
  217. or %g1, %lo(fitos_table_1), %g1
  218. sllx %g2, 2, %g2
  219. jmpl %g1 + %g2, %g0
  220. ba,pt %xcc, fitos_emul_continue
  221. fitos_table_1:
  222. fitod %f0, %f62
  223. fitod %f1, %f62
  224. fitod %f2, %f62
  225. fitod %f3, %f62
  226. fitod %f4, %f62
  227. fitod %f5, %f62
  228. fitod %f6, %f62
  229. fitod %f7, %f62
  230. fitod %f8, %f62
  231. fitod %f9, %f62
  232. fitod %f10, %f62
  233. fitod %f11, %f62
  234. fitod %f12, %f62
  235. fitod %f13, %f62
  236. fitod %f14, %f62
  237. fitod %f15, %f62
  238. fitod %f16, %f62
  239. fitod %f17, %f62
  240. fitod %f18, %f62
  241. fitod %f19, %f62
  242. fitod %f20, %f62
  243. fitod %f21, %f62
  244. fitod %f22, %f62
  245. fitod %f23, %f62
  246. fitod %f24, %f62
  247. fitod %f25, %f62
  248. fitod %f26, %f62
  249. fitod %f27, %f62
  250. fitod %f28, %f62
  251. fitod %f29, %f62
  252. fitod %f30, %f62
  253. fitod %f31, %f62
  254. fitos_emul_continue:
  255. sethi %hi(fitos_table_2), %g1
  256. srl %g3, 25, %g2
  257. or %g1, %lo(fitos_table_2), %g1
  258. and %g2, 0x1f, %g2
  259. sllx %g2, 2, %g2
  260. jmpl %g1 + %g2, %g0
  261. ba,pt %xcc, fitos_emul_fini
  262. fitos_table_2:
  263. fdtos %f62, %f0
  264. fdtos %f62, %f1
  265. fdtos %f62, %f2
  266. fdtos %f62, %f3
  267. fdtos %f62, %f4
  268. fdtos %f62, %f5
  269. fdtos %f62, %f6
  270. fdtos %f62, %f7
  271. fdtos %f62, %f8
  272. fdtos %f62, %f9
  273. fdtos %f62, %f10
  274. fdtos %f62, %f11
  275. fdtos %f62, %f12
  276. fdtos %f62, %f13
  277. fdtos %f62, %f14
  278. fdtos %f62, %f15
  279. fdtos %f62, %f16
  280. fdtos %f62, %f17
  281. fdtos %f62, %f18
  282. fdtos %f62, %f19
  283. fdtos %f62, %f20
  284. fdtos %f62, %f21
  285. fdtos %f62, %f22
  286. fdtos %f62, %f23
  287. fdtos %f62, %f24
  288. fdtos %f62, %f25
  289. fdtos %f62, %f26
  290. fdtos %f62, %f27
  291. fdtos %f62, %f28
  292. fdtos %f62, %f29
  293. fdtos %f62, %f30
  294. fdtos %f62, %f31
  295. fitos_emul_fini:
  296. ldd [%g6 + TI_FPREGS + (62 * 4)], %f62
  297. done
  298. .globl do_fptrap
  299. .align 32
  300. do_fptrap:
  301. stx %fsr, [%g6 + TI_XFSR]
  302. do_fptrap_after_fsr:
  303. ldub [%g6 + TI_FPSAVED], %g3
  304. rd %fprs, %g1
  305. or %g3, %g1, %g3
  306. stb %g3, [%g6 + TI_FPSAVED]
  307. rd %gsr, %g3
  308. stx %g3, [%g6 + TI_GSR]
  309. mov SECONDARY_CONTEXT, %g3
  310. ldxa [%g3] ASI_DMMU, %g5
  311. sethi %hi(sparc64_kern_sec_context), %g2
  312. ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
  313. stxa %g2, [%g3] ASI_DMMU
  314. membar #Sync
  315. add %g6, TI_FPREGS, %g2
  316. andcc %g1, FPRS_DL, %g0
  317. be,pn %icc, 4f
  318. mov 0x40, %g3
  319. stda %f0, [%g2] ASI_BLK_S
  320. stda %f16, [%g2 + %g3] ASI_BLK_S
  321. andcc %g1, FPRS_DU, %g0
  322. be,pn %icc, 5f
  323. 4: add %g2, 128, %g2
  324. stda %f32, [%g2] ASI_BLK_S
  325. stda %f48, [%g2 + %g3] ASI_BLK_S
  326. 5: mov SECONDARY_CONTEXT, %g1
  327. membar #Sync
  328. stxa %g5, [%g1] ASI_DMMU
  329. membar #Sync
  330. ba,pt %xcc, etrap
  331. wr %g0, 0, %fprs
  332. /* The registers for cross calls will be:
  333. *
  334. * DATA 0: [low 32-bits] Address of function to call, jmp to this
  335. * [high 32-bits] MMU Context Argument 0, place in %g5
  336. * DATA 1: Address Argument 1, place in %g1
  337. * DATA 2: Address Argument 2, place in %g7
  338. *
  339. * With this method we can do most of the cross-call tlb/cache
  340. * flushing very quickly.
  341. */
  342. .text
  343. .align 32
  344. .globl do_ivec
  345. do_ivec:
  346. mov 0x40, %g3
  347. ldxa [%g3 + %g0] ASI_INTR_R, %g3
  348. sethi %hi(KERNBASE), %g4
  349. cmp %g3, %g4
  350. bgeu,pn %xcc, do_ivec_xcall
  351. srlx %g3, 32, %g5
  352. stxa %g0, [%g0] ASI_INTR_RECEIVE
  353. membar #Sync
  354. sethi %hi(ivector_table), %g2
  355. sllx %g3, 5, %g3
  356. or %g2, %lo(ivector_table), %g2
  357. add %g2, %g3, %g3
  358. ldub [%g3 + 0x04], %g4 /* pil */
  359. mov 1, %g2
  360. sllx %g2, %g4, %g2
  361. sllx %g4, 2, %g4
  362. TRAP_LOAD_IRQ_WORK
  363. lduw [%g6 + %g4], %g5 /* g5 = irq_work(cpu, pil) */
  364. stw %g5, [%g3 + 0x00] /* bucket->irq_chain = g5 */
  365. stw %g3, [%g6 + %g4] /* irq_work(cpu, pil) = bucket */
  366. wr %g2, 0x0, %set_softint
  367. retry
  368. do_ivec_xcall:
  369. mov 0x50, %g1
  370. ldxa [%g1 + %g0] ASI_INTR_R, %g1
  371. srl %g3, 0, %g3
  372. mov 0x60, %g7
  373. ldxa [%g7 + %g0] ASI_INTR_R, %g7
  374. stxa %g0, [%g0] ASI_INTR_RECEIVE
  375. membar #Sync
  376. ba,pt %xcc, 1f
  377. nop
  378. .align 32
  379. 1: jmpl %g3, %g0
  380. nop
  381. .globl save_alternate_globals
  382. save_alternate_globals: /* %o0 = save_area */
  383. rdpr %pstate, %o5
  384. andn %o5, PSTATE_IE, %o1
  385. wrpr %o1, PSTATE_AG, %pstate
  386. stx %g0, [%o0 + 0x00]
  387. stx %g1, [%o0 + 0x08]
  388. stx %g2, [%o0 + 0x10]
  389. stx %g3, [%o0 + 0x18]
  390. stx %g4, [%o0 + 0x20]
  391. stx %g5, [%o0 + 0x28]
  392. stx %g6, [%o0 + 0x30]
  393. stx %g7, [%o0 + 0x38]
  394. wrpr %o1, PSTATE_IG, %pstate
  395. stx %g0, [%o0 + 0x40]
  396. stx %g1, [%o0 + 0x48]
  397. stx %g2, [%o0 + 0x50]
  398. stx %g3, [%o0 + 0x58]
  399. stx %g4, [%o0 + 0x60]
  400. stx %g5, [%o0 + 0x68]
  401. stx %g6, [%o0 + 0x70]
  402. stx %g7, [%o0 + 0x78]
  403. wrpr %o1, PSTATE_MG, %pstate
  404. stx %g0, [%o0 + 0x80]
  405. stx %g1, [%o0 + 0x88]
  406. stx %g2, [%o0 + 0x90]
  407. stx %g3, [%o0 + 0x98]
  408. stx %g4, [%o0 + 0xa0]
  409. stx %g5, [%o0 + 0xa8]
  410. stx %g6, [%o0 + 0xb0]
  411. stx %g7, [%o0 + 0xb8]
  412. wrpr %o5, 0x0, %pstate
  413. retl
  414. nop
  415. .globl restore_alternate_globals
  416. restore_alternate_globals: /* %o0 = save_area */
  417. rdpr %pstate, %o5
  418. andn %o5, PSTATE_IE, %o1
  419. wrpr %o1, PSTATE_AG, %pstate
  420. ldx [%o0 + 0x00], %g0
  421. ldx [%o0 + 0x08], %g1
  422. ldx [%o0 + 0x10], %g2
  423. ldx [%o0 + 0x18], %g3
  424. ldx [%o0 + 0x20], %g4
  425. ldx [%o0 + 0x28], %g5
  426. ldx [%o0 + 0x30], %g6
  427. ldx [%o0 + 0x38], %g7
  428. wrpr %o1, PSTATE_IG, %pstate
  429. ldx [%o0 + 0x40], %g0
  430. ldx [%o0 + 0x48], %g1
  431. ldx [%o0 + 0x50], %g2
  432. ldx [%o0 + 0x58], %g3
  433. ldx [%o0 + 0x60], %g4
  434. ldx [%o0 + 0x68], %g5
  435. ldx [%o0 + 0x70], %g6
  436. ldx [%o0 + 0x78], %g7
  437. wrpr %o1, PSTATE_MG, %pstate
  438. ldx [%o0 + 0x80], %g0
  439. ldx [%o0 + 0x88], %g1
  440. ldx [%o0 + 0x90], %g2
  441. ldx [%o0 + 0x98], %g3
  442. ldx [%o0 + 0xa0], %g4
  443. ldx [%o0 + 0xa8], %g5
  444. ldx [%o0 + 0xb0], %g6
  445. ldx [%o0 + 0xb8], %g7
  446. wrpr %o5, 0x0, %pstate
  447. retl
  448. nop
  449. .globl getcc, setcc
  450. getcc:
  451. ldx [%o0 + PT_V9_TSTATE], %o1
  452. srlx %o1, 32, %o1
  453. and %o1, 0xf, %o1
  454. retl
  455. stx %o1, [%o0 + PT_V9_G1]
  456. setcc:
  457. ldx [%o0 + PT_V9_TSTATE], %o1
  458. ldx [%o0 + PT_V9_G1], %o2
  459. or %g0, %ulo(TSTATE_ICC), %o3
  460. sllx %o3, 32, %o3
  461. andn %o1, %o3, %o1
  462. sllx %o2, 32, %o2
  463. and %o2, %o3, %o2
  464. or %o1, %o2, %o1
  465. retl
  466. stx %o1, [%o0 + PT_V9_TSTATE]
  467. .globl utrap_trap
  468. utrap_trap: /* %g3=handler,%g4=level */
  469. TRAP_LOAD_THREAD_REG
  470. ldx [%g6 + TI_UTRAPS], %g1
  471. brnz,pt %g1, invoke_utrap
  472. nop
  473. ba,pt %xcc, etrap
  474. rd %pc, %g7
  475. mov %l4, %o1
  476. call bad_trap
  477. add %sp, PTREGS_OFF, %o0
  478. ba,pt %xcc, rtrap
  479. clr %l6
  480. invoke_utrap:
  481. sllx %g3, 3, %g3
  482. ldx [%g1 + %g3], %g1
  483. save %sp, -128, %sp
  484. rdpr %tstate, %l6
  485. rdpr %cwp, %l7
  486. andn %l6, TSTATE_CWP, %l6
  487. wrpr %l6, %l7, %tstate
  488. rdpr %tpc, %l6
  489. rdpr %tnpc, %l7
  490. wrpr %g1, 0, %tnpc
  491. done
  492. /* We need to carefully read the error status, ACK
  493. * the errors, prevent recursive traps, and pass the
  494. * information on to C code for logging.
  495. *
  496. * We pass the AFAR in as-is, and we encode the status
  497. * information as described in asm-sparc64/sfafsr.h
  498. */
  499. .globl __spitfire_access_error
  500. __spitfire_access_error:
  501. /* Disable ESTATE error reporting so that we do not
  502. * take recursive traps and RED state the processor.
  503. */
  504. stxa %g0, [%g0] ASI_ESTATE_ERROR_EN
  505. membar #Sync
  506. mov UDBE_UE, %g1
  507. ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
  508. /* __spitfire_cee_trap branches here with AFSR in %g4 and
  509. * UDBE_CE in %g1. It only clears ESTATE_ERR_CE in the
  510. * ESTATE Error Enable register.
  511. */
  512. __spitfire_cee_trap_continue:
  513. ldxa [%g0] ASI_AFAR, %g5 ! Get AFAR
  514. rdpr %tt, %g3
  515. and %g3, 0x1ff, %g3 ! Paranoia
  516. sllx %g3, SFSTAT_TRAP_TYPE_SHIFT, %g3
  517. or %g4, %g3, %g4
  518. rdpr %tl, %g3
  519. cmp %g3, 1
  520. mov 1, %g3
  521. bleu %xcc, 1f
  522. sllx %g3, SFSTAT_TL_GT_ONE_SHIFT, %g3
  523. or %g4, %g3, %g4
  524. /* Read in the UDB error register state, clearing the
  525. * sticky error bits as-needed. We only clear them if
  526. * the UE bit is set. Likewise, __spitfire_cee_trap
  527. * below will only do so if the CE bit is set.
  528. *
  529. * NOTE: UltraSparc-I/II have high and low UDB error
  530. * registers, corresponding to the two UDB units
  531. * present on those chips. UltraSparc-IIi only
  532. * has a single UDB, called "SDB" in the manual.
  533. * For IIi the upper UDB register always reads
  534. * as zero so for our purposes things will just
  535. * work with the checks below.
  536. */
  537. 1: ldxa [%g0] ASI_UDBH_ERROR_R, %g3
  538. and %g3, 0x3ff, %g7 ! Paranoia
  539. sllx %g7, SFSTAT_UDBH_SHIFT, %g7
  540. or %g4, %g7, %g4
  541. andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
  542. be,pn %xcc, 1f
  543. nop
  544. stxa %g3, [%g0] ASI_UDB_ERROR_W
  545. membar #Sync
  546. 1: mov 0x18, %g3
  547. ldxa [%g3] ASI_UDBL_ERROR_R, %g3
  548. and %g3, 0x3ff, %g7 ! Paranoia
  549. sllx %g7, SFSTAT_UDBL_SHIFT, %g7
  550. or %g4, %g7, %g4
  551. andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
  552. be,pn %xcc, 1f
  553. nop
  554. mov 0x18, %g7
  555. stxa %g3, [%g7] ASI_UDB_ERROR_W
  556. membar #Sync
  557. 1: /* Ok, now that we've latched the error state,
  558. * clear the sticky bits in the AFSR.
  559. */
  560. stxa %g4, [%g0] ASI_AFSR
  561. membar #Sync
  562. rdpr %tl, %g2
  563. cmp %g2, 1
  564. rdpr %pil, %g2
  565. bleu,pt %xcc, 1f
  566. wrpr %g0, 15, %pil
  567. ba,pt %xcc, etraptl1
  568. rd %pc, %g7
  569. ba,pt %xcc, 2f
  570. nop
  571. 1: ba,pt %xcc, etrap_irq
  572. rd %pc, %g7
  573. 2: mov %l4, %o1
  574. mov %l5, %o2
  575. call spitfire_access_error
  576. add %sp, PTREGS_OFF, %o0
  577. ba,pt %xcc, rtrap
  578. clr %l6
  579. /* This is the trap handler entry point for ECC correctable
  580. * errors. They are corrected, but we listen for the trap
  581. * so that the event can be logged.
  582. *
  583. * Disrupting errors are either:
  584. * 1) single-bit ECC errors during UDB reads to system
  585. * memory
  586. * 2) data parity errors during write-back events
  587. *
  588. * As far as I can make out from the manual, the CEE trap
  589. * is only for correctable errors during memory read
  590. * accesses by the front-end of the processor.
  591. *
  592. * The code below is only for trap level 1 CEE events,
  593. * as it is the only situation where we can safely record
  594. * and log. For trap level >1 we just clear the CE bit
  595. * in the AFSR and return.
  596. *
  597. * This is just like __spiftire_access_error above, but it
  598. * specifically handles correctable errors. If an
  599. * uncorrectable error is indicated in the AFSR we
  600. * will branch directly above to __spitfire_access_error
  601. * to handle it instead. Uncorrectable therefore takes
  602. * priority over correctable, and the error logging
  603. * C code will notice this case by inspecting the
  604. * trap type.
  605. */
  606. .globl __spitfire_cee_trap
  607. __spitfire_cee_trap:
  608. ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
  609. mov 1, %g3
  610. sllx %g3, SFAFSR_UE_SHIFT, %g3
  611. andcc %g4, %g3, %g0 ! Check for UE
  612. bne,pn %xcc, __spitfire_access_error
  613. nop
  614. /* Ok, in this case we only have a correctable error.
  615. * Indicate we only wish to capture that state in register
  616. * %g1, and we only disable CE error reporting unlike UE
  617. * handling which disables all errors.
  618. */
  619. ldxa [%g0] ASI_ESTATE_ERROR_EN, %g3
  620. andn %g3, ESTATE_ERR_CE, %g3
  621. stxa %g3, [%g0] ASI_ESTATE_ERROR_EN
  622. membar #Sync
  623. /* Preserve AFSR in %g4, indicate UDB state to capture in %g1 */
  624. ba,pt %xcc, __spitfire_cee_trap_continue
  625. mov UDBE_CE, %g1
  626. .globl __spitfire_data_access_exception
  627. .globl __spitfire_data_access_exception_tl1
  628. __spitfire_data_access_exception_tl1:
  629. rdpr %pstate, %g4
  630. wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
  631. mov TLB_SFSR, %g3
  632. mov DMMU_SFAR, %g5
  633. ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
  634. ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
  635. stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
  636. membar #Sync
  637. rdpr %tt, %g3
  638. cmp %g3, 0x80 ! first win spill/fill trap
  639. blu,pn %xcc, 1f
  640. cmp %g3, 0xff ! last win spill/fill trap
  641. bgu,pn %xcc, 1f
  642. nop
  643. ba,pt %xcc, winfix_dax
  644. rdpr %tpc, %g3
  645. 1: sethi %hi(109f), %g7
  646. ba,pt %xcc, etraptl1
  647. 109: or %g7, %lo(109b), %g7
  648. mov %l4, %o1
  649. mov %l5, %o2
  650. call spitfire_data_access_exception_tl1
  651. add %sp, PTREGS_OFF, %o0
  652. ba,pt %xcc, rtrap
  653. clr %l6
  654. __spitfire_data_access_exception:
  655. rdpr %pstate, %g4
  656. wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
  657. mov TLB_SFSR, %g3
  658. mov DMMU_SFAR, %g5
  659. ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
  660. ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
  661. stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
  662. membar #Sync
  663. sethi %hi(109f), %g7
  664. ba,pt %xcc, etrap
  665. 109: or %g7, %lo(109b), %g7
  666. mov %l4, %o1
  667. mov %l5, %o2
  668. call spitfire_data_access_exception
  669. add %sp, PTREGS_OFF, %o0
  670. ba,pt %xcc, rtrap
  671. clr %l6
  672. .globl __spitfire_insn_access_exception
  673. .globl __spitfire_insn_access_exception_tl1
  674. __spitfire_insn_access_exception_tl1:
  675. rdpr %pstate, %g4
  676. wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
  677. mov TLB_SFSR, %g3
  678. ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
  679. rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
  680. stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
  681. membar #Sync
  682. sethi %hi(109f), %g7
  683. ba,pt %xcc, etraptl1
  684. 109: or %g7, %lo(109b), %g7
  685. mov %l4, %o1
  686. mov %l5, %o2
  687. call spitfire_insn_access_exception_tl1
  688. add %sp, PTREGS_OFF, %o0
  689. ba,pt %xcc, rtrap
  690. clr %l6
  691. __spitfire_insn_access_exception:
  692. rdpr %pstate, %g4
  693. wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
  694. mov TLB_SFSR, %g3
  695. ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
  696. rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
  697. stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
  698. membar #Sync
  699. sethi %hi(109f), %g7
  700. ba,pt %xcc, etrap
  701. 109: or %g7, %lo(109b), %g7
  702. mov %l4, %o1
  703. mov %l5, %o2
  704. call spitfire_insn_access_exception
  705. add %sp, PTREGS_OFF, %o0
  706. ba,pt %xcc, rtrap
  707. clr %l6
  708. /* These get patched into the trap table at boot time
  709. * once we know we have a cheetah processor.
  710. */
  711. .globl cheetah_fecc_trap_vector, cheetah_fecc_trap_vector_tl1
  712. cheetah_fecc_trap_vector:
  713. membar #Sync
  714. ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
  715. andn %g1, DCU_DC | DCU_IC, %g1
  716. stxa %g1, [%g0] ASI_DCU_CONTROL_REG
  717. membar #Sync
  718. sethi %hi(cheetah_fast_ecc), %g2
  719. jmpl %g2 + %lo(cheetah_fast_ecc), %g0
  720. mov 0, %g1
  721. cheetah_fecc_trap_vector_tl1:
  722. membar #Sync
  723. ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
  724. andn %g1, DCU_DC | DCU_IC, %g1
  725. stxa %g1, [%g0] ASI_DCU_CONTROL_REG
  726. membar #Sync
  727. sethi %hi(cheetah_fast_ecc), %g2
  728. jmpl %g2 + %lo(cheetah_fast_ecc), %g0
  729. mov 1, %g1
  730. .globl cheetah_cee_trap_vector, cheetah_cee_trap_vector_tl1
  731. cheetah_cee_trap_vector:
  732. membar #Sync
  733. ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
  734. andn %g1, DCU_IC, %g1
  735. stxa %g1, [%g0] ASI_DCU_CONTROL_REG
  736. membar #Sync
  737. sethi %hi(cheetah_cee), %g2
  738. jmpl %g2 + %lo(cheetah_cee), %g0
  739. mov 0, %g1
  740. cheetah_cee_trap_vector_tl1:
  741. membar #Sync
  742. ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
  743. andn %g1, DCU_IC, %g1
  744. stxa %g1, [%g0] ASI_DCU_CONTROL_REG
  745. membar #Sync
  746. sethi %hi(cheetah_cee), %g2
  747. jmpl %g2 + %lo(cheetah_cee), %g0
  748. mov 1, %g1
  749. .globl cheetah_deferred_trap_vector, cheetah_deferred_trap_vector_tl1
  750. cheetah_deferred_trap_vector:
  751. membar #Sync
  752. ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
  753. andn %g1, DCU_DC | DCU_IC, %g1;
  754. stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
  755. membar #Sync;
  756. sethi %hi(cheetah_deferred_trap), %g2
  757. jmpl %g2 + %lo(cheetah_deferred_trap), %g0
  758. mov 0, %g1
  759. cheetah_deferred_trap_vector_tl1:
  760. membar #Sync;
  761. ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
  762. andn %g1, DCU_DC | DCU_IC, %g1;
  763. stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
  764. membar #Sync;
  765. sethi %hi(cheetah_deferred_trap), %g2
  766. jmpl %g2 + %lo(cheetah_deferred_trap), %g0
  767. mov 1, %g1
  768. /* Cheetah+ specific traps. These are for the new I/D cache parity
  769. * error traps. The first argument to cheetah_plus_parity_handler
  770. * is encoded as follows:
  771. *
  772. * Bit0: 0=dcache,1=icache
  773. * Bit1: 0=recoverable,1=unrecoverable
  774. */
  775. .globl cheetah_plus_dcpe_trap_vector, cheetah_plus_dcpe_trap_vector_tl1
  776. cheetah_plus_dcpe_trap_vector:
  777. membar #Sync
  778. sethi %hi(do_cheetah_plus_data_parity), %g7
  779. jmpl %g7 + %lo(do_cheetah_plus_data_parity), %g0
  780. nop
  781. nop
  782. nop
  783. nop
  784. nop
  785. do_cheetah_plus_data_parity:
  786. rdpr %pil, %g2
  787. wrpr %g0, 15, %pil
  788. ba,pt %xcc, etrap_irq
  789. rd %pc, %g7
  790. mov 0x0, %o0
  791. call cheetah_plus_parity_error
  792. add %sp, PTREGS_OFF, %o1
  793. ba,a,pt %xcc, rtrap_irq
  794. cheetah_plus_dcpe_trap_vector_tl1:
  795. membar #Sync
  796. wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
  797. sethi %hi(do_dcpe_tl1), %g3
  798. jmpl %g3 + %lo(do_dcpe_tl1), %g0
  799. nop
  800. nop
  801. nop
  802. nop
  803. .globl cheetah_plus_icpe_trap_vector, cheetah_plus_icpe_trap_vector_tl1
  804. cheetah_plus_icpe_trap_vector:
  805. membar #Sync
  806. sethi %hi(do_cheetah_plus_insn_parity), %g7
  807. jmpl %g7 + %lo(do_cheetah_plus_insn_parity), %g0
  808. nop
  809. nop
  810. nop
  811. nop
  812. nop
  813. do_cheetah_plus_insn_parity:
  814. rdpr %pil, %g2
  815. wrpr %g0, 15, %pil
  816. ba,pt %xcc, etrap_irq
  817. rd %pc, %g7
  818. mov 0x1, %o0
  819. call cheetah_plus_parity_error
  820. add %sp, PTREGS_OFF, %o1
  821. ba,a,pt %xcc, rtrap_irq
  822. cheetah_plus_icpe_trap_vector_tl1:
  823. membar #Sync
  824. wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
  825. sethi %hi(do_icpe_tl1), %g3
  826. jmpl %g3 + %lo(do_icpe_tl1), %g0
  827. nop
  828. nop
  829. nop
  830. nop
  831. /* If we take one of these traps when tl >= 1, then we
  832. * jump to interrupt globals. If some trap level above us
  833. * was also using interrupt globals, we cannot recover.
  834. * We may use all interrupt global registers except %g6.
  835. */
  836. .globl do_dcpe_tl1, do_icpe_tl1
  837. do_dcpe_tl1:
  838. rdpr %tl, %g1 ! Save original trap level
  839. mov 1, %g2 ! Setup TSTATE checking loop
  840. sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
  841. 1: wrpr %g2, %tl ! Set trap level to check
  842. rdpr %tstate, %g4 ! Read TSTATE for this level
  843. andcc %g4, %g3, %g0 ! Interrupt globals in use?
  844. bne,a,pn %xcc, do_dcpe_tl1_fatal ! Yep, irrecoverable
  845. wrpr %g1, %tl ! Restore original trap level
  846. add %g2, 1, %g2 ! Next trap level
  847. cmp %g2, %g1 ! Hit them all yet?
  848. ble,pt %icc, 1b ! Not yet
  849. nop
  850. wrpr %g1, %tl ! Restore original trap level
  851. do_dcpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
  852. sethi %hi(dcache_parity_tl1_occurred), %g2
  853. lduw [%g2 + %lo(dcache_parity_tl1_occurred)], %g1
  854. add %g1, 1, %g1
  855. stw %g1, [%g2 + %lo(dcache_parity_tl1_occurred)]
  856. /* Reset D-cache parity */
  857. sethi %hi(1 << 16), %g1 ! D-cache size
  858. mov (1 << 5), %g2 ! D-cache line size
  859. sub %g1, %g2, %g1 ! Move down 1 cacheline
  860. 1: srl %g1, 14, %g3 ! Compute UTAG
  861. membar #Sync
  862. stxa %g3, [%g1] ASI_DCACHE_UTAG
  863. membar #Sync
  864. sub %g2, 8, %g3 ! 64-bit data word within line
  865. 2: membar #Sync
  866. stxa %g0, [%g1 + %g3] ASI_DCACHE_DATA
  867. membar #Sync
  868. subcc %g3, 8, %g3 ! Next 64-bit data word
  869. bge,pt %icc, 2b
  870. nop
  871. subcc %g1, %g2, %g1 ! Next cacheline
  872. bge,pt %icc, 1b
  873. nop
  874. ba,pt %xcc, dcpe_icpe_tl1_common
  875. nop
  876. do_dcpe_tl1_fatal:
  877. sethi %hi(1f), %g7
  878. ba,pt %xcc, etraptl1
  879. 1: or %g7, %lo(1b), %g7
  880. mov 0x2, %o0
  881. call cheetah_plus_parity_error
  882. add %sp, PTREGS_OFF, %o1
  883. ba,pt %xcc, rtrap
  884. clr %l6
  885. do_icpe_tl1:
  886. rdpr %tl, %g1 ! Save original trap level
  887. mov 1, %g2 ! Setup TSTATE checking loop
  888. sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
  889. 1: wrpr %g2, %tl ! Set trap level to check
  890. rdpr %tstate, %g4 ! Read TSTATE for this level
  891. andcc %g4, %g3, %g0 ! Interrupt globals in use?
  892. bne,a,pn %xcc, do_icpe_tl1_fatal ! Yep, irrecoverable
  893. wrpr %g1, %tl ! Restore original trap level
  894. add %g2, 1, %g2 ! Next trap level
  895. cmp %g2, %g1 ! Hit them all yet?
  896. ble,pt %icc, 1b ! Not yet
  897. nop
  898. wrpr %g1, %tl ! Restore original trap level
  899. do_icpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
  900. sethi %hi(icache_parity_tl1_occurred), %g2
  901. lduw [%g2 + %lo(icache_parity_tl1_occurred)], %g1
  902. add %g1, 1, %g1
  903. stw %g1, [%g2 + %lo(icache_parity_tl1_occurred)]
  904. /* Flush I-cache */
  905. sethi %hi(1 << 15), %g1 ! I-cache size
  906. mov (1 << 5), %g2 ! I-cache line size
  907. sub %g1, %g2, %g1
  908. 1: or %g1, (2 << 3), %g3
  909. stxa %g0, [%g3] ASI_IC_TAG
  910. membar #Sync
  911. subcc %g1, %g2, %g1
  912. bge,pt %icc, 1b
  913. nop
  914. ba,pt %xcc, dcpe_icpe_tl1_common
  915. nop
  916. do_icpe_tl1_fatal:
  917. sethi %hi(1f), %g7
  918. ba,pt %xcc, etraptl1
  919. 1: or %g7, %lo(1b), %g7
  920. mov 0x3, %o0
  921. call cheetah_plus_parity_error
  922. add %sp, PTREGS_OFF, %o1
  923. ba,pt %xcc, rtrap
  924. clr %l6
  925. dcpe_icpe_tl1_common:
  926. /* Flush D-cache, re-enable D/I caches in DCU and finally
  927. * retry the trapping instruction.
  928. */
  929. sethi %hi(1 << 16), %g1 ! D-cache size
  930. mov (1 << 5), %g2 ! D-cache line size
  931. sub %g1, %g2, %g1
  932. 1: stxa %g0, [%g1] ASI_DCACHE_TAG
  933. membar #Sync
  934. subcc %g1, %g2, %g1
  935. bge,pt %icc, 1b
  936. nop
  937. ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
  938. or %g1, (DCU_DC | DCU_IC), %g1
  939. stxa %g1, [%g0] ASI_DCU_CONTROL_REG
  940. membar #Sync
  941. retry
  942. /* Capture I/D/E-cache state into per-cpu error scoreboard.
  943. *
  944. * %g1: (TL>=0) ? 1 : 0
  945. * %g2: scratch
  946. * %g3: scratch
  947. * %g4: AFSR
  948. * %g5: AFAR
  949. * %g6: unused, will have current thread ptr after etrap
  950. * %g7: scratch
  951. */
  952. __cheetah_log_error:
  953. /* Put "TL1" software bit into AFSR. */
  954. and %g1, 0x1, %g1
  955. sllx %g1, 63, %g2
  956. or %g4, %g2, %g4
  957. /* Get log entry pointer for this cpu at this trap level. */
  958. BRANCH_IF_JALAPENO(g2,g3,50f)
  959. ldxa [%g0] ASI_SAFARI_CONFIG, %g2
  960. srlx %g2, 17, %g2
  961. ba,pt %xcc, 60f
  962. and %g2, 0x3ff, %g2
  963. 50: ldxa [%g0] ASI_JBUS_CONFIG, %g2
  964. srlx %g2, 17, %g2
  965. and %g2, 0x1f, %g2
  966. 60: sllx %g2, 9, %g2
  967. sethi %hi(cheetah_error_log), %g3
  968. ldx [%g3 + %lo(cheetah_error_log)], %g3
  969. brz,pn %g3, 80f
  970. nop
  971. add %g3, %g2, %g3
  972. sllx %g1, 8, %g1
  973. add %g3, %g1, %g1
  974. /* %g1 holds pointer to the top of the logging scoreboard */
  975. ldx [%g1 + 0x0], %g7
  976. cmp %g7, -1
  977. bne,pn %xcc, 80f
  978. nop
  979. stx %g4, [%g1 + 0x0]
  980. stx %g5, [%g1 + 0x8]
  981. add %g1, 0x10, %g1
  982. /* %g1 now points to D-cache logging area */
  983. set 0x3ff8, %g2 /* DC_addr mask */
  984. and %g5, %g2, %g2 /* DC_addr bits of AFAR */
  985. srlx %g5, 12, %g3
  986. or %g3, 1, %g3 /* PHYS tag + valid */
  987. 10: ldxa [%g2] ASI_DCACHE_TAG, %g7
  988. cmp %g3, %g7 /* TAG match? */
  989. bne,pt %xcc, 13f
  990. nop
  991. /* Yep, what we want, capture state. */
  992. stx %g2, [%g1 + 0x20]
  993. stx %g7, [%g1 + 0x28]
  994. /* A membar Sync is required before and after utag access. */
  995. membar #Sync
  996. ldxa [%g2] ASI_DCACHE_UTAG, %g7
  997. membar #Sync
  998. stx %g7, [%g1 + 0x30]
  999. ldxa [%g2] ASI_DCACHE_SNOOP_TAG, %g7
  1000. stx %g7, [%g1 + 0x38]
  1001. clr %g3
  1002. 12: ldxa [%g2 + %g3] ASI_DCACHE_DATA, %g7
  1003. stx %g7, [%g1]
  1004. add %g3, (1 << 5), %g3
  1005. cmp %g3, (4 << 5)
  1006. bl,pt %xcc, 12b
  1007. add %g1, 0x8, %g1
  1008. ba,pt %xcc, 20f
  1009. add %g1, 0x20, %g1
  1010. 13: sethi %hi(1 << 14), %g7
  1011. add %g2, %g7, %g2
  1012. srlx %g2, 14, %g7
  1013. cmp %g7, 4
  1014. bl,pt %xcc, 10b
  1015. nop
  1016. add %g1, 0x40, %g1
  1017. /* %g1 now points to I-cache logging area */
  1018. 20: set 0x1fe0, %g2 /* IC_addr mask */
  1019. and %g5, %g2, %g2 /* IC_addr bits of AFAR */
  1020. sllx %g2, 1, %g2 /* IC_addr[13:6]==VA[12:5] */
  1021. srlx %g5, (13 - 8), %g3 /* Make PTAG */
  1022. andn %g3, 0xff, %g3 /* Mask off undefined bits */
  1023. 21: ldxa [%g2] ASI_IC_TAG, %g7
  1024. andn %g7, 0xff, %g7
  1025. cmp %g3, %g7
  1026. bne,pt %xcc, 23f
  1027. nop
  1028. /* Yep, what we want, capture state. */
  1029. stx %g2, [%g1 + 0x40]
  1030. stx %g7, [%g1 + 0x48]
  1031. add %g2, (1 << 3), %g2
  1032. ldxa [%g2] ASI_IC_TAG, %g7
  1033. add %g2, (1 << 3), %g2
  1034. stx %g7, [%g1 + 0x50]
  1035. ldxa [%g2] ASI_IC_TAG, %g7
  1036. add %g2, (1 << 3), %g2
  1037. stx %g7, [%g1 + 0x60]
  1038. ldxa [%g2] ASI_IC_TAG, %g7
  1039. stx %g7, [%g1 + 0x68]
  1040. sub %g2, (3 << 3), %g2
  1041. ldxa [%g2] ASI_IC_STAG, %g7
  1042. stx %g7, [%g1 + 0x58]
  1043. clr %g3
  1044. srlx %g2, 2, %g2
  1045. 22: ldxa [%g2 + %g3] ASI_IC_INSTR, %g7
  1046. stx %g7, [%g1]
  1047. add %g3, (1 << 3), %g3
  1048. cmp %g3, (8 << 3)
  1049. bl,pt %xcc, 22b
  1050. add %g1, 0x8, %g1
  1051. ba,pt %xcc, 30f
  1052. add %g1, 0x30, %g1
  1053. 23: sethi %hi(1 << 14), %g7
  1054. add %g2, %g7, %g2
  1055. srlx %g2, 14, %g7
  1056. cmp %g7, 4
  1057. bl,pt %xcc, 21b
  1058. nop
  1059. add %g1, 0x70, %g1
  1060. /* %g1 now points to E-cache logging area */
  1061. 30: andn %g5, (32 - 1), %g2
  1062. stx %g2, [%g1 + 0x20]
  1063. ldxa [%g2] ASI_EC_TAG_DATA, %g7
  1064. stx %g7, [%g1 + 0x28]
  1065. ldxa [%g2] ASI_EC_R, %g0
  1066. clr %g3
  1067. 31: ldxa [%g3] ASI_EC_DATA, %g7
  1068. stx %g7, [%g1 + %g3]
  1069. add %g3, 0x8, %g3
  1070. cmp %g3, 0x20
  1071. bl,pt %xcc, 31b
  1072. nop
  1073. 80:
  1074. rdpr %tt, %g2
  1075. cmp %g2, 0x70
  1076. be c_fast_ecc
  1077. cmp %g2, 0x63
  1078. be c_cee
  1079. nop
  1080. ba,pt %xcc, c_deferred
  1081. /* Cheetah FECC trap handling, we get here from tl{0,1}_fecc
  1082. * in the trap table. That code has done a memory barrier
  1083. * and has disabled both the I-cache and D-cache in the DCU
  1084. * control register. The I-cache is disabled so that we may
  1085. * capture the corrupted cache line, and the D-cache is disabled
  1086. * because corrupt data may have been placed there and we don't
  1087. * want to reference it.
  1088. *
  1089. * %g1 is one if this trap occurred at %tl >= 1.
  1090. *
  1091. * Next, we turn off error reporting so that we don't recurse.
  1092. */
  1093. .globl cheetah_fast_ecc
  1094. cheetah_fast_ecc:
  1095. ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
  1096. andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
  1097. stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
  1098. membar #Sync
  1099. /* Fetch and clear AFSR/AFAR */
  1100. ldxa [%g0] ASI_AFSR, %g4
  1101. ldxa [%g0] ASI_AFAR, %g5
  1102. stxa %g4, [%g0] ASI_AFSR
  1103. membar #Sync
  1104. ba,pt %xcc, __cheetah_log_error
  1105. nop
  1106. c_fast_ecc:
  1107. rdpr %pil, %g2
  1108. wrpr %g0, 15, %pil
  1109. ba,pt %xcc, etrap_irq
  1110. rd %pc, %g7
  1111. mov %l4, %o1
  1112. mov %l5, %o2
  1113. call cheetah_fecc_handler
  1114. add %sp, PTREGS_OFF, %o0
  1115. ba,a,pt %xcc, rtrap_irq
  1116. /* Our caller has disabled I-cache and performed membar Sync. */
  1117. .globl cheetah_cee
  1118. cheetah_cee:
  1119. ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
  1120. andn %g2, ESTATE_ERROR_CEEN, %g2
  1121. stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
  1122. membar #Sync
  1123. /* Fetch and clear AFSR/AFAR */
  1124. ldxa [%g0] ASI_AFSR, %g4
  1125. ldxa [%g0] ASI_AFAR, %g5
  1126. stxa %g4, [%g0] ASI_AFSR
  1127. membar #Sync
  1128. ba,pt %xcc, __cheetah_log_error
  1129. nop
  1130. c_cee:
  1131. rdpr %pil, %g2
  1132. wrpr %g0, 15, %pil
  1133. ba,pt %xcc, etrap_irq
  1134. rd %pc, %g7
  1135. mov %l4, %o1
  1136. mov %l5, %o2
  1137. call cheetah_cee_handler
  1138. add %sp, PTREGS_OFF, %o0
  1139. ba,a,pt %xcc, rtrap_irq
  1140. /* Our caller has disabled I-cache+D-cache and performed membar Sync. */
  1141. .globl cheetah_deferred_trap
  1142. cheetah_deferred_trap:
  1143. ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
  1144. andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
  1145. stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
  1146. membar #Sync
  1147. /* Fetch and clear AFSR/AFAR */
  1148. ldxa [%g0] ASI_AFSR, %g4
  1149. ldxa [%g0] ASI_AFAR, %g5
  1150. stxa %g4, [%g0] ASI_AFSR
  1151. membar #Sync
  1152. ba,pt %xcc, __cheetah_log_error
  1153. nop
  1154. c_deferred:
  1155. rdpr %pil, %g2
  1156. wrpr %g0, 15, %pil
  1157. ba,pt %xcc, etrap_irq
  1158. rd %pc, %g7
  1159. mov %l4, %o1
  1160. mov %l5, %o2
  1161. call cheetah_deferred_handler
  1162. add %sp, PTREGS_OFF, %o0
  1163. ba,a,pt %xcc, rtrap_irq
  1164. .globl __do_privact
  1165. __do_privact:
  1166. mov TLB_SFSR, %g3
  1167. stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
  1168. membar #Sync
  1169. sethi %hi(109f), %g7
  1170. ba,pt %xcc, etrap
  1171. 109: or %g7, %lo(109b), %g7
  1172. call do_privact
  1173. add %sp, PTREGS_OFF, %o0
  1174. ba,pt %xcc, rtrap
  1175. clr %l6
  1176. .globl do_mna
  1177. do_mna:
  1178. rdpr %tl, %g3
  1179. cmp %g3, 1
  1180. /* Setup %g4/%g5 now as they are used in the
  1181. * winfixup code.
  1182. */
  1183. mov TLB_SFSR, %g3
  1184. mov DMMU_SFAR, %g4
  1185. ldxa [%g4] ASI_DMMU, %g4
  1186. ldxa [%g3] ASI_DMMU, %g5
  1187. stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
  1188. membar #Sync
  1189. bgu,pn %icc, winfix_mna
  1190. rdpr %tpc, %g3
  1191. 1: sethi %hi(109f), %g7
  1192. ba,pt %xcc, etrap
  1193. 109: or %g7, %lo(109b), %g7
  1194. mov %l4, %o1
  1195. mov %l5, %o2
  1196. call mem_address_unaligned
  1197. add %sp, PTREGS_OFF, %o0
  1198. ba,pt %xcc, rtrap
  1199. clr %l6
  1200. .globl do_lddfmna
  1201. do_lddfmna:
  1202. sethi %hi(109f), %g7
  1203. mov TLB_SFSR, %g4
  1204. ldxa [%g4] ASI_DMMU, %g5
  1205. stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
  1206. membar #Sync
  1207. mov DMMU_SFAR, %g4
  1208. ldxa [%g4] ASI_DMMU, %g4
  1209. ba,pt %xcc, etrap
  1210. 109: or %g7, %lo(109b), %g7
  1211. mov %l4, %o1
  1212. mov %l5, %o2
  1213. call handle_lddfmna
  1214. add %sp, PTREGS_OFF, %o0
  1215. ba,pt %xcc, rtrap
  1216. clr %l6
  1217. .globl do_stdfmna
  1218. do_stdfmna:
  1219. sethi %hi(109f), %g7
  1220. mov TLB_SFSR, %g4
  1221. ldxa [%g4] ASI_DMMU, %g5
  1222. stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
  1223. membar #Sync
  1224. mov DMMU_SFAR, %g4
  1225. ldxa [%g4] ASI_DMMU, %g4
  1226. ba,pt %xcc, etrap
  1227. 109: or %g7, %lo(109b), %g7
  1228. mov %l4, %o1
  1229. mov %l5, %o2
  1230. call handle_stdfmna
  1231. add %sp, PTREGS_OFF, %o0
  1232. ba,pt %xcc, rtrap
  1233. clr %l6
  1234. .globl breakpoint_trap
  1235. breakpoint_trap:
  1236. call sparc_breakpoint
  1237. add %sp, PTREGS_OFF, %o0
  1238. ba,pt %xcc, rtrap
  1239. nop
  1240. #if defined(CONFIG_SUNOS_EMUL) || defined(CONFIG_SOLARIS_EMUL) || \
  1241. defined(CONFIG_SOLARIS_EMUL_MODULE)
  1242. /* SunOS uses syscall zero as the 'indirect syscall' it looks
  1243. * like indir_syscall(scall_num, arg0, arg1, arg2...); etc.
  1244. * This is complete brain damage.
  1245. */
  1246. .globl sunos_indir
  1247. sunos_indir:
  1248. srl %o0, 0, %o0
  1249. mov %o7, %l4
  1250. cmp %o0, NR_SYSCALLS
  1251. blu,a,pt %icc, 1f
  1252. sll %o0, 0x2, %o0
  1253. sethi %hi(sunos_nosys), %l6
  1254. b,pt %xcc, 2f
  1255. or %l6, %lo(sunos_nosys), %l6
  1256. 1: sethi %hi(sunos_sys_table), %l7
  1257. or %l7, %lo(sunos_sys_table), %l7
  1258. lduw [%l7 + %o0], %l6
  1259. 2: mov %o1, %o0
  1260. mov %o2, %o1
  1261. mov %o3, %o2
  1262. mov %o4, %o3
  1263. mov %o5, %o4
  1264. call %l6
  1265. mov %l4, %o7
  1266. .globl sunos_getpid
  1267. sunos_getpid:
  1268. call sys_getppid
  1269. nop
  1270. call sys_getpid
  1271. stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
  1272. b,pt %xcc, ret_sys_call
  1273. stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  1274. /* SunOS getuid() returns uid in %o0 and euid in %o1 */
  1275. .globl sunos_getuid
  1276. sunos_getuid:
  1277. call sys32_geteuid16
  1278. nop
  1279. call sys32_getuid16
  1280. stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
  1281. b,pt %xcc, ret_sys_call
  1282. stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  1283. /* SunOS getgid() returns gid in %o0 and egid in %o1 */
  1284. .globl sunos_getgid
  1285. sunos_getgid:
  1286. call sys32_getegid16
  1287. nop
  1288. call sys32_getgid16
  1289. stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
  1290. b,pt %xcc, ret_sys_call
  1291. stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  1292. #endif
  1293. /* SunOS's execv() call only specifies the argv argument, the
  1294. * environment settings are the same as the calling processes.
  1295. */
  1296. .globl sunos_execv
  1297. sys_execve:
  1298. sethi %hi(sparc_execve), %g1
  1299. ba,pt %xcc, execve_merge
  1300. or %g1, %lo(sparc_execve), %g1
  1301. #ifdef CONFIG_COMPAT
  1302. .globl sys_execve
  1303. sunos_execv:
  1304. stx %g0, [%sp + PTREGS_OFF + PT_V9_I2]
  1305. .globl sys32_execve
  1306. sys32_execve:
  1307. sethi %hi(sparc32_execve), %g1
  1308. or %g1, %lo(sparc32_execve), %g1
  1309. #endif
  1310. execve_merge:
  1311. flushw
  1312. jmpl %g1, %g0
  1313. add %sp, PTREGS_OFF, %o0
  1314. .globl sys_pipe, sys_sigpause, sys_nis_syscall
  1315. .globl sys_rt_sigreturn
  1316. .globl sys_ptrace
  1317. .globl sys_sigaltstack
  1318. .align 32
  1319. sys_pipe: ba,pt %xcc, sparc_pipe
  1320. add %sp, PTREGS_OFF, %o0
  1321. sys_nis_syscall:ba,pt %xcc, c_sys_nis_syscall
  1322. add %sp, PTREGS_OFF, %o0
  1323. sys_memory_ordering:
  1324. ba,pt %xcc, sparc_memory_ordering
  1325. add %sp, PTREGS_OFF, %o1
  1326. sys_sigaltstack:ba,pt %xcc, do_sigaltstack
  1327. add %i6, STACK_BIAS, %o2
  1328. #ifdef CONFIG_COMPAT
  1329. .globl sys32_sigstack
  1330. sys32_sigstack: ba,pt %xcc, do_sys32_sigstack
  1331. mov %i6, %o2
  1332. .globl sys32_sigaltstack
  1333. sys32_sigaltstack:
  1334. ba,pt %xcc, do_sys32_sigaltstack
  1335. mov %i6, %o2
  1336. #endif
  1337. .align 32
  1338. #ifdef CONFIG_COMPAT
  1339. .globl sys32_sigreturn
  1340. sys32_sigreturn:
  1341. add %sp, PTREGS_OFF, %o0
  1342. call do_sigreturn32
  1343. add %o7, 1f-.-4, %o7
  1344. nop
  1345. #endif
  1346. sys_rt_sigreturn:
  1347. add %sp, PTREGS_OFF, %o0
  1348. call do_rt_sigreturn
  1349. add %o7, 1f-.-4, %o7
  1350. nop
  1351. #ifdef CONFIG_COMPAT
  1352. .globl sys32_rt_sigreturn
  1353. sys32_rt_sigreturn:
  1354. add %sp, PTREGS_OFF, %o0
  1355. call do_rt_sigreturn32
  1356. add %o7, 1f-.-4, %o7
  1357. nop
  1358. #endif
  1359. sys_ptrace: add %sp, PTREGS_OFF, %o0
  1360. call do_ptrace
  1361. add %o7, 1f-.-4, %o7
  1362. nop
  1363. .align 32
  1364. 1: ldx [%curptr + TI_FLAGS], %l5
  1365. andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
  1366. be,pt %icc, rtrap
  1367. clr %l6
  1368. add %sp, PTREGS_OFF, %o0
  1369. call syscall_trace
  1370. mov 1, %o1
  1371. ba,pt %xcc, rtrap
  1372. clr %l6
  1373. /* This is how fork() was meant to be done, 8 instruction entry.
  1374. *
  1375. * I questioned the following code briefly, let me clear things
  1376. * up so you must not reason on it like I did.
  1377. *
  1378. * Know the fork_kpsr etc. we use in the sparc32 port? We don't
  1379. * need it here because the only piece of window state we copy to
  1380. * the child is the CWP register. Even if the parent sleeps,
  1381. * we are safe because we stuck it into pt_regs of the parent
  1382. * so it will not change.
  1383. *
  1384. * XXX This raises the question, whether we can do the same on
  1385. * XXX sparc32 to get rid of fork_kpsr _and_ fork_kwim. The
  1386. * XXX answer is yes. We stick fork_kpsr in UREG_G0 and
  1387. * XXX fork_kwim in UREG_G1 (global registers are considered
  1388. * XXX volatile across a system call in the sparc ABI I think
  1389. * XXX if it isn't we can use regs->y instead, anyone who depends
  1390. * XXX upon the Y register being preserved across a fork deserves
  1391. * XXX to lose).
  1392. *
  1393. * In fact we should take advantage of that fact for other things
  1394. * during system calls...
  1395. */
  1396. .globl sys_fork, sys_vfork, sys_clone, sparc_exit
  1397. .globl ret_from_syscall
  1398. .align 32
  1399. sys_vfork: /* Under Linux, vfork and fork are just special cases of clone. */
  1400. sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
  1401. or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
  1402. ba,pt %xcc, sys_clone
  1403. sys_fork: clr %o1
  1404. mov SIGCHLD, %o0
  1405. sys_clone: flushw
  1406. movrz %o1, %fp, %o1
  1407. mov 0, %o3
  1408. ba,pt %xcc, sparc_do_fork
  1409. add %sp, PTREGS_OFF, %o2
  1410. ret_from_syscall:
  1411. /* Clear current_thread_info()->new_child, and
  1412. * check performance counter stuff too.
  1413. */
  1414. stb %g0, [%g6 + TI_NEW_CHILD]
  1415. ldx [%g6 + TI_FLAGS], %l0
  1416. call schedule_tail
  1417. mov %g7, %o0
  1418. andcc %l0, _TIF_PERFCTR, %g0
  1419. be,pt %icc, 1f
  1420. nop
  1421. ldx [%g6 + TI_PCR], %o7
  1422. wr %g0, %o7, %pcr
  1423. /* Blackbird errata workaround. See commentary in
  1424. * smp.c:smp_percpu_timer_interrupt() for more
  1425. * information.
  1426. */
  1427. ba,pt %xcc, 99f
  1428. nop
  1429. .align 64
  1430. 99: wr %g0, %g0, %pic
  1431. rd %pic, %g0
  1432. 1: b,pt %xcc, ret_sys_call
  1433. ldx [%sp + PTREGS_OFF + PT_V9_I0], %o0
  1434. sparc_exit: wrpr %g0, (PSTATE_RMO | PSTATE_PEF | PSTATE_PRIV), %pstate
  1435. rdpr %otherwin, %g1
  1436. rdpr %cansave, %g3
  1437. add %g3, %g1, %g3
  1438. wrpr %g3, 0x0, %cansave
  1439. wrpr %g0, 0x0, %otherwin
  1440. wrpr %g0, (PSTATE_RMO | PSTATE_PEF | PSTATE_PRIV | PSTATE_IE), %pstate
  1441. ba,pt %xcc, sys_exit
  1442. stb %g0, [%g6 + TI_WSAVED]
  1443. linux_sparc_ni_syscall:
  1444. sethi %hi(sys_ni_syscall), %l7
  1445. b,pt %xcc, 4f
  1446. or %l7, %lo(sys_ni_syscall), %l7
  1447. linux_syscall_trace32:
  1448. add %sp, PTREGS_OFF, %o0
  1449. call syscall_trace
  1450. clr %o1
  1451. srl %i0, 0, %o0
  1452. srl %i4, 0, %o4
  1453. srl %i1, 0, %o1
  1454. srl %i2, 0, %o2
  1455. b,pt %xcc, 2f
  1456. srl %i3, 0, %o3
  1457. linux_syscall_trace:
  1458. add %sp, PTREGS_OFF, %o0
  1459. call syscall_trace
  1460. clr %o1
  1461. mov %i0, %o0
  1462. mov %i1, %o1
  1463. mov %i2, %o2
  1464. mov %i3, %o3
  1465. b,pt %xcc, 2f
  1466. mov %i4, %o4
  1467. /* Linux 32-bit and SunOS system calls enter here... */
  1468. .align 32
  1469. .globl linux_sparc_syscall32
  1470. linux_sparc_syscall32:
  1471. /* Direct access to user regs, much faster. */
  1472. cmp %g1, NR_SYSCALLS ! IEU1 Group
  1473. bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
  1474. srl %i0, 0, %o0 ! IEU0
  1475. sll %g1, 2, %l4 ! IEU0 Group
  1476. srl %i4, 0, %o4 ! IEU1
  1477. lduw [%l7 + %l4], %l7 ! Load
  1478. srl %i1, 0, %o1 ! IEU0 Group
  1479. ldx [%curptr + TI_FLAGS], %l0 ! Load
  1480. srl %i5, 0, %o5 ! IEU1
  1481. srl %i2, 0, %o2 ! IEU0 Group
  1482. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
  1483. bne,pn %icc, linux_syscall_trace32 ! CTI
  1484. mov %i0, %l5 ! IEU1
  1485. call %l7 ! CTI Group brk forced
  1486. srl %i3, 0, %o3 ! IEU0
  1487. ba,a,pt %xcc, 3f
  1488. /* Linux native and SunOS system calls enter here... */
  1489. .align 32
  1490. .globl linux_sparc_syscall, ret_sys_call
  1491. linux_sparc_syscall:
  1492. /* Direct access to user regs, much faster. */
  1493. cmp %g1, NR_SYSCALLS ! IEU1 Group
  1494. bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
  1495. mov %i0, %o0 ! IEU0
  1496. sll %g1, 2, %l4 ! IEU0 Group
  1497. mov %i1, %o1 ! IEU1
  1498. lduw [%l7 + %l4], %l7 ! Load
  1499. 4: mov %i2, %o2 ! IEU0 Group
  1500. ldx [%curptr + TI_FLAGS], %l0 ! Load
  1501. mov %i3, %o3 ! IEU1
  1502. mov %i4, %o4 ! IEU0 Group
  1503. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
  1504. bne,pn %icc, linux_syscall_trace ! CTI Group
  1505. mov %i0, %l5 ! IEU0
  1506. 2: call %l7 ! CTI Group brk forced
  1507. mov %i5, %o5 ! IEU0
  1508. nop
  1509. 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  1510. ret_sys_call:
  1511. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
  1512. ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
  1513. sra %o0, 0, %o0
  1514. mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
  1515. sllx %g2, 32, %g2
  1516. /* Check if force_successful_syscall_return()
  1517. * was invoked.
  1518. */
  1519. ldub [%curptr + TI_SYS_NOERROR], %l2
  1520. brnz,a,pn %l2, 80f
  1521. stb %g0, [%curptr + TI_SYS_NOERROR]
  1522. cmp %o0, -ERESTART_RESTARTBLOCK
  1523. bgeu,pn %xcc, 1f
  1524. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
  1525. 80:
  1526. /* System call success, clear Carry condition code. */
  1527. andn %g3, %g2, %g3
  1528. stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
  1529. bne,pn %icc, linux_syscall_trace2
  1530. add %l1, 0x4, %l2 ! npc = npc+4
  1531. stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
  1532. ba,pt %xcc, rtrap_clr_l6
  1533. stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
  1534. 1:
  1535. /* System call failure, set Carry condition code.
  1536. * Also, get abs(errno) to return to the process.
  1537. */
  1538. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
  1539. sub %g0, %o0, %o0
  1540. or %g3, %g2, %g3
  1541. stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  1542. mov 1, %l6
  1543. stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
  1544. bne,pn %icc, linux_syscall_trace2
  1545. add %l1, 0x4, %l2 ! npc = npc+4
  1546. stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
  1547. b,pt %xcc, rtrap
  1548. stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
  1549. linux_syscall_trace2:
  1550. add %sp, PTREGS_OFF, %o0
  1551. call syscall_trace
  1552. mov 1, %o1
  1553. stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
  1554. ba,pt %xcc, rtrap
  1555. stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
  1556. .align 32
  1557. .globl __flushw_user
  1558. __flushw_user:
  1559. rdpr %otherwin, %g1
  1560. brz,pn %g1, 2f
  1561. clr %g2
  1562. 1: save %sp, -128, %sp
  1563. rdpr %otherwin, %g1
  1564. brnz,pt %g1, 1b
  1565. add %g2, 1, %g2
  1566. 1: sub %g2, 1, %g2
  1567. brnz,pt %g2, 1b
  1568. restore %g0, %g0, %g0
  1569. 2: retl
  1570. nop
  1571. /* Read cpu ID from hardware, return in %g6.
  1572. * (callers_pc - 4) is in %g1. Patched at boot time.
  1573. *
  1574. * Default is spitfire implementation.
  1575. *
  1576. * The instruction sequence needs to be 5 instructions
  1577. * in order to fit the longest implementation, which is
  1578. * currently starfire.
  1579. */
  1580. .align 32
  1581. .globl __get_cpu_id
  1582. __get_cpu_id:
  1583. ldxa [%g0] ASI_UPA_CONFIG, %g6
  1584. srlx %g6, 17, %g6
  1585. jmpl %g1 + 0x4, %g0
  1586. and %g6, 0x1f, %g6
  1587. nop
  1588. __get_cpu_id_cheetah_safari:
  1589. ldxa [%g0] ASI_SAFARI_CONFIG, %g6
  1590. srlx %g6, 17, %g6
  1591. jmpl %g1 + 0x4, %g0
  1592. and %g6, 0x3ff, %g6
  1593. nop
  1594. __get_cpu_id_cheetah_jbus:
  1595. ldxa [%g0] ASI_JBUS_CONFIG, %g6
  1596. srlx %g6, 17, %g6
  1597. jmpl %g1 + 0x4, %g0
  1598. and %g6, 0x1f, %g6
  1599. nop
  1600. __get_cpu_id_starfire:
  1601. sethi %hi(0x1fff40000d0 >> 9), %g6
  1602. sllx %g6, 9, %g6
  1603. or %g6, 0xd0, %g6
  1604. jmpl %g1 + 0x4, %g0
  1605. lduwa [%g6] ASI_PHYS_BYPASS_EC_E, %g6
  1606. .globl per_cpu_patch
  1607. per_cpu_patch:
  1608. sethi %hi(this_is_starfire), %o0
  1609. lduw [%o0 + %lo(this_is_starfire)], %o1
  1610. sethi %hi(__get_cpu_id_starfire), %o0
  1611. brnz,pn %o1, 10f
  1612. or %o0, %lo(__get_cpu_id_starfire), %o0
  1613. sethi %hi(tlb_type), %o0
  1614. lduw [%o0 + %lo(tlb_type)], %o1
  1615. brz,pt %o1, 11f
  1616. nop
  1617. rdpr %ver, %o0
  1618. srlx %o0, 32, %o0
  1619. sethi %hi(0x003e0016), %o1
  1620. or %o1, %lo(0x003e0016), %o1
  1621. cmp %o0, %o1
  1622. sethi %hi(__get_cpu_id_cheetah_jbus), %o0
  1623. be,pn %icc, 10f
  1624. or %o0, %lo(__get_cpu_id_cheetah_jbus), %o0
  1625. sethi %hi(__get_cpu_id_cheetah_safari), %o0
  1626. or %o0, %lo(__get_cpu_id_cheetah_safari), %o0
  1627. 10:
  1628. sethi %hi(__get_cpu_id), %o1
  1629. or %o1, %lo(__get_cpu_id), %o1
  1630. lduw [%o0 + 0x00], %o2
  1631. stw %o2, [%o1 + 0x00]
  1632. flush %o1 + 0x00
  1633. lduw [%o0 + 0x04], %o2
  1634. stw %o2, [%o1 + 0x04]
  1635. flush %o1 + 0x04
  1636. lduw [%o0 + 0x08], %o2
  1637. stw %o2, [%o1 + 0x08]
  1638. flush %o1 + 0x08
  1639. lduw [%o0 + 0x0c], %o2
  1640. stw %o2, [%o1 + 0x0c]
  1641. flush %o1 + 0x0c
  1642. lduw [%o0 + 0x10], %o2
  1643. stw %o2, [%o1 + 0x10]
  1644. flush %o1 + 0x10
  1645. 11:
  1646. retl
  1647. nop