entry.S 34 KB

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