[BACK]Return to kgdb_machdep.c CVS log [TXT][DIR] Up to [local] / sys / arch / sparc / sparc

Annotation of sys/arch/sparc/sparc/kgdb_machdep.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: kgdb_machdep.c,v 1.8 2005/11/13 17:50:45 fgsch Exp $ */
                      2: /*     $NetBSD: kgdb_machdep.c,v 1.1 1997/08/31 21:22:45 pk Exp $ */
                      3: /*-
                      4:  * Copyright (c) 1997 The NetBSD Foundation, Inc.
                      5:  * All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to The NetBSD Foundation
                      8:  * by Paul Kranenburg.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
                     20:  *        This product includes software developed by the NetBSD
                     21:  *        Foundation, Inc. and its contributors.
                     22:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     23:  *    contributors may be used to endorse or promote products derived
                     24:  *    from this software without specific prior written permission.
                     25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     27:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     28:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     29:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     30:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     31:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     32:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     33:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     34:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     35:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     36:  * POSSIBILITY OF SUCH DAMAGE.
                     37:  */
                     38:
                     39: /*
                     40:  * Copyright (c) 1992, 1993
                     41:  *     The Regents of the University of California.  All rights reserved.
                     42:  * Copyright (c) 1995
                     43:  *     The President and Fellows of Harvard College. All rights reserved.
                     44:  *
                     45:  * This software was developed by the Computer Systems Engineering group
                     46:  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
                     47:  * contributed to Berkeley.
                     48:  *
                     49:  * All advertising materials mentioning features or use of this software
                     50:  * must display the following acknowledgements:
                     51:  *     This product includes software developed by the University of
                     52:  *     California, Lawrence Berkeley Laboratory.
                     53:  *
                     54:  *     This product includes software developed by Harvard University.
                     55:  *
                     56:  * Redistribution and use in source and binary forms, with or without
                     57:  * modification, are permitted provided that the following conditions
                     58:  * are met:
                     59:  * 1. Redistributions of source code must retain the above copyright
                     60:  *    notice, this list of conditions and the following disclaimer.
                     61:  * 2. Redistributions in binary form must reproduce the above copyright
                     62:  *    notice, this list of conditions and the following disclaimer in the
                     63:  *    documentation and/or other materials provided with the distribution.
                     64:  * 3. Neither the name of the University nor the names of its contributors
                     65:  *    may be used to endorse or promote products derived from this software
                     66:  *    without specific prior written permission.
                     67:  *
                     68:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     69:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     70:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     71:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     72:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     73:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     74:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     75:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     76:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     77:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     78:  * SUCH DAMAGE.
                     79:  *
                     80:  *     @(#)kgdb_stub.c 8.1 (Berkeley) 6/11/93
                     81:  */
                     82:
                     83: /*
                     84:  * Machine dependent routines needed by kern/kgdb_stub.c
                     85:  */
                     86: #ifdef KGDB
                     87:
                     88: #include <sys/param.h>
                     89: #include <sys/systm.h>
                     90: #include <sys/buf.h>
                     91: #include <sys/kgdb.h>
                     92:
                     93: #include <uvm/uvm_extern.h>
                     94:
                     95: #include <machine/ctlreg.h>
                     96: #include <machine/psl.h>
                     97: #include <machine/reg.h>
                     98: #include <machine/trap.h>
                     99: #include <machine/cpu.h>
                    100:
                    101: #include <sparc/sparc/asm.h>
                    102:
                    103: #if defined(SUN4M)
                    104: #define getpte4m(va) \
                    105:        lda(((vaddr_t)va & 0xFFFFF000) | ASI_SRMMUFP_L3, ASI_SRMMUFP)
                    106: #endif
                    107:
                    108: #if defined(SUN4) || defined(SUN4C)
                    109: #define        getpte4(va)             lda(va, ASI_PTE)
                    110: #define        setpte4(va, pte)        sta(va, ASI_PTE, pte)
                    111: #endif
                    112:
                    113: static __inline void kgdb_copy(char *, char *, int);
                    114: static __inline void kgdb_zero(char *, int);
                    115:
                    116: /*
                    117:  * This little routine exists simply so that bcopy() can be debugged.
                    118:  */
                    119: static __inline void
                    120: kgdb_copy(src, dst, len)
                    121:        register char *src, *dst;
                    122:        register int len;
                    123: {
                    124:
                    125:        while (--len >= 0)
                    126:                *dst++ = *src++;
                    127: }
                    128:
                    129: /* ditto for bzero */
                    130: static __inline void
                    131: kgdb_zero(ptr, len)
                    132:        register char *ptr;
                    133:        register int len;
                    134: {
                    135:        while (--len >= 0)
                    136:                *ptr++ = (char) 0;
                    137: }
                    138:
                    139: /*
                    140:  * Translate a trap number into a unix compatible signal value.
                    141:  * (gdb only understands unix signal numbers).
                    142:  * XXX should this be done at the other end?
                    143:  */
                    144: int
                    145: kgdb_signal(type)
                    146:        int type;
                    147: {
                    148:        int sigval;
                    149:
                    150:        switch (type) {
                    151:
                    152:        case T_AST:
                    153:                sigval = SIGINT;
                    154:                break;
                    155:
                    156:        case T_TEXTFAULT:
                    157:        case T_DATAFAULT:
                    158:                sigval = SIGSEGV;
                    159:                break;
                    160:
                    161:        case T_ALIGN:
                    162:                sigval = SIGBUS;
                    163:                break;
                    164:
                    165:        case T_ILLINST:
                    166:        case T_PRIVINST:
                    167:        case T_DIV0:
                    168:                sigval = SIGILL;
                    169:                break;
                    170:
                    171:        case T_FPE:
                    172:                sigval = SIGFPE;
                    173:                break;
                    174:
                    175:        case T_BREAKPOINT:
                    176:                sigval = SIGTRAP;
                    177:                break;
                    178:
                    179:        case T_KGDB_EXEC:
                    180:                sigval = SIGIOT;
                    181:                break;
                    182:
                    183:        default:
                    184:                sigval = SIGEMT;
                    185:                break;
                    186:        }
                    187:        return (sigval);
                    188: }
                    189:
                    190: /*
                    191:  * Definitions exported from gdb (& then made prettier).
                    192:  */
                    193: #define        GDB_G0          0
                    194: #define        GDB_O0          8
                    195: #define        GDB_L0          16
                    196: #define        GDB_I0          24
                    197: #define        GDB_FP0         32
                    198: #define        GDB_Y           64
                    199: #define        GDB_PSR         65
                    200: #define        GDB_WIM         66
                    201: #define        GDB_TBR         67
                    202: #define        GDB_PC          68
                    203: #define        GDB_NPC         69
                    204: #define        GDB_FSR         70
                    205: #define        GDB_CSR         71
                    206:
                    207: #define REGISTER_BYTES         (KGDB_NUMREGS * 4)
                    208: #define REGISTER_BYTE(n)       ((n) * 4)
                    209:
                    210: /*
                    211:  * Translate the values stored in the kernel regs struct to the format
                    212:  * understood by gdb.
                    213:  */
                    214: void
                    215: kgdb_getregs(regs, gdb_regs)
                    216:        db_regs_t *regs;
                    217:        kgdb_reg_t *gdb_regs;
                    218: {
                    219:        struct trapframe *tf = &regs->db_tf;
                    220:
                    221:        /* %g0..%g7 and %o0..%o7: from trapframe */
                    222:        gdb_regs[0] = 0;
                    223:        kgdb_copy((caddr_t)&tf->tf_global[1], (caddr_t)&gdb_regs[1], 15 * 4);
                    224:
                    225:        /* %l0..%l7 and %i0..%i7: from stack */
                    226:        kgdb_copy((caddr_t)tf->tf_out[6], (caddr_t)&gdb_regs[GDB_L0], 16 * 4);
                    227:
                    228:        /* %f0..%f31 -- fake, kernel does not use FP */
                    229:        kgdb_zero((caddr_t)&gdb_regs[GDB_FP0], 32 * 4);
                    230:
                    231:        /* %y, %psr, %wim, %tbr, %pc, %npc, %fsr, %csr */
                    232:        gdb_regs[GDB_Y] = tf->tf_y;
                    233:        gdb_regs[GDB_PSR] = tf->tf_psr;
                    234:        gdb_regs[GDB_WIM] = tf->tf_global[0];   /* input only! */
                    235:        gdb_regs[GDB_TBR] = 0;                  /* fake */
                    236:        gdb_regs[GDB_PC] = tf->tf_pc;
                    237:        gdb_regs[GDB_NPC] = tf->tf_npc;
                    238:        gdb_regs[GDB_FSR] = 0;                  /* fake */
                    239:        gdb_regs[GDB_CSR] = 0;                  /* fake */
                    240: }
                    241:
                    242: /*
                    243:  * Reverse the above.
                    244:  */
                    245: void
                    246: kgdb_setregs(regs, gdb_regs)
                    247:        db_regs_t *regs;
                    248:        kgdb_reg_t *gdb_regs;
                    249: {
                    250:        struct trapframe *tf = &regs->db_tf;
                    251:
                    252:        kgdb_copy((caddr_t)&gdb_regs[1], (caddr_t)&tf->tf_global[1], 15 * 4);
                    253:        kgdb_copy((caddr_t)&gdb_regs[GDB_L0], (caddr_t)tf->tf_out[6], 16 * 4);
                    254:        tf->tf_y = gdb_regs[GDB_Y];
                    255:        tf->tf_psr = gdb_regs[GDB_PSR];
                    256:        tf->tf_pc = gdb_regs[GDB_PC];
                    257:        tf->tf_npc = gdb_regs[GDB_NPC];
                    258: }
                    259:
                    260: /*
                    261:  * Determine if memory at [va..(va+len)] is valid.
                    262:  */
                    263: int
                    264: kgdb_acc(vaddr_t va, size_t len)
                    265: {
                    266:        int pte;
                    267:        vaddr_t eva;
                    268:
                    269:        eva = round_page(va + len);
                    270:        va = trunc_page(va);
                    271:
                    272:        /* XXX icky: valid address but causes timeout */
                    273:        if (va >= (vaddr_t)0xfffff000)
                    274:                return (0);
                    275:
                    276:        for (; va < eva; va += NBPG) {
                    277: #if defined(SUN4M)
                    278:                if (CPU_ISSUN4M) {
                    279:                        pte = getpte4m(va);
                    280:                        if ((pte & SRMMU_TETYPE) != SRMMU_TEPTE)
                    281:                                return (0);
                    282:                }
                    283: #endif
                    284: #if defined(SUN4) || defined(SUN4C)
                    285:                if (CPU_ISSUN4C || CPU_ISSUN4) {
                    286:                        pte = getpte4(va);
                    287:                        if ((pte & PG_V) == 0)
                    288:                                return (0);
                    289:                }
                    290: #endif
                    291:        }
                    292:
                    293:        return (1);
                    294: }
                    295: #endif

CVSweb