1/* $OpenBSD: debug.s,v 1.9 2015/06/27 10:51:46 dlg Exp $ */
2/* $NetBSD: debug.s,v 1.5 1999/06/18 18:11:56 thorpej Exp $ */
3
4/*-
5 * Copyright (c) 1999 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10 * NASA Ames Research Center.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#if defined (MULTIPROCESSOR)
35.file	5 __FILE__
36.loc	5 __LINE__
37#else
38.file	4 __FILE__
39.loc	4 __LINE__
40#endif
41
42/*
43 * Debugger glue.
44 */
45
46	.text
47
48/*
49 * Debugger stack.
50 */
51#define	DEBUG_STACK_SIZE	8192
52BSS(debug_stack_bottom, DEBUG_STACK_SIZE)
53
54#define	debug_stack_top	(debug_stack_bottom + DEBUG_STACK_SIZE)
55
56/*
57 * alpha_debug:
58 *
59 *	Single debugger entry point, handling the housekeeping
60 *	chores we need to deal with.
61 *
62 *	Arguments are:
63 *
64 *		a0	a0 from trap
65 *		a1	a1 from trap
66 *		a2	a2 from trap
67 *		a3	kernel trap entry point
68 *		a4	frame pointer
69 */
70NESTED_NOPROFILE(alpha_debug, 5, 32, ra, IM_RA|IM_S0, 0)
71	br	pv, 1f
721:	LDGP(pv)
73	lda	t0, FRAME_SIZE*8(a4)	/* what would sp have been? */
74	stq	t0, FRAME_SP*8(a4)	/* belatedly save sp for ddb view */
75	lda	sp, -32(sp)		/* set up stack frame */
76	stq	ra, (32-8)(sp)		/* save ra */
77	stq	s0, (32-16)(sp)		/* save s0 */
78
79	/* Remember our current stack pointer. */
80	mov	sp, s0
81
82#if defined(MULTIPROCESSOR)
83	/* Pause all other CPUs. */
84	ldiq	a0, 1
85	CALL(cpu_pause_resume_all)
86#endif
87
88	/*
89	 * Switch to the debug stack if we're not on it already.
90	 */
91	lda	t0, debug_stack_bottom
92	cmpule	sp, t0, t1		/* sp <= debug_stack_bottom */
93	bne	t1, 2f			/* yes, switch now */
94
95	lda	t0, debug_stack_top
96	cmpule	t0, sp, t1		/* debug_stack_top <= sp? */
97	bne	t1, 3f			/* yes, we're on the debug stack */
98
992:	lda	sp, debug_stack_top	/* sp <- debug_stack_top */
100
1013:	/* Dispatch to the debugger - arguments are already in place. */
102	CALL(ddb_trap)
103
104	/* Debugger return value in v0; switch back to our previous stack. */
105	mov	s0, sp
106
107#if defined(MULTIPROCESSOR)
108	mov	v0, s0
109
110	/* Resume all other CPUs. */
111	mov	zero, a0
112	CALL(cpu_pause_resume_all)
113
114	mov	s0, v0
115#endif
116
117	ldq	ra, (32-8)(sp)		/* restore ra */
118	ldq	s0, (32-16)(sp)		/* restore s0 */
119	lda	sp, 32(sp)		/* pop stack frame */
120	RET
121	END(alpha_debug)
122
123#if defined(MULTIPROCESSOR) && defined(MP_LOCKDEBUG)
124NESTED(alpha_ipi_process_with_frame, 2, 8 * FRAME_SIZE, ra, IM_RA, 0)
125	.set noat
126	lda	sp, -(8 * FRAME_SIZE)(sp)		/* set up stack frame */
127
128	stq	v0,(FRAME_V0*8)(sp)
129	stq	t0,(FRAME_T0*8)(sp)
130	stq	t1,(FRAME_T1*8)(sp)
131	stq	t2,(FRAME_T2*8)(sp)
132	stq	t3,(FRAME_T3*8)(sp)
133	stq	t4,(FRAME_T4*8)(sp)
134	stq	t5,(FRAME_T5*8)(sp)
135	stq	t6,(FRAME_T6*8)(sp)
136	stq	t7,(FRAME_T7*8)(sp)
137	stq	s0,(FRAME_S0*8)(sp)
138	stq	s1,(FRAME_S1*8)(sp)
139	stq	s2,(FRAME_S2*8)(sp)
140	stq	s3,(FRAME_S3*8)(sp)
141	stq	s4,(FRAME_S4*8)(sp)
142	stq	s5,(FRAME_S5*8)(sp)
143	stq	s6,(FRAME_S6*8)(sp)
144	stq	a3,(FRAME_A3*8)(sp)
145	stq	a4,(FRAME_A4*8)(sp)
146	stq	a5,(FRAME_A5*8)(sp)
147	stq	t8,(FRAME_T8*8)(sp)
148	stq	t9,(FRAME_T9*8)(sp)
149	stq	t10,(FRAME_T10*8)(sp)
150	stq	t11,(FRAME_T11*8)(sp)
151	stq	ra,(FRAME_RA*8)(sp)
152	stq	t12,(FRAME_T12*8)(sp)
153	stq	at_reg,(FRAME_AT*8)(sp)
154	lda	a1,(8*FRAME_SIZE)(sp)
155	stq	a1,(FRAME_SP*8)(sp)
156
157	stq	zero,(FRAME_PS*8)(sp)
158	stq	zero,(FRAME_PC*8)(sp)
159	stq	zero,(FRAME_GP*8)(sp)
160	stq	zero,(FRAME_A0*8)(sp)
161	stq	zero,(FRAME_A1*8)(sp)
162	stq	zero,(FRAME_A2*8)(sp)
163
164	mov	sp, a1
165	CALL(alpha_ipi_process)
166
167	ldq	ra,(FRAME_RA*8)(sp)
168	lda	sp, (8 * FRAME_SIZE)(sp)		/* pop stack frame */
169	RET
170	END(alpha_ipi_process_with_frame)
171	.set at
172#endif
173