Annotation of sys/arch/i386/stand/libsa/debug.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: debug.c,v 1.13 2004/03/09 19:12:12 tom Exp $ */
! 2:
! 3: /*
! 4: * Copyright (c) 1997 Michael Shalayeff
! 5: * All rights reserved.
! 6: *
! 7: * Redistribution and use in source and binary forms, with or without
! 8: * modification, are permitted provided that the following conditions
! 9: * are met:
! 10: * 1. Redistributions of source code must retain the above copyright
! 11: * notice, this list of conditions and the following disclaimer.
! 12: * 2. Redistributions in binary form must reproduce the above copyright
! 13: * notice, this list of conditions and the following disclaimer in the
! 14: * documentation and/or other materials provided with the distribution.
! 15: *
! 16: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! 17: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
! 18: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 19: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 20: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 21: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 22: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 23: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 24: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 25: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 26: * SUCH DAMAGE.
! 27: *
! 28: */
! 29:
! 30: #include <lib/libsa/stand.h>
! 31: #include <debug.h>
! 32: #include <dev/cons.h>
! 33:
! 34: #define VBASE (0xb8000)
! 35:
! 36: char *const reg_names[] = { REG_NAMES };
! 37: const int nreg = NENTS(reg_names);
! 38: struct reg reg;
! 39: u_int32_t *const reg_values[] = { REG_VALUES(reg) };
! 40: char *const trap_names[] = { TRAP_NAMES };
! 41:
! 42: void d_putc(dev_t, int);
! 43:
! 44: #ifdef DEBUG_DEBUG
! 45: #define CKPT(c) (*(u_short volatile *)(VBASE+160) = (0x1700 | (c)))
! 46: #else
! 47: #define CKPT(c) /* c */
! 48: #endif
! 49:
! 50: void
! 51: debug_init(void)
! 52: {
! 53: }
! 54:
! 55:
! 56: void
! 57: dump_regs(u_int trapno, u_int arg)
! 58: {
! 59: register int i;
! 60: /* make it local, so it won't rely on .data/.bss corruption */
! 61: struct consdev d_cons, *save_cons;
! 62:
! 63: /* init cons mod */
! 64: save_cons = cn_tab;
! 65: bzero(&d_cons, sizeof(d_cons));
! 66: d_cons.cn_putc = &d_putc;
! 67: cn_tab = &d_cons;
! 68:
! 69: /* Trap info */
! 70: printf("\ftrap: %u(%x): %s\ncn_tab=%p\n",
! 71: trapno, arg, trap_names[trapno], save_cons);
! 72:
! 73: /* Register dump */
! 74: for (i = 1; i <= nreg; i++)
! 75: printf("%s\t%x%c", reg_names[i-1], *reg_values[i-1],
! 76: ((i%4)? ' ': '\n'));
! 77:
! 78: dump_mem("Code dump", (void *)*reg_values[8], 8);
! 79: /* %ebx (void *)((*reg_values[3] + 15) & ~0x0F) */
! 80: dump_mem("Memory dump", (void *)0x1a000, 48);
! 81: dump_mem("Stack trace", (void *)(*reg_values[4]), 48);
! 82:
! 83: /* restore the console */
! 84: cn_tab = save_cons;
! 85: }
! 86:
! 87: void
! 88: dump_mem(char *l, void *p, size_t n)
! 89: {
! 90: register int i;
! 91:
! 92: printf("%s [%p]:%s", l, p, (n > 6? "\n":" "));
! 93: for (i = 1; i <= n; i++)
! 94: printf("%x%c", *(u_int32_t *)p++, ((i%8)? ' ': '\n'));
! 95: if (n % 8)
! 96: printf("\n");
! 97: }
! 98:
! 99:
! 100: u_int d_pos;
! 101:
! 102: void
! 103: d_putc(dev_t d, int c)
! 104: {
! 105: switch (c) {
! 106: case '\n': d_pos += 80; break;
! 107: case '\r': d_pos -= d_pos % 80; break;
! 108: case '\b': d_pos--; break;
! 109: case '\f': bzero((void *)VBASE, 80*25*2); d_pos = 0; break;
! 110: /* print it */
! 111: default:
! 112: ((u_int16_t volatile *)VBASE)[d_pos++] = 0x0700 | (u_char)c;
! 113: break;
! 114: }
! 115: }
CVSweb