entry.S 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667
  1. /* arch/sparc/kernel/entry.S: Sparc trap low-level entry points.
  2. *
  3. * Copyright (C) 1995, 2007 David S. Miller (davem@davemloft.net)
  4. * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
  5. * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
  6. * Copyright (C) 1996-1999 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  7. * Copyright (C) 1997 Anton Blanchard (anton@progsoc.uts.edu.au)
  8. */
  9. #include <linux/errno.h>
  10. #include <asm/head.h>
  11. #include <asm/asi.h>
  12. #include <asm/smp.h>
  13. #include <asm/contregs.h>
  14. #include <asm/ptrace.h>
  15. #include <asm/asm-offsets.h>
  16. #include <asm/psr.h>
  17. #include <asm/vaddrs.h>
  18. #include <asm/memreg.h>
  19. #include <asm/page.h>
  20. #include <asm/pgtable.h>
  21. #include <asm/pgtsun4c.h>
  22. #include <asm/winmacro.h>
  23. #include <asm/signal.h>
  24. #include <asm/obio.h>
  25. #include <asm/mxcc.h>
  26. #include <asm/thread_info.h>
  27. #include <asm/param.h>
  28. #include <asm/unistd.h>
  29. #include <asm/asmmacro.h>
  30. #define curptr g6
  31. /* These are just handy. */
  32. #define _SV save %sp, -STACKFRAME_SZ, %sp
  33. #define _RS restore
  34. #define FLUSH_ALL_KERNEL_WINDOWS \
  35. _SV; _SV; _SV; _SV; _SV; _SV; _SV; \
  36. _RS; _RS; _RS; _RS; _RS; _RS; _RS;
  37. .text
  38. #ifdef CONFIG_KGDB
  39. .align 4
  40. .globl arch_kgdb_breakpoint
  41. .type arch_kgdb_breakpoint,#function
  42. arch_kgdb_breakpoint:
  43. ta 0x7d
  44. retl
  45. nop
  46. .size arch_kgdb_breakpoint,.-arch_kgdb_breakpoint
  47. #endif
  48. #if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
  49. .align 4
  50. .globl floppy_hardint
  51. floppy_hardint:
  52. /*
  53. * This code cannot touch registers %l0 %l1 and %l2
  54. * because SAVE_ALL depends on their values. It depends
  55. * on %l3 also, but we regenerate it before a call.
  56. * Other registers are:
  57. * %l3 -- base address of fdc registers
  58. * %l4 -- pdma_vaddr
  59. * %l5 -- scratch for ld/st address
  60. * %l6 -- pdma_size
  61. * %l7 -- scratch [floppy byte, ld/st address, aux. data]
  62. */
  63. /* Do we have work to do? */
  64. sethi %hi(doing_pdma), %l7
  65. ld [%l7 + %lo(doing_pdma)], %l7
  66. cmp %l7, 0
  67. be floppy_dosoftint
  68. nop
  69. /* Load fdc register base */
  70. sethi %hi(fdc_status), %l3
  71. ld [%l3 + %lo(fdc_status)], %l3
  72. /* Setup register addresses */
  73. sethi %hi(pdma_vaddr), %l5 ! transfer buffer
  74. ld [%l5 + %lo(pdma_vaddr)], %l4
  75. sethi %hi(pdma_size), %l5 ! bytes to go
  76. ld [%l5 + %lo(pdma_size)], %l6
  77. next_byte:
  78. ldub [%l3], %l7
  79. andcc %l7, 0x80, %g0 ! Does fifo still have data
  80. bz floppy_fifo_emptied ! fifo has been emptied...
  81. andcc %l7, 0x20, %g0 ! in non-dma mode still?
  82. bz floppy_overrun ! nope, overrun
  83. andcc %l7, 0x40, %g0 ! 0=write 1=read
  84. bz floppy_write
  85. sub %l6, 0x1, %l6
  86. /* Ok, actually read this byte */
  87. ldub [%l3 + 1], %l7
  88. orcc %g0, %l6, %g0
  89. stb %l7, [%l4]
  90. bne next_byte
  91. add %l4, 0x1, %l4
  92. b floppy_tdone
  93. nop
  94. floppy_write:
  95. /* Ok, actually write this byte */
  96. ldub [%l4], %l7
  97. orcc %g0, %l6, %g0
  98. stb %l7, [%l3 + 1]
  99. bne next_byte
  100. add %l4, 0x1, %l4
  101. /* fall through... */
  102. floppy_tdone:
  103. sethi %hi(pdma_vaddr), %l5
  104. st %l4, [%l5 + %lo(pdma_vaddr)]
  105. sethi %hi(pdma_size), %l5
  106. st %l6, [%l5 + %lo(pdma_size)]
  107. /* Flip terminal count pin */
  108. set auxio_register, %l7
  109. ld [%l7], %l7
  110. set sparc_cpu_model, %l5
  111. ld [%l5], %l5
  112. subcc %l5, 1, %g0 /* enum { sun4c = 1 }; */
  113. be 1f
  114. ldub [%l7], %l5
  115. or %l5, 0xc2, %l5
  116. stb %l5, [%l7]
  117. andn %l5, 0x02, %l5
  118. b 2f
  119. nop
  120. 1:
  121. or %l5, 0xf4, %l5
  122. stb %l5, [%l7]
  123. andn %l5, 0x04, %l5
  124. 2:
  125. /* Kill some time so the bits set */
  126. WRITE_PAUSE
  127. WRITE_PAUSE
  128. stb %l5, [%l7]
  129. /* Prevent recursion */
  130. sethi %hi(doing_pdma), %l7
  131. b floppy_dosoftint
  132. st %g0, [%l7 + %lo(doing_pdma)]
  133. /* We emptied the FIFO, but we haven't read everything
  134. * as of yet. Store the current transfer address and
  135. * bytes left to read so we can continue when the next
  136. * fast IRQ comes in.
  137. */
  138. floppy_fifo_emptied:
  139. sethi %hi(pdma_vaddr), %l5
  140. st %l4, [%l5 + %lo(pdma_vaddr)]
  141. sethi %hi(pdma_size), %l7
  142. st %l6, [%l7 + %lo(pdma_size)]
  143. /* Restore condition codes */
  144. wr %l0, 0x0, %psr
  145. WRITE_PAUSE
  146. jmp %l1
  147. rett %l2
  148. floppy_overrun:
  149. sethi %hi(pdma_vaddr), %l5
  150. st %l4, [%l5 + %lo(pdma_vaddr)]
  151. sethi %hi(pdma_size), %l5
  152. st %l6, [%l5 + %lo(pdma_size)]
  153. /* Prevent recursion */
  154. sethi %hi(doing_pdma), %l7
  155. st %g0, [%l7 + %lo(doing_pdma)]
  156. /* fall through... */
  157. floppy_dosoftint:
  158. rd %wim, %l3
  159. SAVE_ALL
  160. /* Set all IRQs off. */
  161. or %l0, PSR_PIL, %l4
  162. wr %l4, 0x0, %psr
  163. WRITE_PAUSE
  164. wr %l4, PSR_ET, %psr
  165. WRITE_PAUSE
  166. mov 11, %o0 ! floppy irq level (unused anyway)
  167. mov %g0, %o1 ! devid is not used in fast interrupts
  168. call sparc_floppy_irq
  169. add %sp, STACKFRAME_SZ, %o2 ! struct pt_regs *regs
  170. RESTORE_ALL
  171. #endif /* (CONFIG_BLK_DEV_FD) */
  172. /* Bad trap handler */
  173. .globl bad_trap_handler
  174. bad_trap_handler:
  175. SAVE_ALL
  176. wr %l0, PSR_ET, %psr
  177. WRITE_PAUSE
  178. add %sp, STACKFRAME_SZ, %o0 ! pt_regs
  179. call do_hw_interrupt
  180. mov %l7, %o1 ! trap number
  181. RESTORE_ALL
  182. /* For now all IRQ's not registered get sent here. handler_irq() will
  183. * see if a routine is registered to handle this interrupt and if not
  184. * it will say so on the console.
  185. */
  186. .align 4
  187. .globl real_irq_entry, patch_handler_irq
  188. real_irq_entry:
  189. SAVE_ALL
  190. #ifdef CONFIG_SMP
  191. .globl patchme_maybe_smp_msg
  192. cmp %l7, 11
  193. patchme_maybe_smp_msg:
  194. bgu maybe_smp4m_msg
  195. nop
  196. #endif
  197. real_irq_continue:
  198. or %l0, PSR_PIL, %g2
  199. wr %g2, 0x0, %psr
  200. WRITE_PAUSE
  201. wr %g2, PSR_ET, %psr
  202. WRITE_PAUSE
  203. mov %l7, %o0 ! irq level
  204. patch_handler_irq:
  205. call handler_irq
  206. add %sp, STACKFRAME_SZ, %o1 ! pt_regs ptr
  207. or %l0, PSR_PIL, %g2 ! restore PIL after handler_irq
  208. wr %g2, PSR_ET, %psr ! keep ET up
  209. WRITE_PAUSE
  210. RESTORE_ALL
  211. #ifdef CONFIG_SMP
  212. /* SMP per-cpu ticker interrupts are handled specially. */
  213. smp4m_ticker:
  214. bne real_irq_continue+4
  215. or %l0, PSR_PIL, %g2
  216. wr %g2, 0x0, %psr
  217. WRITE_PAUSE
  218. wr %g2, PSR_ET, %psr
  219. WRITE_PAUSE
  220. call smp4m_percpu_timer_interrupt
  221. add %sp, STACKFRAME_SZ, %o0
  222. wr %l0, PSR_ET, %psr
  223. WRITE_PAUSE
  224. RESTORE_ALL
  225. /* Here is where we check for possible SMP IPI passed to us
  226. * on some level other than 15 which is the NMI and only used
  227. * for cross calls. That has a separate entry point below.
  228. *
  229. * IPIs are sent on Level 12, 13 and 14. See IRQ_IPI_*.
  230. */
  231. maybe_smp4m_msg:
  232. GET_PROCESSOR4M_ID(o3)
  233. sethi %hi(sun4m_irq_percpu), %l5
  234. sll %o3, 2, %o3
  235. or %l5, %lo(sun4m_irq_percpu), %o5
  236. sethi %hi(0x70000000), %o2 ! Check all soft-IRQs
  237. ld [%o5 + %o3], %o1
  238. ld [%o1 + 0x00], %o3 ! sun4m_irq_percpu[cpu]->pending
  239. andcc %o3, %o2, %g0
  240. be,a smp4m_ticker
  241. cmp %l7, 14
  242. /* Soft-IRQ IPI */
  243. st %o2, [%o1 + 0x04] ! sun4m_irq_percpu[cpu]->clear=0x70000000
  244. WRITE_PAUSE
  245. ld [%o1 + 0x00], %g0 ! sun4m_irq_percpu[cpu]->pending
  246. WRITE_PAUSE
  247. or %l0, PSR_PIL, %l4
  248. wr %l4, 0x0, %psr
  249. WRITE_PAUSE
  250. wr %l4, PSR_ET, %psr
  251. WRITE_PAUSE
  252. srl %o3, 28, %o2 ! shift for simpler checks below
  253. maybe_smp4m_msg_check_single:
  254. andcc %o2, 0x1, %g0
  255. beq,a maybe_smp4m_msg_check_mask
  256. andcc %o2, 0x2, %g0
  257. call smp_call_function_single_interrupt
  258. nop
  259. andcc %o2, 0x2, %g0
  260. maybe_smp4m_msg_check_mask:
  261. beq,a maybe_smp4m_msg_check_resched
  262. andcc %o2, 0x4, %g0
  263. call smp_call_function_interrupt
  264. nop
  265. andcc %o2, 0x4, %g0
  266. maybe_smp4m_msg_check_resched:
  267. /* rescheduling is done in RESTORE_ALL regardless, but incr stats */
  268. beq,a maybe_smp4m_msg_out
  269. nop
  270. call smp_resched_interrupt
  271. nop
  272. maybe_smp4m_msg_out:
  273. RESTORE_ALL
  274. .align 4
  275. .globl linux_trap_ipi15
  276. linux_trap_ipi15:
  277. SAVE_ALL
  278. sethi %hi(0x80000000), %o2
  279. GET_PROCESSOR4M_ID(o0)
  280. sethi %hi(sun4m_irq_percpu), %l5
  281. or %l5, %lo(sun4m_irq_percpu), %o5
  282. sll %o0, 2, %o0
  283. ld [%o5 + %o0], %o5
  284. ld [%o5 + 0x00], %o3 ! sun4m_irq_percpu[cpu]->pending
  285. andcc %o3, %o2, %g0
  286. be 1f ! Must be an NMI async memory error
  287. st %o2, [%o5 + 0x04] ! sun4m_irq_percpu[cpu]->clear=0x80000000
  288. WRITE_PAUSE
  289. ld [%o5 + 0x00], %g0 ! sun4m_irq_percpu[cpu]->pending
  290. WRITE_PAUSE
  291. or %l0, PSR_PIL, %l4
  292. wr %l4, 0x0, %psr
  293. WRITE_PAUSE
  294. wr %l4, PSR_ET, %psr
  295. WRITE_PAUSE
  296. call smp4m_cross_call_irq
  297. nop
  298. b ret_trap_lockless_ipi
  299. clr %l6
  300. 1:
  301. /* NMI async memory error handling. */
  302. sethi %hi(0x80000000), %l4
  303. sethi %hi(sun4m_irq_global), %o5
  304. ld [%o5 + %lo(sun4m_irq_global)], %l5
  305. st %l4, [%l5 + 0x0c] ! sun4m_irq_global->mask_set=0x80000000
  306. WRITE_PAUSE
  307. ld [%l5 + 0x00], %g0 ! sun4m_irq_global->pending
  308. WRITE_PAUSE
  309. or %l0, PSR_PIL, %l4
  310. wr %l4, 0x0, %psr
  311. WRITE_PAUSE
  312. wr %l4, PSR_ET, %psr
  313. WRITE_PAUSE
  314. call sun4m_nmi
  315. nop
  316. st %l4, [%l5 + 0x08] ! sun4m_irq_global->mask_clear=0x80000000
  317. WRITE_PAUSE
  318. ld [%l5 + 0x00], %g0 ! sun4m_irq_global->pending
  319. WRITE_PAUSE
  320. RESTORE_ALL
  321. .globl smp4d_ticker
  322. /* SMP per-cpu ticker interrupts are handled specially. */
  323. smp4d_ticker:
  324. SAVE_ALL
  325. or %l0, PSR_PIL, %g2
  326. sethi %hi(CC_ICLR), %o0
  327. sethi %hi(1 << 14), %o1
  328. or %o0, %lo(CC_ICLR), %o0
  329. stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 14 in MXCC's ICLR */
  330. wr %g2, 0x0, %psr
  331. WRITE_PAUSE
  332. wr %g2, PSR_ET, %psr
  333. WRITE_PAUSE
  334. call smp4d_percpu_timer_interrupt
  335. add %sp, STACKFRAME_SZ, %o0
  336. wr %l0, PSR_ET, %psr
  337. WRITE_PAUSE
  338. RESTORE_ALL
  339. .align 4
  340. .globl linux_trap_ipi15_sun4d
  341. linux_trap_ipi15_sun4d:
  342. SAVE_ALL
  343. sethi %hi(CC_BASE), %o4
  344. sethi %hi(MXCC_ERR_ME|MXCC_ERR_PEW|MXCC_ERR_ASE|MXCC_ERR_PEE), %o2
  345. or %o4, (CC_EREG - CC_BASE), %o0
  346. ldda [%o0] ASI_M_MXCC, %o0
  347. andcc %o0, %o2, %g0
  348. bne 1f
  349. sethi %hi(BB_STAT2), %o2
  350. lduba [%o2] ASI_M_CTL, %o2
  351. andcc %o2, BB_STAT2_MASK, %g0
  352. bne 2f
  353. or %o4, (CC_ICLR - CC_BASE), %o0
  354. sethi %hi(1 << 15), %o1
  355. stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 15 in MXCC's ICLR */
  356. or %l0, PSR_PIL, %l4
  357. wr %l4, 0x0, %psr
  358. WRITE_PAUSE
  359. wr %l4, PSR_ET, %psr
  360. WRITE_PAUSE
  361. call smp4d_cross_call_irq
  362. nop
  363. b ret_trap_lockless_ipi
  364. clr %l6
  365. 1: /* MXCC error */
  366. 2: /* BB error */
  367. /* Disable PIL 15 */
  368. set CC_IMSK, %l4
  369. lduha [%l4] ASI_M_MXCC, %l5
  370. sethi %hi(1 << 15), %l7
  371. or %l5, %l7, %l5
  372. stha %l5, [%l4] ASI_M_MXCC
  373. /* FIXME */
  374. 1: b,a 1b
  375. #ifdef CONFIG_SPARC_LEON
  376. .globl smpleon_ipi
  377. .extern leon_ipi_interrupt
  378. /* SMP per-cpu IPI interrupts are handled specially. */
  379. smpleon_ipi:
  380. SAVE_ALL
  381. or %l0, PSR_PIL, %g2
  382. wr %g2, 0x0, %psr
  383. WRITE_PAUSE
  384. wr %g2, PSR_ET, %psr
  385. WRITE_PAUSE
  386. call leonsmp_ipi_interrupt
  387. add %sp, STACKFRAME_SZ, %o1 ! pt_regs
  388. wr %l0, PSR_ET, %psr
  389. WRITE_PAUSE
  390. RESTORE_ALL
  391. .align 4
  392. .globl linux_trap_ipi15_leon
  393. linux_trap_ipi15_leon:
  394. SAVE_ALL
  395. or %l0, PSR_PIL, %l4
  396. wr %l4, 0x0, %psr
  397. WRITE_PAUSE
  398. wr %l4, PSR_ET, %psr
  399. WRITE_PAUSE
  400. call leon_cross_call_irq
  401. nop
  402. b ret_trap_lockless_ipi
  403. clr %l6
  404. #endif /* CONFIG_SPARC_LEON */
  405. #endif /* CONFIG_SMP */
  406. /* This routine handles illegal instructions and privileged
  407. * instruction attempts from user code.
  408. */
  409. .align 4
  410. .globl bad_instruction
  411. bad_instruction:
  412. sethi %hi(0xc1f80000), %l4
  413. ld [%l1], %l5
  414. sethi %hi(0x81d80000), %l7
  415. and %l5, %l4, %l5
  416. cmp %l5, %l7
  417. be 1f
  418. SAVE_ALL
  419. wr %l0, PSR_ET, %psr ! re-enable traps
  420. WRITE_PAUSE
  421. add %sp, STACKFRAME_SZ, %o0
  422. mov %l1, %o1
  423. mov %l2, %o2
  424. call do_illegal_instruction
  425. mov %l0, %o3
  426. RESTORE_ALL
  427. 1: /* unimplemented flush - just skip */
  428. jmpl %l2, %g0
  429. rett %l2 + 4
  430. .align 4
  431. .globl priv_instruction
  432. priv_instruction:
  433. SAVE_ALL
  434. wr %l0, PSR_ET, %psr
  435. WRITE_PAUSE
  436. add %sp, STACKFRAME_SZ, %o0
  437. mov %l1, %o1
  438. mov %l2, %o2
  439. call do_priv_instruction
  440. mov %l0, %o3
  441. RESTORE_ALL
  442. /* This routine handles unaligned data accesses. */
  443. .align 4
  444. .globl mna_handler
  445. mna_handler:
  446. andcc %l0, PSR_PS, %g0
  447. be mna_fromuser
  448. nop
  449. SAVE_ALL
  450. wr %l0, PSR_ET, %psr
  451. WRITE_PAUSE
  452. ld [%l1], %o1
  453. call kernel_unaligned_trap
  454. add %sp, STACKFRAME_SZ, %o0
  455. RESTORE_ALL
  456. mna_fromuser:
  457. SAVE_ALL
  458. wr %l0, PSR_ET, %psr ! re-enable traps
  459. WRITE_PAUSE
  460. ld [%l1], %o1
  461. call user_unaligned_trap
  462. add %sp, STACKFRAME_SZ, %o0
  463. RESTORE_ALL
  464. /* This routine handles floating point disabled traps. */
  465. .align 4
  466. .globl fpd_trap_handler
  467. fpd_trap_handler:
  468. SAVE_ALL
  469. wr %l0, PSR_ET, %psr ! re-enable traps
  470. WRITE_PAUSE
  471. add %sp, STACKFRAME_SZ, %o0
  472. mov %l1, %o1
  473. mov %l2, %o2
  474. call do_fpd_trap
  475. mov %l0, %o3
  476. RESTORE_ALL
  477. /* This routine handles Floating Point Exceptions. */
  478. .align 4
  479. .globl fpe_trap_handler
  480. fpe_trap_handler:
  481. set fpsave_magic, %l5
  482. cmp %l1, %l5
  483. be 1f
  484. sethi %hi(fpsave), %l5
  485. or %l5, %lo(fpsave), %l5
  486. cmp %l1, %l5
  487. bne 2f
  488. sethi %hi(fpsave_catch2), %l5
  489. or %l5, %lo(fpsave_catch2), %l5
  490. wr %l0, 0x0, %psr
  491. WRITE_PAUSE
  492. jmp %l5
  493. rett %l5 + 4
  494. 1:
  495. sethi %hi(fpsave_catch), %l5
  496. or %l5, %lo(fpsave_catch), %l5
  497. wr %l0, 0x0, %psr
  498. WRITE_PAUSE
  499. jmp %l5
  500. rett %l5 + 4
  501. 2:
  502. SAVE_ALL
  503. wr %l0, PSR_ET, %psr ! re-enable traps
  504. WRITE_PAUSE
  505. add %sp, STACKFRAME_SZ, %o0
  506. mov %l1, %o1
  507. mov %l2, %o2
  508. call do_fpe_trap
  509. mov %l0, %o3
  510. RESTORE_ALL
  511. /* This routine handles Tag Overflow Exceptions. */
  512. .align 4
  513. .globl do_tag_overflow
  514. do_tag_overflow:
  515. SAVE_ALL
  516. wr %l0, PSR_ET, %psr ! re-enable traps
  517. WRITE_PAUSE
  518. add %sp, STACKFRAME_SZ, %o0
  519. mov %l1, %o1
  520. mov %l2, %o2
  521. call handle_tag_overflow
  522. mov %l0, %o3
  523. RESTORE_ALL
  524. /* This routine handles Watchpoint Exceptions. */
  525. .align 4
  526. .globl do_watchpoint
  527. do_watchpoint:
  528. SAVE_ALL
  529. wr %l0, PSR_ET, %psr ! re-enable traps
  530. WRITE_PAUSE
  531. add %sp, STACKFRAME_SZ, %o0
  532. mov %l1, %o1
  533. mov %l2, %o2
  534. call handle_watchpoint
  535. mov %l0, %o3
  536. RESTORE_ALL
  537. /* This routine handles Register Access Exceptions. */
  538. .align 4
  539. .globl do_reg_access
  540. do_reg_access:
  541. SAVE_ALL
  542. wr %l0, PSR_ET, %psr ! re-enable traps
  543. WRITE_PAUSE
  544. add %sp, STACKFRAME_SZ, %o0
  545. mov %l1, %o1
  546. mov %l2, %o2
  547. call handle_reg_access
  548. mov %l0, %o3
  549. RESTORE_ALL
  550. /* This routine handles Co-Processor Disabled Exceptions. */
  551. .align 4
  552. .globl do_cp_disabled
  553. do_cp_disabled:
  554. SAVE_ALL
  555. wr %l0, PSR_ET, %psr ! re-enable traps
  556. WRITE_PAUSE
  557. add %sp, STACKFRAME_SZ, %o0
  558. mov %l1, %o1
  559. mov %l2, %o2
  560. call handle_cp_disabled
  561. mov %l0, %o3
  562. RESTORE_ALL
  563. /* This routine handles Co-Processor Exceptions. */
  564. .align 4
  565. .globl do_cp_exception
  566. do_cp_exception:
  567. SAVE_ALL
  568. wr %l0, PSR_ET, %psr ! re-enable traps
  569. WRITE_PAUSE
  570. add %sp, STACKFRAME_SZ, %o0
  571. mov %l1, %o1
  572. mov %l2, %o2
  573. call handle_cp_exception
  574. mov %l0, %o3
  575. RESTORE_ALL
  576. /* This routine handles Hardware Divide By Zero Exceptions. */
  577. .align 4
  578. .globl do_hw_divzero
  579. do_hw_divzero:
  580. SAVE_ALL
  581. wr %l0, PSR_ET, %psr ! re-enable traps
  582. WRITE_PAUSE
  583. add %sp, STACKFRAME_SZ, %o0
  584. mov %l1, %o1
  585. mov %l2, %o2
  586. call handle_hw_divzero
  587. mov %l0, %o3
  588. RESTORE_ALL
  589. .align 4
  590. .globl do_flush_windows
  591. do_flush_windows:
  592. SAVE_ALL
  593. wr %l0, PSR_ET, %psr
  594. WRITE_PAUSE
  595. andcc %l0, PSR_PS, %g0
  596. bne dfw_kernel
  597. nop
  598. call flush_user_windows
  599. nop
  600. /* Advance over the trap instruction. */
  601. ld [%sp + STACKFRAME_SZ + PT_NPC], %l1
  602. add %l1, 0x4, %l2
  603. st %l1, [%sp + STACKFRAME_SZ + PT_PC]
  604. st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
  605. RESTORE_ALL
  606. .globl flush_patch_one
  607. /* We get these for debugging routines using __builtin_return_address() */
  608. dfw_kernel:
  609. flush_patch_one:
  610. FLUSH_ALL_KERNEL_WINDOWS
  611. /* Advance over the trap instruction. */
  612. ld [%sp + STACKFRAME_SZ + PT_NPC], %l1
  613. add %l1, 0x4, %l2
  614. st %l1, [%sp + STACKFRAME_SZ + PT_PC]
  615. st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
  616. RESTORE_ALL
  617. /* The getcc software trap. The user wants the condition codes from
  618. * the %psr in register %g1.
  619. */
  620. .align 4
  621. .globl getcc_trap_handler
  622. getcc_trap_handler:
  623. srl %l0, 20, %g1 ! give user
  624. and %g1, 0xf, %g1 ! only ICC bits in %psr
  625. jmp %l2 ! advance over trap instruction
  626. rett %l2 + 0x4 ! like this...
  627. /* The setcc software trap. The user has condition codes in %g1
  628. * that it would like placed in the %psr. Be careful not to flip
  629. * any unintentional bits!
  630. */
  631. .align 4
  632. .globl setcc_trap_handler
  633. setcc_trap_handler:
  634. sll %g1, 0x14, %l4
  635. set PSR_ICC, %l5
  636. andn %l0, %l5, %l0 ! clear ICC bits in %psr
  637. and %l4, %l5, %l4 ! clear non-ICC bits in user value
  638. or %l4, %l0, %l4 ! or them in... mix mix mix
  639. wr %l4, 0x0, %psr ! set new %psr
  640. WRITE_PAUSE ! TI scumbags...
  641. jmp %l2 ! advance over trap instruction
  642. rett %l2 + 0x4 ! like this...
  643. #ifndef CONFIG_SMP
  644. .align 4
  645. .globl linux_trap_ipi15
  646. linux_trap_ipi15:
  647. SAVE_ALL
  648. /* Now it is safe to re-enable traps without recursion. */
  649. or %l0, PSR_PIL, %l0
  650. wr %l0, PSR_ET, %psr
  651. WRITE_PAUSE
  652. /* Now call the c-code with the pt_regs frame ptr and the
  653. * memory error registers as arguments. The ordering chosen
  654. * here is due to unlatching semantics.
  655. */
  656. sethi %hi(AC_SYNC_ERR), %o0
  657. add %o0, 0x4, %o0
  658. lda [%o0] ASI_CONTROL, %o2 ! sync vaddr
  659. sub %o0, 0x4, %o0
  660. lda [%o0] ASI_CONTROL, %o1 ! sync error
  661. add %o0, 0xc, %o0
  662. lda [%o0] ASI_CONTROL, %o4 ! async vaddr
  663. sub %o0, 0x4, %o0
  664. lda [%o0] ASI_CONTROL, %o3 ! async error
  665. call sparc_lvl15_nmi
  666. add %sp, STACKFRAME_SZ, %o0
  667. RESTORE_ALL
  668. #endif /* CONFIG_SMP */
  669. .align 4
  670. .globl invalid_segment_patch1_ff
  671. .globl invalid_segment_patch2_ff
  672. invalid_segment_patch1_ff: cmp %l4, 0xff
  673. invalid_segment_patch2_ff: mov 0xff, %l3
  674. .align 4
  675. .globl invalid_segment_patch1_1ff
  676. .globl invalid_segment_patch2_1ff
  677. invalid_segment_patch1_1ff: cmp %l4, 0x1ff
  678. invalid_segment_patch2_1ff: mov 0x1ff, %l3
  679. .align 4
  680. .globl num_context_patch1_16, num_context_patch2_16
  681. num_context_patch1_16: mov 0x10, %l7
  682. num_context_patch2_16: mov 0x10, %l7
  683. .align 4
  684. .globl vac_linesize_patch_32
  685. vac_linesize_patch_32: subcc %l7, 32, %l7
  686. .align 4
  687. .globl vac_hwflush_patch1_on, vac_hwflush_patch2_on
  688. /*
  689. * Ugly, but we can't use hardware flushing on the sun4 and we'd require
  690. * two instructions (Anton)
  691. */
  692. vac_hwflush_patch1_on: addcc %l7, -PAGE_SIZE, %l7
  693. vac_hwflush_patch2_on: sta %g0, [%l3 + %l7] ASI_HWFLUSHSEG
  694. .globl invalid_segment_patch1, invalid_segment_patch2
  695. .globl num_context_patch1
  696. .globl vac_linesize_patch, vac_hwflush_patch1
  697. .globl vac_hwflush_patch2
  698. .align 4
  699. .globl sun4c_fault
  700. ! %l0 = %psr
  701. ! %l1 = %pc
  702. ! %l2 = %npc
  703. ! %l3 = %wim
  704. ! %l7 = 1 for textfault
  705. ! We want error in %l5, vaddr in %l6
  706. sun4c_fault:
  707. sethi %hi(AC_SYNC_ERR), %l4
  708. add %l4, 0x4, %l6 ! AC_SYNC_VA in %l6
  709. lda [%l6] ASI_CONTROL, %l5 ! Address
  710. lda [%l4] ASI_CONTROL, %l6 ! Error, retained for a bit
  711. andn %l5, 0xfff, %l5 ! Encode all info into l7
  712. srl %l6, 14, %l4
  713. and %l4, 2, %l4
  714. or %l5, %l4, %l4
  715. or %l4, %l7, %l7 ! l7 = [addr,write,txtfault]
  716. andcc %l0, PSR_PS, %g0
  717. be sun4c_fault_fromuser
  718. andcc %l7, 1, %g0 ! Text fault?
  719. be 1f
  720. sethi %hi(KERNBASE), %l4
  721. mov %l1, %l5 ! PC
  722. 1:
  723. cmp %l5, %l4
  724. blu sun4c_fault_fromuser
  725. sethi %hi(~((1 << SUN4C_REAL_PGDIR_SHIFT) - 1)), %l4
  726. /* If the kernel references a bum kernel pointer, or a pte which
  727. * points to a non existent page in ram, we will run this code
  728. * _forever_ and lock up the machine!!!!! So we must check for
  729. * this condition, the AC_SYNC_ERR bits are what we must examine.
  730. * Also a parity error would make this happen as well. So we just
  731. * check that we are in fact servicing a tlb miss and not some
  732. * other type of fault for the kernel.
  733. */
  734. andcc %l6, 0x80, %g0
  735. be sun4c_fault_fromuser
  736. and %l5, %l4, %l5
  737. /* Test for NULL pte_t * in vmalloc area. */
  738. sethi %hi(VMALLOC_START), %l4
  739. cmp %l5, %l4
  740. blu,a invalid_segment_patch1
  741. lduXa [%l5] ASI_SEGMAP, %l4
  742. sethi %hi(swapper_pg_dir), %l4
  743. srl %l5, SUN4C_PGDIR_SHIFT, %l6
  744. or %l4, %lo(swapper_pg_dir), %l4
  745. sll %l6, 2, %l6
  746. ld [%l4 + %l6], %l4
  747. andcc %l4, PAGE_MASK, %g0
  748. be sun4c_fault_fromuser
  749. lduXa [%l5] ASI_SEGMAP, %l4
  750. invalid_segment_patch1:
  751. cmp %l4, 0x7f
  752. bne 1f
  753. sethi %hi(sun4c_kfree_ring), %l4
  754. or %l4, %lo(sun4c_kfree_ring), %l4
  755. ld [%l4 + 0x18], %l3
  756. deccc %l3 ! do we have a free entry?
  757. bcs,a 2f ! no, unmap one.
  758. sethi %hi(sun4c_kernel_ring), %l4
  759. st %l3, [%l4 + 0x18] ! sun4c_kfree_ring.num_entries--
  760. ld [%l4 + 0x00], %l6 ! entry = sun4c_kfree_ring.ringhd.next
  761. st %l5, [%l6 + 0x08] ! entry->vaddr = address
  762. ld [%l6 + 0x00], %l3 ! next = entry->next
  763. ld [%l6 + 0x04], %l7 ! entry->prev
  764. st %l7, [%l3 + 0x04] ! next->prev = entry->prev
  765. st %l3, [%l7 + 0x00] ! entry->prev->next = next
  766. sethi %hi(sun4c_kernel_ring), %l4
  767. or %l4, %lo(sun4c_kernel_ring), %l4
  768. ! head = &sun4c_kernel_ring.ringhd
  769. ld [%l4 + 0x00], %l7 ! head->next
  770. st %l4, [%l6 + 0x04] ! entry->prev = head
  771. st %l7, [%l6 + 0x00] ! entry->next = head->next
  772. st %l6, [%l7 + 0x04] ! head->next->prev = entry
  773. st %l6, [%l4 + 0x00] ! head->next = entry
  774. ld [%l4 + 0x18], %l3
  775. inc %l3 ! sun4c_kernel_ring.num_entries++
  776. st %l3, [%l4 + 0x18]
  777. b 4f
  778. ld [%l6 + 0x08], %l5
  779. 2:
  780. or %l4, %lo(sun4c_kernel_ring), %l4
  781. ! head = &sun4c_kernel_ring.ringhd
  782. ld [%l4 + 0x04], %l6 ! entry = head->prev
  783. ld [%l6 + 0x08], %l3 ! tmp = entry->vaddr
  784. ! Flush segment from the cache.
  785. sethi %hi((64 * 1024)), %l7
  786. 9:
  787. vac_hwflush_patch1:
  788. vac_linesize_patch:
  789. subcc %l7, 16, %l7
  790. bne 9b
  791. vac_hwflush_patch2:
  792. sta %g0, [%l3 + %l7] ASI_FLUSHSEG
  793. st %l5, [%l6 + 0x08] ! entry->vaddr = address
  794. ld [%l6 + 0x00], %l5 ! next = entry->next
  795. ld [%l6 + 0x04], %l7 ! entry->prev
  796. st %l7, [%l5 + 0x04] ! next->prev = entry->prev
  797. st %l5, [%l7 + 0x00] ! entry->prev->next = next
  798. st %l4, [%l6 + 0x04] ! entry->prev = head
  799. ld [%l4 + 0x00], %l7 ! head->next
  800. st %l7, [%l6 + 0x00] ! entry->next = head->next
  801. st %l6, [%l7 + 0x04] ! head->next->prev = entry
  802. st %l6, [%l4 + 0x00] ! head->next = entry
  803. mov %l3, %l5 ! address = tmp
  804. 4:
  805. num_context_patch1:
  806. mov 0x08, %l7
  807. ld [%l6 + 0x08], %l4
  808. ldub [%l6 + 0x0c], %l3
  809. or %l4, %l3, %l4 ! encode new vaddr/pseg into l4
  810. sethi %hi(AC_CONTEXT), %l3
  811. lduba [%l3] ASI_CONTROL, %l6
  812. /* Invalidate old mapping, instantiate new mapping,
  813. * for each context. Registers l6/l7 are live across
  814. * this loop.
  815. */
  816. 3: deccc %l7
  817. sethi %hi(AC_CONTEXT), %l3
  818. stba %l7, [%l3] ASI_CONTROL
  819. invalid_segment_patch2:
  820. mov 0x7f, %l3
  821. stXa %l3, [%l5] ASI_SEGMAP
  822. andn %l4, 0x1ff, %l3
  823. bne 3b
  824. stXa %l4, [%l3] ASI_SEGMAP
  825. sethi %hi(AC_CONTEXT), %l3
  826. stba %l6, [%l3] ASI_CONTROL
  827. andn %l4, 0x1ff, %l5
  828. 1:
  829. sethi %hi(VMALLOC_START), %l4
  830. cmp %l5, %l4
  831. bgeu 1f
  832. mov 1 << (SUN4C_REAL_PGDIR_SHIFT - PAGE_SHIFT), %l7
  833. sethi %hi(KERNBASE), %l6
  834. sub %l5, %l6, %l4
  835. srl %l4, PAGE_SHIFT, %l4
  836. sethi %hi((SUN4C_PAGE_KERNEL & 0xf4000000)), %l3
  837. or %l3, %l4, %l3
  838. sethi %hi(PAGE_SIZE), %l4
  839. 2:
  840. sta %l3, [%l5] ASI_PTE
  841. deccc %l7
  842. inc %l3
  843. bne 2b
  844. add %l5, %l4, %l5
  845. b 7f
  846. sethi %hi(sun4c_kernel_faults), %l4
  847. 1:
  848. srl %l5, SUN4C_PGDIR_SHIFT, %l3
  849. sethi %hi(swapper_pg_dir), %l4
  850. or %l4, %lo(swapper_pg_dir), %l4
  851. sll %l3, 2, %l3
  852. ld [%l4 + %l3], %l4
  853. and %l4, PAGE_MASK, %l4
  854. srl %l5, (PAGE_SHIFT - 2), %l6
  855. and %l6, ((SUN4C_PTRS_PER_PTE - 1) << 2), %l6
  856. add %l6, %l4, %l6
  857. sethi %hi(PAGE_SIZE), %l4
  858. 2:
  859. ld [%l6], %l3
  860. deccc %l7
  861. sta %l3, [%l5] ASI_PTE
  862. add %l6, 0x4, %l6
  863. bne 2b
  864. add %l5, %l4, %l5
  865. sethi %hi(sun4c_kernel_faults), %l4
  866. 7:
  867. ld [%l4 + %lo(sun4c_kernel_faults)], %l3
  868. inc %l3
  869. st %l3, [%l4 + %lo(sun4c_kernel_faults)]
  870. /* Restore condition codes */
  871. wr %l0, 0x0, %psr
  872. WRITE_PAUSE
  873. jmp %l1
  874. rett %l2
  875. sun4c_fault_fromuser:
  876. SAVE_ALL
  877. nop
  878. mov %l7, %o1 ! Decode the info from %l7
  879. mov %l7, %o2
  880. and %o1, 1, %o1 ! arg2 = text_faultp
  881. mov %l7, %o3
  882. and %o2, 2, %o2 ! arg3 = writep
  883. andn %o3, 0xfff, %o3 ! arg4 = faulting address
  884. wr %l0, PSR_ET, %psr
  885. WRITE_PAUSE
  886. call do_sun4c_fault
  887. add %sp, STACKFRAME_SZ, %o0 ! arg1 = pt_regs ptr
  888. RESTORE_ALL
  889. .align 4
  890. .globl srmmu_fault
  891. srmmu_fault:
  892. mov 0x400, %l5
  893. mov 0x300, %l4
  894. lda [%l5] ASI_M_MMUREGS, %l6 ! read sfar first
  895. lda [%l4] ASI_M_MMUREGS, %l5 ! read sfsr last
  896. andn %l6, 0xfff, %l6
  897. srl %l5, 6, %l5 ! and encode all info into l7
  898. and %l5, 2, %l5
  899. or %l5, %l6, %l6
  900. or %l6, %l7, %l7 ! l7 = [addr,write,txtfault]
  901. SAVE_ALL
  902. mov %l7, %o1
  903. mov %l7, %o2
  904. and %o1, 1, %o1 ! arg2 = text_faultp
  905. mov %l7, %o3
  906. and %o2, 2, %o2 ! arg3 = writep
  907. andn %o3, 0xfff, %o3 ! arg4 = faulting address
  908. wr %l0, PSR_ET, %psr
  909. WRITE_PAUSE
  910. call do_sparc_fault
  911. add %sp, STACKFRAME_SZ, %o0 ! arg1 = pt_regs ptr
  912. RESTORE_ALL
  913. .align 4
  914. .globl sys_nis_syscall
  915. sys_nis_syscall:
  916. mov %o7, %l5
  917. add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
  918. call c_sys_nis_syscall
  919. mov %l5, %o7
  920. .align 4
  921. .globl sys_execve
  922. sys_execve:
  923. mov %o7, %l5
  924. add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
  925. call sparc_execve
  926. mov %l5, %o7
  927. .globl sunos_execv
  928. sunos_execv:
  929. st %g0, [%sp + STACKFRAME_SZ + PT_I2]
  930. call sparc_execve
  931. add %sp, STACKFRAME_SZ, %o0
  932. b ret_sys_call
  933. ld [%sp + STACKFRAME_SZ + PT_I0], %o0
  934. .align 4
  935. .globl sys_sparc_pipe
  936. sys_sparc_pipe:
  937. mov %o7, %l5
  938. add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
  939. call sparc_pipe
  940. mov %l5, %o7
  941. .align 4
  942. .globl sys_sigaltstack
  943. sys_sigaltstack:
  944. mov %o7, %l5
  945. mov %fp, %o2
  946. call do_sigaltstack
  947. mov %l5, %o7
  948. .align 4
  949. .globl sys_sigstack
  950. sys_sigstack:
  951. mov %o7, %l5
  952. mov %fp, %o2
  953. call do_sys_sigstack
  954. mov %l5, %o7
  955. .align 4
  956. .globl sys_sigreturn
  957. sys_sigreturn:
  958. call do_sigreturn
  959. add %sp, STACKFRAME_SZ, %o0
  960. ld [%curptr + TI_FLAGS], %l5
  961. andcc %l5, _TIF_SYSCALL_TRACE, %g0
  962. be 1f
  963. nop
  964. call syscall_trace
  965. nop
  966. 1:
  967. /* We don't want to muck with user registers like a
  968. * normal syscall, just return.
  969. */
  970. RESTORE_ALL
  971. .align 4
  972. .globl sys_rt_sigreturn
  973. sys_rt_sigreturn:
  974. call do_rt_sigreturn
  975. add %sp, STACKFRAME_SZ, %o0
  976. ld [%curptr + TI_FLAGS], %l5
  977. andcc %l5, _TIF_SYSCALL_TRACE, %g0
  978. be 1f
  979. nop
  980. add %sp, STACKFRAME_SZ, %o0
  981. call syscall_trace
  982. mov 1, %o1
  983. 1:
  984. /* We are returning to a signal handler. */
  985. RESTORE_ALL
  986. /* Now that we have a real sys_clone, sys_fork() is
  987. * implemented in terms of it. Our _real_ implementation
  988. * of SunOS vfork() will use sys_vfork().
  989. *
  990. * XXX These three should be consolidated into mostly shared
  991. * XXX code just like on sparc64... -DaveM
  992. */
  993. .align 4
  994. .globl sys_fork, flush_patch_two
  995. sys_fork:
  996. mov %o7, %l5
  997. flush_patch_two:
  998. FLUSH_ALL_KERNEL_WINDOWS;
  999. ld [%curptr + TI_TASK], %o4
  1000. rd %psr, %g4
  1001. WRITE_PAUSE
  1002. mov SIGCHLD, %o0 ! arg0: clone flags
  1003. rd %wim, %g5
  1004. WRITE_PAUSE
  1005. mov %fp, %o1 ! arg1: usp
  1006. std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
  1007. add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
  1008. mov 0, %o3
  1009. call sparc_do_fork
  1010. mov %l5, %o7
  1011. /* Whee, kernel threads! */
  1012. .globl sys_clone, flush_patch_three
  1013. sys_clone:
  1014. mov %o7, %l5
  1015. flush_patch_three:
  1016. FLUSH_ALL_KERNEL_WINDOWS;
  1017. ld [%curptr + TI_TASK], %o4
  1018. rd %psr, %g4
  1019. WRITE_PAUSE
  1020. /* arg0,1: flags,usp -- loaded already */
  1021. cmp %o1, 0x0 ! Is new_usp NULL?
  1022. rd %wim, %g5
  1023. WRITE_PAUSE
  1024. be,a 1f
  1025. mov %fp, %o1 ! yes, use callers usp
  1026. andn %o1, 7, %o1 ! no, align to 8 bytes
  1027. 1:
  1028. std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
  1029. add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
  1030. mov 0, %o3
  1031. call sparc_do_fork
  1032. mov %l5, %o7
  1033. /* Whee, real vfork! */
  1034. .globl sys_vfork, flush_patch_four
  1035. sys_vfork:
  1036. flush_patch_four:
  1037. FLUSH_ALL_KERNEL_WINDOWS;
  1038. ld [%curptr + TI_TASK], %o4
  1039. rd %psr, %g4
  1040. WRITE_PAUSE
  1041. rd %wim, %g5
  1042. WRITE_PAUSE
  1043. std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
  1044. sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
  1045. mov %fp, %o1
  1046. or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
  1047. sethi %hi(sparc_do_fork), %l1
  1048. mov 0, %o3
  1049. jmpl %l1 + %lo(sparc_do_fork), %g0
  1050. add %sp, STACKFRAME_SZ, %o2
  1051. .align 4
  1052. linux_sparc_ni_syscall:
  1053. sethi %hi(sys_ni_syscall), %l7
  1054. b syscall_is_too_hard
  1055. or %l7, %lo(sys_ni_syscall), %l7
  1056. linux_fast_syscall:
  1057. andn %l7, 3, %l7
  1058. mov %i0, %o0
  1059. mov %i1, %o1
  1060. mov %i2, %o2
  1061. jmpl %l7 + %g0, %g0
  1062. mov %i3, %o3
  1063. linux_syscall_trace:
  1064. add %sp, STACKFRAME_SZ, %o0
  1065. call syscall_trace
  1066. mov 0, %o1
  1067. cmp %o0, 0
  1068. bne 3f
  1069. mov -ENOSYS, %o0
  1070. mov %i0, %o0
  1071. mov %i1, %o1
  1072. mov %i2, %o2
  1073. mov %i3, %o3
  1074. b 2f
  1075. mov %i4, %o4
  1076. .globl ret_from_fork
  1077. ret_from_fork:
  1078. call schedule_tail
  1079. ld [%g3 + TI_TASK], %o0
  1080. b ret_sys_call
  1081. ld [%sp + STACKFRAME_SZ + PT_I0], %o0
  1082. /* Linux native system calls enter here... */
  1083. .align 4
  1084. .globl linux_sparc_syscall
  1085. linux_sparc_syscall:
  1086. sethi %hi(PSR_SYSCALL), %l4
  1087. or %l0, %l4, %l0
  1088. /* Direct access to user regs, must faster. */
  1089. cmp %g1, NR_syscalls
  1090. bgeu linux_sparc_ni_syscall
  1091. sll %g1, 2, %l4
  1092. ld [%l7 + %l4], %l7
  1093. andcc %l7, 1, %g0
  1094. bne linux_fast_syscall
  1095. /* Just do first insn from SAVE_ALL in the delay slot */
  1096. syscall_is_too_hard:
  1097. SAVE_ALL_HEAD
  1098. rd %wim, %l3
  1099. wr %l0, PSR_ET, %psr
  1100. mov %i0, %o0
  1101. mov %i1, %o1
  1102. mov %i2, %o2
  1103. ld [%curptr + TI_FLAGS], %l5
  1104. mov %i3, %o3
  1105. andcc %l5, _TIF_SYSCALL_TRACE, %g0
  1106. mov %i4, %o4
  1107. bne linux_syscall_trace
  1108. mov %i0, %l5
  1109. 2:
  1110. call %l7
  1111. mov %i5, %o5
  1112. 3:
  1113. st %o0, [%sp + STACKFRAME_SZ + PT_I0]
  1114. ret_sys_call:
  1115. ld [%curptr + TI_FLAGS], %l6
  1116. cmp %o0, -ERESTART_RESTARTBLOCK
  1117. ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
  1118. set PSR_C, %g2
  1119. bgeu 1f
  1120. andcc %l6, _TIF_SYSCALL_TRACE, %g0
  1121. /* System call success, clear Carry condition code. */
  1122. andn %g3, %g2, %g3
  1123. clr %l6
  1124. st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
  1125. bne linux_syscall_trace2
  1126. ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
  1127. add %l1, 0x4, %l2 /* npc = npc+4 */
  1128. st %l1, [%sp + STACKFRAME_SZ + PT_PC]
  1129. b ret_trap_entry
  1130. st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
  1131. 1:
  1132. /* System call failure, set Carry condition code.
  1133. * Also, get abs(errno) to return to the process.
  1134. */
  1135. sub %g0, %o0, %o0
  1136. or %g3, %g2, %g3
  1137. st %o0, [%sp + STACKFRAME_SZ + PT_I0]
  1138. mov 1, %l6
  1139. st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
  1140. bne linux_syscall_trace2
  1141. ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
  1142. add %l1, 0x4, %l2 /* npc = npc+4 */
  1143. st %l1, [%sp + STACKFRAME_SZ + PT_PC]
  1144. b ret_trap_entry
  1145. st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
  1146. linux_syscall_trace2:
  1147. add %sp, STACKFRAME_SZ, %o0
  1148. mov 1, %o1
  1149. call syscall_trace
  1150. add %l1, 0x4, %l2 /* npc = npc+4 */
  1151. st %l1, [%sp + STACKFRAME_SZ + PT_PC]
  1152. b ret_trap_entry
  1153. st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
  1154. /* Saving and restoring the FPU state is best done from lowlevel code.
  1155. *
  1156. * void fpsave(unsigned long *fpregs, unsigned long *fsr,
  1157. * void *fpqueue, unsigned long *fpqdepth)
  1158. */
  1159. .globl fpsave
  1160. fpsave:
  1161. st %fsr, [%o1] ! this can trap on us if fpu is in bogon state
  1162. ld [%o1], %g1
  1163. set 0x2000, %g4
  1164. andcc %g1, %g4, %g0
  1165. be 2f
  1166. mov 0, %g2
  1167. /* We have an fpqueue to save. */
  1168. 1:
  1169. std %fq, [%o2]
  1170. fpsave_magic:
  1171. st %fsr, [%o1]
  1172. ld [%o1], %g3
  1173. andcc %g3, %g4, %g0
  1174. add %g2, 1, %g2
  1175. bne 1b
  1176. add %o2, 8, %o2
  1177. 2:
  1178. st %g2, [%o3]
  1179. std %f0, [%o0 + 0x00]
  1180. std %f2, [%o0 + 0x08]
  1181. std %f4, [%o0 + 0x10]
  1182. std %f6, [%o0 + 0x18]
  1183. std %f8, [%o0 + 0x20]
  1184. std %f10, [%o0 + 0x28]
  1185. std %f12, [%o0 + 0x30]
  1186. std %f14, [%o0 + 0x38]
  1187. std %f16, [%o0 + 0x40]
  1188. std %f18, [%o0 + 0x48]
  1189. std %f20, [%o0 + 0x50]
  1190. std %f22, [%o0 + 0x58]
  1191. std %f24, [%o0 + 0x60]
  1192. std %f26, [%o0 + 0x68]
  1193. std %f28, [%o0 + 0x70]
  1194. retl
  1195. std %f30, [%o0 + 0x78]
  1196. /* Thanks for Theo Deraadt and the authors of the Sprite/netbsd/openbsd
  1197. * code for pointing out this possible deadlock, while we save state
  1198. * above we could trap on the fsr store so our low level fpu trap
  1199. * code has to know how to deal with this.
  1200. */
  1201. fpsave_catch:
  1202. b fpsave_magic + 4
  1203. st %fsr, [%o1]
  1204. fpsave_catch2:
  1205. b fpsave + 4
  1206. st %fsr, [%o1]
  1207. /* void fpload(unsigned long *fpregs, unsigned long *fsr); */
  1208. .globl fpload
  1209. fpload:
  1210. ldd [%o0 + 0x00], %f0
  1211. ldd [%o0 + 0x08], %f2
  1212. ldd [%o0 + 0x10], %f4
  1213. ldd [%o0 + 0x18], %f6
  1214. ldd [%o0 + 0x20], %f8
  1215. ldd [%o0 + 0x28], %f10
  1216. ldd [%o0 + 0x30], %f12
  1217. ldd [%o0 + 0x38], %f14
  1218. ldd [%o0 + 0x40], %f16
  1219. ldd [%o0 + 0x48], %f18
  1220. ldd [%o0 + 0x50], %f20
  1221. ldd [%o0 + 0x58], %f22
  1222. ldd [%o0 + 0x60], %f24
  1223. ldd [%o0 + 0x68], %f26
  1224. ldd [%o0 + 0x70], %f28
  1225. ldd [%o0 + 0x78], %f30
  1226. ld [%o1], %fsr
  1227. retl
  1228. nop
  1229. /* __ndelay and __udelay take two arguments:
  1230. * 0 - nsecs or usecs to delay
  1231. * 1 - per_cpu udelay_val (loops per jiffy)
  1232. *
  1233. * Note that ndelay gives HZ times higher resolution but has a 10ms
  1234. * limit. udelay can handle up to 1s.
  1235. */
  1236. .globl __ndelay
  1237. __ndelay:
  1238. save %sp, -STACKFRAME_SZ, %sp
  1239. mov %i0, %o0
  1240. call .umul ! round multiplier up so large ns ok
  1241. mov 0x1ae, %o1 ! 2**32 / (1 000 000 000 / HZ)
  1242. call .umul
  1243. mov %i1, %o1 ! udelay_val
  1244. ba delay_continue
  1245. mov %o1, %o0 ! >>32 later for better resolution
  1246. .globl __udelay
  1247. __udelay:
  1248. save %sp, -STACKFRAME_SZ, %sp
  1249. mov %i0, %o0
  1250. sethi %hi(0x10c7), %o1 ! round multiplier up so large us ok
  1251. call .umul
  1252. or %o1, %lo(0x10c7), %o1 ! 2**32 / 1 000 000
  1253. call .umul
  1254. mov %i1, %o1 ! udelay_val
  1255. sethi %hi(0x028f4b62), %l0 ! Add in rounding constant * 2**32,
  1256. or %g0, %lo(0x028f4b62), %l0
  1257. addcc %o0, %l0, %o0 ! 2**32 * 0.009 999
  1258. bcs,a 3f
  1259. add %o1, 0x01, %o1
  1260. 3:
  1261. call .umul
  1262. mov HZ, %o0 ! >>32 earlier for wider range
  1263. delay_continue:
  1264. cmp %o0, 0x0
  1265. 1:
  1266. bne 1b
  1267. subcc %o0, 1, %o0
  1268. ret
  1269. restore
  1270. /* Handle a software breakpoint */
  1271. /* We have to inform parent that child has stopped */
  1272. .align 4
  1273. .globl breakpoint_trap
  1274. breakpoint_trap:
  1275. rd %wim,%l3
  1276. SAVE_ALL
  1277. wr %l0, PSR_ET, %psr
  1278. WRITE_PAUSE
  1279. st %i0, [%sp + STACKFRAME_SZ + PT_G0] ! for restarting syscalls
  1280. call sparc_breakpoint
  1281. add %sp, STACKFRAME_SZ, %o0
  1282. RESTORE_ALL
  1283. #ifdef CONFIG_KGDB
  1284. .align 4
  1285. .globl kgdb_trap_low
  1286. .type kgdb_trap_low,#function
  1287. kgdb_trap_low:
  1288. rd %wim,%l3
  1289. SAVE_ALL
  1290. wr %l0, PSR_ET, %psr
  1291. WRITE_PAUSE
  1292. call kgdb_trap
  1293. add %sp, STACKFRAME_SZ, %o0
  1294. RESTORE_ALL
  1295. .size kgdb_trap_low,.-kgdb_trap_low
  1296. #endif
  1297. .align 4
  1298. .globl flush_patch_exception
  1299. flush_patch_exception:
  1300. FLUSH_ALL_KERNEL_WINDOWS;
  1301. ldd [%o0], %o6
  1302. jmpl %o7 + 0xc, %g0 ! see asm-sparc/processor.h
  1303. mov 1, %g1 ! signal EFAULT condition
  1304. .align 4
  1305. .globl kill_user_windows, kuw_patch1_7win
  1306. .globl kuw_patch1
  1307. kuw_patch1_7win: sll %o3, 6, %o3
  1308. /* No matter how much overhead this routine has in the worst
  1309. * case scenerio, it is several times better than taking the
  1310. * traps with the old method of just doing flush_user_windows().
  1311. */
  1312. kill_user_windows:
  1313. ld [%g6 + TI_UWINMASK], %o0 ! get current umask
  1314. orcc %g0, %o0, %g0 ! if no bits set, we are done
  1315. be 3f ! nothing to do
  1316. rd %psr, %o5 ! must clear interrupts
  1317. or %o5, PSR_PIL, %o4 ! or else that could change
  1318. wr %o4, 0x0, %psr ! the uwinmask state
  1319. WRITE_PAUSE ! burn them cycles
  1320. 1:
  1321. ld [%g6 + TI_UWINMASK], %o0 ! get consistent state
  1322. orcc %g0, %o0, %g0 ! did an interrupt come in?
  1323. be 4f ! yep, we are done
  1324. rd %wim, %o3 ! get current wim
  1325. srl %o3, 1, %o4 ! simulate a save
  1326. kuw_patch1:
  1327. sll %o3, 7, %o3 ! compute next wim
  1328. or %o4, %o3, %o3 ! result
  1329. andncc %o0, %o3, %o0 ! clean this bit in umask
  1330. bne kuw_patch1 ! not done yet
  1331. srl %o3, 1, %o4 ! begin another save simulation
  1332. wr %o3, 0x0, %wim ! set the new wim
  1333. st %g0, [%g6 + TI_UWINMASK] ! clear uwinmask
  1334. 4:
  1335. wr %o5, 0x0, %psr ! re-enable interrupts
  1336. WRITE_PAUSE ! burn baby burn
  1337. 3:
  1338. retl ! return
  1339. st %g0, [%g6 + TI_W_SAVED] ! no windows saved
  1340. .align 4
  1341. .globl restore_current
  1342. restore_current:
  1343. LOAD_CURRENT(g6, o0)
  1344. retl
  1345. nop
  1346. #ifdef CONFIG_PCIC_PCI
  1347. #include <asm/pcic.h>
  1348. .align 4
  1349. .globl linux_trap_ipi15_pcic
  1350. linux_trap_ipi15_pcic:
  1351. rd %wim, %l3
  1352. SAVE_ALL
  1353. /*
  1354. * First deactivate NMI
  1355. * or we cannot drop ET, cannot get window spill traps.
  1356. * The busy loop is necessary because the PIO error
  1357. * sometimes does not go away quickly and we trap again.
  1358. */
  1359. sethi %hi(pcic_regs), %o1
  1360. ld [%o1 + %lo(pcic_regs)], %o2
  1361. ! Get pending status for printouts later.
  1362. ld [%o2 + PCI_SYS_INT_PENDING], %o0
  1363. mov PCI_SYS_INT_PENDING_CLEAR_ALL, %o1
  1364. stb %o1, [%o2 + PCI_SYS_INT_PENDING_CLEAR]
  1365. 1:
  1366. ld [%o2 + PCI_SYS_INT_PENDING], %o1
  1367. andcc %o1, ((PCI_SYS_INT_PENDING_PIO|PCI_SYS_INT_PENDING_PCI)>>24), %g0
  1368. bne 1b
  1369. nop
  1370. or %l0, PSR_PIL, %l4
  1371. wr %l4, 0x0, %psr
  1372. WRITE_PAUSE
  1373. wr %l4, PSR_ET, %psr
  1374. WRITE_PAUSE
  1375. call pcic_nmi
  1376. add %sp, STACKFRAME_SZ, %o1 ! struct pt_regs *regs
  1377. RESTORE_ALL
  1378. .globl pcic_nmi_trap_patch
  1379. pcic_nmi_trap_patch:
  1380. sethi %hi(linux_trap_ipi15_pcic), %l3
  1381. jmpl %l3 + %lo(linux_trap_ipi15_pcic), %g0
  1382. rd %psr, %l0
  1383. .word 0
  1384. #endif /* CONFIG_PCIC_PCI */
  1385. .globl flushw_all
  1386. flushw_all:
  1387. save %sp, -0x40, %sp
  1388. save %sp, -0x40, %sp
  1389. save %sp, -0x40, %sp
  1390. save %sp, -0x40, %sp
  1391. save %sp, -0x40, %sp
  1392. save %sp, -0x40, %sp
  1393. save %sp, -0x40, %sp
  1394. restore
  1395. restore
  1396. restore
  1397. restore
  1398. restore
  1399. restore
  1400. ret
  1401. restore
  1402. /* End of entry.S */