1/* $NetBSD: debug.s,v 1.11 2008/04/28 20:23:10 martin Exp $ */ 2 3/*- 4 * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9 * NASA Ames Research Center. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33__KERNEL_RCSID(6, "$NetBSD: debug.s,v 1.11 2008/04/28 20:23:10 martin Exp $") 34 35#include "opt_multiprocessor.h" 36#include "opt_kgdb.h" 37 38/* 39 * Debugger glue. 40 */ 41 42 .text 43inc6: .stabs __FILE__,132,0,0,inc6; .loc 1 __LINE__ 44 45/* 46 * Debugger stack. 47 */ 48#define DEBUG_STACK_SIZE 8192 49BSS(debug_stack_bottom, DEBUG_STACK_SIZE) 50 51#define debug_stack_top (debug_stack_bottom + DEBUG_STACK_SIZE) 52 53/* 54 * alpha_debug: 55 * 56 * Single debugger entry point, handling the housekeeping 57 * chores we need to deal with. 58 * 59 * Arguments are: 60 * 61 * a0 a0 from trap 62 * a1 a1 from trap 63 * a2 a2 from trap 64 * a3 kernel trap entry point 65 * a4 frame pointer 66 */ 67NESTED_NOPROFILE(alpha_debug, 5, 32, ra, IM_RA|IM_S0, 0) 68 br pv, 1f 691: LDGP(pv) 70 lda t0, FRAME_SIZE*8(a4) /* what would sp have been? */ 71 stq t0, FRAME_SP*8(a4) /* belatedly save sp for ddb view */ 72 lda sp, -32(sp) /* set up stack frame */ 73 stq ra, (32-8)(sp) /* save ra */ 74 stq s0, (32-16)(sp) /* save s0 */ 75 76 /* Remember our current stack pointer. */ 77 mov sp, s0 78 79#if defined(MULTIPROCESSOR) 80 /* Pause all other CPUs. */ 81 ldiq a0, 1 82 CALL(cpu_pause_resume_all) 83#endif 84 85 /* 86 * Switch to the debug stack if we're not on it already. 87 */ 88 lda t0, debug_stack_bottom 89 cmpule sp, t0, t1 /* sp <= debug_stack_bottom */ 90 bne t1, 2f /* yes, switch now */ 91 92 lda t0, debug_stack_top 93 cmpule t0, sp, t1 /* debug_stack_top <= sp? */ 94 bne t1, 3f /* yes, we're on the debug stack */ 95 962: lda sp, debug_stack_top /* sp <- debug_stack_top */ 97 983: /* Dispatch to the debugger - arguments are already in place. */ 99#if defined(KGDB) 100 mov a3, a0 /* a0 == entry (trap type) */ 101 mov a4, a1 /* a1 == frame pointer */ 102 CALL(kgdb_trap) 103 br 9f 104#endif 105#if defined(DDB) 106 CALL(ddb_trap) 107 br 9f 108#endif 1099: /* Debugger return value in v0; switch back to our previous stack. */ 110 mov s0, sp 111 112#if defined(MULTIPROCESSOR) 113 mov v0, s0 114 115 /* Resume all other CPUs. */ 116 mov zero, a0 117 CALL(cpu_pause_resume_all) 118 119 mov s0, v0 120#endif 121 122 ldq ra, (32-8)(sp) /* restore ra */ 123 ldq s0, (32-16)(sp) /* restore s0 */ 124 lda sp, 32(sp) /* pop stack frame */ 125 RET 126 END(alpha_debug) 127