entry.S 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666
  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. .globl syscall_is_too_hard
  1094. syscall_is_too_hard:
  1095. SAVE_ALL_HEAD
  1096. rd %wim, %l3
  1097. wr %l0, PSR_ET, %psr
  1098. mov %i0, %o0
  1099. mov %i1, %o1
  1100. mov %i2, %o2
  1101. ld [%curptr + TI_FLAGS], %l5
  1102. mov %i3, %o3
  1103. andcc %l5, _TIF_SYSCALL_TRACE, %g0
  1104. mov %i4, %o4
  1105. bne linux_syscall_trace
  1106. mov %i0, %l5
  1107. 2:
  1108. call %l7
  1109. mov %i5, %o5
  1110. st %o0, [%sp + STACKFRAME_SZ + PT_I0]
  1111. ret_sys_call:
  1112. ld [%curptr + TI_FLAGS], %l6
  1113. cmp %o0, -ERESTART_RESTARTBLOCK
  1114. ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
  1115. set PSR_C, %g2
  1116. bgeu 1f
  1117. andcc %l6, _TIF_SYSCALL_TRACE, %g0
  1118. /* System call success, clear Carry condition code. */
  1119. andn %g3, %g2, %g3
  1120. clr %l6
  1121. st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
  1122. bne linux_syscall_trace2
  1123. ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
  1124. add %l1, 0x4, %l2 /* npc = npc+4 */
  1125. st %l1, [%sp + STACKFRAME_SZ + PT_PC]
  1126. b ret_trap_entry
  1127. st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
  1128. 1:
  1129. /* System call failure, set Carry condition code.
  1130. * Also, get abs(errno) to return to the process.
  1131. */
  1132. sub %g0, %o0, %o0
  1133. or %g3, %g2, %g3
  1134. st %o0, [%sp + STACKFRAME_SZ + PT_I0]
  1135. mov 1, %l6
  1136. st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
  1137. bne linux_syscall_trace2
  1138. ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
  1139. add %l1, 0x4, %l2 /* npc = npc+4 */
  1140. st %l1, [%sp + STACKFRAME_SZ + PT_PC]
  1141. b ret_trap_entry
  1142. st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
  1143. linux_syscall_trace2:
  1144. call syscall_trace
  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. /* Saving and restoring the FPU state is best done from lowlevel code.
  1150. *
  1151. * void fpsave(unsigned long *fpregs, unsigned long *fsr,
  1152. * void *fpqueue, unsigned long *fpqdepth)
  1153. */
  1154. .globl fpsave
  1155. fpsave:
  1156. st %fsr, [%o1] ! this can trap on us if fpu is in bogon state
  1157. ld [%o1], %g1
  1158. set 0x2000, %g4
  1159. andcc %g1, %g4, %g0
  1160. be 2f
  1161. mov 0, %g2
  1162. /* We have an fpqueue to save. */
  1163. 1:
  1164. std %fq, [%o2]
  1165. fpsave_magic:
  1166. st %fsr, [%o1]
  1167. ld [%o1], %g3
  1168. andcc %g3, %g4, %g0
  1169. add %g2, 1, %g2
  1170. bne 1b
  1171. add %o2, 8, %o2
  1172. 2:
  1173. st %g2, [%o3]
  1174. std %f0, [%o0 + 0x00]
  1175. std %f2, [%o0 + 0x08]
  1176. std %f4, [%o0 + 0x10]
  1177. std %f6, [%o0 + 0x18]
  1178. std %f8, [%o0 + 0x20]
  1179. std %f10, [%o0 + 0x28]
  1180. std %f12, [%o0 + 0x30]
  1181. std %f14, [%o0 + 0x38]
  1182. std %f16, [%o0 + 0x40]
  1183. std %f18, [%o0 + 0x48]
  1184. std %f20, [%o0 + 0x50]
  1185. std %f22, [%o0 + 0x58]
  1186. std %f24, [%o0 + 0x60]
  1187. std %f26, [%o0 + 0x68]
  1188. std %f28, [%o0 + 0x70]
  1189. retl
  1190. std %f30, [%o0 + 0x78]
  1191. /* Thanks for Theo Deraadt and the authors of the Sprite/netbsd/openbsd
  1192. * code for pointing out this possible deadlock, while we save state
  1193. * above we could trap on the fsr store so our low level fpu trap
  1194. * code has to know how to deal with this.
  1195. */
  1196. fpsave_catch:
  1197. b fpsave_magic + 4
  1198. st %fsr, [%o1]
  1199. fpsave_catch2:
  1200. b fpsave + 4
  1201. st %fsr, [%o1]
  1202. /* void fpload(unsigned long *fpregs, unsigned long *fsr); */
  1203. .globl fpload
  1204. fpload:
  1205. ldd [%o0 + 0x00], %f0
  1206. ldd [%o0 + 0x08], %f2
  1207. ldd [%o0 + 0x10], %f4
  1208. ldd [%o0 + 0x18], %f6
  1209. ldd [%o0 + 0x20], %f8
  1210. ldd [%o0 + 0x28], %f10
  1211. ldd [%o0 + 0x30], %f12
  1212. ldd [%o0 + 0x38], %f14
  1213. ldd [%o0 + 0x40], %f16
  1214. ldd [%o0 + 0x48], %f18
  1215. ldd [%o0 + 0x50], %f20
  1216. ldd [%o0 + 0x58], %f22
  1217. ldd [%o0 + 0x60], %f24
  1218. ldd [%o0 + 0x68], %f26
  1219. ldd [%o0 + 0x70], %f28
  1220. ldd [%o0 + 0x78], %f30
  1221. ld [%o1], %fsr
  1222. retl
  1223. nop
  1224. /* __ndelay and __udelay take two arguments:
  1225. * 0 - nsecs or usecs to delay
  1226. * 1 - per_cpu udelay_val (loops per jiffy)
  1227. *
  1228. * Note that ndelay gives HZ times higher resolution but has a 10ms
  1229. * limit. udelay can handle up to 1s.
  1230. */
  1231. .globl __ndelay
  1232. __ndelay:
  1233. save %sp, -STACKFRAME_SZ, %sp
  1234. mov %i0, %o0
  1235. call .umul ! round multiplier up so large ns ok
  1236. mov 0x1ae, %o1 ! 2**32 / (1 000 000 000 / HZ)
  1237. call .umul
  1238. mov %i1, %o1 ! udelay_val
  1239. ba delay_continue
  1240. mov %o1, %o0 ! >>32 later for better resolution
  1241. .globl __udelay
  1242. __udelay:
  1243. save %sp, -STACKFRAME_SZ, %sp
  1244. mov %i0, %o0
  1245. sethi %hi(0x10c7), %o1 ! round multiplier up so large us ok
  1246. call .umul
  1247. or %o1, %lo(0x10c7), %o1 ! 2**32 / 1 000 000
  1248. call .umul
  1249. mov %i1, %o1 ! udelay_val
  1250. sethi %hi(0x028f4b62), %l0 ! Add in rounding constant * 2**32,
  1251. or %g0, %lo(0x028f4b62), %l0
  1252. addcc %o0, %l0, %o0 ! 2**32 * 0.009 999
  1253. bcs,a 3f
  1254. add %o1, 0x01, %o1
  1255. 3:
  1256. call .umul
  1257. mov HZ, %o0 ! >>32 earlier for wider range
  1258. delay_continue:
  1259. cmp %o0, 0x0
  1260. 1:
  1261. bne 1b
  1262. subcc %o0, 1, %o0
  1263. ret
  1264. restore
  1265. /* Handle a software breakpoint */
  1266. /* We have to inform parent that child has stopped */
  1267. .align 4
  1268. .globl breakpoint_trap
  1269. breakpoint_trap:
  1270. rd %wim,%l3
  1271. SAVE_ALL
  1272. wr %l0, PSR_ET, %psr
  1273. WRITE_PAUSE
  1274. st %i0, [%sp + STACKFRAME_SZ + PT_G0] ! for restarting syscalls
  1275. call sparc_breakpoint
  1276. add %sp, STACKFRAME_SZ, %o0
  1277. RESTORE_ALL
  1278. #ifdef CONFIG_KGDB
  1279. .align 4
  1280. .globl kgdb_trap_low
  1281. .type kgdb_trap_low,#function
  1282. kgdb_trap_low:
  1283. rd %wim,%l3
  1284. SAVE_ALL
  1285. wr %l0, PSR_ET, %psr
  1286. WRITE_PAUSE
  1287. call kgdb_trap
  1288. add %sp, STACKFRAME_SZ, %o0
  1289. RESTORE_ALL
  1290. .size kgdb_trap_low,.-kgdb_trap_low
  1291. #endif
  1292. .align 4
  1293. .globl __handle_exception, flush_patch_exception
  1294. __handle_exception:
  1295. flush_patch_exception:
  1296. FLUSH_ALL_KERNEL_WINDOWS;
  1297. ldd [%o0], %o6
  1298. jmpl %o7 + 0xc, %g0 ! see asm-sparc/processor.h
  1299. mov 1, %g1 ! signal EFAULT condition
  1300. .align 4
  1301. .globl kill_user_windows, kuw_patch1_7win
  1302. .globl kuw_patch1
  1303. kuw_patch1_7win: sll %o3, 6, %o3
  1304. /* No matter how much overhead this routine has in the worst
  1305. * case scenerio, it is several times better than taking the
  1306. * traps with the old method of just doing flush_user_windows().
  1307. */
  1308. kill_user_windows:
  1309. ld [%g6 + TI_UWINMASK], %o0 ! get current umask
  1310. orcc %g0, %o0, %g0 ! if no bits set, we are done
  1311. be 3f ! nothing to do
  1312. rd %psr, %o5 ! must clear interrupts
  1313. or %o5, PSR_PIL, %o4 ! or else that could change
  1314. wr %o4, 0x0, %psr ! the uwinmask state
  1315. WRITE_PAUSE ! burn them cycles
  1316. 1:
  1317. ld [%g6 + TI_UWINMASK], %o0 ! get consistent state
  1318. orcc %g0, %o0, %g0 ! did an interrupt come in?
  1319. be 4f ! yep, we are done
  1320. rd %wim, %o3 ! get current wim
  1321. srl %o3, 1, %o4 ! simulate a save
  1322. kuw_patch1:
  1323. sll %o3, 7, %o3 ! compute next wim
  1324. or %o4, %o3, %o3 ! result
  1325. andncc %o0, %o3, %o0 ! clean this bit in umask
  1326. bne kuw_patch1 ! not done yet
  1327. srl %o3, 1, %o4 ! begin another save simulation
  1328. wr %o3, 0x0, %wim ! set the new wim
  1329. st %g0, [%g6 + TI_UWINMASK] ! clear uwinmask
  1330. 4:
  1331. wr %o5, 0x0, %psr ! re-enable interrupts
  1332. WRITE_PAUSE ! burn baby burn
  1333. 3:
  1334. retl ! return
  1335. st %g0, [%g6 + TI_W_SAVED] ! no windows saved
  1336. .align 4
  1337. .globl restore_current
  1338. restore_current:
  1339. LOAD_CURRENT(g6, o0)
  1340. retl
  1341. nop
  1342. #ifdef CONFIG_PCI
  1343. #include <asm/pcic.h>
  1344. .align 4
  1345. .globl linux_trap_ipi15_pcic
  1346. linux_trap_ipi15_pcic:
  1347. rd %wim, %l3
  1348. SAVE_ALL
  1349. /*
  1350. * First deactivate NMI
  1351. * or we cannot drop ET, cannot get window spill traps.
  1352. * The busy loop is necessary because the PIO error
  1353. * sometimes does not go away quickly and we trap again.
  1354. */
  1355. sethi %hi(pcic_regs), %o1
  1356. ld [%o1 + %lo(pcic_regs)], %o2
  1357. ! Get pending status for printouts later.
  1358. ld [%o2 + PCI_SYS_INT_PENDING], %o0
  1359. mov PCI_SYS_INT_PENDING_CLEAR_ALL, %o1
  1360. stb %o1, [%o2 + PCI_SYS_INT_PENDING_CLEAR]
  1361. 1:
  1362. ld [%o2 + PCI_SYS_INT_PENDING], %o1
  1363. andcc %o1, ((PCI_SYS_INT_PENDING_PIO|PCI_SYS_INT_PENDING_PCI)>>24), %g0
  1364. bne 1b
  1365. nop
  1366. or %l0, PSR_PIL, %l4
  1367. wr %l4, 0x0, %psr
  1368. WRITE_PAUSE
  1369. wr %l4, PSR_ET, %psr
  1370. WRITE_PAUSE
  1371. call pcic_nmi
  1372. add %sp, STACKFRAME_SZ, %o1 ! struct pt_regs *regs
  1373. RESTORE_ALL
  1374. .globl pcic_nmi_trap_patch
  1375. pcic_nmi_trap_patch:
  1376. sethi %hi(linux_trap_ipi15_pcic), %l3
  1377. jmpl %l3 + %lo(linux_trap_ipi15_pcic), %g0
  1378. rd %psr, %l0
  1379. .word 0
  1380. #endif /* CONFIG_PCI */
  1381. .globl flushw_all
  1382. flushw_all:
  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. save %sp, -0x40, %sp
  1389. save %sp, -0x40, %sp
  1390. restore
  1391. restore
  1392. restore
  1393. restore
  1394. restore
  1395. restore
  1396. ret
  1397. restore
  1398. /* End of entry.S */