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