subr_spldebug.c revision 1.2.4.3 1 1.2.4.3 yamt /* $NetBSD: subr_spldebug.c,v 1.2.4.3 2010/08/11 22:54:42 yamt Exp $ */
2 1.2.4.2 yamt
3 1.2.4.2 yamt /*-
4 1.2.4.3 yamt * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
5 1.2.4.2 yamt * All rights reserved.
6 1.2.4.2 yamt *
7 1.2.4.2 yamt * This code is derived from software contributed to The NetBSD Foundation
8 1.2.4.2 yamt * by David Young.
9 1.2.4.2 yamt *
10 1.2.4.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.2.4.2 yamt * modification, are permitted provided that the following conditions
12 1.2.4.2 yamt * are met:
13 1.2.4.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.2.4.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.2.4.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.4.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.2.4.2 yamt * documentation and/or other materials provided with the distribution.
18 1.2.4.2 yamt *
19 1.2.4.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2.4.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2.4.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2.4.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2.4.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2.4.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2.4.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2.4.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2.4.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2.4.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2.4.2 yamt * POSSIBILITY OF SUCH DAMAGE.
30 1.2.4.2 yamt */
31 1.2.4.2 yamt
32 1.2.4.2 yamt /*
33 1.2.4.2 yamt * Interrupt priority level debugging code.
34 1.2.4.2 yamt */
35 1.2.4.2 yamt
36 1.2.4.2 yamt #include <sys/cdefs.h>
37 1.2.4.3 yamt __KERNEL_RCSID(0, "$NetBSD: subr_spldebug.c,v 1.2.4.3 2010/08/11 22:54:42 yamt Exp $");
38 1.2.4.2 yamt
39 1.2.4.2 yamt #include <sys/param.h>
40 1.2.4.2 yamt #include <sys/spldebug.h>
41 1.2.4.2 yamt #include <sys/systm.h>
42 1.2.4.2 yamt #include <sys/kernel.h>
43 1.2.4.2 yamt #include <sys/cpu.h>
44 1.2.4.2 yamt #include <machine/return.h>
45 1.2.4.2 yamt
46 1.2.4.2 yamt #define SPLRAISE_STACKLEN 32
47 1.2.4.2 yamt
48 1.2.4.2 yamt void *splraise_retaddrs[MAXCPUS][SPLRAISE_STACKLEN][4];
49 1.2.4.2 yamt int splraise_depth[MAXCPUS] = {0};
50 1.2.4.2 yamt int spllowered_to[MAXCPUS] = {0};
51 1.2.4.2 yamt void *spllowered_from[MAXCPUS][2] = {{0}};
52 1.2.4.2 yamt bool spldebug = false;
53 1.2.4.2 yamt
54 1.2.4.2 yamt void spldebug_start(void);
55 1.2.4.2 yamt void spldebug_stop(void);
56 1.2.4.2 yamt
57 1.2.4.2 yamt void
58 1.2.4.2 yamt spldebug_start(void)
59 1.2.4.2 yamt {
60 1.2.4.2 yamt spldebug = true;
61 1.2.4.2 yamt }
62 1.2.4.2 yamt
63 1.2.4.2 yamt void
64 1.2.4.2 yamt spldebug_stop(void)
65 1.2.4.2 yamt {
66 1.2.4.2 yamt spldebug = false;
67 1.2.4.2 yamt }
68 1.2.4.2 yamt
69 1.2.4.2 yamt void
70 1.2.4.2 yamt spldebug_lower(int ipl)
71 1.2.4.2 yamt {
72 1.2.4.2 yamt u_int cidx;
73 1.2.4.2 yamt
74 1.2.4.2 yamt if (!spldebug)
75 1.2.4.2 yamt return;
76 1.2.4.2 yamt
77 1.2.4.2 yamt if (ipl == IPL_HIGH)
78 1.2.4.2 yamt return;
79 1.2.4.2 yamt
80 1.2.4.2 yamt cidx = cpu_index(curcpu());
81 1.2.4.2 yamt
82 1.2.4.3 yamt KASSERT(cidx < maxcpus);
83 1.2.4.2 yamt
84 1.2.4.2 yamt splraise_depth[cidx] = 0;
85 1.2.4.2 yamt spllowered_to[cidx] = ipl;
86 1.2.4.2 yamt #if 0
87 1.2.4.2 yamt spllowered_from[cidx][0] = return_address(0);
88 1.2.4.2 yamt spllowered_from[cidx][1] = return_address(1);
89 1.2.4.2 yamt #endif
90 1.2.4.2 yamt }
91 1.2.4.2 yamt
92 1.2.4.2 yamt void
93 1.2.4.2 yamt spldebug_raise(int ipl)
94 1.2.4.2 yamt {
95 1.2.4.2 yamt int i;
96 1.2.4.2 yamt u_int cidx;
97 1.2.4.2 yamt void **retaddrs;
98 1.2.4.2 yamt
99 1.2.4.2 yamt if (!spldebug)
100 1.2.4.2 yamt return;
101 1.2.4.2 yamt
102 1.2.4.2 yamt if (ipl != IPL_HIGH)
103 1.2.4.2 yamt return;
104 1.2.4.2 yamt
105 1.2.4.2 yamt cidx = cpu_index(curcpu());
106 1.2.4.2 yamt
107 1.2.4.3 yamt KASSERT(cidx < maxcpus);
108 1.2.4.2 yamt
109 1.2.4.2 yamt if (splraise_depth[cidx] >= SPLRAISE_STACKLEN)
110 1.2.4.2 yamt return;
111 1.2.4.2 yamt
112 1.2.4.2 yamt retaddrs = &splraise_retaddrs[cidx][splraise_depth[cidx]++][0];
113 1.2.4.2 yamt
114 1.2.4.2 yamt retaddrs[0] = retaddrs[1] = retaddrs[2] = retaddrs[3] = NULL;
115 1.2.4.2 yamt
116 1.2.4.2 yamt for (i = 0; i < 4; i++) {
117 1.2.4.2 yamt retaddrs[i] = return_address(i);
118 1.2.4.2 yamt
119 1.2.4.2 yamt if (retaddrs[i] == NULL)
120 1.2.4.2 yamt break;
121 1.2.4.2 yamt }
122 1.2.4.2 yamt }
123