entry.S 45 KB

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