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
5*3446Smrj * Common Development and Distribution License (the "License").
6*3446Smrj * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*3446Smrj * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate * Intel-specific portions of the DPI
300Sstevel@tonic-gate */
310Sstevel@tonic-gate
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <sys/trap.h>
340Sstevel@tonic-gate
350Sstevel@tonic-gate #include <kmdb/kmdb_dpi_impl.h>
360Sstevel@tonic-gate #include <kmdb/kmdb_fault.h>
370Sstevel@tonic-gate #include <kmdb/kmdb_kdi.h>
380Sstevel@tonic-gate #include <mdb/mdb_err.h>
390Sstevel@tonic-gate #include <mdb/mdb_debug.h>
400Sstevel@tonic-gate #include <mdb/mdb_kreg.h>
410Sstevel@tonic-gate #include <mdb/mdb.h>
420Sstevel@tonic-gate
430Sstevel@tonic-gate void
kmdb_dpi_handle_fault(kreg_t trapno,kreg_t pc,kreg_t sp,int cpuid)440Sstevel@tonic-gate kmdb_dpi_handle_fault(kreg_t trapno, kreg_t pc, kreg_t sp, int cpuid)
450Sstevel@tonic-gate {
460Sstevel@tonic-gate kmdb_kdi_system_claim();
470Sstevel@tonic-gate
480Sstevel@tonic-gate mdb_dprintf(MDB_DBG_DPI, "\ndpi_handle_fault: trapno %u, pc 0x%0?p, "
490Sstevel@tonic-gate "sp 0x%0?p\n", (int)trapno, pc, sp);
500Sstevel@tonic-gate
510Sstevel@tonic-gate switch (trapno) {
520Sstevel@tonic-gate case T_GPFLT:
530Sstevel@tonic-gate errno = EACCES;
540Sstevel@tonic-gate default:
550Sstevel@tonic-gate errno = EMDB_NOMAP;
560Sstevel@tonic-gate }
570Sstevel@tonic-gate
580Sstevel@tonic-gate if (kmdb_dpi_fault_pcb != NULL) {
590Sstevel@tonic-gate longjmp(*kmdb_dpi_fault_pcb, 1);
600Sstevel@tonic-gate /*NOTREACHED*/
610Sstevel@tonic-gate }
620Sstevel@tonic-gate
630Sstevel@tonic-gate /* Debugger fault */
640Sstevel@tonic-gate kmdb_fault(trapno, pc, sp, cpuid);
650Sstevel@tonic-gate }
660Sstevel@tonic-gate
670Sstevel@tonic-gate /*ARGSUSED*/
680Sstevel@tonic-gate int
kmdb_dpi_get_register(const char * regname,kreg_t * kregp)690Sstevel@tonic-gate kmdb_dpi_get_register(const char *regname, kreg_t *kregp)
700Sstevel@tonic-gate {
711234Sjohnlev return (mdb.m_dpi->dpo_get_register(regname, kregp));
720Sstevel@tonic-gate }
730Sstevel@tonic-gate
740Sstevel@tonic-gate /*ARGSUSED*/
750Sstevel@tonic-gate int
kmdb_dpi_set_register(const char * regname,kreg_t kreg)760Sstevel@tonic-gate kmdb_dpi_set_register(const char *regname, kreg_t kreg)
770Sstevel@tonic-gate {
781234Sjohnlev return (mdb.m_dpi->dpo_set_register(regname, kreg));
790Sstevel@tonic-gate }
800Sstevel@tonic-gate
810Sstevel@tonic-gate /*
820Sstevel@tonic-gate * Continue/resume handling. If the target calls kmdb_dpi_resume(), it
830Sstevel@tonic-gate * expects that the world will be resumed, and that the call will return
840Sstevel@tonic-gate * when the world has stopped again.
850Sstevel@tonic-gate *
860Sstevel@tonic-gate * For support, we have resume_return(), which is called from main() when
870Sstevel@tonic-gate * the continuation has completed (when the world has stopped again).
880Sstevel@tonic-gate * set_resume_exit() tells where to jump to actually restart the world.
890Sstevel@tonic-gate *
900Sstevel@tonic-gate * CAUTION: This routine may be called *after* mdb_destroy.
910Sstevel@tonic-gate */
920Sstevel@tonic-gate void
kmdb_dpi_resume_common(int cmd)930Sstevel@tonic-gate kmdb_dpi_resume_common(int cmd)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate kreg_t pc, trapno;
960Sstevel@tonic-gate
970Sstevel@tonic-gate ASSERT(kmdb_dpi_resume_requested == 0);
980Sstevel@tonic-gate
990Sstevel@tonic-gate if (setjmp(kmdb_dpi_resume_pcb) == 0) {
1000Sstevel@tonic-gate (void) kmdb_dpi_get_register("pc", &pc);
1010Sstevel@tonic-gate mdb_dprintf(MDB_DBG_PROC, "Resume requested, pc is %p\n",
1020Sstevel@tonic-gate (void *)pc);
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate if (cmd != KMDB_DPI_CMD_RESUME_UNLOAD)
1050Sstevel@tonic-gate kmdb_dpi_resume_requested = 1;
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate longjmp(kmdb_dpi_entry_pcb, cmd);
1080Sstevel@tonic-gate /*NOTREACHED*/
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate } else {
1110Sstevel@tonic-gate (void) kmdb_dpi_get_register("pc", &pc);
1120Sstevel@tonic-gate (void) kmdb_dpi_get_register("trapno", &trapno);
1130Sstevel@tonic-gate mdb_dprintf(MDB_DBG_PROC, "Back from resume, pc: %p, "
1140Sstevel@tonic-gate "trapno: %u\n", (void *)pc, (int)trapno);
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate kmdb_dpi_resume_requested = 0;
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate switch (trapno) {
1190Sstevel@tonic-gate case T_BPTFLT:
1200Sstevel@tonic-gate kmdb_dpi_set_state(DPI_STATE_FAULTED,
1210Sstevel@tonic-gate DPI_STATE_WHY_BKPT);
1220Sstevel@tonic-gate break;
1230Sstevel@tonic-gate case T_DBGENTR:
1240Sstevel@tonic-gate kmdb_dpi_set_state(DPI_STATE_STOPPED, 0);
1250Sstevel@tonic-gate break;
1260Sstevel@tonic-gate default:
1270Sstevel@tonic-gate kmdb_dpi_set_state(DPI_STATE_FAULTED,
1280Sstevel@tonic-gate DPI_STATE_WHY_TRAP);
1290Sstevel@tonic-gate break;
1300Sstevel@tonic-gate }
1310Sstevel@tonic-gate }
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate mdb_dprintf(MDB_DBG_PROC, "returning from resume\n");
1340Sstevel@tonic-gate }
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate void
kmdb_dpi_reboot(void)1370Sstevel@tonic-gate kmdb_dpi_reboot(void)
1380Sstevel@tonic-gate {
1390Sstevel@tonic-gate /*
1400Sstevel@tonic-gate * We're going to skip all of the niceties we employ in resume_common,
1410Sstevel@tonic-gate * as we don't plan to ever return.
1420Sstevel@tonic-gate */
1430Sstevel@tonic-gate longjmp(kmdb_dpi_entry_pcb, KMDB_DPI_CMD_REBOOT);
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate
1460Sstevel@tonic-gate void
kmdb_dpi_msr_add(const kdi_msr_t * msrs)147*3446Smrj kmdb_dpi_msr_add(const kdi_msr_t *msrs)
1480Sstevel@tonic-gate {
1490Sstevel@tonic-gate mdb.m_dpi->dpo_msr_add(msrs);
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate uint64_t
kmdb_dpi_msr_get(uint_t msr)1530Sstevel@tonic-gate kmdb_dpi_msr_get(uint_t msr)
1540Sstevel@tonic-gate {
1550Sstevel@tonic-gate return (mdb.m_dpi->dpo_msr_get(DPI_MASTER_CPUID, msr));
1560Sstevel@tonic-gate }
1570Sstevel@tonic-gate
1580Sstevel@tonic-gate uint64_t
kmdb_dpi_msr_get_by_cpu(int cpuid,uint_t msr)1590Sstevel@tonic-gate kmdb_dpi_msr_get_by_cpu(int cpuid, uint_t msr)
1600Sstevel@tonic-gate {
1610Sstevel@tonic-gate return (mdb.m_dpi->dpo_msr_get(cpuid, msr));
1620Sstevel@tonic-gate }
163