Home | History | Annotate | Line # | Download | only in kern
subr_spldebug.c revision 1.2.6.1
      1  1.2.6.1   rmind /*	$NetBSD: subr_spldebug.c,v 1.2.6.1 2010/05/30 05:17:58 rmind Exp $	*/
      2      1.1  dyoung 
      3      1.1  dyoung /*-
      4  1.2.6.1   rmind  * Copyright (c) 2009, 2010 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.2.6.1   rmind __KERNEL_RCSID(0, "$NetBSD: subr_spldebug.c,v 1.2.6.1 2010/05/30 05:17:58 rmind 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 #define SPLRAISE_STACKLEN 32
     47      1.1  dyoung 
     48      1.1  dyoung void *splraise_retaddrs[MAXCPUS][SPLRAISE_STACKLEN][4];
     49      1.1  dyoung int splraise_depth[MAXCPUS] = {0};
     50      1.1  dyoung int spllowered_to[MAXCPUS] = {0};
     51      1.1  dyoung void *spllowered_from[MAXCPUS][2] = {{0}};
     52      1.1  dyoung bool spldebug = false;
     53      1.1  dyoung 
     54      1.2  dyoung void	spldebug_start(void);
     55      1.2  dyoung void	spldebug_stop(void);
     56      1.1  dyoung 
     57      1.1  dyoung void
     58      1.2  dyoung spldebug_start(void)
     59      1.1  dyoung {
     60      1.1  dyoung 	spldebug = true;
     61      1.1  dyoung }
     62      1.1  dyoung 
     63      1.1  dyoung void
     64      1.2  dyoung spldebug_stop(void)
     65      1.1  dyoung {
     66      1.1  dyoung 	spldebug = false;
     67      1.1  dyoung }
     68      1.1  dyoung 
     69      1.1  dyoung void
     70      1.1  dyoung spldebug_lower(int ipl)
     71      1.1  dyoung {
     72      1.2  dyoung 	u_int cidx;
     73      1.1  dyoung 
     74      1.1  dyoung 	if (!spldebug)
     75      1.1  dyoung 		return;
     76      1.1  dyoung 
     77      1.2  dyoung 	if (ipl == IPL_HIGH)
     78      1.1  dyoung 		return;
     79      1.1  dyoung 
     80      1.2  dyoung 	cidx = cpu_index(curcpu());
     81      1.1  dyoung 
     82  1.2.6.1   rmind 	KASSERT(cidx < maxcpus);
     83      1.1  dyoung 
     84      1.2  dyoung 	splraise_depth[cidx] = 0;
     85      1.2  dyoung 	spllowered_to[cidx] = ipl;
     86      1.1  dyoung #if 0
     87      1.2  dyoung 	spllowered_from[cidx][0] = return_address(0);
     88      1.2  dyoung 	spllowered_from[cidx][1] = return_address(1);
     89      1.1  dyoung #endif
     90      1.1  dyoung }
     91      1.1  dyoung 
     92      1.1  dyoung void
     93      1.1  dyoung spldebug_raise(int ipl)
     94      1.1  dyoung {
     95      1.1  dyoung 	int i;
     96      1.2  dyoung 	u_int cidx;
     97      1.1  dyoung 	void **retaddrs;
     98      1.1  dyoung 
     99      1.1  dyoung 	if (!spldebug)
    100      1.1  dyoung 		return;
    101      1.1  dyoung 
    102      1.2  dyoung 	if (ipl != IPL_HIGH)
    103      1.1  dyoung 		return;
    104      1.1  dyoung 
    105      1.2  dyoung 	cidx = cpu_index(curcpu());
    106      1.1  dyoung 
    107  1.2.6.1   rmind 	KASSERT(cidx < maxcpus);
    108      1.1  dyoung 
    109      1.2  dyoung 	if (splraise_depth[cidx] >= SPLRAISE_STACKLEN)
    110      1.1  dyoung 		return;
    111      1.1  dyoung 
    112      1.2  dyoung 	retaddrs = &splraise_retaddrs[cidx][splraise_depth[cidx]++][0];
    113      1.1  dyoung 
    114      1.1  dyoung 	retaddrs[0] = retaddrs[1] = retaddrs[2] = retaddrs[3] = NULL;
    115      1.1  dyoung 
    116      1.1  dyoung 	for (i = 0; i < 4; i++) {
    117      1.1  dyoung 		retaddrs[i] = return_address(i);
    118      1.1  dyoung 
    119      1.1  dyoung 		if (retaddrs[i] == NULL)
    120      1.1  dyoung 			break;
    121      1.1  dyoung 	}
    122      1.1  dyoung }
    123