entry.S 35 KB

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