xref: /netbsd-src/sys/arch/alpha/alpha/debug.s (revision 7dc70dba0e3e84f0503a9e8ae3cf169bdb453b8f)
1/* $NetBSD: debug.s,v 1.13 2020/09/18 00:04:58 thorpej 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.13 2020/09/18 00:04:58 thorpej Exp $")
34
35#include "opt_multiprocessor.h"
36#include "opt_ddb.h"
37#include "opt_kgdb.h"
38
39/*
40 * Debugger glue.
41 */
42
43	.text
44inc6:	.stabs	__FILE__,132,0,0,inc6; .loc	1 __LINE__
45
46/*
47 * Debugger stack.
48 */
49#define	DEBUG_STACK_SIZE	8192
50BSS(debug_stack_bottom, DEBUG_STACK_SIZE)
51
52#define debug_stack_top		(debug_stack_bottom + DEBUG_STACK_SIZE)
53
54/*
55 * alpha_debug:
56 *
57 *	Single debugger entry point, handling the housekeeping
58 *	chores we need to deal with.
59 *
60 *	Arguments are:
61 *
62 *		a0	a0 from trap
63 *		a1	a1 from trap
64 *		a2	a2 from trap
65 *		a3	kernel trap entry point
66 *		a4	frame pointer
67 */
68NESTED_NOPROFILE(alpha_debug, 5, 64, ra,
69    IM_RA|IM_S0|IM_S1|IM_S2|IM_S3|IM_S4|IM_S5, 0)
70	br	pv, 1f
711:	LDGP(pv)
72	lda	t0, FRAME_SIZE*8(a4)	/* what would sp have been? */
73	stq	t0, FRAME_SP*8(a4)	/* belatedly save sp for ddb view */
74	lda	sp, -64(sp)		/* set up stack frame */
75	stq	s0, (0*8)(sp)		/* save s0 ... */
76	stq	s1, (1*8)(sp)
77	stq	s2, (2*8)(sp)
78	stq	s3, (3*8)(sp)
79	stq	s4, (4*8)(sp)
80	stq	s5, (5*8)(sp)		/* ... through s5 */
81	stq	ra, (6*8)(sp)		/* save ra */
82
83	/* Remember our current stack pointer. */
84	mov	sp, s5
85
86	/* Save off our arguments. */
87	mov	a0, s0
88	mov	a1, s1
89	mov	a2, s2
90	mov	a3, s3
91	mov	a4, s4
92
93#if defined(MULTIPROCESSOR)
94	/* Pause all other CPUs. */
95	ldiq	a0, 1
96	CALL(cpu_pause_resume_all)
97#endif
98
99	/*
100	 * Switch to the debug stack if we're not on it already.
101	 */
102	lda	t0, debug_stack_bottom
103	cmpule	sp, t0, t1		/* sp <= debug_stack_bottom */
104	bne	t1, 2f			/* yes, switch now */
105
106	lda	t0, debug_stack_top
107	cmpule	t0, sp, t1		/* debug_stack_top <= sp? */
108	bne	t1, 3f			/* yes, we're on the debug stack */
109
1102:	lda	sp, debug_stack_top	/* sp <- debug_stack_top */
111
1123:	/* Dispatch to the debugger. */
113#if defined(KGDB)
114	mov	s3, a0			/* a0 == entry (trap type) */
115	mov	s4, a1			/* a1 == frame pointer */
116	CALL(kgdb_trap)
117	br	9f
118#endif
119#if defined(DDB)
120	mov	s0, a1			/* same arguments as the call */
121	mov	s1, a1			/* to alpha_debug() */
122	mov	s2, a2			/* (these may have been clobbered */
123	mov	s3, a3			/* when pausing other CPUs.) */
124	mov	s4, a4
125	CALL(ddb_trap)
126	br	9f
127#endif
1289:	/* Debugger return value in v0; switch back to our previous stack. */
129	mov	s5, sp
130
131#if defined(MULTIPROCESSOR)
132	mov	v0, s0
133
134	/* Resume all other CPUs. */
135	mov	zero, a0
136	CALL(cpu_pause_resume_all)
137
138	mov	s0, v0
139#endif
140
141	ldq	s0, (0*8)(sp)		/* restore s0 ... */
142	ldq	s1, (1*8)(sp)
143	ldq	s2, (2*8)(sp)
144	ldq	s3, (3*8)(sp)
145	ldq	s4, (4*8)(sp)
146	ldq	s5, (5*8)(sp)		/* ... through s5 */
147	ldq	ra, (6*8)(sp)		/* restore ra */
148	lda	sp, 64(sp)		/* pop stack frame */
149	RET
150	END(alpha_debug)
151