entry.S 34 KB

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