1 /* $NetBSD: db_machdep.c,v 1.3 2011/01/22 19:35:48 skrll Exp $ */ 2 3 /*- 4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Nick Hudson 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.3 2011/01/22 19:35:48 skrll Exp $"); 34 35 #include <sys/param.h> 36 #include <sys/lwp.h> 37 38 #include <machine/db_machdep.h> 39 40 #include <ddb/db_command.h> 41 #include <ddb/db_output.h> 42 43 const struct db_command db_machine_command_table[] = { 44 { DDB_ADD_CMD("frame", db_dump_trap, 0, 45 "Displays the contents of a trapframe", 46 "[/u] [addr]", 47 " addr:\tdisplay this trap frame (current kernel frame otherwise)\n" 48 " /u:\tdisplay the current userland trap frame") }, 49 { DDB_ADD_CMD(NULL, NULL, 0, NULL, NULL, NULL) } 50 }; 51 52 void 53 db_dump_trap(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif) 54 { 55 struct trapframe *tf; 56 const char *cp = modif; 57 bool lwpaddr = false; 58 char c; 59 60 tf = DDB_REGS; 61 while ((c = *cp++) != 0) { 62 if (c == 'l') 63 lwpaddr = true; 64 } 65 66 /* Or an arbitrary trapframe */ 67 if (have_addr) { 68 if (lwpaddr) { 69 struct lwp *l; 70 71 l = (struct lwp *)addr; 72 tf = (struct trapframe *)l->l_md.md_regs; 73 } else { 74 tf = (struct trapframe *)addr; 75 } 76 } 77 78 db_printf("General registers\n"); 79 db_printf("r00-03 %08x %08x %08x %08x\n", 80 0, tf->tf_r1, tf->tf_rp, tf->tf_r3); 81 db_printf("r04-07 %08x %08x %08x %08x\n", 82 tf->tf_r4, tf->tf_r5, tf->tf_r6, tf->tf_r7); 83 db_printf("r08-11 %08x %08x %08x %08x\n", 84 tf->tf_r8, tf->tf_r9, tf->tf_r10, tf->tf_r11); 85 db_printf("r12-15 %08x %08x %08x %08x\n", 86 tf->tf_r12, tf->tf_r13, tf->tf_r14, tf->tf_r15); 87 db_printf("r16-19 %08x %08x %08x %08x\n", 88 tf->tf_r16, tf->tf_r17, tf->tf_r18, tf->tf_t4); 89 db_printf("r20-23 %08x %08x %08x %08x\n", 90 tf->tf_t3, tf->tf_t2, tf->tf_t1, tf->tf_arg3); 91 db_printf("r24-27 %08x %08x %08x %08x\n", 92 tf->tf_arg2, tf->tf_arg1, tf->tf_arg0, tf->tf_dp); 93 db_printf("r28-31 %08x %08x %08x %08x\n", 94 tf->tf_ret0, tf->tf_ret1, tf->tf_sp, tf->tf_r31); 95 db_printf("\n"); 96 db_printf("Space registers\n"); 97 db_printf("s00-03 %08x %08x %08x %08x\n", 98 tf->tf_sr0, tf->tf_sr1, tf->tf_sr2, tf->tf_sr3); 99 db_printf("s04-07 %08x %08x %08x %08x\n", 100 tf->tf_sr4, tf->tf_sr5, tf->tf_sr6, tf->tf_sr7); 101 db_printf("\n"); 102 db_printf("Instruction queues\n"); 103 db_printf("iisq: %08x %08x\niioq: %08x %08x\n", 104 tf->tf_iisq_head, tf->tf_iisq_tail, tf->tf_iioq_head, 105 tf->tf_iioq_tail); 106 db_printf("\n"); 107 db_printf("Interrupt state\n"); 108 db_printf("isr: %08x\nior: %08x\niir: %08x\n", 109 tf->tf_isr, tf->tf_ior, tf->tf_iir); 110 db_printf("\n"); 111 db_printf("Other state\n"); 112 db_printf("eiem: %08x\n", tf->tf_eiem); 113 db_printf("ipsw: %08x\n", tf->tf_ipsw); 114 db_printf("flags: %08x\n", tf->tf_flags); 115 db_printf("sar: %08x\n", tf->tf_sar); 116 db_printf("pidr1: %08x\n", tf->tf_pidr1); /* cr8 */ 117 db_printf("pidr2: %08x\n", tf->tf_pidr2); /* cr9 */ 118 #if pbably_not_worth_it 119 db_printf("pidr3: %08x\n", tf->tf_pidr3); /* cr12 */ 120 db_printf("pidr4: %08x\n", tf->tf_pidr4); /* cr13 */ 121 #endif 122 db_printf("rctr: %08x\n", tf->tf_rctr); /* cr0 */ 123 db_printf("ccr: %08x\n", tf->tf_ccr); /* cr10 */ 124 db_printf("eirr: %08x\n", tf->tf_eirr); /* cr23 - DDB */ 125 db_printf("cr24: %08x\n", tf->tf_cr24); /* cr24 - DDB */ 126 db_printf("vtop: %08x\n", tf->tf_vtop); /* cr25 - DDB */ 127 db_printf("cr27: %08x\n", tf->tf_cr27); /* - DDB */ 128 db_printf("cr28: %08x\n", tf->tf_cr28); /* - DDB */ 129 db_printf("cr30: %08x\n", tf->tf_cr30); /* uaddr */ 130 } 131