2 * (C) Copyright 2003, Psyent Corporation <www.psyent.com>
3 * Scott McNutt <smcnutt@psyent.com>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 /*************************************************************************
27 * Register window underflow
29 * The register window underflow exception occurs whenever the lowest
30 * valid register window is in use (CWP=LO_LIMIT) and a save instruction
31 * is issued. The save moves CWP below LO_LIMIT, %sp is set as normal,
32 * then the exception is generated prior to executing the instruction
34 ************************************************************************/
41 /* Sixteen words are always allocated by the compiler in every
42 * procedure's stack frame, always starting at %sp, for saving
43 * 'in' and 'local' registers on a window overflow.
45 * Save the 'global' and 'in' regs on stack. They are restored
46 * at cwp = HI_LIMIT. The 'local' regs aren't in-use at this point.
48 sts [%sp,0], %g0 /* Save 'global' regs*/
57 sts [%sp,8], %i0 /* Save 'in' regs */
66 /* Save current %sp and return address in a global so they are
67 * available at cwp = HI_LIMIT ... where the 'global'/'in' regs
68 * are restored. NOTE: %sp changes with cwp.
73 /* Get LO_LIMIT/HI_LIMIT to know where to start & stop. Note: in
74 * the underflow exception, cwp is __NOT__ guaranteed to be zero.
75 * If the OCI debug module is enabled the reset value for LO_LIMIT
76 * is 2, not 1 -- so cwp can be 1 or 0.
82 and %g1, 0x1f /* g1 <- LO_LIMIT */
85 and %g2,0x1f /* g2 <- HI_LIMIT */
87 /* Set istatus so cwp = HI_LIMIT after tret
91 not %g5 /* mask to clr cwp */
94 and %g0, %g5 /* clear cwp field */
98 or %g0, %g4 /* cwp = HI_LIMIT */
100 wrctl %g0 /* update istatus */
102 /* Now move up the register file, saving as we go. When loop
103 * is first entered, %g1 is at LO_LIMIT.
107 sts [%sp,0], %l0 /* Save "local" regs*/
116 sts [%sp,8], %i0 /* Save 'in' regs */
125 cmp %g1, %g2 /* cwp == HI_LIMIT ? */
126 skps cc_ne /* if so, we're done */
130 inc %g1 /* g1 <- cwp++ */
134 /* At this point cwp = HI_LIMIT, so the global/in regs that were
135 * in place when the underflow occurred must be restored using
136 * the original stack pointer (saved in g6).
139 mov %o7, %g7 /* restore return addr */
140 mov %sp, %g6 /* Restore original sp */
142 lds %g0, [%sp,0] /* Restore 'global' regs*/
151 lds %i0, [%sp,8] /* Restore 'in' regs*/
160 tret %o7 /* All done */
162 /*************************************************************************
163 * Register window overflow
165 * The register window overflow exception occurs whenever the highest
166 * valid register window is in use (cwp = HI_LIMIT) and a restore
167 * instruction is issued. Control is transferred to the overflow handler
168 * before the instruction following restore is executed.
170 * When a register window overflow exception is taken, the exception
171 * handler sees cwp at HI_LIMIT.
172 ************************************************************************/
179 /* Save 'global'/'in' regs on the stack -- will restore when cwp
180 * is at LO_LIMIT. Locals don't need saving as they are going away.
182 sts [%sp,0], %g0 /* Save "global" regs*/
191 sts [%sp,8], %i0 /* Save 'in' regs */
200 /* The current %sp must be available in global to restore regs
201 * saved on stack. Need return addr as well ;-)
206 /* Get HI_LIMIT & LO_LIMIT
212 and %g1, 0x1f /* g1 <- LO_LIMIT */
215 and %g2,0x1f /* g2 <- HI_LIMIT */
217 /* Set istatus so cwp = LO_LIMIT after tret
221 not %g5 /* mask to clr cwp */
224 and %g0, %g5 /* clear cwp field */
226 mov %g4, %g1 /* g4 <- LO_LIMIT */
228 or %g0, %g4 /* cwp = LO_LIMIT */
230 wrctl %g0 /* update istatus */
232 /* Move to cwp = LO_LIMIT-1 and restore 'in' regs.
234 subi %g4,(1 << 4) /* g4 <- LO_LIMIT - 1 */
236 and %g0, %g5 /* clear cwp field */
237 or %g0, %g4 /* cwp = LO_LIMIT - 1 */
238 wrctl %g0 /* update status */
241 mov %sp, %g6 /* Restore sp */
242 lds %i0, [%sp,8] /* Restore 'in' regs */
248 lds %i6, [%sp,14] /* sp in next window */
251 /* Starting at LO_LIMIT-1, move up the register file, restoring
256 lds %l0, [%sp,0] /* Restore 'local' regs*/
265 lds %i0, [%sp,8] /* Restore 'in' regs */
271 lds %i6, [%sp,14] /* sp in next window */
274 cmp %g1, %g2 /* cwp == HI_LIMIT ? */
275 skps cc_ne /* if so, we're done */
283 /* All windows have been updated at this point, but the globals
284 * still need to be restored. Go to cwp = LO_LIMIT-1 to get
285 * some registers to use.
289 and %g0, %g5 /* clear cwp field */
290 or %g0, %g4 /* cwp = LO_LIMIT - 1 */
291 wrctl %g0 /* update status */
294 /* Now there are some registers available to use in restoring
300 lds %g0, [%sp,0] /* Restore "global" regs*/
309 /* The tret moves istatus -> status. istatus was already set for
315 /*************************************************************************
316 * Default exception handler
318 * The default handler passes control to external_interrupt(). So trap
319 * or hardware interrupt hanlders can be installed using the familiar
320 * irq_install_handler().
322 * Here, the stack is fixed-up and cwp is incremented prior to calling
323 * external_interrupt(). This lets the underflow and overflow handlers
324 * operate normally during the exception.
325 ************************************************************************/
327 .global _def_xhandler
332 /* Allocate some stack space: 16 words at %sp to accomodate
333 * a reg window underflow, 8 words to save interrupted task's
334 * 'out' regs (which are now the 'in' regs), 8 words to preserve
335 * the 'global' regs and 3 words to save the return address,
336 * status and istatus. istatus must be saved in the event an
337 * underflow occurs in a dispatched handler. status is saved so
338 * a handler can access it on stack.
340 pfx %hi((16+16+3) * 4)
341 subi %fp, %lo((16+16+3) * 4)
344 /* Save the 'global' regs and the interrupted task's 'out' regs
345 * (our 'in' regs) along with the return addr, status & istatus.
346 * First 16 words are for underflow exception.
348 rdctl %l0 /* status */
352 sts [%sp,16+0], %g0 /* Save 'global' regs*/
361 sts [%sp,16+8], %i0 /* Save 'in' regs */
370 sts [%sp,16+16], %l0 /* status */
371 sts [%sp,16+17], %l1 /* istatus */
372 sts [%sp,16+18], %o7 /* return addr */
374 /* Move to cwp+1 ... this guarantees cwp is at or above LO_LIMIT.
375 * Need to set IPRI=3 and IE=1 to enable underflow exceptions.
376 * NOTE: only the 'out' regs have been saved ... can't touch
377 * the 'in' or 'local' here.
380 rdctl %o0 /* o0 <- status */
383 movi %o1, %lo(0x7e00)
385 and %o0, %o1 /* clear IPRI */
388 movi %o1, %lo(0x8600)
389 or %o0, %o1 /* IPRI=3, IE=1 */
391 wrctl %o0 /* o0 -> status */
394 /* It's ok to call a C routine now since cwp >= LO_LIMIT,
395 * interrupt task's registers are/will be preserved, and
396 * underflow exceptions can be handled.
398 pfx %hi(external_interrupt@h)
399 movi %o1, %lo(external_interrupt@h)
400 pfx %xhi(external_interrupt@h)
401 movhi %o1, %xlo(external_interrupt@h)
402 bgen %o0, 4+2 /* 16 * 4 */
403 add %o0, %sp /* Ptr to regs */
407 /* Move back to the exception register window, restore the 'out'
408 * registers, then return from exception.
410 rdctl %o0 /* o0 <- status */
412 wrctl %o0 /* cwp-- */
416 lds %g0, [%sp,16+0] /* Restore 'global' regs*/
425 lds %i0, [%sp,16+8] /* Restore 'in' regs*/
434 lds %l0, [%sp,16+16] /* status */
435 lds %l1, [%sp,16+17] /* istatus */
436 lds %o7, [%sp,16+18] /* return addr */
439 wrctl %l1 /* restore istatus */
441 pfx %hi((16+16+3) * 4)
442 addi %sp, %lo((16+16+3) * 4)
448 /*************************************************************************
449 * Timebase Timer Interrupt -- This has identical structure to above,
450 * but calls timer_interrupt(). Doing it this way keeps things similar
451 * to other architectures (e.g. ppc).
452 ************************************************************************/
454 .global _timebase_int
459 /* Allocate stack space.
461 pfx %hi((16+16+3) * 4)
462 subi %fp, %lo((16+16+3) * 4)
465 /* Save the 'global' regs & 'out' regs (our 'in' regs)
467 rdctl %l0 /* status */
471 sts [%sp,16+0], %g0 /* Save 'global' regs*/
480 sts [%sp,16+8], %i0 /* Save 'in' regs */
489 sts [%sp,16+16], %l0 /* status */
490 sts [%sp,16+17], %l1 /* istatus */
491 sts [%sp,16+18], %o7 /* return addr */
496 rdctl %o0 /* o0 <- status */
499 movi %o1, %lo(0x7e00)
501 and %o0, %o1 /* clear IPRI */
504 movi %o1, %lo(0x8600)
505 or %o0, %o1 /* IPRI=3, IE=1 */
507 wrctl %o0 /* o0 -> status */
510 /* Call timer_interrupt()
512 pfx %hi(timer_interrupt@h)
513 movi %o1, %lo(timer_interrupt@h)
514 pfx %xhi(timer_interrupt@h)
515 movhi %o1, %xlo(timer_interrupt@h)
516 bgen %o0, 4+2 /* 16 * 4 */
517 add %o0, %sp /* Ptr to regs */
521 /* Move back to the exception register window, restore the 'out'
522 * registers, then return from exception.
524 rdctl %o0 /* o0 <- status */
526 wrctl %o0 /* cwp-- */
530 lds %g0, [%sp,16+0] /* Restore 'global' regs*/
539 lds %i0, [%sp,16+8] /* Restore 'in' regs*/
548 lds %l0, [%sp,16+16] /* status */
549 lds %l1, [%sp,16+17] /* istatus */
550 lds %o7, [%sp,16+18] /* return addr */
553 wrctl %l1 /* restore istatus */
555 pfx %hi((16+16+3) * 4)
556 addi %sp, %lo((16+16+3) * 4)
561 /*************************************************************************
563 ************************************************************************/
565 .global _brkpt_hw_int, _brkpt_sw_int