entry.S 34 KB

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