Home | History | Annotate | Line # | Download | only in x68k
kgdb_glue.c revision 1.5
      1  1.5      agc /*	$NetBSD: kgdb_glue.c,v 1.5 2003/08/07 16:30:29 agc Exp $	*/
      2  1.1      oki 
      3  1.1      oki /*
      4  1.1      oki  * Copyright (c) 1991, 1993
      5  1.1      oki  *	The Regents of the University of California.  All rights reserved.
      6  1.1      oki  *
      7  1.1      oki  * This software was developed by the Computer Systems Engineering group
      8  1.1      oki  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9  1.1      oki  * contributed to Berkeley.
     10  1.1      oki  *
     11  1.1      oki  * All advertising materials mentioning features or use of this software
     12  1.1      oki  * must display the following acknowledgement:
     13  1.1      oki  *	This product includes software developed by the University of
     14  1.1      oki  *	California, Lawrence Berkeley Laboratories.
     15  1.1      oki  *
     16  1.1      oki  * Redistribution and use in source and binary forms, with or without
     17  1.1      oki  * modification, are permitted provided that the following conditions
     18  1.1      oki  * are met:
     19  1.1      oki  * 1. Redistributions of source code must retain the above copyright
     20  1.1      oki  *    notice, this list of conditions and the following disclaimer.
     21  1.1      oki  * 2. Redistributions in binary form must reproduce the above copyright
     22  1.1      oki  *    notice, this list of conditions and the following disclaimer in the
     23  1.1      oki  *    documentation and/or other materials provided with the distribution.
     24  1.5      agc  * 3. Neither the name of the University nor the names of its contributors
     25  1.1      oki  *    may be used to endorse or promote products derived from this software
     26  1.1      oki  *    without specific prior written permission.
     27  1.1      oki  *
     28  1.1      oki  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29  1.1      oki  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30  1.1      oki  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31  1.1      oki  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32  1.1      oki  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33  1.1      oki  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34  1.1      oki  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35  1.1      oki  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36  1.1      oki  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37  1.1      oki  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38  1.1      oki  * SUCH DAMAGE.
     39  1.1      oki  *
     40  1.1      oki  *	@(#)kgdb_glue.c	8.2 (Berkeley) 1/12/94
     41  1.1      oki  */
     42  1.1      oki 
     43  1.1      oki /*
     44  1.1      oki  * This file must be compiled with gcc -fno-defer-pop.
     45  1.1      oki  */
     46  1.1      oki 
     47  1.4    lukem #include <sys/cdefs.h>
     48  1.5      agc __KERNEL_RCSID(0, "$NetBSD: kgdb_glue.c,v 1.5 2003/08/07 16:30:29 agc Exp $");
     49  1.4    lukem 
     50  1.3    lukem #include "opt_kgdb.h"
     51  1.3    lukem 
     52  1.1      oki #ifdef KGDB
     53  1.1      oki 
     54  1.1      oki #include <sys/param.h>
     55  1.1      oki 
     56  1.1      oki #include <machine/frame.h>
     57  1.1      oki #include <machine/reg.h>
     58  1.1      oki 
     59  1.1      oki #ifndef lint
     60  1.5      agc static char rcsid[] = "$NetBSD: kgdb_glue.c,v 1.5 2003/08/07 16:30:29 agc Exp $";
     61  1.1      oki #endif
     62  1.1      oki 
     63  1.1      oki #define KGDB_STACKSIZE 0x800
     64  1.1      oki #define KGDB_STACKWORDS (KGDB_STACKSIZE / sizeof(u_long))
     65  1.1      oki 
     66  1.1      oki u_long kgdb_stack[KGDB_STACKWORDS];
     67  1.1      oki 
     68  1.2  minoura #define getsp(v) asm("movl %%sp, %0" : "=r" (v))
     69  1.2  minoura #define setsp(v) asm("movl %0, %%sp" :: "r" (v))
     70  1.1      oki 
     71  1.1      oki static inline void
     72  1.1      oki copywords(src, dst, nbytes)
     73  1.1      oki 	register u_long *src, *dst;
     74  1.1      oki 	register u_int nbytes;
     75  1.1      oki {
     76  1.1      oki 	u_long *limit = src + (nbytes / sizeof(u_long));
     77  1.1      oki 
     78  1.1      oki 	do {
     79  1.1      oki 		*dst++ = *src++;
     80  1.1      oki 	} while (src < limit);
     81  1.1      oki 	if (nbytes & 2)
     82  1.1      oki 		*(u_short *)dst = *(u_short *)src;
     83  1.1      oki }
     84  1.1      oki 
     85  1.1      oki kgdb_trap_glue(type, frame)
     86  1.1      oki 	int type;
     87  1.1      oki 	struct frame frame;
     88  1.1      oki {
     89  1.1      oki 	u_long osp, nsp;
     90  1.1      oki 	u_int fsize, s;
     91  1.1      oki 	extern short exframesize[];
     92  1.1      oki 
     93  1.1      oki 	/*
     94  1.1      oki 	 * After a kernel mode trap, the saved sp doesn't point to the right
     95  1.1      oki 	 * place.  The correct value is the top of the frame (i.e. before the
     96  1.1      oki 	 * KGDB trap).
     97  1.1      oki 	 *
     98  1.1      oki 	 * XXX this may have to change if we implement an interrupt stack.
     99  1.1      oki 	 */
    100  1.1      oki 	fsize = sizeof(frame) - sizeof(frame.F_u) + exframesize[frame.f_format];
    101  1.1      oki 	frame.f_regs[SP] = (u_long)&frame + fsize;
    102  1.1      oki 
    103  1.1      oki 	/*
    104  1.1      oki 	 * Copy the interrupt context and frame to the new stack.
    105  1.1      oki 	 * We're throwing away trap()'s frame since we're going to do
    106  1.1      oki 	 * our own rte.
    107  1.1      oki 	 */
    108  1.1      oki 	nsp = (u_long)&kgdb_stack[KGDB_STACKWORDS] -
    109  1.1      oki 	      roundup(fsize, sizeof(u_long));
    110  1.1      oki 
    111  1.1      oki 	copywords((u_long *)&frame, (u_long *)nsp, fsize);
    112  1.1      oki 
    113  1.1      oki 	s = splhigh();
    114  1.1      oki 
    115  1.1      oki 	getsp(osp);
    116  1.1      oki 	setsp(nsp);
    117  1.1      oki 
    118  1.1      oki 	if (kgdb_trap(type, (struct frame *)nsp) == 0) {
    119  1.1      oki 		/*
    120  1.1      oki 		 * Get back on kernel stack.  This thread of control
    121  1.1      oki 		 * will return back up through trap().  If kgdb_trap()
    122  1.1      oki 		 * returns 0, it didn't handle the trap at all so
    123  1.1      oki 		 * the stack is still intact and everything will
    124  1.1      oki 		 * unwind okay from here up.
    125  1.1      oki 		 */
    126  1.1      oki 		setsp(osp);
    127  1.1      oki 		splx(s);
    128  1.1      oki 		return 0;
    129  1.1      oki 	}
    130  1.1      oki 	/*
    131  1.1      oki 	 * Copy back context, which has possibly changed.  Even the
    132  1.1      oki 	 * sp might have changed.
    133  1.1      oki 	 */
    134  1.1      oki 	osp = ((struct frame *)nsp)->f_regs[SP] - fsize;
    135  1.1      oki 	copywords((u_long *)nsp, (u_long *)osp, fsize);
    136  1.1      oki 	setsp(osp);
    137  1.1      oki 
    138  1.1      oki 	/*
    139  1.1      oki 	 * Restore the possible new context from frame, pop the
    140  1.1      oki 	 * unneeded usp (we trapped from kernel mode) and pad word,
    141  1.1      oki 	 * and return to the trapped thread.
    142  1.1      oki 	 */
    143  1.2  minoura 	asm("moveml %sp@+,#0x7FFF; addql #8,sp; rte");
    144  1.1      oki }
    145  1.1      oki 
    146  1.1      oki int kgdb_testval;
    147  1.1      oki 
    148  1.1      oki kgdb_test(i)
    149  1.1      oki 	int i;
    150  1.1      oki {
    151  1.1      oki         ++kgdb_testval;
    152  1.1      oki         return (i + 1);
    153  1.1      oki }
    154  1.1      oki #endif /* KGDB */
    155