entry.S 42 KB

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