entry.S 48 KB

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