entry.S 34 KB

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