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

Annotation of sys/arch/m68k/m68k/regdump.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: regdump.c,v 1.6 2006/06/11 20:48:13 miod Exp $        */
                      2: /*     $NetBSD: regdump.c,v 1.1 1997/04/09 19:21:47 thorpej Exp $      */
                      3:
                      4: /*
                      5:  * Copyright (c) 1988 University of Utah.
                      6:  * Copyright (c) 1982, 1986, 1990, 1993
                      7:  *     The Regents of the University of California.  All rights reserved.
                      8:  *
                      9:  * This code is derived from software contributed to Berkeley by
                     10:  * the Systems Programming Group of the University of Utah Computer
                     11:  * Science Department.
                     12:  *
                     13:  * Redistribution and use in source and binary forms, with or without
                     14:  * modification, are permitted provided that the following conditions
                     15:  * are met:
                     16:  * 1. Redistributions of source code must retain the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer.
                     18:  * 2. Redistributions in binary form must reproduce the above copyright
                     19:  *    notice, this list of conditions and the following disclaimer in the
                     20:  *    documentation and/or other materials provided with the distribution.
                     21:  * 3. Neither the name of the University nor the names of its contributors
                     22:  *    may be used to endorse or promote products derived from this software
                     23:  *    without specific prior written permission.
                     24:  *
                     25:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     26:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     27:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     28:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     29:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     30:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     31:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     32:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     33:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     34:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     35:  * SUCH DAMAGE.
                     36:  *
                     37:  *     from: Utah Hdr: machdep.c 1.74 92/12/20
                     38:  *     from: @(#)machdep.c     8.10 (Berkeley) 4/20/94
                     39:  */
                     40:
                     41: #include <sys/param.h>
                     42: #include <sys/systm.h>
                     43: #include <sys/proc.h>
                     44:
                     45: #include <machine/cpu.h>
                     46: #include <machine/frame.h>
                     47: #include <machine/reg.h>
                     48: #include <machine/psl.h>
                     49:
                     50: void dumpmem(int *, int, int);
                     51: char *hexstr(int, int);
                     52:
                     53: /*
                     54:  * Print a register and stack dump.
                     55:  */
                     56: void
                     57: regdump(tf, sbytes)
                     58:        struct trapframe *tf; /* must not be register */
                     59:        int sbytes;
                     60: {
                     61:        static int doingdump = 0;
                     62:        register int i;
                     63:        int s;
                     64:
                     65:        if (doingdump)
                     66:                return;
                     67:        s = splhigh();
                     68:        doingdump = 1;
                     69:        printf("pid = %d, pc = %s, ",
                     70:            curproc ? curproc->p_pid : -1, hexstr(tf->tf_pc, 8));
                     71:        printf("ps = %s, ", hexstr(tf->tf_sr, 4));
                     72:        printf("sfc = %s, ", hexstr(getsfc(), 4));
                     73:        printf("dfc = %s\n", hexstr(getdfc(), 4));
                     74:        printf("Registers:\n     ");
                     75:        for (i = 0; i < 8; i++)
                     76:                printf("        %d", i);
                     77:        printf("\ndreg:");
                     78:        for (i = 0; i < 8; i++)
                     79:                printf(" %s", hexstr(tf->tf_regs[i], 8));
                     80:        printf("\nareg:");
                     81:        for (i = 0; i < 8; i++)
                     82:                printf(" %s", hexstr(tf->tf_regs[i+8], 8));
                     83:        if (sbytes > 0) {
                     84:                if (tf->tf_sr & PSL_S) {
                     85:                        printf("\n\nKernel stack (%s):",
                     86:                            hexstr((int)(((int *)&tf)-1), 8));
                     87:                        dumpmem(((int *)&tf)-1, sbytes, 0);
                     88:                } else {
                     89:                        printf("\n\nUser stack (%s):",
                     90:                            hexstr(tf->tf_regs[SP], 8));
                     91:                        dumpmem((int *)tf->tf_regs[SP], sbytes, 1);
                     92:                }
                     93:        }
                     94:        doingdump = 0;
                     95:        splx(s);
                     96: }
                     97:
                     98: void
                     99: dumpmem(ptr, sz, ustack)
                    100:        int *ptr;
                    101:        int sz, ustack;
                    102: {
                    103:        int i, val;
                    104:        int limit;
                    105:
                    106:        /* Stay in the same page */
                    107:        limit = ((int)ptr) | (NBPG-3);
                    108:
                    109:        for (i = 0; i < sz; i++) {
                    110:                if ((i & 7) == 0)
                    111:                        printf("\n%s: ", hexstr((int)ptr, 6));
                    112:                else
                    113:                        printf(" ");
                    114:                if (ustack == 1) {
                    115:                        if (copyin(ptr++, &val, sizeof(int)) != 0)
                    116:                                break;
                    117:                } else {
                    118:                        if (((int) ptr) >= limit)
                    119:                                break;
                    120:                        val = *ptr++;
                    121:                }
                    122:                printf("%s", hexstr(val, 8));
                    123:        }
                    124:        printf("\n");
                    125: }
                    126:
                    127: char *
                    128: hexstr(val, len)
                    129:        register int val;
                    130:        int len;
                    131: {
                    132:        static char nbuf[9];
                    133:        register int x, i;
                    134:
                    135:        if (len > 8)
                    136:                return("");
                    137:        nbuf[len] = '\0';
                    138:        for (i = len-1; i >= 0; --i) {
                    139:                x = val & 0xF;
                    140:                /* Isn't this a cool trick? */
                    141:                nbuf[i] = "0123456789ABCDEF"[x];
                    142:                val >>= 4;
                    143:        }
                    144:        return(nbuf);
                    145: }

CVSweb