1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 /* 30 * SPARC-specific portions of the DPI 31 */ 32 33 #include <sys/types.h> 34 #include <sys/mmu.h> 35 #include <sys/trap.h> 36 #include <sys/machtrap.h> 37 38 #include <kmdb/kmdb_dpi_impl.h> 39 #include <kmdb/kmdb_asmutil.h> 40 #include <kmdb/kmdb_promif.h> 41 #include <kmdb/kmdb_fault.h> 42 #include <mdb/mdb_err.h> 43 #include <mdb/mdb_debug.h> 44 #include <mdb/mdb_kreg.h> 45 #include <mdb/mdb.h> 46 47 void 48 kmdb_dpi_handle_fault(kreg_t tt, kreg_t tpc, kreg_t tnpc, kreg_t sp, int cpuid) 49 { 50 mdb_dprintf(MDB_DBG_DPI, "\ndpi_handle_fault: tt 0x%01lx, tpc 0x%0?p, " 51 "tnpc 0x%0?p, sp 0x%0?p, fault_pcb 0x%0?p\n", tt, tpc, tnpc, sp, 52 kmdb_dpi_fault_pcb); 53 54 switch (tt) { 55 case FAST_PROT_TT: 56 errno = EACCES; 57 break; 58 case T_DATA_ERROR: 59 errno = EIO; 60 break; 61 #ifdef sun4v 62 case T_DATA_MMU_MISS: 63 #endif /* sun4v */ 64 case FAST_DMMU_MISS_TT: 65 default: 66 errno = EMDB_NOMAP; 67 } 68 69 if (kmdb_dpi_fault_pcb != NULL) { 70 longjmp(*kmdb_dpi_fault_pcb, 1); 71 /*NOTREACHED*/ 72 } 73 74 /* Debugger fault */ 75 kmdb_fault(tt, tpc, sp, cpuid); 76 } 77 78 int 79 kmdb_dpi_get_register(const char *regname, kreg_t *kregp) 80 { 81 return (mdb.m_dpi->dpo_get_register(regname, kregp)); 82 } 83 84 int 85 kmdb_dpi_set_register(const char *regname, kreg_t kreg) 86 { 87 return (mdb.m_dpi->dpo_set_register(regname, kreg)); 88 } 89 90 int 91 kmdb_dpi_get_rwin(int cpuid, int win, struct rwindow *rwin) 92 { 93 return (mdb.m_dpi->dpo_get_rwin(cpuid, win, rwin)); 94 } 95 96 int 97 kmdb_dpi_get_nwin(int cpuid) 98 { 99 return (mdb.m_dpi->dpo_get_nwin(cpuid)); 100 } 101 102 void 103 kmdb_dpi_kernpanic(int cpuid) 104 { 105 mdb.m_dpi->dpo_kernpanic(cpuid); 106 } 107 108 /* 109 * Continue/resume handling. If the target calls kmdb_dpi_resume(), it 110 * expects that the world will be resumed, and that the call will return 111 * when the world has stopped again. 112 * 113 * For support, we have resume_return(), which is called from main() when 114 * the continuation has completed (when the world has stopped again). 115 * set_resume_exit() tells where to jump to actually restart the world. 116 * 117 * CAUTION: This routine may be called *after* mdb_destroy. 118 */ 119 void 120 kmdb_dpi_resume_common(int cmd) 121 { 122 kreg_t pc, tt; 123 124 ASSERT(kmdb_dpi_resume_requested == 0); 125 126 if (setjmp(kmdb_dpi_resume_pcb) == 0) { 127 (void) kmdb_dpi_get_register("pc", &pc); 128 mdb_dprintf(MDB_DBG_PROC, "Resume requested, pc is %p\n", 129 (void *)pc); 130 131 if (cmd != KMDB_DPI_CMD_RESUME_UNLOAD) 132 kmdb_dpi_resume_requested = 1; 133 134 longjmp(kmdb_dpi_entry_pcb, cmd); 135 /*NOTREACHED*/ 136 137 } else { 138 (void) kmdb_dpi_get_register("pc", &pc); 139 (void) kmdb_dpi_get_register("tt", &tt); 140 mdb_dprintf(MDB_DBG_PROC, "Back from resume, pc: %p, tt: %lx\n", 141 (void *)pc, tt); 142 143 kmdb_dpi_resume_requested = 0; 144 145 switch (tt) { 146 case T_PA_WATCHPOINT: 147 kmdb_dpi_set_state(DPI_STATE_FAULTED, 148 DPI_STATE_WHY_P_WAPT); 149 break; 150 case T_VA_WATCHPOINT: 151 kmdb_dpi_set_state(DPI_STATE_FAULTED, 152 DPI_STATE_WHY_V_WAPT); 153 break; 154 case ST_KMDB_BREAKPOINT|T_SOFTWARE_TRAP: 155 case ST_MON_BREAKPOINT|T_SOFTWARE_TRAP: /* Shouldn't happen */ 156 kmdb_dpi_set_state(DPI_STATE_FAULTED, 157 DPI_STATE_WHY_BKPT); 158 break; 159 case ST_KMDB_TRAP|T_SOFTWARE_TRAP: 160 kmdb_dpi_set_state(DPI_STATE_STOPPED, 0); 161 break; 162 default: 163 kmdb_dpi_set_state(DPI_STATE_FAULTED, 164 DPI_STATE_WHY_TRAP); 165 break; 166 } 167 } 168 } 169