Home | History | Annotate | Line # | Download | only in x68k
kgdb_glue.c revision 1.9
      1  1.9  isaki /*	$NetBSD: kgdb_glue.c,v 1.9 2007/05/12 06:31:19 isaki 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.9  isaki __KERNEL_RCSID(0, "$NetBSD: kgdb_glue.c,v 1.9 2007/05/12 06:31:19 isaki 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.9  isaki static char rcsid[] = "$NetBSD: kgdb_glue.c,v 1.9 2007/05/12 06:31:19 isaki 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.8  perry #define getsp(v) __asm("movl %%sp, %0" : "=r" (v))
     69  1.8  perry #define setsp(v) __asm("movl %0, %%sp" :: "r" (v))
     70  1.1    oki 
     71  1.1    oki static inline void
     72  1.6    chs copywords(u_long *src, u_long *dst, u_int nbytes)
     73  1.1    oki {
     74  1.1    oki 	u_long *limit = src + (nbytes / sizeof(u_long));
     75  1.1    oki 
     76  1.1    oki 	do {
     77  1.1    oki 		*dst++ = *src++;
     78  1.1    oki 	} while (src < limit);
     79  1.1    oki 	if (nbytes & 2)
     80  1.1    oki 		*(u_short *)dst = *(u_short *)src;
     81  1.1    oki }
     82  1.1    oki 
     83  1.6    chs int
     84  1.6    chs kgdb_trap_glue(int type, struct frame frame)
     85  1.1    oki {
     86  1.1    oki 	u_long osp, nsp;
     87  1.1    oki 	u_int fsize, s;
     88  1.1    oki 	extern short exframesize[];
     89  1.1    oki 
     90  1.1    oki 	/*
     91  1.1    oki 	 * After a kernel mode trap, the saved sp doesn't point to the right
     92  1.1    oki 	 * place.  The correct value is the top of the frame (i.e. before the
     93  1.1    oki 	 * KGDB trap).
     94  1.1    oki 	 *
     95  1.1    oki 	 * XXX this may have to change if we implement an interrupt stack.
     96  1.1    oki 	 */
     97  1.1    oki 	fsize = sizeof(frame) - sizeof(frame.F_u) + exframesize[frame.f_format];
     98  1.1    oki 	frame.f_regs[SP] = (u_long)&frame + fsize;
     99  1.1    oki 
    100  1.1    oki 	/*
    101  1.1    oki 	 * Copy the interrupt context and frame to the new stack.
    102  1.1    oki 	 * We're throwing away trap()'s frame since we're going to do
    103  1.1    oki 	 * our own rte.
    104  1.1    oki 	 */
    105  1.1    oki 	nsp = (u_long)&kgdb_stack[KGDB_STACKWORDS] -
    106  1.1    oki 	      roundup(fsize, sizeof(u_long));
    107  1.1    oki 
    108  1.1    oki 	copywords((u_long *)&frame, (u_long *)nsp, fsize);
    109  1.1    oki 
    110  1.1    oki 	s = splhigh();
    111  1.1    oki 
    112  1.1    oki 	getsp(osp);
    113  1.1    oki 	setsp(nsp);
    114  1.1    oki 
    115  1.1    oki 	if (kgdb_trap(type, (struct frame *)nsp) == 0) {
    116  1.1    oki 		/*
    117  1.1    oki 		 * Get back on kernel stack.  This thread of control
    118  1.1    oki 		 * will return back up through trap().  If kgdb_trap()
    119  1.1    oki 		 * returns 0, it didn't handle the trap at all so
    120  1.1    oki 		 * the stack is still intact and everything will
    121  1.1    oki 		 * unwind okay from here up.
    122  1.1    oki 		 */
    123  1.1    oki 		setsp(osp);
    124  1.1    oki 		splx(s);
    125  1.1    oki 		return 0;
    126  1.1    oki 	}
    127  1.1    oki 	/*
    128  1.1    oki 	 * Copy back context, which has possibly changed.  Even the
    129  1.1    oki 	 * sp might have changed.
    130  1.1    oki 	 */
    131  1.1    oki 	osp = ((struct frame *)nsp)->f_regs[SP] - fsize;
    132  1.1    oki 	copywords((u_long *)nsp, (u_long *)osp, fsize);
    133  1.1    oki 	setsp(osp);
    134  1.1    oki 
    135  1.1    oki 	/*
    136  1.1    oki 	 * Restore the possible new context from frame, pop the
    137  1.1    oki 	 * unneeded usp (we trapped from kernel mode) and pad word,
    138  1.1    oki 	 * and return to the trapped thread.
    139  1.1    oki 	 */
    140  1.8  perry 	__asm("moveml %sp@+,#0x7FFF; addql #8,sp; rte");
    141  1.1    oki }
    142  1.1    oki 
    143  1.1    oki int kgdb_testval;
    144  1.1    oki 
    145  1.6    chs int
    146  1.6    chs kgdb_test(int i)
    147  1.1    oki {
    148  1.9  isaki 	++kgdb_testval;
    149  1.9  isaki 	return (i + 1);
    150  1.1    oki }
    151  1.1    oki #endif /* KGDB */
    152