entry.S 42 KB

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