entry.S 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790
  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. .globl __do_data_access_exception
  636. .globl __do_data_access_exception_tl1
  637. __do_data_access_exception_tl1:
  638. rdpr %pstate, %g4
  639. wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
  640. mov TLB_SFSR, %g3
  641. mov DMMU_SFAR, %g5
  642. ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
  643. ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
  644. stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
  645. membar #Sync
  646. rdpr %tt, %g3
  647. cmp %g3, 0x80 ! first win spill/fill trap
  648. blu,pn %xcc, 1f
  649. cmp %g3, 0xff ! last win spill/fill trap
  650. bgu,pn %xcc, 1f
  651. nop
  652. ba,pt %xcc, winfix_dax
  653. rdpr %tpc, %g3
  654. 1: sethi %hi(109f), %g7
  655. ba,pt %xcc, etraptl1
  656. 109: or %g7, %lo(109b), %g7
  657. mov %l4, %o1
  658. mov %l5, %o2
  659. call data_access_exception_tl1
  660. add %sp, PTREGS_OFF, %o0
  661. ba,pt %xcc, rtrap
  662. clr %l6
  663. __do_data_access_exception:
  664. rdpr %pstate, %g4
  665. wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
  666. mov TLB_SFSR, %g3
  667. mov DMMU_SFAR, %g5
  668. ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
  669. ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
  670. stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
  671. membar #Sync
  672. sethi %hi(109f), %g7
  673. ba,pt %xcc, etrap
  674. 109: or %g7, %lo(109b), %g7
  675. mov %l4, %o1
  676. mov %l5, %o2
  677. call data_access_exception
  678. add %sp, PTREGS_OFF, %o0
  679. ba,pt %xcc, rtrap
  680. clr %l6
  681. .globl __do_instruction_access_exception
  682. .globl __do_instruction_access_exception_tl1
  683. __do_instruction_access_exception_tl1:
  684. rdpr %pstate, %g4
  685. wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
  686. mov TLB_SFSR, %g3
  687. ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
  688. rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
  689. stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
  690. membar #Sync
  691. sethi %hi(109f), %g7
  692. ba,pt %xcc, etraptl1
  693. 109: or %g7, %lo(109b), %g7
  694. mov %l4, %o1
  695. mov %l5, %o2
  696. call instruction_access_exception_tl1
  697. add %sp, PTREGS_OFF, %o0
  698. ba,pt %xcc, rtrap
  699. clr %l6
  700. __do_instruction_access_exception:
  701. rdpr %pstate, %g4
  702. wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
  703. mov TLB_SFSR, %g3
  704. ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
  705. rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
  706. stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
  707. membar #Sync
  708. sethi %hi(109f), %g7
  709. ba,pt %xcc, etrap
  710. 109: or %g7, %lo(109b), %g7
  711. mov %l4, %o1
  712. mov %l5, %o2
  713. call instruction_access_exception
  714. add %sp, PTREGS_OFF, %o0
  715. ba,pt %xcc, rtrap
  716. clr %l6
  717. /* This is the trap handler entry point for ECC correctable
  718. * errors. They are corrected, but we listen for the trap
  719. * so that the event can be logged.
  720. *
  721. * Disrupting errors are either:
  722. * 1) single-bit ECC errors during UDB reads to system
  723. * memory
  724. * 2) data parity errors during write-back events
  725. *
  726. * As far as I can make out from the manual, the CEE trap
  727. * is only for correctable errors during memory read
  728. * accesses by the front-end of the processor.
  729. *
  730. * The code below is only for trap level 1 CEE events,
  731. * as it is the only situation where we can safely record
  732. * and log. For trap level >1 we just clear the CE bit
  733. * in the AFSR and return.
  734. */
  735. /* Our trap handling infrastructure allows us to preserve
  736. * two 64-bit values during etrap for arguments to
  737. * subsequent C code. Therefore we encode the information
  738. * as follows:
  739. *
  740. * value 1) Full 64-bits of AFAR
  741. * value 2) Low 33-bits of AFSR, then bits 33-->42
  742. * are UDBL error status and bits 43-->52
  743. * are UDBH error status
  744. */
  745. .align 64
  746. .globl cee_trap
  747. cee_trap:
  748. ldxa [%g0] ASI_AFSR, %g1 ! Read AFSR
  749. ldxa [%g0] ASI_AFAR, %g2 ! Read AFAR
  750. sllx %g1, 31, %g1 ! Clear reserved bits
  751. srlx %g1, 31, %g1 ! in AFSR
  752. /* NOTE: UltraSparc-I/II have high and low UDB error
  753. * registers, corresponding to the two UDB units
  754. * present on those chips. UltraSparc-IIi only
  755. * has a single UDB, called "SDB" in the manual.
  756. * For IIi the upper UDB register always reads
  757. * as zero so for our purposes things will just
  758. * work with the checks below.
  759. */
  760. ldxa [%g0] ASI_UDBL_ERROR_R, %g3 ! Read UDB-Low error status
  761. andcc %g3, (1 << 8), %g4 ! Check CE bit
  762. sllx %g3, (64 - 10), %g3 ! Clear reserved bits
  763. srlx %g3, (64 - 10), %g3 ! in UDB-Low error status
  764. sllx %g3, (33 + 0), %g3 ! Shift up to encoding area
  765. or %g1, %g3, %g1 ! Or it in
  766. be,pn %xcc, 1f ! Branch if CE bit was clear
  767. nop
  768. stxa %g4, [%g0] ASI_UDB_ERROR_W ! Clear CE sticky bit in UDBL
  769. membar #Sync ! Synchronize ASI stores
  770. 1: mov 0x18, %g5 ! Addr of UDB-High error status
  771. ldxa [%g5] ASI_UDBH_ERROR_R, %g3 ! Read it
  772. andcc %g3, (1 << 8), %g4 ! Check CE bit
  773. sllx %g3, (64 - 10), %g3 ! Clear reserved bits
  774. srlx %g3, (64 - 10), %g3 ! in UDB-High error status
  775. sllx %g3, (33 + 10), %g3 ! Shift up to encoding area
  776. or %g1, %g3, %g1 ! Or it in
  777. be,pn %xcc, 1f ! Branch if CE bit was clear
  778. nop
  779. nop
  780. stxa %g4, [%g5] ASI_UDB_ERROR_W ! Clear CE sticky bit in UDBH
  781. membar #Sync ! Synchronize ASI stores
  782. 1: mov 1, %g5 ! AFSR CE bit is
  783. sllx %g5, 20, %g5 ! bit 20
  784. stxa %g5, [%g0] ASI_AFSR ! Clear CE sticky bit in AFSR
  785. membar #Sync ! Synchronize ASI stores
  786. sllx %g2, (64 - 41), %g2 ! Clear reserved bits
  787. srlx %g2, (64 - 41), %g2 ! in latched AFAR
  788. andn %g2, 0x0f, %g2 ! Finish resv bit clearing
  789. mov %g1, %g4 ! Move AFSR+UDB* into save reg
  790. mov %g2, %g5 ! Move AFAR into save reg
  791. rdpr %pil, %g2
  792. wrpr %g0, 15, %pil
  793. ba,pt %xcc, etrap_irq
  794. rd %pc, %g7
  795. mov %l4, %o0
  796. mov %l5, %o1
  797. call cee_log
  798. add %sp, PTREGS_OFF, %o2
  799. ba,a,pt %xcc, rtrap_irq
  800. /* Capture I/D/E-cache state into per-cpu error scoreboard.
  801. *
  802. * %g1: (TL>=0) ? 1 : 0
  803. * %g2: scratch
  804. * %g3: scratch
  805. * %g4: AFSR
  806. * %g5: AFAR
  807. * %g6: current thread ptr
  808. * %g7: scratch
  809. */
  810. #define CHEETAH_LOG_ERROR \
  811. /* Put "TL1" software bit into AFSR. */ \
  812. and %g1, 0x1, %g1; \
  813. sllx %g1, 63, %g2; \
  814. or %g4, %g2, %g4; \
  815. /* Get log entry pointer for this cpu at this trap level. */ \
  816. BRANCH_IF_JALAPENO(g2,g3,50f) \
  817. ldxa [%g0] ASI_SAFARI_CONFIG, %g2; \
  818. srlx %g2, 17, %g2; \
  819. ba,pt %xcc, 60f; \
  820. and %g2, 0x3ff, %g2; \
  821. 50: ldxa [%g0] ASI_JBUS_CONFIG, %g2; \
  822. srlx %g2, 17, %g2; \
  823. and %g2, 0x1f, %g2; \
  824. 60: sllx %g2, 9, %g2; \
  825. sethi %hi(cheetah_error_log), %g3; \
  826. ldx [%g3 + %lo(cheetah_error_log)], %g3; \
  827. brz,pn %g3, 80f; \
  828. nop; \
  829. add %g3, %g2, %g3; \
  830. sllx %g1, 8, %g1; \
  831. add %g3, %g1, %g1; \
  832. /* %g1 holds pointer to the top of the logging scoreboard */ \
  833. ldx [%g1 + 0x0], %g7; \
  834. cmp %g7, -1; \
  835. bne,pn %xcc, 80f; \
  836. nop; \
  837. stx %g4, [%g1 + 0x0]; \
  838. stx %g5, [%g1 + 0x8]; \
  839. add %g1, 0x10, %g1; \
  840. /* %g1 now points to D-cache logging area */ \
  841. set 0x3ff8, %g2; /* DC_addr mask */ \
  842. and %g5, %g2, %g2; /* DC_addr bits of AFAR */ \
  843. srlx %g5, 12, %g3; \
  844. or %g3, 1, %g3; /* PHYS tag + valid */ \
  845. 10: ldxa [%g2] ASI_DCACHE_TAG, %g7; \
  846. cmp %g3, %g7; /* TAG match? */ \
  847. bne,pt %xcc, 13f; \
  848. nop; \
  849. /* Yep, what we want, capture state. */ \
  850. stx %g2, [%g1 + 0x20]; \
  851. stx %g7, [%g1 + 0x28]; \
  852. /* A membar Sync is required before and after utag access. */ \
  853. membar #Sync; \
  854. ldxa [%g2] ASI_DCACHE_UTAG, %g7; \
  855. membar #Sync; \
  856. stx %g7, [%g1 + 0x30]; \
  857. ldxa [%g2] ASI_DCACHE_SNOOP_TAG, %g7; \
  858. stx %g7, [%g1 + 0x38]; \
  859. clr %g3; \
  860. 12: ldxa [%g2 + %g3] ASI_DCACHE_DATA, %g7; \
  861. stx %g7, [%g1]; \
  862. add %g3, (1 << 5), %g3; \
  863. cmp %g3, (4 << 5); \
  864. bl,pt %xcc, 12b; \
  865. add %g1, 0x8, %g1; \
  866. ba,pt %xcc, 20f; \
  867. add %g1, 0x20, %g1; \
  868. 13: sethi %hi(1 << 14), %g7; \
  869. add %g2, %g7, %g2; \
  870. srlx %g2, 14, %g7; \
  871. cmp %g7, 4; \
  872. bl,pt %xcc, 10b; \
  873. nop; \
  874. add %g1, 0x40, %g1; \
  875. 20: /* %g1 now points to I-cache logging area */ \
  876. set 0x1fe0, %g2; /* IC_addr mask */ \
  877. and %g5, %g2, %g2; /* IC_addr bits of AFAR */ \
  878. sllx %g2, 1, %g2; /* IC_addr[13:6]==VA[12:5] */ \
  879. srlx %g5, (13 - 8), %g3; /* Make PTAG */ \
  880. andn %g3, 0xff, %g3; /* Mask off undefined bits */ \
  881. 21: ldxa [%g2] ASI_IC_TAG, %g7; \
  882. andn %g7, 0xff, %g7; \
  883. cmp %g3, %g7; \
  884. bne,pt %xcc, 23f; \
  885. nop; \
  886. /* Yep, what we want, capture state. */ \
  887. stx %g2, [%g1 + 0x40]; \
  888. stx %g7, [%g1 + 0x48]; \
  889. add %g2, (1 << 3), %g2; \
  890. ldxa [%g2] ASI_IC_TAG, %g7; \
  891. add %g2, (1 << 3), %g2; \
  892. stx %g7, [%g1 + 0x50]; \
  893. ldxa [%g2] ASI_IC_TAG, %g7; \
  894. add %g2, (1 << 3), %g2; \
  895. stx %g7, [%g1 + 0x60]; \
  896. ldxa [%g2] ASI_IC_TAG, %g7; \
  897. stx %g7, [%g1 + 0x68]; \
  898. sub %g2, (3 << 3), %g2; \
  899. ldxa [%g2] ASI_IC_STAG, %g7; \
  900. stx %g7, [%g1 + 0x58]; \
  901. clr %g3; \
  902. srlx %g2, 2, %g2; \
  903. 22: ldxa [%g2 + %g3] ASI_IC_INSTR, %g7; \
  904. stx %g7, [%g1]; \
  905. add %g3, (1 << 3), %g3; \
  906. cmp %g3, (8 << 3); \
  907. bl,pt %xcc, 22b; \
  908. add %g1, 0x8, %g1; \
  909. ba,pt %xcc, 30f; \
  910. add %g1, 0x30, %g1; \
  911. 23: sethi %hi(1 << 14), %g7; \
  912. add %g2, %g7, %g2; \
  913. srlx %g2, 14, %g7; \
  914. cmp %g7, 4; \
  915. bl,pt %xcc, 21b; \
  916. nop; \
  917. add %g1, 0x70, %g1; \
  918. 30: /* %g1 now points to E-cache logging area */ \
  919. andn %g5, (32 - 1), %g2; /* E-cache subblock */ \
  920. stx %g2, [%g1 + 0x20]; \
  921. ldxa [%g2] ASI_EC_TAG_DATA, %g7; \
  922. stx %g7, [%g1 + 0x28]; \
  923. ldxa [%g2] ASI_EC_R, %g0; \
  924. clr %g3; \
  925. 31: ldxa [%g3] ASI_EC_DATA, %g7; \
  926. stx %g7, [%g1 + %g3]; \
  927. add %g3, 0x8, %g3; \
  928. cmp %g3, 0x20; \
  929. bl,pt %xcc, 31b; \
  930. nop; \
  931. 80: /* DONE */
  932. /* These get patched into the trap table at boot time
  933. * once we know we have a cheetah processor.
  934. */
  935. .globl cheetah_fecc_trap_vector, cheetah_fecc_trap_vector_tl1
  936. cheetah_fecc_trap_vector:
  937. membar #Sync
  938. ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
  939. andn %g1, DCU_DC | DCU_IC, %g1
  940. stxa %g1, [%g0] ASI_DCU_CONTROL_REG
  941. membar #Sync
  942. sethi %hi(cheetah_fast_ecc), %g2
  943. jmpl %g2 + %lo(cheetah_fast_ecc), %g0
  944. mov 0, %g1
  945. cheetah_fecc_trap_vector_tl1:
  946. membar #Sync
  947. ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
  948. andn %g1, DCU_DC | DCU_IC, %g1
  949. stxa %g1, [%g0] ASI_DCU_CONTROL_REG
  950. membar #Sync
  951. sethi %hi(cheetah_fast_ecc), %g2
  952. jmpl %g2 + %lo(cheetah_fast_ecc), %g0
  953. mov 1, %g1
  954. .globl cheetah_cee_trap_vector, cheetah_cee_trap_vector_tl1
  955. cheetah_cee_trap_vector:
  956. membar #Sync
  957. ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
  958. andn %g1, DCU_IC, %g1
  959. stxa %g1, [%g0] ASI_DCU_CONTROL_REG
  960. membar #Sync
  961. sethi %hi(cheetah_cee), %g2
  962. jmpl %g2 + %lo(cheetah_cee), %g0
  963. mov 0, %g1
  964. cheetah_cee_trap_vector_tl1:
  965. membar #Sync
  966. ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
  967. andn %g1, DCU_IC, %g1
  968. stxa %g1, [%g0] ASI_DCU_CONTROL_REG
  969. membar #Sync
  970. sethi %hi(cheetah_cee), %g2
  971. jmpl %g2 + %lo(cheetah_cee), %g0
  972. mov 1, %g1
  973. .globl cheetah_deferred_trap_vector, cheetah_deferred_trap_vector_tl1
  974. cheetah_deferred_trap_vector:
  975. membar #Sync
  976. ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
  977. andn %g1, DCU_DC | DCU_IC, %g1;
  978. stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
  979. membar #Sync;
  980. sethi %hi(cheetah_deferred_trap), %g2
  981. jmpl %g2 + %lo(cheetah_deferred_trap), %g0
  982. mov 0, %g1
  983. cheetah_deferred_trap_vector_tl1:
  984. membar #Sync;
  985. ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
  986. andn %g1, DCU_DC | DCU_IC, %g1;
  987. stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
  988. membar #Sync;
  989. sethi %hi(cheetah_deferred_trap), %g2
  990. jmpl %g2 + %lo(cheetah_deferred_trap), %g0
  991. mov 1, %g1
  992. /* Cheetah+ specific traps. These are for the new I/D cache parity
  993. * error traps. The first argument to cheetah_plus_parity_handler
  994. * is encoded as follows:
  995. *
  996. * Bit0: 0=dcache,1=icache
  997. * Bit1: 0=recoverable,1=unrecoverable
  998. */
  999. .globl cheetah_plus_dcpe_trap_vector, cheetah_plus_dcpe_trap_vector_tl1
  1000. cheetah_plus_dcpe_trap_vector:
  1001. membar #Sync
  1002. sethi %hi(do_cheetah_plus_data_parity), %g7
  1003. jmpl %g7 + %lo(do_cheetah_plus_data_parity), %g0
  1004. nop
  1005. nop
  1006. nop
  1007. nop
  1008. nop
  1009. do_cheetah_plus_data_parity:
  1010. ba,pt %xcc, etrap
  1011. rd %pc, %g7
  1012. mov 0x0, %o0
  1013. call cheetah_plus_parity_error
  1014. add %sp, PTREGS_OFF, %o1
  1015. ba,pt %xcc, rtrap
  1016. clr %l6
  1017. cheetah_plus_dcpe_trap_vector_tl1:
  1018. membar #Sync
  1019. wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
  1020. sethi %hi(do_dcpe_tl1), %g3
  1021. jmpl %g3 + %lo(do_dcpe_tl1), %g0
  1022. nop
  1023. nop
  1024. nop
  1025. nop
  1026. .globl cheetah_plus_icpe_trap_vector, cheetah_plus_icpe_trap_vector_tl1
  1027. cheetah_plus_icpe_trap_vector:
  1028. membar #Sync
  1029. sethi %hi(do_cheetah_plus_insn_parity), %g7
  1030. jmpl %g7 + %lo(do_cheetah_plus_insn_parity), %g0
  1031. nop
  1032. nop
  1033. nop
  1034. nop
  1035. nop
  1036. do_cheetah_plus_insn_parity:
  1037. ba,pt %xcc, etrap
  1038. rd %pc, %g7
  1039. mov 0x1, %o0
  1040. call cheetah_plus_parity_error
  1041. add %sp, PTREGS_OFF, %o1
  1042. ba,pt %xcc, rtrap
  1043. clr %l6
  1044. cheetah_plus_icpe_trap_vector_tl1:
  1045. membar #Sync
  1046. wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
  1047. sethi %hi(do_icpe_tl1), %g3
  1048. jmpl %g3 + %lo(do_icpe_tl1), %g0
  1049. nop
  1050. nop
  1051. nop
  1052. nop
  1053. /* If we take one of these traps when tl >= 1, then we
  1054. * jump to interrupt globals. If some trap level above us
  1055. * was also using interrupt globals, we cannot recover.
  1056. * We may use all interrupt global registers except %g6.
  1057. */
  1058. .globl do_dcpe_tl1, do_icpe_tl1
  1059. do_dcpe_tl1:
  1060. rdpr %tl, %g1 ! Save original trap level
  1061. mov 1, %g2 ! Setup TSTATE checking loop
  1062. sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
  1063. 1: wrpr %g2, %tl ! Set trap level to check
  1064. rdpr %tstate, %g4 ! Read TSTATE for this level
  1065. andcc %g4, %g3, %g0 ! Interrupt globals in use?
  1066. bne,a,pn %xcc, do_dcpe_tl1_fatal ! Yep, irrecoverable
  1067. wrpr %g1, %tl ! Restore original trap level
  1068. add %g2, 1, %g2 ! Next trap level
  1069. cmp %g2, %g1 ! Hit them all yet?
  1070. ble,pt %icc, 1b ! Not yet
  1071. nop
  1072. wrpr %g1, %tl ! Restore original trap level
  1073. do_dcpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
  1074. /* Reset D-cache parity */
  1075. sethi %hi(1 << 16), %g1 ! D-cache size
  1076. mov (1 << 5), %g2 ! D-cache line size
  1077. sub %g1, %g2, %g1 ! Move down 1 cacheline
  1078. 1: srl %g1, 14, %g3 ! Compute UTAG
  1079. membar #Sync
  1080. stxa %g3, [%g1] ASI_DCACHE_UTAG
  1081. membar #Sync
  1082. sub %g2, 8, %g3 ! 64-bit data word within line
  1083. 2: membar #Sync
  1084. stxa %g0, [%g1 + %g3] ASI_DCACHE_DATA
  1085. membar #Sync
  1086. subcc %g3, 8, %g3 ! Next 64-bit data word
  1087. bge,pt %icc, 2b
  1088. nop
  1089. subcc %g1, %g2, %g1 ! Next cacheline
  1090. bge,pt %icc, 1b
  1091. nop
  1092. ba,pt %xcc, dcpe_icpe_tl1_common
  1093. nop
  1094. do_dcpe_tl1_fatal:
  1095. sethi %hi(1f), %g7
  1096. ba,pt %xcc, etraptl1
  1097. 1: or %g7, %lo(1b), %g7
  1098. mov 0x2, %o0
  1099. call cheetah_plus_parity_error
  1100. add %sp, PTREGS_OFF, %o1
  1101. ba,pt %xcc, rtrap
  1102. clr %l6
  1103. do_icpe_tl1:
  1104. rdpr %tl, %g1 ! Save original trap level
  1105. mov 1, %g2 ! Setup TSTATE checking loop
  1106. sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
  1107. 1: wrpr %g2, %tl ! Set trap level to check
  1108. rdpr %tstate, %g4 ! Read TSTATE for this level
  1109. andcc %g4, %g3, %g0 ! Interrupt globals in use?
  1110. bne,a,pn %xcc, do_icpe_tl1_fatal ! Yep, irrecoverable
  1111. wrpr %g1, %tl ! Restore original trap level
  1112. add %g2, 1, %g2 ! Next trap level
  1113. cmp %g2, %g1 ! Hit them all yet?
  1114. ble,pt %icc, 1b ! Not yet
  1115. nop
  1116. wrpr %g1, %tl ! Restore original trap level
  1117. do_icpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
  1118. /* Flush I-cache */
  1119. sethi %hi(1 << 15), %g1 ! I-cache size
  1120. mov (1 << 5), %g2 ! I-cache line size
  1121. sub %g1, %g2, %g1
  1122. 1: or %g1, (2 << 3), %g3
  1123. stxa %g0, [%g3] ASI_IC_TAG
  1124. membar #Sync
  1125. subcc %g1, %g2, %g1
  1126. bge,pt %icc, 1b
  1127. nop
  1128. ba,pt %xcc, dcpe_icpe_tl1_common
  1129. nop
  1130. do_icpe_tl1_fatal:
  1131. sethi %hi(1f), %g7
  1132. ba,pt %xcc, etraptl1
  1133. 1: or %g7, %lo(1b), %g7
  1134. mov 0x3, %o0
  1135. call cheetah_plus_parity_error
  1136. add %sp, PTREGS_OFF, %o1
  1137. ba,pt %xcc, rtrap
  1138. clr %l6
  1139. dcpe_icpe_tl1_common:
  1140. /* Flush D-cache, re-enable D/I caches in DCU and finally
  1141. * retry the trapping instruction.
  1142. */
  1143. sethi %hi(1 << 16), %g1 ! D-cache size
  1144. mov (1 << 5), %g2 ! D-cache line size
  1145. sub %g1, %g2, %g1
  1146. 1: stxa %g0, [%g1] ASI_DCACHE_TAG
  1147. membar #Sync
  1148. subcc %g1, %g2, %g1
  1149. bge,pt %icc, 1b
  1150. nop
  1151. ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
  1152. or %g1, (DCU_DC | DCU_IC), %g1
  1153. stxa %g1, [%g0] ASI_DCU_CONTROL_REG
  1154. membar #Sync
  1155. retry
  1156. /* Cheetah FECC trap handling, we get here from tl{0,1}_fecc
  1157. * in the trap table. That code has done a memory barrier
  1158. * and has disabled both the I-cache and D-cache in the DCU
  1159. * control register. The I-cache is disabled so that we may
  1160. * capture the corrupted cache line, and the D-cache is disabled
  1161. * because corrupt data may have been placed there and we don't
  1162. * want to reference it.
  1163. *
  1164. * %g1 is one if this trap occurred at %tl >= 1.
  1165. *
  1166. * Next, we turn off error reporting so that we don't recurse.
  1167. */
  1168. .globl cheetah_fast_ecc
  1169. cheetah_fast_ecc:
  1170. ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
  1171. andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
  1172. stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
  1173. membar #Sync
  1174. /* Fetch and clear AFSR/AFAR */
  1175. ldxa [%g0] ASI_AFSR, %g4
  1176. ldxa [%g0] ASI_AFAR, %g5
  1177. stxa %g4, [%g0] ASI_AFSR
  1178. membar #Sync
  1179. CHEETAH_LOG_ERROR
  1180. rdpr %pil, %g2
  1181. wrpr %g0, 15, %pil
  1182. ba,pt %xcc, etrap_irq
  1183. rd %pc, %g7
  1184. mov %l4, %o1
  1185. mov %l5, %o2
  1186. call cheetah_fecc_handler
  1187. add %sp, PTREGS_OFF, %o0
  1188. ba,a,pt %xcc, rtrap_irq
  1189. /* Our caller has disabled I-cache and performed membar Sync. */
  1190. .globl cheetah_cee
  1191. cheetah_cee:
  1192. ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
  1193. andn %g2, ESTATE_ERROR_CEEN, %g2
  1194. stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
  1195. membar #Sync
  1196. /* Fetch and clear AFSR/AFAR */
  1197. ldxa [%g0] ASI_AFSR, %g4
  1198. ldxa [%g0] ASI_AFAR, %g5
  1199. stxa %g4, [%g0] ASI_AFSR
  1200. membar #Sync
  1201. CHEETAH_LOG_ERROR
  1202. rdpr %pil, %g2
  1203. wrpr %g0, 15, %pil
  1204. ba,pt %xcc, etrap_irq
  1205. rd %pc, %g7
  1206. mov %l4, %o1
  1207. mov %l5, %o2
  1208. call cheetah_cee_handler
  1209. add %sp, PTREGS_OFF, %o0
  1210. ba,a,pt %xcc, rtrap_irq
  1211. /* Our caller has disabled I-cache+D-cache and performed membar Sync. */
  1212. .globl cheetah_deferred_trap
  1213. cheetah_deferred_trap:
  1214. ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
  1215. andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
  1216. stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
  1217. membar #Sync
  1218. /* Fetch and clear AFSR/AFAR */
  1219. ldxa [%g0] ASI_AFSR, %g4
  1220. ldxa [%g0] ASI_AFAR, %g5
  1221. stxa %g4, [%g0] ASI_AFSR
  1222. membar #Sync
  1223. CHEETAH_LOG_ERROR
  1224. rdpr %pil, %g2
  1225. wrpr %g0, 15, %pil
  1226. ba,pt %xcc, etrap_irq
  1227. rd %pc, %g7
  1228. mov %l4, %o1
  1229. mov %l5, %o2
  1230. call cheetah_deferred_handler
  1231. add %sp, PTREGS_OFF, %o0
  1232. ba,a,pt %xcc, rtrap_irq
  1233. .globl __do_privact
  1234. __do_privact:
  1235. mov TLB_SFSR, %g3
  1236. stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
  1237. membar #Sync
  1238. sethi %hi(109f), %g7
  1239. ba,pt %xcc, etrap
  1240. 109: or %g7, %lo(109b), %g7
  1241. call do_privact
  1242. add %sp, PTREGS_OFF, %o0
  1243. ba,pt %xcc, rtrap
  1244. clr %l6
  1245. .globl do_mna
  1246. do_mna:
  1247. rdpr %tl, %g3
  1248. cmp %g3, 1
  1249. /* Setup %g4/%g5 now as they are used in the
  1250. * winfixup code.
  1251. */
  1252. mov TLB_SFSR, %g3
  1253. mov DMMU_SFAR, %g4
  1254. ldxa [%g4] ASI_DMMU, %g4
  1255. ldxa [%g3] ASI_DMMU, %g5
  1256. stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
  1257. membar #Sync
  1258. bgu,pn %icc, winfix_mna
  1259. rdpr %tpc, %g3
  1260. 1: sethi %hi(109f), %g7
  1261. ba,pt %xcc, etrap
  1262. 109: or %g7, %lo(109b), %g7
  1263. mov %l4, %o1
  1264. mov %l5, %o2
  1265. call mem_address_unaligned
  1266. add %sp, PTREGS_OFF, %o0
  1267. ba,pt %xcc, rtrap
  1268. clr %l6
  1269. .globl do_lddfmna
  1270. do_lddfmna:
  1271. sethi %hi(109f), %g7
  1272. mov TLB_SFSR, %g4
  1273. ldxa [%g4] ASI_DMMU, %g5
  1274. stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
  1275. membar #Sync
  1276. mov DMMU_SFAR, %g4
  1277. ldxa [%g4] ASI_DMMU, %g4
  1278. ba,pt %xcc, etrap
  1279. 109: or %g7, %lo(109b), %g7
  1280. mov %l4, %o1
  1281. mov %l5, %o2
  1282. call handle_lddfmna
  1283. add %sp, PTREGS_OFF, %o0
  1284. ba,pt %xcc, rtrap
  1285. clr %l6
  1286. .globl do_stdfmna
  1287. do_stdfmna:
  1288. sethi %hi(109f), %g7
  1289. mov TLB_SFSR, %g4
  1290. ldxa [%g4] ASI_DMMU, %g5
  1291. stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
  1292. membar #Sync
  1293. mov DMMU_SFAR, %g4
  1294. ldxa [%g4] ASI_DMMU, %g4
  1295. ba,pt %xcc, etrap
  1296. 109: or %g7, %lo(109b), %g7
  1297. mov %l4, %o1
  1298. mov %l5, %o2
  1299. call handle_stdfmna
  1300. add %sp, PTREGS_OFF, %o0
  1301. ba,pt %xcc, rtrap
  1302. clr %l6
  1303. .globl breakpoint_trap
  1304. breakpoint_trap:
  1305. call sparc_breakpoint
  1306. add %sp, PTREGS_OFF, %o0
  1307. ba,pt %xcc, rtrap
  1308. nop
  1309. #if defined(CONFIG_SUNOS_EMUL) || defined(CONFIG_SOLARIS_EMUL) || \
  1310. defined(CONFIG_SOLARIS_EMUL_MODULE)
  1311. /* SunOS uses syscall zero as the 'indirect syscall' it looks
  1312. * like indir_syscall(scall_num, arg0, arg1, arg2...); etc.
  1313. * This is complete brain damage.
  1314. */
  1315. .globl sunos_indir
  1316. sunos_indir:
  1317. srl %o0, 0, %o0
  1318. mov %o7, %l4
  1319. cmp %o0, NR_SYSCALLS
  1320. blu,a,pt %icc, 1f
  1321. sll %o0, 0x2, %o0
  1322. sethi %hi(sunos_nosys), %l6
  1323. b,pt %xcc, 2f
  1324. or %l6, %lo(sunos_nosys), %l6
  1325. 1: sethi %hi(sunos_sys_table), %l7
  1326. or %l7, %lo(sunos_sys_table), %l7
  1327. lduw [%l7 + %o0], %l6
  1328. 2: mov %o1, %o0
  1329. mov %o2, %o1
  1330. mov %o3, %o2
  1331. mov %o4, %o3
  1332. mov %o5, %o4
  1333. call %l6
  1334. mov %l4, %o7
  1335. .globl sunos_getpid
  1336. sunos_getpid:
  1337. call sys_getppid
  1338. nop
  1339. call sys_getpid
  1340. stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
  1341. b,pt %xcc, ret_sys_call
  1342. stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  1343. /* SunOS getuid() returns uid in %o0 and euid in %o1 */
  1344. .globl sunos_getuid
  1345. sunos_getuid:
  1346. call sys32_geteuid16
  1347. nop
  1348. call sys32_getuid16
  1349. stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
  1350. b,pt %xcc, ret_sys_call
  1351. stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  1352. /* SunOS getgid() returns gid in %o0 and egid in %o1 */
  1353. .globl sunos_getgid
  1354. sunos_getgid:
  1355. call sys32_getegid16
  1356. nop
  1357. call sys32_getgid16
  1358. stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
  1359. b,pt %xcc, ret_sys_call
  1360. stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  1361. #endif
  1362. /* SunOS's execv() call only specifies the argv argument, the
  1363. * environment settings are the same as the calling processes.
  1364. */
  1365. .globl sunos_execv
  1366. sys_execve:
  1367. sethi %hi(sparc_execve), %g1
  1368. ba,pt %xcc, execve_merge
  1369. or %g1, %lo(sparc_execve), %g1
  1370. #ifdef CONFIG_COMPAT
  1371. .globl sys_execve
  1372. sunos_execv:
  1373. stx %g0, [%sp + PTREGS_OFF + PT_V9_I2]
  1374. .globl sys32_execve
  1375. sys32_execve:
  1376. sethi %hi(sparc32_execve), %g1
  1377. or %g1, %lo(sparc32_execve), %g1
  1378. #endif
  1379. execve_merge:
  1380. flushw
  1381. jmpl %g1, %g0
  1382. add %sp, PTREGS_OFF, %o0
  1383. .globl sys_pipe, sys_sigpause, sys_nis_syscall
  1384. .globl sys_sigsuspend, sys_rt_sigsuspend
  1385. .globl sys_rt_sigreturn
  1386. .globl sys_ptrace
  1387. .globl sys_sigaltstack
  1388. .align 32
  1389. sys_pipe: ba,pt %xcc, sparc_pipe
  1390. add %sp, PTREGS_OFF, %o0
  1391. sys_nis_syscall:ba,pt %xcc, c_sys_nis_syscall
  1392. add %sp, PTREGS_OFF, %o0
  1393. sys_memory_ordering:
  1394. ba,pt %xcc, sparc_memory_ordering
  1395. add %sp, PTREGS_OFF, %o1
  1396. sys_sigaltstack:ba,pt %xcc, do_sigaltstack
  1397. add %i6, STACK_BIAS, %o2
  1398. #ifdef CONFIG_COMPAT
  1399. .globl sys32_sigstack
  1400. sys32_sigstack: ba,pt %xcc, do_sys32_sigstack
  1401. mov %i6, %o2
  1402. .globl sys32_sigaltstack
  1403. sys32_sigaltstack:
  1404. ba,pt %xcc, do_sys32_sigaltstack
  1405. mov %i6, %o2
  1406. #endif
  1407. .align 32
  1408. sys_sigsuspend: add %sp, PTREGS_OFF, %o0
  1409. call do_sigsuspend
  1410. add %o7, 1f-.-4, %o7
  1411. nop
  1412. sys_rt_sigsuspend: /* NOTE: %o0,%o1 have a correct value already */
  1413. add %sp, PTREGS_OFF, %o2
  1414. call do_rt_sigsuspend
  1415. add %o7, 1f-.-4, %o7
  1416. nop
  1417. #ifdef CONFIG_COMPAT
  1418. .globl sys32_rt_sigsuspend
  1419. sys32_rt_sigsuspend: /* NOTE: %o0,%o1 have a correct value already */
  1420. srl %o0, 0, %o0
  1421. add %sp, PTREGS_OFF, %o2
  1422. call do_rt_sigsuspend32
  1423. add %o7, 1f-.-4, %o7
  1424. #endif
  1425. /* NOTE: %o0 has a correct value already */
  1426. sys_sigpause: add %sp, PTREGS_OFF, %o1
  1427. call do_sigpause
  1428. add %o7, 1f-.-4, %o7
  1429. nop
  1430. #ifdef CONFIG_COMPAT
  1431. .globl sys32_sigreturn
  1432. sys32_sigreturn:
  1433. add %sp, PTREGS_OFF, %o0
  1434. call do_sigreturn32
  1435. add %o7, 1f-.-4, %o7
  1436. nop
  1437. #endif
  1438. sys_rt_sigreturn:
  1439. add %sp, PTREGS_OFF, %o0
  1440. call do_rt_sigreturn
  1441. add %o7, 1f-.-4, %o7
  1442. nop
  1443. #ifdef CONFIG_COMPAT
  1444. .globl sys32_rt_sigreturn
  1445. sys32_rt_sigreturn:
  1446. add %sp, PTREGS_OFF, %o0
  1447. call do_rt_sigreturn32
  1448. add %o7, 1f-.-4, %o7
  1449. nop
  1450. #endif
  1451. sys_ptrace: add %sp, PTREGS_OFF, %o0
  1452. call do_ptrace
  1453. add %o7, 1f-.-4, %o7
  1454. nop
  1455. .align 32
  1456. 1: ldx [%curptr + TI_FLAGS], %l5
  1457. andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
  1458. be,pt %icc, rtrap
  1459. clr %l6
  1460. add %sp, PTREGS_OFF, %o0
  1461. call syscall_trace
  1462. mov 1, %o1
  1463. ba,pt %xcc, rtrap
  1464. clr %l6
  1465. /* This is how fork() was meant to be done, 8 instruction entry.
  1466. *
  1467. * I questioned the following code briefly, let me clear things
  1468. * up so you must not reason on it like I did.
  1469. *
  1470. * Know the fork_kpsr etc. we use in the sparc32 port? We don't
  1471. * need it here because the only piece of window state we copy to
  1472. * the child is the CWP register. Even if the parent sleeps,
  1473. * we are safe because we stuck it into pt_regs of the parent
  1474. * so it will not change.
  1475. *
  1476. * XXX This raises the question, whether we can do the same on
  1477. * XXX sparc32 to get rid of fork_kpsr _and_ fork_kwim. The
  1478. * XXX answer is yes. We stick fork_kpsr in UREG_G0 and
  1479. * XXX fork_kwim in UREG_G1 (global registers are considered
  1480. * XXX volatile across a system call in the sparc ABI I think
  1481. * XXX if it isn't we can use regs->y instead, anyone who depends
  1482. * XXX upon the Y register being preserved across a fork deserves
  1483. * XXX to lose).
  1484. *
  1485. * In fact we should take advantage of that fact for other things
  1486. * during system calls...
  1487. */
  1488. .globl sys_fork, sys_vfork, sys_clone, sparc_exit
  1489. .globl ret_from_syscall
  1490. .align 32
  1491. sys_vfork: /* Under Linux, vfork and fork are just special cases of clone. */
  1492. sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
  1493. or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
  1494. ba,pt %xcc, sys_clone
  1495. sys_fork: clr %o1
  1496. mov SIGCHLD, %o0
  1497. sys_clone: flushw
  1498. movrz %o1, %fp, %o1
  1499. mov 0, %o3
  1500. ba,pt %xcc, sparc_do_fork
  1501. add %sp, PTREGS_OFF, %o2
  1502. ret_from_syscall:
  1503. /* Clear current_thread_info()->new_child, and
  1504. * check performance counter stuff too.
  1505. */
  1506. stb %g0, [%g6 + TI_NEW_CHILD]
  1507. ldx [%g6 + TI_FLAGS], %l0
  1508. call schedule_tail
  1509. mov %g7, %o0
  1510. andcc %l0, _TIF_PERFCTR, %g0
  1511. be,pt %icc, 1f
  1512. nop
  1513. ldx [%g6 + TI_PCR], %o7
  1514. wr %g0, %o7, %pcr
  1515. /* Blackbird errata workaround. See commentary in
  1516. * smp.c:smp_percpu_timer_interrupt() for more
  1517. * information.
  1518. */
  1519. ba,pt %xcc, 99f
  1520. nop
  1521. .align 64
  1522. 99: wr %g0, %g0, %pic
  1523. rd %pic, %g0
  1524. 1: b,pt %xcc, ret_sys_call
  1525. ldx [%sp + PTREGS_OFF + PT_V9_I0], %o0
  1526. sparc_exit: wrpr %g0, (PSTATE_RMO | PSTATE_PEF | PSTATE_PRIV), %pstate
  1527. rdpr %otherwin, %g1
  1528. rdpr %cansave, %g3
  1529. add %g3, %g1, %g3
  1530. wrpr %g3, 0x0, %cansave
  1531. wrpr %g0, 0x0, %otherwin
  1532. wrpr %g0, (PSTATE_RMO | PSTATE_PEF | PSTATE_PRIV | PSTATE_IE), %pstate
  1533. ba,pt %xcc, sys_exit
  1534. stb %g0, [%g6 + TI_WSAVED]
  1535. linux_sparc_ni_syscall:
  1536. sethi %hi(sys_ni_syscall), %l7
  1537. b,pt %xcc, 4f
  1538. or %l7, %lo(sys_ni_syscall), %l7
  1539. linux_syscall_trace32:
  1540. add %sp, PTREGS_OFF, %o0
  1541. call syscall_trace
  1542. clr %o1
  1543. srl %i0, 0, %o0
  1544. srl %i4, 0, %o4
  1545. srl %i1, 0, %o1
  1546. srl %i2, 0, %o2
  1547. b,pt %xcc, 2f
  1548. srl %i3, 0, %o3
  1549. linux_syscall_trace:
  1550. add %sp, PTREGS_OFF, %o0
  1551. call syscall_trace
  1552. clr %o1
  1553. mov %i0, %o0
  1554. mov %i1, %o1
  1555. mov %i2, %o2
  1556. mov %i3, %o3
  1557. b,pt %xcc, 2f
  1558. mov %i4, %o4
  1559. /* Linux 32-bit and SunOS system calls enter here... */
  1560. .align 32
  1561. .globl linux_sparc_syscall32
  1562. linux_sparc_syscall32:
  1563. /* Direct access to user regs, much faster. */
  1564. cmp %g1, NR_SYSCALLS ! IEU1 Group
  1565. bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
  1566. srl %i0, 0, %o0 ! IEU0
  1567. sll %g1, 2, %l4 ! IEU0 Group
  1568. srl %i4, 0, %o4 ! IEU1
  1569. lduw [%l7 + %l4], %l7 ! Load
  1570. srl %i1, 0, %o1 ! IEU0 Group
  1571. ldx [%curptr + TI_FLAGS], %l0 ! Load
  1572. srl %i5, 0, %o5 ! IEU1
  1573. srl %i2, 0, %o2 ! IEU0 Group
  1574. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
  1575. bne,pn %icc, linux_syscall_trace32 ! CTI
  1576. mov %i0, %l5 ! IEU1
  1577. call %l7 ! CTI Group brk forced
  1578. srl %i3, 0, %o3 ! IEU0
  1579. ba,a,pt %xcc, 3f
  1580. /* Linux native and SunOS system calls enter here... */
  1581. .align 32
  1582. .globl linux_sparc_syscall, ret_sys_call
  1583. linux_sparc_syscall:
  1584. /* Direct access to user regs, much faster. */
  1585. cmp %g1, NR_SYSCALLS ! IEU1 Group
  1586. bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
  1587. mov %i0, %o0 ! IEU0
  1588. sll %g1, 2, %l4 ! IEU0 Group
  1589. mov %i1, %o1 ! IEU1
  1590. lduw [%l7 + %l4], %l7 ! Load
  1591. 4: mov %i2, %o2 ! IEU0 Group
  1592. ldx [%curptr + TI_FLAGS], %l0 ! Load
  1593. mov %i3, %o3 ! IEU1
  1594. mov %i4, %o4 ! IEU0 Group
  1595. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
  1596. bne,pn %icc, linux_syscall_trace ! CTI Group
  1597. mov %i0, %l5 ! IEU0
  1598. 2: call %l7 ! CTI Group brk forced
  1599. mov %i5, %o5 ! IEU0
  1600. nop
  1601. 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  1602. ret_sys_call:
  1603. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
  1604. ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
  1605. sra %o0, 0, %o0
  1606. mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
  1607. sllx %g2, 32, %g2
  1608. /* Check if force_successful_syscall_return()
  1609. * was invoked.
  1610. */
  1611. ldub [%curptr + TI_SYS_NOERROR], %l0
  1612. brz,pt %l0, 1f
  1613. nop
  1614. ba,pt %xcc, 80f
  1615. stb %g0, [%curptr + TI_SYS_NOERROR]
  1616. 1:
  1617. cmp %o0, -ERESTART_RESTARTBLOCK
  1618. bgeu,pn %xcc, 1f
  1619. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
  1620. 80:
  1621. /* System call success, clear Carry condition code. */
  1622. andn %g3, %g2, %g3
  1623. stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
  1624. bne,pn %icc, linux_syscall_trace2
  1625. add %l1, 0x4, %l2 ! npc = npc+4
  1626. stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
  1627. ba,pt %xcc, rtrap_clr_l6
  1628. stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
  1629. 1:
  1630. /* System call failure, set Carry condition code.
  1631. * Also, get abs(errno) to return to the process.
  1632. */
  1633. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
  1634. sub %g0, %o0, %o0
  1635. or %g3, %g2, %g3
  1636. stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  1637. mov 1, %l6
  1638. stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
  1639. bne,pn %icc, linux_syscall_trace2
  1640. add %l1, 0x4, %l2 ! npc = npc+4
  1641. stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
  1642. b,pt %xcc, rtrap
  1643. stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
  1644. linux_syscall_trace2:
  1645. add %sp, PTREGS_OFF, %o0
  1646. call syscall_trace
  1647. mov 1, %o1
  1648. stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
  1649. ba,pt %xcc, rtrap
  1650. stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
  1651. .align 32
  1652. .globl __flushw_user
  1653. __flushw_user:
  1654. rdpr %otherwin, %g1
  1655. brz,pn %g1, 2f
  1656. clr %g2
  1657. 1: save %sp, -128, %sp
  1658. rdpr %otherwin, %g1
  1659. brnz,pt %g1, 1b
  1660. add %g2, 1, %g2
  1661. 1: sub %g2, 1, %g2
  1662. brnz,pt %g2, 1b
  1663. restore %g0, %g0, %g0
  1664. 2: retl
  1665. nop