entry.S 34 KB

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