10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
220Sstevel@tonic-gate /*
23*1234Sjohnlev * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate * SPARC-specific portions of the DPI
310Sstevel@tonic-gate */
320Sstevel@tonic-gate
330Sstevel@tonic-gate #include <sys/types.h>
340Sstevel@tonic-gate #include <sys/mmu.h>
350Sstevel@tonic-gate #include <sys/trap.h>
360Sstevel@tonic-gate #include <sys/machtrap.h>
370Sstevel@tonic-gate
380Sstevel@tonic-gate #include <kmdb/kmdb_dpi_impl.h>
390Sstevel@tonic-gate #include <kmdb/kmdb_asmutil.h>
400Sstevel@tonic-gate #include <kmdb/kmdb_promif.h>
410Sstevel@tonic-gate #include <kmdb/kmdb_fault.h>
420Sstevel@tonic-gate #include <mdb/mdb_err.h>
430Sstevel@tonic-gate #include <mdb/mdb_debug.h>
440Sstevel@tonic-gate #include <mdb/mdb_kreg.h>
450Sstevel@tonic-gate #include <mdb/mdb.h>
460Sstevel@tonic-gate
470Sstevel@tonic-gate void
kmdb_dpi_handle_fault(kreg_t tt,kreg_t tpc,kreg_t tnpc,kreg_t sp,int cpuid)480Sstevel@tonic-gate kmdb_dpi_handle_fault(kreg_t tt, kreg_t tpc, kreg_t tnpc, kreg_t sp, int cpuid)
490Sstevel@tonic-gate {
500Sstevel@tonic-gate mdb_dprintf(MDB_DBG_DPI, "\ndpi_handle_fault: tt 0x%01lx, tpc 0x%0?p, "
510Sstevel@tonic-gate "tnpc 0x%0?p, sp 0x%0?p, fault_pcb 0x%0?p\n", tt, tpc, tnpc, sp,
520Sstevel@tonic-gate kmdb_dpi_fault_pcb);
530Sstevel@tonic-gate
540Sstevel@tonic-gate switch (tt) {
550Sstevel@tonic-gate case FAST_PROT_TT:
560Sstevel@tonic-gate errno = EACCES;
570Sstevel@tonic-gate break;
580Sstevel@tonic-gate case T_DATA_ERROR:
590Sstevel@tonic-gate errno = EIO;
600Sstevel@tonic-gate break;
610Sstevel@tonic-gate #ifdef sun4v
620Sstevel@tonic-gate case T_DATA_MMU_MISS:
630Sstevel@tonic-gate #endif /* sun4v */
640Sstevel@tonic-gate case FAST_DMMU_MISS_TT:
650Sstevel@tonic-gate default:
660Sstevel@tonic-gate errno = EMDB_NOMAP;
670Sstevel@tonic-gate }
680Sstevel@tonic-gate
690Sstevel@tonic-gate if (kmdb_dpi_fault_pcb != NULL) {
700Sstevel@tonic-gate longjmp(*kmdb_dpi_fault_pcb, 1);
710Sstevel@tonic-gate /*NOTREACHED*/
720Sstevel@tonic-gate }
730Sstevel@tonic-gate
740Sstevel@tonic-gate /* Debugger fault */
750Sstevel@tonic-gate kmdb_fault(tt, tpc, sp, cpuid);
760Sstevel@tonic-gate }
770Sstevel@tonic-gate
780Sstevel@tonic-gate int
kmdb_dpi_get_register(const char * regname,kreg_t * kregp)790Sstevel@tonic-gate kmdb_dpi_get_register(const char *regname, kreg_t *kregp)
800Sstevel@tonic-gate {
81*1234Sjohnlev return (mdb.m_dpi->dpo_get_register(regname, kregp));
820Sstevel@tonic-gate }
830Sstevel@tonic-gate
840Sstevel@tonic-gate int
kmdb_dpi_set_register(const char * regname,kreg_t kreg)850Sstevel@tonic-gate kmdb_dpi_set_register(const char *regname, kreg_t kreg)
860Sstevel@tonic-gate {
87*1234Sjohnlev return (mdb.m_dpi->dpo_set_register(regname, kreg));
880Sstevel@tonic-gate }
890Sstevel@tonic-gate
900Sstevel@tonic-gate int
kmdb_dpi_get_rwin(int cpuid,int win,struct rwindow * rwin)910Sstevel@tonic-gate kmdb_dpi_get_rwin(int cpuid, int win, struct rwindow *rwin)
920Sstevel@tonic-gate {
930Sstevel@tonic-gate return (mdb.m_dpi->dpo_get_rwin(cpuid, win, rwin));
940Sstevel@tonic-gate }
950Sstevel@tonic-gate
960Sstevel@tonic-gate int
kmdb_dpi_get_nwin(int cpuid)970Sstevel@tonic-gate kmdb_dpi_get_nwin(int cpuid)
980Sstevel@tonic-gate {
990Sstevel@tonic-gate return (mdb.m_dpi->dpo_get_nwin(cpuid));
1000Sstevel@tonic-gate }
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate void
kmdb_dpi_kernpanic(int cpuid)1030Sstevel@tonic-gate kmdb_dpi_kernpanic(int cpuid)
1040Sstevel@tonic-gate {
1050Sstevel@tonic-gate mdb.m_dpi->dpo_kernpanic(cpuid);
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate /*
1090Sstevel@tonic-gate * Continue/resume handling. If the target calls kmdb_dpi_resume(), it
1100Sstevel@tonic-gate * expects that the world will be resumed, and that the call will return
1110Sstevel@tonic-gate * when the world has stopped again.
1120Sstevel@tonic-gate *
1130Sstevel@tonic-gate * For support, we have resume_return(), which is called from main() when
1140Sstevel@tonic-gate * the continuation has completed (when the world has stopped again).
1150Sstevel@tonic-gate * set_resume_exit() tells where to jump to actually restart the world.
1160Sstevel@tonic-gate *
1170Sstevel@tonic-gate * CAUTION: This routine may be called *after* mdb_destroy.
1180Sstevel@tonic-gate */
1190Sstevel@tonic-gate void
kmdb_dpi_resume_common(int cmd)1200Sstevel@tonic-gate kmdb_dpi_resume_common(int cmd)
1210Sstevel@tonic-gate {
1220Sstevel@tonic-gate kreg_t pc, tt;
1230Sstevel@tonic-gate
1240Sstevel@tonic-gate ASSERT(kmdb_dpi_resume_requested == 0);
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate if (setjmp(kmdb_dpi_resume_pcb) == 0) {
1270Sstevel@tonic-gate (void) kmdb_dpi_get_register("pc", &pc);
1280Sstevel@tonic-gate mdb_dprintf(MDB_DBG_PROC, "Resume requested, pc is %p\n",
1290Sstevel@tonic-gate (void *)pc);
1300Sstevel@tonic-gate
1310Sstevel@tonic-gate if (cmd != KMDB_DPI_CMD_RESUME_UNLOAD)
1320Sstevel@tonic-gate kmdb_dpi_resume_requested = 1;
1330Sstevel@tonic-gate
1340Sstevel@tonic-gate longjmp(kmdb_dpi_entry_pcb, cmd);
1350Sstevel@tonic-gate /*NOTREACHED*/
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate } else {
1380Sstevel@tonic-gate (void) kmdb_dpi_get_register("pc", &pc);
1390Sstevel@tonic-gate (void) kmdb_dpi_get_register("tt", &tt);
1400Sstevel@tonic-gate mdb_dprintf(MDB_DBG_PROC, "Back from resume, pc: %p, tt: %lx\n",
1410Sstevel@tonic-gate (void *)pc, tt);
1420Sstevel@tonic-gate
1430Sstevel@tonic-gate kmdb_dpi_resume_requested = 0;
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate switch (tt) {
1460Sstevel@tonic-gate case T_PA_WATCHPOINT:
1470Sstevel@tonic-gate kmdb_dpi_set_state(DPI_STATE_FAULTED,
1480Sstevel@tonic-gate DPI_STATE_WHY_P_WAPT);
1490Sstevel@tonic-gate break;
1500Sstevel@tonic-gate case T_VA_WATCHPOINT:
1510Sstevel@tonic-gate kmdb_dpi_set_state(DPI_STATE_FAULTED,
1520Sstevel@tonic-gate DPI_STATE_WHY_V_WAPT);
1530Sstevel@tonic-gate break;
1540Sstevel@tonic-gate case ST_KMDB_BREAKPOINT|T_SOFTWARE_TRAP:
1550Sstevel@tonic-gate case ST_MON_BREAKPOINT|T_SOFTWARE_TRAP: /* Shouldn't happen */
1560Sstevel@tonic-gate kmdb_dpi_set_state(DPI_STATE_FAULTED,
1570Sstevel@tonic-gate DPI_STATE_WHY_BKPT);
1580Sstevel@tonic-gate break;
1590Sstevel@tonic-gate case ST_KMDB_TRAP|T_SOFTWARE_TRAP:
1600Sstevel@tonic-gate kmdb_dpi_set_state(DPI_STATE_STOPPED, 0);
1610Sstevel@tonic-gate break;
1620Sstevel@tonic-gate default:
1630Sstevel@tonic-gate kmdb_dpi_set_state(DPI_STATE_FAULTED,
1640Sstevel@tonic-gate DPI_STATE_WHY_TRAP);
1650Sstevel@tonic-gate break;
1660Sstevel@tonic-gate }
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate }
169