entry.S 48 KB

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