blob: 1b87ea088e1a34f987cca45f9cb9146a28e05229 [file] [log] [blame]
David S. Miller0a808a32007-08-02 00:19:14 -07001/* arch/sparc/kernel/entry.S: Sparc trap low-level entry points.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
David S. Miller0a808a32007-08-02 00:19:14 -07003 * Copyright (C) 1995, 2007 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/errno.h>
11
12#include <asm/head.h>
13#include <asm/asi.h>
14#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/contregs.h>
16#include <asm/ptrace.h>
Sam Ravnborg47003492005-09-09 20:35:55 +020017#include <asm/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/psr.h>
19#include <asm/vaddrs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/page.h>
Sam Ravnborgb1a8bf92008-06-13 20:20:54 +020021#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#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>
David S. Miller59359ff2006-11-05 16:51:03 -080028#include <asm/unistd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#include <asm/asmmacro.h>
31
32#define curptr g6
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034/* These are just handy. */
35#define _SV save %sp, -STACKFRAME_SZ, %sp
36#define _RS restore
37
38#define FLUSH_ALL_KERNEL_WINDOWS \
39 _SV; _SV; _SV; _SV; _SV; _SV; _SV; \
40 _RS; _RS; _RS; _RS; _RS; _RS; _RS;
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 .text
David S. Millere2fdd7f2008-04-29 02:38:50 -070043
44#ifdef CONFIG_KGDB
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 .align 4
David S. Millere2fdd7f2008-04-29 02:38:50 -070046 .globl arch_kgdb_breakpoint
47 .type arch_kgdb_breakpoint,#function
48arch_kgdb_breakpoint:
49 ta 0x7d
50 retl
51 nop
52 .size arch_kgdb_breakpoint,.-arch_kgdb_breakpoint
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#endif
54
David S. Miller0a808a32007-08-02 00:19:14 -070055#if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 .align 4
57 .globl floppy_hardint
58floppy_hardint:
59 /*
60 * This code cannot touch registers %l0 %l1 and %l2
61 * because SAVE_ALL depends on their values. It depends
62 * on %l3 also, but we regenerate it before a call.
63 * Other registers are:
64 * %l3 -- base address of fdc registers
65 * %l4 -- pdma_vaddr
66 * %l5 -- scratch for ld/st address
67 * %l6 -- pdma_size
68 * %l7 -- scratch [floppy byte, ld/st address, aux. data]
69 */
70
71 /* Do we have work to do? */
72 sethi %hi(doing_pdma), %l7
73 ld [%l7 + %lo(doing_pdma)], %l7
74 cmp %l7, 0
75 be floppy_dosoftint
76 nop
77
78 /* Load fdc register base */
79 sethi %hi(fdc_status), %l3
80 ld [%l3 + %lo(fdc_status)], %l3
81
82 /* Setup register addresses */
83 sethi %hi(pdma_vaddr), %l5 ! transfer buffer
84 ld [%l5 + %lo(pdma_vaddr)], %l4
85 sethi %hi(pdma_size), %l5 ! bytes to go
86 ld [%l5 + %lo(pdma_size)], %l6
87next_byte:
88 ldub [%l3], %l7
89
90 andcc %l7, 0x80, %g0 ! Does fifo still have data
91 bz floppy_fifo_emptied ! fifo has been emptied...
92 andcc %l7, 0x20, %g0 ! in non-dma mode still?
93 bz floppy_overrun ! nope, overrun
94 andcc %l7, 0x40, %g0 ! 0=write 1=read
95 bz floppy_write
96 sub %l6, 0x1, %l6
97
98 /* Ok, actually read this byte */
99 ldub [%l3 + 1], %l7
100 orcc %g0, %l6, %g0
101 stb %l7, [%l4]
102 bne next_byte
103 add %l4, 0x1, %l4
104
105 b floppy_tdone
106 nop
107
108floppy_write:
109 /* Ok, actually write this byte */
110 ldub [%l4], %l7
111 orcc %g0, %l6, %g0
112 stb %l7, [%l3 + 1]
113 bne next_byte
114 add %l4, 0x1, %l4
115
116 /* fall through... */
117floppy_tdone:
118 sethi %hi(pdma_vaddr), %l5
119 st %l4, [%l5 + %lo(pdma_vaddr)]
120 sethi %hi(pdma_size), %l5
121 st %l6, [%l5 + %lo(pdma_size)]
122 /* Flip terminal count pin */
123 set auxio_register, %l7
124 ld [%l7], %l7
125
126 set sparc_cpu_model, %l5
127 ld [%l5], %l5
David S. Miller288e58c2012-05-11 20:59:57 -0700128 ldub [%l7], %l5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 or %l5, 0xc2, %l5
131 stb %l5, [%l7]
132 andn %l5, 0x02, %l5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
1342:
135 /* Kill some time so the bits set */
136 WRITE_PAUSE
137 WRITE_PAUSE
138
139 stb %l5, [%l7]
140
141 /* Prevent recursion */
142 sethi %hi(doing_pdma), %l7
143 b floppy_dosoftint
144 st %g0, [%l7 + %lo(doing_pdma)]
145
146 /* We emptied the FIFO, but we haven't read everything
147 * as of yet. Store the current transfer address and
148 * bytes left to read so we can continue when the next
149 * fast IRQ comes in.
150 */
151floppy_fifo_emptied:
152 sethi %hi(pdma_vaddr), %l5
153 st %l4, [%l5 + %lo(pdma_vaddr)]
154 sethi %hi(pdma_size), %l7
155 st %l6, [%l7 + %lo(pdma_size)]
156
157 /* Restore condition codes */
158 wr %l0, 0x0, %psr
159 WRITE_PAUSE
160
161 jmp %l1
162 rett %l2
163
164floppy_overrun:
165 sethi %hi(pdma_vaddr), %l5
166 st %l4, [%l5 + %lo(pdma_vaddr)]
167 sethi %hi(pdma_size), %l5
168 st %l6, [%l5 + %lo(pdma_size)]
169 /* Prevent recursion */
170 sethi %hi(doing_pdma), %l7
171 st %g0, [%l7 + %lo(doing_pdma)]
172
173 /* fall through... */
174floppy_dosoftint:
175 rd %wim, %l3
176 SAVE_ALL
177
178 /* Set all IRQs off. */
179 or %l0, PSR_PIL, %l4
180 wr %l4, 0x0, %psr
181 WRITE_PAUSE
182 wr %l4, PSR_ET, %psr
183 WRITE_PAUSE
184
185 mov 11, %o0 ! floppy irq level (unused anyway)
186 mov %g0, %o1 ! devid is not used in fast interrupts
187 call sparc_floppy_irq
188 add %sp, STACKFRAME_SZ, %o2 ! struct pt_regs *regs
189
190 RESTORE_ALL
191
192#endif /* (CONFIG_BLK_DEV_FD) */
193
194 /* Bad trap handler */
195 .globl bad_trap_handler
196bad_trap_handler:
197 SAVE_ALL
198
199 wr %l0, PSR_ET, %psr
200 WRITE_PAUSE
201
202 add %sp, STACKFRAME_SZ, %o0 ! pt_regs
203 call do_hw_interrupt
204 mov %l7, %o1 ! trap number
205
206 RESTORE_ALL
207
208/* For now all IRQ's not registered get sent here. handler_irq() will
209 * see if a routine is registered to handle this interrupt and if not
210 * it will say so on the console.
211 */
212
213 .align 4
214 .globl real_irq_entry, patch_handler_irq
215real_irq_entry:
216 SAVE_ALL
217
218#ifdef CONFIG_SMP
219 .globl patchme_maybe_smp_msg
220
Daniel Hellstroma7d82a02011-06-09 02:54:08 +0000221 cmp %l7, 11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222patchme_maybe_smp_msg:
223 bgu maybe_smp4m_msg
224 nop
225#endif
226
227real_irq_continue:
228 or %l0, PSR_PIL, %g2
229 wr %g2, 0x0, %psr
230 WRITE_PAUSE
231 wr %g2, PSR_ET, %psr
232 WRITE_PAUSE
233 mov %l7, %o0 ! irq level
234patch_handler_irq:
235 call handler_irq
236 add %sp, STACKFRAME_SZ, %o1 ! pt_regs ptr
237 or %l0, PSR_PIL, %g2 ! restore PIL after handler_irq
238 wr %g2, PSR_ET, %psr ! keep ET up
239 WRITE_PAUSE
240
241 RESTORE_ALL
242
243#ifdef CONFIG_SMP
244 /* SMP per-cpu ticker interrupts are handled specially. */
245smp4m_ticker:
246 bne real_irq_continue+4
247 or %l0, PSR_PIL, %g2
248 wr %g2, 0x0, %psr
249 WRITE_PAUSE
250 wr %g2, PSR_ET, %psr
251 WRITE_PAUSE
252 call smp4m_percpu_timer_interrupt
253 add %sp, STACKFRAME_SZ, %o0
254 wr %l0, PSR_ET, %psr
255 WRITE_PAUSE
256 RESTORE_ALL
257
258 /* Here is where we check for possible SMP IPI passed to us
259 * on some level other than 15 which is the NMI and only used
260 * for cross calls. That has a separate entry point below.
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000261 *
262 * IPIs are sent on Level 12, 13 and 14. See IRQ_IPI_*.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 */
264maybe_smp4m_msg:
265 GET_PROCESSOR4M_ID(o3)
David S. Miller69c010b2008-09-19 21:17:43 -0700266 sethi %hi(sun4m_irq_percpu), %l5
267 sll %o3, 2, %o3
268 or %l5, %lo(sun4m_irq_percpu), %o5
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000269 sethi %hi(0x70000000), %o2 ! Check all soft-IRQs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 ld [%o5 + %o3], %o1
David S. Miller69c010b2008-09-19 21:17:43 -0700271 ld [%o1 + 0x00], %o3 ! sun4m_irq_percpu[cpu]->pending
272 andcc %o3, %o2, %g0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 be,a smp4m_ticker
274 cmp %l7, 14
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000275 /* Soft-IRQ IPI */
276 st %o2, [%o1 + 0x04] ! sun4m_irq_percpu[cpu]->clear=0x70000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 WRITE_PAUSE
David S. Miller69c010b2008-09-19 21:17:43 -0700278 ld [%o1 + 0x00], %g0 ! sun4m_irq_percpu[cpu]->pending
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 WRITE_PAUSE
280 or %l0, PSR_PIL, %l4
281 wr %l4, 0x0, %psr
282 WRITE_PAUSE
283 wr %l4, PSR_ET, %psr
284 WRITE_PAUSE
Will Simoneau1ef48592011-07-16 10:45:12 -0700285 srl %o3, 28, %o2 ! shift for simpler checks below
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000286maybe_smp4m_msg_check_single:
287 andcc %o2, 0x1, %g0
288 beq,a maybe_smp4m_msg_check_mask
289 andcc %o2, 0x2, %g0
290 call smp_call_function_single_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 nop
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000292 andcc %o2, 0x2, %g0
293maybe_smp4m_msg_check_mask:
294 beq,a maybe_smp4m_msg_check_resched
295 andcc %o2, 0x4, %g0
296 call smp_call_function_interrupt
297 nop
298 andcc %o2, 0x4, %g0
299maybe_smp4m_msg_check_resched:
300 /* rescheduling is done in RESTORE_ALL regardless, but incr stats */
301 beq,a maybe_smp4m_msg_out
302 nop
303 call smp_resched_interrupt
304 nop
305maybe_smp4m_msg_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 RESTORE_ALL
307
308 .align 4
Sam Ravnborg2c1cfb22012-05-11 11:35:04 +0000309 .globl linux_trap_ipi15
310linux_trap_ipi15:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 SAVE_ALL
312 sethi %hi(0x80000000), %o2
313 GET_PROCESSOR4M_ID(o0)
David S. Miller69c010b2008-09-19 21:17:43 -0700314 sethi %hi(sun4m_irq_percpu), %l5
315 or %l5, %lo(sun4m_irq_percpu), %o5
316 sll %o0, 2, %o0
317 ld [%o5 + %o0], %o5
318 ld [%o5 + 0x00], %o3 ! sun4m_irq_percpu[cpu]->pending
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 andcc %o3, %o2, %g0
320 be 1f ! Must be an NMI async memory error
David S. Miller69c010b2008-09-19 21:17:43 -0700321 st %o2, [%o5 + 0x04] ! sun4m_irq_percpu[cpu]->clear=0x80000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 WRITE_PAUSE
David S. Miller69c010b2008-09-19 21:17:43 -0700323 ld [%o5 + 0x00], %g0 ! sun4m_irq_percpu[cpu]->pending
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 WRITE_PAUSE
325 or %l0, PSR_PIL, %l4
326 wr %l4, 0x0, %psr
327 WRITE_PAUSE
328 wr %l4, PSR_ET, %psr
329 WRITE_PAUSE
330 call smp4m_cross_call_irq
331 nop
332 b ret_trap_lockless_ipi
333 clr %l6
3341:
335 /* NMI async memory error handling. */
336 sethi %hi(0x80000000), %l4
David S. Miller69c010b2008-09-19 21:17:43 -0700337 sethi %hi(sun4m_irq_global), %o5
338 ld [%o5 + %lo(sun4m_irq_global)], %l5
339 st %l4, [%l5 + 0x0c] ! sun4m_irq_global->mask_set=0x80000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 WRITE_PAUSE
David S. Miller69c010b2008-09-19 21:17:43 -0700341 ld [%l5 + 0x00], %g0 ! sun4m_irq_global->pending
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 WRITE_PAUSE
343 or %l0, PSR_PIL, %l4
344 wr %l4, 0x0, %psr
345 WRITE_PAUSE
346 wr %l4, PSR_ET, %psr
347 WRITE_PAUSE
348 call sun4m_nmi
349 nop
David S. Miller69c010b2008-09-19 21:17:43 -0700350 st %l4, [%l5 + 0x08] ! sun4m_irq_global->mask_clear=0x80000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 WRITE_PAUSE
David S. Miller69c010b2008-09-19 21:17:43 -0700352 ld [%l5 + 0x00], %g0 ! sun4m_irq_global->pending
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 WRITE_PAUSE
354 RESTORE_ALL
355
356 .globl smp4d_ticker
357 /* SMP per-cpu ticker interrupts are handled specially. */
358smp4d_ticker:
359 SAVE_ALL
360 or %l0, PSR_PIL, %g2
361 sethi %hi(CC_ICLR), %o0
362 sethi %hi(1 << 14), %o1
363 or %o0, %lo(CC_ICLR), %o0
364 stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 14 in MXCC's ICLR */
365 wr %g2, 0x0, %psr
366 WRITE_PAUSE
367 wr %g2, PSR_ET, %psr
368 WRITE_PAUSE
369 call smp4d_percpu_timer_interrupt
370 add %sp, STACKFRAME_SZ, %o0
371 wr %l0, PSR_ET, %psr
372 WRITE_PAUSE
373 RESTORE_ALL
374
375 .align 4
376 .globl linux_trap_ipi15_sun4d
377linux_trap_ipi15_sun4d:
378 SAVE_ALL
379 sethi %hi(CC_BASE), %o4
380 sethi %hi(MXCC_ERR_ME|MXCC_ERR_PEW|MXCC_ERR_ASE|MXCC_ERR_PEE), %o2
381 or %o4, (CC_EREG - CC_BASE), %o0
382 ldda [%o0] ASI_M_MXCC, %o0
383 andcc %o0, %o2, %g0
384 bne 1f
385 sethi %hi(BB_STAT2), %o2
386 lduba [%o2] ASI_M_CTL, %o2
387 andcc %o2, BB_STAT2_MASK, %g0
388 bne 2f
389 or %o4, (CC_ICLR - CC_BASE), %o0
390 sethi %hi(1 << 15), %o1
391 stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 15 in MXCC's ICLR */
392 or %l0, PSR_PIL, %l4
393 wr %l4, 0x0, %psr
394 WRITE_PAUSE
395 wr %l4, PSR_ET, %psr
396 WRITE_PAUSE
397 call smp4d_cross_call_irq
398 nop
399 b ret_trap_lockless_ipi
400 clr %l6
401
4021: /* MXCC error */
4032: /* BB error */
404 /* Disable PIL 15 */
405 set CC_IMSK, %l4
406 lduha [%l4] ASI_M_MXCC, %l5
407 sethi %hi(1 << 15), %l7
408 or %l5, %l7, %l5
409 stha %l5, [%l4] ASI_M_MXCC
410 /* FIXME */
4111: b,a 1b
412
Konrad Eisele84017072009-08-31 22:08:13 +0000413#ifdef CONFIG_SPARC_LEON
Daniel Hellstrom1ca0c802011-05-02 00:08:52 +0000414 .globl smpleon_ipi
415 .extern leon_ipi_interrupt
416 /* SMP per-cpu IPI interrupts are handled specially. */
417smpleon_ipi:
418 SAVE_ALL
419 or %l0, PSR_PIL, %g2
420 wr %g2, 0x0, %psr
421 WRITE_PAUSE
422 wr %g2, PSR_ET, %psr
423 WRITE_PAUSE
424 call leonsmp_ipi_interrupt
425 add %sp, STACKFRAME_SZ, %o1 ! pt_regs
426 wr %l0, PSR_ET, %psr
427 WRITE_PAUSE
428 RESTORE_ALL
429
Konrad Eisele84017072009-08-31 22:08:13 +0000430 .align 4
431 .globl linux_trap_ipi15_leon
432linux_trap_ipi15_leon:
433 SAVE_ALL
434 or %l0, PSR_PIL, %l4
435 wr %l4, 0x0, %psr
436 WRITE_PAUSE
437 wr %l4, PSR_ET, %psr
438 WRITE_PAUSE
439 call leon_cross_call_irq
440 nop
441 b ret_trap_lockless_ipi
442 clr %l6
443
444#endif /* CONFIG_SPARC_LEON */
445
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446#endif /* CONFIG_SMP */
447
448 /* This routine handles illegal instructions and privileged
449 * instruction attempts from user code.
450 */
451 .align 4
452 .globl bad_instruction
453bad_instruction:
454 sethi %hi(0xc1f80000), %l4
455 ld [%l1], %l5
456 sethi %hi(0x81d80000), %l7
457 and %l5, %l4, %l5
458 cmp %l5, %l7
459 be 1f
460 SAVE_ALL
461
462 wr %l0, PSR_ET, %psr ! re-enable traps
463 WRITE_PAUSE
464
465 add %sp, STACKFRAME_SZ, %o0
466 mov %l1, %o1
467 mov %l2, %o2
468 call do_illegal_instruction
469 mov %l0, %o3
470
471 RESTORE_ALL
472
4731: /* unimplemented flush - just skip */
474 jmpl %l2, %g0
475 rett %l2 + 4
476
477 .align 4
478 .globl priv_instruction
479priv_instruction:
480 SAVE_ALL
481
482 wr %l0, PSR_ET, %psr
483 WRITE_PAUSE
484
485 add %sp, STACKFRAME_SZ, %o0
486 mov %l1, %o1
487 mov %l2, %o2
488 call do_priv_instruction
489 mov %l0, %o3
490
491 RESTORE_ALL
492
493 /* This routine handles unaligned data accesses. */
494 .align 4
495 .globl mna_handler
496mna_handler:
497 andcc %l0, PSR_PS, %g0
498 be mna_fromuser
499 nop
500
501 SAVE_ALL
502
503 wr %l0, PSR_ET, %psr
504 WRITE_PAUSE
505
506 ld [%l1], %o1
507 call kernel_unaligned_trap
508 add %sp, STACKFRAME_SZ, %o0
509
510 RESTORE_ALL
511
512mna_fromuser:
513 SAVE_ALL
514
515 wr %l0, PSR_ET, %psr ! re-enable traps
516 WRITE_PAUSE
517
518 ld [%l1], %o1
519 call user_unaligned_trap
520 add %sp, STACKFRAME_SZ, %o0
521
522 RESTORE_ALL
523
524 /* This routine handles floating point disabled traps. */
525 .align 4
526 .globl fpd_trap_handler
527fpd_trap_handler:
528 SAVE_ALL
529
530 wr %l0, PSR_ET, %psr ! re-enable traps
531 WRITE_PAUSE
532
533 add %sp, STACKFRAME_SZ, %o0
534 mov %l1, %o1
535 mov %l2, %o2
536 call do_fpd_trap
537 mov %l0, %o3
538
539 RESTORE_ALL
540
541 /* This routine handles Floating Point Exceptions. */
542 .align 4
543 .globl fpe_trap_handler
544fpe_trap_handler:
545 set fpsave_magic, %l5
546 cmp %l1, %l5
547 be 1f
548 sethi %hi(fpsave), %l5
549 or %l5, %lo(fpsave), %l5
550 cmp %l1, %l5
551 bne 2f
552 sethi %hi(fpsave_catch2), %l5
553 or %l5, %lo(fpsave_catch2), %l5
554 wr %l0, 0x0, %psr
555 WRITE_PAUSE
556 jmp %l5
557 rett %l5 + 4
5581:
559 sethi %hi(fpsave_catch), %l5
560 or %l5, %lo(fpsave_catch), %l5
561 wr %l0, 0x0, %psr
562 WRITE_PAUSE
563 jmp %l5
564 rett %l5 + 4
565
5662:
567 SAVE_ALL
568
569 wr %l0, PSR_ET, %psr ! re-enable traps
570 WRITE_PAUSE
571
572 add %sp, STACKFRAME_SZ, %o0
573 mov %l1, %o1
574 mov %l2, %o2
575 call do_fpe_trap
576 mov %l0, %o3
577
578 RESTORE_ALL
579
580 /* This routine handles Tag Overflow Exceptions. */
581 .align 4
582 .globl do_tag_overflow
583do_tag_overflow:
584 SAVE_ALL
585
586 wr %l0, PSR_ET, %psr ! re-enable traps
587 WRITE_PAUSE
588
589 add %sp, STACKFRAME_SZ, %o0
590 mov %l1, %o1
591 mov %l2, %o2
592 call handle_tag_overflow
593 mov %l0, %o3
594
595 RESTORE_ALL
596
597 /* This routine handles Watchpoint Exceptions. */
598 .align 4
599 .globl do_watchpoint
600do_watchpoint:
601 SAVE_ALL
602
603 wr %l0, PSR_ET, %psr ! re-enable traps
604 WRITE_PAUSE
605
606 add %sp, STACKFRAME_SZ, %o0
607 mov %l1, %o1
608 mov %l2, %o2
609 call handle_watchpoint
610 mov %l0, %o3
611
612 RESTORE_ALL
613
614 /* This routine handles Register Access Exceptions. */
615 .align 4
616 .globl do_reg_access
617do_reg_access:
618 SAVE_ALL
619
620 wr %l0, PSR_ET, %psr ! re-enable traps
621 WRITE_PAUSE
622
623 add %sp, STACKFRAME_SZ, %o0
624 mov %l1, %o1
625 mov %l2, %o2
626 call handle_reg_access
627 mov %l0, %o3
628
629 RESTORE_ALL
630
631 /* This routine handles Co-Processor Disabled Exceptions. */
632 .align 4
633 .globl do_cp_disabled
634do_cp_disabled:
635 SAVE_ALL
636
637 wr %l0, PSR_ET, %psr ! re-enable traps
638 WRITE_PAUSE
639
640 add %sp, STACKFRAME_SZ, %o0
641 mov %l1, %o1
642 mov %l2, %o2
643 call handle_cp_disabled
644 mov %l0, %o3
645
646 RESTORE_ALL
647
648 /* This routine handles Co-Processor Exceptions. */
649 .align 4
650 .globl do_cp_exception
651do_cp_exception:
652 SAVE_ALL
653
654 wr %l0, PSR_ET, %psr ! re-enable traps
655 WRITE_PAUSE
656
657 add %sp, STACKFRAME_SZ, %o0
658 mov %l1, %o1
659 mov %l2, %o2
660 call handle_cp_exception
661 mov %l0, %o3
662
663 RESTORE_ALL
664
665 /* This routine handles Hardware Divide By Zero Exceptions. */
666 .align 4
667 .globl do_hw_divzero
668do_hw_divzero:
669 SAVE_ALL
670
671 wr %l0, PSR_ET, %psr ! re-enable traps
672 WRITE_PAUSE
673
674 add %sp, STACKFRAME_SZ, %o0
675 mov %l1, %o1
676 mov %l2, %o2
677 call handle_hw_divzero
678 mov %l0, %o3
679
680 RESTORE_ALL
681
682 .align 4
683 .globl do_flush_windows
684do_flush_windows:
685 SAVE_ALL
686
687 wr %l0, PSR_ET, %psr
688 WRITE_PAUSE
689
690 andcc %l0, PSR_PS, %g0
691 bne dfw_kernel
692 nop
693
694 call flush_user_windows
695 nop
696
697 /* Advance over the trap instruction. */
698 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1
699 add %l1, 0x4, %l2
700 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
701 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
702
703 RESTORE_ALL
704
705 .globl flush_patch_one
706
707 /* We get these for debugging routines using __builtin_return_address() */
708dfw_kernel:
709flush_patch_one:
710 FLUSH_ALL_KERNEL_WINDOWS
711
712 /* Advance over the trap instruction. */
713 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1
714 add %l1, 0x4, %l2
715 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
716 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
717
718 RESTORE_ALL
719
720 /* The getcc software trap. The user wants the condition codes from
721 * the %psr in register %g1.
722 */
723
724 .align 4
725 .globl getcc_trap_handler
726getcc_trap_handler:
727 srl %l0, 20, %g1 ! give user
728 and %g1, 0xf, %g1 ! only ICC bits in %psr
729 jmp %l2 ! advance over trap instruction
730 rett %l2 + 0x4 ! like this...
731
732 /* The setcc software trap. The user has condition codes in %g1
733 * that it would like placed in the %psr. Be careful not to flip
734 * any unintentional bits!
735 */
736
737 .align 4
738 .globl setcc_trap_handler
739setcc_trap_handler:
740 sll %g1, 0x14, %l4
741 set PSR_ICC, %l5
742 andn %l0, %l5, %l0 ! clear ICC bits in %psr
743 and %l4, %l5, %l4 ! clear non-ICC bits in user value
744 or %l4, %l0, %l4 ! or them in... mix mix mix
745
746 wr %l4, 0x0, %psr ! set new %psr
747 WRITE_PAUSE ! TI scumbags...
748
749 jmp %l2 ! advance over trap instruction
750 rett %l2 + 0x4 ! like this...
751
Sam Ravnborg2c1cfb22012-05-11 11:35:04 +0000752#ifndef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 .align 4
Sam Ravnborg2c1cfb22012-05-11 11:35:04 +0000754 .globl linux_trap_ipi15
755linux_trap_ipi15:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 SAVE_ALL
757
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 /* Now it is safe to re-enable traps without recursion. */
759 or %l0, PSR_PIL, %l0
760 wr %l0, PSR_ET, %psr
761 WRITE_PAUSE
762
763 /* Now call the c-code with the pt_regs frame ptr and the
764 * memory error registers as arguments. The ordering chosen
765 * here is due to unlatching semantics.
766 */
767 sethi %hi(AC_SYNC_ERR), %o0
768 add %o0, 0x4, %o0
769 lda [%o0] ASI_CONTROL, %o2 ! sync vaddr
770 sub %o0, 0x4, %o0
771 lda [%o0] ASI_CONTROL, %o1 ! sync error
772 add %o0, 0xc, %o0
773 lda [%o0] ASI_CONTROL, %o4 ! async vaddr
774 sub %o0, 0x4, %o0
775 lda [%o0] ASI_CONTROL, %o3 ! async error
776 call sparc_lvl15_nmi
777 add %sp, STACKFRAME_SZ, %o0
778
779 RESTORE_ALL
780
Sam Ravnborg2c1cfb22012-05-11 11:35:04 +0000781#endif /* CONFIG_SMP */
782
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 .align 4
784 .globl invalid_segment_patch1_ff
785 .globl invalid_segment_patch2_ff
786invalid_segment_patch1_ff: cmp %l4, 0xff
787invalid_segment_patch2_ff: mov 0xff, %l3
788
789 .align 4
790 .globl invalid_segment_patch1_1ff
791 .globl invalid_segment_patch2_1ff
792invalid_segment_patch1_1ff: cmp %l4, 0x1ff
793invalid_segment_patch2_1ff: mov 0x1ff, %l3
794
795 .align 4
796 .globl num_context_patch1_16, num_context_patch2_16
797num_context_patch1_16: mov 0x10, %l7
798num_context_patch2_16: mov 0x10, %l7
799
800 .align 4
801 .globl vac_linesize_patch_32
802vac_linesize_patch_32: subcc %l7, 32, %l7
803
804 .align 4
805 .globl vac_hwflush_patch1_on, vac_hwflush_patch2_on
806
807/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300808 * Ugly, but we can't use hardware flushing on the sun4 and we'd require
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 * two instructions (Anton)
810 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811vac_hwflush_patch1_on: addcc %l7, -PAGE_SIZE, %l7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813vac_hwflush_patch2_on: sta %g0, [%l3 + %l7] ASI_HWFLUSHSEG
814
815 .globl invalid_segment_patch1, invalid_segment_patch2
816 .globl num_context_patch1
817 .globl vac_linesize_patch, vac_hwflush_patch1
818 .globl vac_hwflush_patch2
819
820 .align 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 .globl srmmu_fault
822srmmu_fault:
823 mov 0x400, %l5
824 mov 0x300, %l4
825
826 lda [%l5] ASI_M_MMUREGS, %l6 ! read sfar first
827 lda [%l4] ASI_M_MMUREGS, %l5 ! read sfsr last
828
829 andn %l6, 0xfff, %l6
830 srl %l5, 6, %l5 ! and encode all info into l7
831
832 and %l5, 2, %l5
833 or %l5, %l6, %l6
834
835 or %l6, %l7, %l7 ! l7 = [addr,write,txtfault]
836
837 SAVE_ALL
838
839 mov %l7, %o1
840 mov %l7, %o2
841 and %o1, 1, %o1 ! arg2 = text_faultp
842 mov %l7, %o3
843 and %o2, 2, %o2 ! arg3 = writep
844 andn %o3, 0xfff, %o3 ! arg4 = faulting address
845
846 wr %l0, PSR_ET, %psr
847 WRITE_PAUSE
848
849 call do_sparc_fault
850 add %sp, STACKFRAME_SZ, %o0 ! arg1 = pt_regs ptr
851
852 RESTORE_ALL
853
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 .align 4
855 .globl sys_nis_syscall
856sys_nis_syscall:
857 mov %o7, %l5
858 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
859 call c_sys_nis_syscall
860 mov %l5, %o7
861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 .align 4
863 .globl sys_execve
864sys_execve:
865 mov %o7, %l5
866 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
867 call sparc_execve
868 mov %l5, %o7
869
David S. Millerec98c6b2008-04-20 02:14:23 -0700870 .globl sunos_execv
871sunos_execv:
872 st %g0, [%sp + STACKFRAME_SZ + PT_I2]
873
874 call sparc_execve
875 add %sp, STACKFRAME_SZ, %o0
876
877 b ret_sys_call
878 ld [%sp + STACKFRAME_SZ + PT_I0], %o0
879
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 .align 4
Heiko Carstens11347232009-01-14 14:13:56 +0100881 .globl sys_sparc_pipe
882sys_sparc_pipe:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 mov %o7, %l5
884 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
885 call sparc_pipe
886 mov %l5, %o7
887
888 .align 4
889 .globl sys_sigaltstack
890sys_sigaltstack:
891 mov %o7, %l5
892 mov %fp, %o2
893 call do_sigaltstack
894 mov %l5, %o7
895
896 .align 4
897 .globl sys_sigstack
898sys_sigstack:
899 mov %o7, %l5
900 mov %fp, %o2
901 call do_sys_sigstack
902 mov %l5, %o7
903
904 .align 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 .globl sys_sigreturn
906sys_sigreturn:
907 call do_sigreturn
908 add %sp, STACKFRAME_SZ, %o0
909
910 ld [%curptr + TI_FLAGS], %l5
911 andcc %l5, _TIF_SYSCALL_TRACE, %g0
912 be 1f
913 nop
914
915 call syscall_trace
916 nop
917
9181:
919 /* We don't want to muck with user registers like a
920 * normal syscall, just return.
921 */
922 RESTORE_ALL
923
924 .align 4
925 .globl sys_rt_sigreturn
926sys_rt_sigreturn:
927 call do_rt_sigreturn
928 add %sp, STACKFRAME_SZ, %o0
929
930 ld [%curptr + TI_FLAGS], %l5
931 andcc %l5, _TIF_SYSCALL_TRACE, %g0
932 be 1f
933 nop
934
David S. Miller1c133b42008-07-27 03:13:13 -0700935 add %sp, STACKFRAME_SZ, %o0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 call syscall_trace
David S. Miller1c133b42008-07-27 03:13:13 -0700937 mov 1, %o1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
9391:
940 /* We are returning to a signal handler. */
941 RESTORE_ALL
942
943 /* Now that we have a real sys_clone, sys_fork() is
944 * implemented in terms of it. Our _real_ implementation
945 * of SunOS vfork() will use sys_vfork().
946 *
947 * XXX These three should be consolidated into mostly shared
948 * XXX code just like on sparc64... -DaveM
949 */
950 .align 4
951 .globl sys_fork, flush_patch_two
952sys_fork:
953 mov %o7, %l5
954flush_patch_two:
955 FLUSH_ALL_KERNEL_WINDOWS;
956 ld [%curptr + TI_TASK], %o4
957 rd %psr, %g4
958 WRITE_PAUSE
959 mov SIGCHLD, %o0 ! arg0: clone flags
960 rd %wim, %g5
961 WRITE_PAUSE
962 mov %fp, %o1 ! arg1: usp
963 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
964 add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
965 mov 0, %o3
966 call sparc_do_fork
967 mov %l5, %o7
968
969 /* Whee, kernel threads! */
970 .globl sys_clone, flush_patch_three
971sys_clone:
972 mov %o7, %l5
973flush_patch_three:
974 FLUSH_ALL_KERNEL_WINDOWS;
975 ld [%curptr + TI_TASK], %o4
976 rd %psr, %g4
977 WRITE_PAUSE
978
979 /* arg0,1: flags,usp -- loaded already */
980 cmp %o1, 0x0 ! Is new_usp NULL?
981 rd %wim, %g5
982 WRITE_PAUSE
983 be,a 1f
984 mov %fp, %o1 ! yes, use callers usp
985 andn %o1, 7, %o1 ! no, align to 8 bytes
9861:
987 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
988 add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
989 mov 0, %o3
990 call sparc_do_fork
991 mov %l5, %o7
992
993 /* Whee, real vfork! */
994 .globl sys_vfork, flush_patch_four
995sys_vfork:
996flush_patch_four:
997 FLUSH_ALL_KERNEL_WINDOWS;
998 ld [%curptr + TI_TASK], %o4
999 rd %psr, %g4
1000 WRITE_PAUSE
1001 rd %wim, %g5
1002 WRITE_PAUSE
1003 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1004 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1005 mov %fp, %o1
1006 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1007 sethi %hi(sparc_do_fork), %l1
1008 mov 0, %o3
1009 jmpl %l1 + %lo(sparc_do_fork), %g0
1010 add %sp, STACKFRAME_SZ, %o2
1011
1012 .align 4
1013linux_sparc_ni_syscall:
1014 sethi %hi(sys_ni_syscall), %l7
1015 b syscall_is_too_hard
1016 or %l7, %lo(sys_ni_syscall), %l7
1017
1018linux_fast_syscall:
1019 andn %l7, 3, %l7
1020 mov %i0, %o0
1021 mov %i1, %o1
1022 mov %i2, %o2
1023 jmpl %l7 + %g0, %g0
1024 mov %i3, %o3
1025
1026linux_syscall_trace:
David S. Miller1c133b42008-07-27 03:13:13 -07001027 add %sp, STACKFRAME_SZ, %o0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 call syscall_trace
David S. Miller1c133b42008-07-27 03:13:13 -07001029 mov 0, %o1
1030 cmp %o0, 0
1031 bne 3f
1032 mov -ENOSYS, %o0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 mov %i0, %o0
1034 mov %i1, %o1
1035 mov %i2, %o2
1036 mov %i3, %o3
1037 b 2f
1038 mov %i4, %o4
1039
1040 .globl ret_from_fork
1041ret_from_fork:
1042 call schedule_tail
Tkhai Kirill47c7c972011-03-31 00:52:38 -07001043 ld [%g3 + TI_TASK], %o0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 b ret_sys_call
1045 ld [%sp + STACKFRAME_SZ + PT_I0], %o0
1046
David S. Millerec98c6b2008-04-20 02:14:23 -07001047 /* Linux native system calls enter here... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 .align 4
1049 .globl linux_sparc_syscall
1050linux_sparc_syscall:
David S. Miller28e61032008-05-11 02:07:19 -07001051 sethi %hi(PSR_SYSCALL), %l4
1052 or %l0, %l4, %l0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 /* Direct access to user regs, must faster. */
David S. Millerc658ad12009-12-11 00:44:47 -08001054 cmp %g1, NR_syscalls
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 bgeu linux_sparc_ni_syscall
1056 sll %g1, 2, %l4
1057 ld [%l7 + %l4], %l7
1058 andcc %l7, 1, %g0
1059 bne linux_fast_syscall
1060 /* Just do first insn from SAVE_ALL in the delay slot */
1061
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062syscall_is_too_hard:
1063 SAVE_ALL_HEAD
1064 rd %wim, %l3
1065
1066 wr %l0, PSR_ET, %psr
1067 mov %i0, %o0
1068 mov %i1, %o1
1069 mov %i2, %o2
1070
1071 ld [%curptr + TI_FLAGS], %l5
1072 mov %i3, %o3
1073 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1074 mov %i4, %o4
1075 bne linux_syscall_trace
1076 mov %i0, %l5
10772:
1078 call %l7
1079 mov %i5, %o5
1080
David S. Miller1c133b42008-07-27 03:13:13 -070010813:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1083
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084ret_sys_call:
1085 ld [%curptr + TI_FLAGS], %l6
1086 cmp %o0, -ERESTART_RESTARTBLOCK
1087 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1088 set PSR_C, %g2
1089 bgeu 1f
1090 andcc %l6, _TIF_SYSCALL_TRACE, %g0
1091
1092 /* System call success, clear Carry condition code. */
1093 andn %g3, %g2, %g3
1094 clr %l6
1095 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1096 bne linux_syscall_trace2
1097 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1098 add %l1, 0x4, %l2 /* npc = npc+4 */
1099 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1100 b ret_trap_entry
1101 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
11021:
1103 /* System call failure, set Carry condition code.
1104 * Also, get abs(errno) to return to the process.
1105 */
1106 sub %g0, %o0, %o0
1107 or %g3, %g2, %g3
1108 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1109 mov 1, %l6
1110 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1111 bne linux_syscall_trace2
1112 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1113 add %l1, 0x4, %l2 /* npc = npc+4 */
1114 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1115 b ret_trap_entry
1116 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1117
1118linux_syscall_trace2:
David S. Miller1c133b42008-07-27 03:13:13 -07001119 add %sp, STACKFRAME_SZ, %o0
1120 mov 1, %o1
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 call syscall_trace
1122 add %l1, 0x4, %l2 /* npc = npc+4 */
1123 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1124 b ret_trap_entry
1125 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1126
1127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128/* Saving and restoring the FPU state is best done from lowlevel code.
1129 *
1130 * void fpsave(unsigned long *fpregs, unsigned long *fsr,
1131 * void *fpqueue, unsigned long *fpqdepth)
1132 */
1133
1134 .globl fpsave
1135fpsave:
1136 st %fsr, [%o1] ! this can trap on us if fpu is in bogon state
1137 ld [%o1], %g1
1138 set 0x2000, %g4
1139 andcc %g1, %g4, %g0
1140 be 2f
1141 mov 0, %g2
1142
1143 /* We have an fpqueue to save. */
11441:
1145 std %fq, [%o2]
1146fpsave_magic:
1147 st %fsr, [%o1]
1148 ld [%o1], %g3
1149 andcc %g3, %g4, %g0
1150 add %g2, 1, %g2
1151 bne 1b
1152 add %o2, 8, %o2
1153
11542:
1155 st %g2, [%o3]
1156
1157 std %f0, [%o0 + 0x00]
1158 std %f2, [%o0 + 0x08]
1159 std %f4, [%o0 + 0x10]
1160 std %f6, [%o0 + 0x18]
1161 std %f8, [%o0 + 0x20]
1162 std %f10, [%o0 + 0x28]
1163 std %f12, [%o0 + 0x30]
1164 std %f14, [%o0 + 0x38]
1165 std %f16, [%o0 + 0x40]
1166 std %f18, [%o0 + 0x48]
1167 std %f20, [%o0 + 0x50]
1168 std %f22, [%o0 + 0x58]
1169 std %f24, [%o0 + 0x60]
1170 std %f26, [%o0 + 0x68]
1171 std %f28, [%o0 + 0x70]
1172 retl
1173 std %f30, [%o0 + 0x78]
1174
1175 /* Thanks for Theo Deraadt and the authors of the Sprite/netbsd/openbsd
1176 * code for pointing out this possible deadlock, while we save state
1177 * above we could trap on the fsr store so our low level fpu trap
1178 * code has to know how to deal with this.
1179 */
1180fpsave_catch:
1181 b fpsave_magic + 4
1182 st %fsr, [%o1]
1183
1184fpsave_catch2:
1185 b fpsave + 4
1186 st %fsr, [%o1]
1187
1188 /* void fpload(unsigned long *fpregs, unsigned long *fsr); */
1189
1190 .globl fpload
1191fpload:
1192 ldd [%o0 + 0x00], %f0
1193 ldd [%o0 + 0x08], %f2
1194 ldd [%o0 + 0x10], %f4
1195 ldd [%o0 + 0x18], %f6
1196 ldd [%o0 + 0x20], %f8
1197 ldd [%o0 + 0x28], %f10
1198 ldd [%o0 + 0x30], %f12
1199 ldd [%o0 + 0x38], %f14
1200 ldd [%o0 + 0x40], %f16
1201 ldd [%o0 + 0x48], %f18
1202 ldd [%o0 + 0x50], %f20
1203 ldd [%o0 + 0x58], %f22
1204 ldd [%o0 + 0x60], %f24
1205 ldd [%o0 + 0x68], %f26
1206 ldd [%o0 + 0x70], %f28
1207 ldd [%o0 + 0x78], %f30
1208 ld [%o1], %fsr
1209 retl
1210 nop
1211
1212 /* __ndelay and __udelay take two arguments:
1213 * 0 - nsecs or usecs to delay
1214 * 1 - per_cpu udelay_val (loops per jiffy)
1215 *
1216 * Note that ndelay gives HZ times higher resolution but has a 10ms
1217 * limit. udelay can handle up to 1s.
1218 */
1219 .globl __ndelay
1220__ndelay:
1221 save %sp, -STACKFRAME_SZ, %sp
1222 mov %i0, %o0
Mark Fortescue196bffa2007-07-21 19:17:41 -07001223 call .umul ! round multiplier up so large ns ok
1224 mov 0x1ae, %o1 ! 2**32 / (1 000 000 000 / HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 call .umul
1226 mov %i1, %o1 ! udelay_val
1227 ba delay_continue
1228 mov %o1, %o0 ! >>32 later for better resolution
1229
1230 .globl __udelay
1231__udelay:
1232 save %sp, -STACKFRAME_SZ, %sp
1233 mov %i0, %o0
Mark Fortescue196bffa2007-07-21 19:17:41 -07001234 sethi %hi(0x10c7), %o1 ! round multiplier up so large us ok
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 call .umul
Mark Fortescue196bffa2007-07-21 19:17:41 -07001236 or %o1, %lo(0x10c7), %o1 ! 2**32 / 1 000 000
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 call .umul
1238 mov %i1, %o1 ! udelay_val
Mark Fortescue196bffa2007-07-21 19:17:41 -07001239 sethi %hi(0x028f4b62), %l0 ! Add in rounding constant * 2**32,
1240 or %g0, %lo(0x028f4b62), %l0
1241 addcc %o0, %l0, %o0 ! 2**32 * 0.009 999
1242 bcs,a 3f
1243 add %o1, 0x01, %o1
12443:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 call .umul
1246 mov HZ, %o0 ! >>32 earlier for wider range
1247
1248delay_continue:
1249 cmp %o0, 0x0
12501:
1251 bne 1b
1252 subcc %o0, 1, %o0
1253
1254 ret
1255 restore
1256
1257 /* Handle a software breakpoint */
1258 /* We have to inform parent that child has stopped */
1259 .align 4
1260 .globl breakpoint_trap
1261breakpoint_trap:
1262 rd %wim,%l3
1263 SAVE_ALL
1264 wr %l0, PSR_ET, %psr
1265 WRITE_PAUSE
1266
1267 st %i0, [%sp + STACKFRAME_SZ + PT_G0] ! for restarting syscalls
1268 call sparc_breakpoint
1269 add %sp, STACKFRAME_SZ, %o0
1270
1271 RESTORE_ALL
1272
David S. Millere2fdd7f2008-04-29 02:38:50 -07001273#ifdef CONFIG_KGDB
1274 .align 4
1275 .globl kgdb_trap_low
1276 .type kgdb_trap_low,#function
1277kgdb_trap_low:
1278 rd %wim,%l3
1279 SAVE_ALL
1280 wr %l0, PSR_ET, %psr
1281 WRITE_PAUSE
1282
1283 call kgdb_trap
1284 add %sp, STACKFRAME_SZ, %o0
1285
1286 RESTORE_ALL
1287 .size kgdb_trap_low,.-kgdb_trap_low
1288#endif
1289
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 .align 4
Adrian Bunkc61c65c2008-06-05 11:40:58 -07001291 .globl flush_patch_exception
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292flush_patch_exception:
1293 FLUSH_ALL_KERNEL_WINDOWS;
1294 ldd [%o0], %o6
1295 jmpl %o7 + 0xc, %g0 ! see asm-sparc/processor.h
1296 mov 1, %g1 ! signal EFAULT condition
1297
1298 .align 4
1299 .globl kill_user_windows, kuw_patch1_7win
1300 .globl kuw_patch1
1301kuw_patch1_7win: sll %o3, 6, %o3
1302
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 */
1307kill_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
13151:
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
1321kuw_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
13294:
1330 wr %o5, 0x0, %psr ! re-enable interrupts
1331 WRITE_PAUSE ! burn baby burn
13323:
1333 retl ! return
1334 st %g0, [%g6 + TI_W_SAVED] ! no windows saved
1335
1336 .align 4
1337 .globl restore_current
1338restore_current:
1339 LOAD_CURRENT(g6, o0)
1340 retl
1341 nop
1342
Daniel Hellstromcfe3af52011-05-23 21:04:46 +00001343#ifdef CONFIG_PCIC_PCI
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344#include <asm/pcic.h>
1345
1346 .align 4
1347 .globl linux_trap_ipi15_pcic
1348linux_trap_ipi15_pcic:
1349 rd %wim, %l3
1350 SAVE_ALL
1351
1352 /*
1353 * First deactivate NMI
1354 * or we cannot drop ET, cannot get window spill traps.
1355 * The busy loop is necessary because the PIO error
1356 * sometimes does not go away quickly and we trap again.
1357 */
1358 sethi %hi(pcic_regs), %o1
1359 ld [%o1 + %lo(pcic_regs)], %o2
1360
1361 ! Get pending status for printouts later.
1362 ld [%o2 + PCI_SYS_INT_PENDING], %o0
1363
1364 mov PCI_SYS_INT_PENDING_CLEAR_ALL, %o1
1365 stb %o1, [%o2 + PCI_SYS_INT_PENDING_CLEAR]
13661:
1367 ld [%o2 + PCI_SYS_INT_PENDING], %o1
1368 andcc %o1, ((PCI_SYS_INT_PENDING_PIO|PCI_SYS_INT_PENDING_PCI)>>24), %g0
1369 bne 1b
1370 nop
1371
1372 or %l0, PSR_PIL, %l4
1373 wr %l4, 0x0, %psr
1374 WRITE_PAUSE
1375 wr %l4, PSR_ET, %psr
1376 WRITE_PAUSE
1377
1378 call pcic_nmi
1379 add %sp, STACKFRAME_SZ, %o1 ! struct pt_regs *regs
1380 RESTORE_ALL
1381
1382 .globl pcic_nmi_trap_patch
1383pcic_nmi_trap_patch:
1384 sethi %hi(linux_trap_ipi15_pcic), %l3
1385 jmpl %l3 + %lo(linux_trap_ipi15_pcic), %g0
1386 rd %psr, %l0
1387 .word 0
1388
Daniel Hellstromcfe3af52011-05-23 21:04:46 +00001389#endif /* CONFIG_PCIC_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390
David S. Millere2fdd7f2008-04-29 02:38:50 -07001391 .globl flushw_all
1392flushw_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
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409/* End of entry.S */