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 (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * Copyright 2018 Joyent, Inc.
  26  */
  27 
  28 /*
  29  * Libkvm Kernel Target SPARC v7 component
  30  *
  31  * This file provides the ISA-dependent portion of the libkvm kernel target.
  32  * For more details on the implementation refer to mdb_kvm.c.
  33  */
  34 
  35 #include <sys/types.h>
  36 #include <sys/machtypes.h>
  37 #include <sys/regset.h>
  38 #include <sys/frame.h>
  39 #include <sys/stack.h>
  40 #include <sys/sysmacros.h>
  41 #include <sys/panic.h>
  42 #include <strings.h>
  43 
  44 #include <mdb/mdb_target_impl.h>
  45 #include <mdb/mdb_disasm.h>
  46 #include <mdb/mdb_modapi.h>
  47 #include <mdb/mdb_conf.h>
  48 #include <mdb/mdb_kreg.h>
  49 #include <mdb/mdb_kvm.h>
  50 #include <mdb/mdb_err.h>
  51 #include <mdb/mdb_debug.h>
  52 #include <mdb/mdb.h>
  53 
  54 /*
  55  * The mdb_tgt_gregset type is opaque to callers of the target interface
  56  * and to our own target common code.  We now can define it explicitly.
  57  */
  58 struct mdb_tgt_gregset {
  59         kreg_t kregs[KREG_NGREG];
  60 };
  61 
  62 /*
  63  * We also define an array of register names and their corresponding
  64  * array indices.  This is used by the getareg and putareg entry points,
  65  * and also by our register variable discipline.
  66  */
  67 static const mdb_tgt_regdesc_t kt_sparcv7_regs[] = {
  68         { "g0", KREG_G0, MDB_TGT_R_EXPORT },
  69         { "g1", KREG_G1, MDB_TGT_R_EXPORT },
  70         { "g2", KREG_G2, MDB_TGT_R_EXPORT },
  71         { "g3", KREG_G3, MDB_TGT_R_EXPORT },
  72         { "g4", KREG_G4, MDB_TGT_R_EXPORT },
  73         { "g5", KREG_G5, MDB_TGT_R_EXPORT },
  74         { "g6", KREG_G6, MDB_TGT_R_EXPORT },
  75         { "g7", KREG_G7, MDB_TGT_R_EXPORT },
  76         { "o0", KREG_O0, MDB_TGT_R_EXPORT },
  77         { "o1", KREG_O1, MDB_TGT_R_EXPORT },
  78         { "o2", KREG_O2, MDB_TGT_R_EXPORT },
  79         { "o3", KREG_O3, MDB_TGT_R_EXPORT },
  80         { "o4", KREG_O4, MDB_TGT_R_EXPORT },
  81         { "o5", KREG_O5, MDB_TGT_R_EXPORT },
  82         { "o6", KREG_O6, MDB_TGT_R_EXPORT },
  83         { "o7", KREG_O7, MDB_TGT_R_EXPORT },
  84         { "l0", KREG_L0, MDB_TGT_R_EXPORT },
  85         { "l1", KREG_L1, MDB_TGT_R_EXPORT },
  86         { "l2", KREG_L2, MDB_TGT_R_EXPORT },
  87         { "l3", KREG_L3, MDB_TGT_R_EXPORT },
  88         { "l4", KREG_L4, MDB_TGT_R_EXPORT },
  89         { "l5", KREG_L5, MDB_TGT_R_EXPORT },
  90         { "l6", KREG_L6, MDB_TGT_R_EXPORT },
  91         { "l7", KREG_L7, MDB_TGT_R_EXPORT },
  92         { "i0", KREG_I0, MDB_TGT_R_EXPORT },
  93         { "i1", KREG_I1, MDB_TGT_R_EXPORT },
  94         { "i2", KREG_I2, MDB_TGT_R_EXPORT },
  95         { "i3", KREG_I3, MDB_TGT_R_EXPORT },
  96         { "i4", KREG_I4, MDB_TGT_R_EXPORT },
  97         { "i5", KREG_I5, MDB_TGT_R_EXPORT },
  98         { "i6", KREG_I6, MDB_TGT_R_EXPORT },
  99         { "i7", KREG_I7, MDB_TGT_R_EXPORT },
 100         { "psr", KREG_PSR, MDB_TGT_R_EXPORT },
 101         { "pc", KREG_PC, MDB_TGT_R_EXPORT },
 102         { "npc", KREG_NPC, MDB_TGT_R_EXPORT },
 103         { "y", KREG_Y, 0 },
 104         { "wim", KREG_WIM, MDB_TGT_R_EXPORT | MDB_TGT_R_PRIV },
 105         { "tbr", KREG_TBR, MDB_TGT_R_EXPORT | MDB_TGT_R_PRIV },
 106         { "sp", KREG_SP, MDB_TGT_R_EXPORT | MDB_TGT_R_ALIAS },
 107         { "fp", KREG_FP, MDB_TGT_R_EXPORT | MDB_TGT_R_ALIAS },
 108         { NULL, 0, 0 }
 109 };
 110 
 111 static int
 112 kt_getareg(mdb_tgt_t *t, mdb_tgt_tid_t tid,
 113     const char *rname, mdb_tgt_reg_t *rp)
 114 {
 115         const mdb_tgt_regdesc_t *rdp;
 116         kt_data_t *kt = t->t_data;
 117 
 118         if (tid != kt->k_tid)
 119                 return (set_errno(EMDB_NOREGS));
 120 
 121         for (rdp = kt->k_rds; rdp->rd_name != NULL; rdp++) {
 122                 if (strcmp(rname, rdp->rd_name) == 0) {
 123                         *rp = kt->k_regs->kregs[rdp->rd_num];
 124                         return (0);
 125                 }
 126         }
 127 
 128         return (set_errno(EMDB_BADREG));
 129 }
 130 
 131 static int
 132 kt_putareg(mdb_tgt_t *t, mdb_tgt_tid_t tid, const char *rname, mdb_tgt_reg_t r)
 133 {
 134         const mdb_tgt_regdesc_t *rdp;
 135         kt_data_t *kt = t->t_data;
 136 
 137         if (tid != kt->k_tid)
 138                 return (set_errno(EMDB_NOREGS));
 139 
 140         for (rdp = kt->k_rds; rdp->rd_name != NULL; rdp++) {
 141                 if (strcmp(rname, rdp->rd_name) == 0) {
 142                         kt->k_regs->kregs[rdp->rd_num] = r;
 143                         return (0);
 144                 }
 145         }
 146 
 147         return (set_errno(EMDB_BADREG));
 148 }
 149 
 150 static int
 151 kt_stack_iter(mdb_tgt_t *t, const mdb_tgt_gregset_t *gsp,
 152     mdb_tgt_stack_f *func, void *arg)
 153 {
 154         mdb_tgt_gregset_t gregs;
 155         kreg_t *kregs = &gregs.kregs[0];
 156         int got_pc = (gsp->kregs[KREG_PC] != 0);
 157 
 158         struct rwindow rwin;
 159         uintptr_t sp;
 160         long argv[6];
 161         int i;
 162 
 163         bcopy(gsp, &gregs, sizeof (gregs));
 164 
 165         for (;;) {
 166                 for (i = 0; i < 6; i++)
 167                         argv[i] = kregs[KREG_I0 + i];
 168 
 169                 if (got_pc && func(arg, kregs[KREG_PC], 6, argv, &gregs) != 0)
 170                         break;
 171 
 172                 kregs[KREG_PC] = kregs[KREG_I7];
 173                 kregs[KREG_NPC] = kregs[KREG_PC] + 4;
 174 
 175                 bcopy(&kregs[KREG_I0], &kregs[KREG_O0], 8 * sizeof (kreg_t));
 176                 got_pc |= (kregs[KREG_PC] != 0);
 177 
 178                 if ((sp = kregs[KREG_FP]) == 0)
 179                         break; /* Stop if we're at the end of the stack */
 180 
 181                 if (sp & (STACK_ALIGN - 1))
 182                         return (set_errno(EMDB_STKALIGN));
 183 
 184                 if (mdb_tgt_vread(t, &rwin, sizeof (rwin), sp) != sizeof (rwin))
 185                         return (-1); /* Failed to read frame */
 186 
 187                 for (i = 0; i < 8; i++)
 188                         kregs[KREG_L0 + i] = (uintptr_t)rwin.rw_local[i];
 189                 for (i = 0; i < 8; i++)
 190                         kregs[KREG_I0 + i] = (uintptr_t)rwin.rw_in[i];
 191         }
 192 
 193         return (0);
 194 }
 195 
 196 /*ARGSUSED*/
 197 static int
 198 kt_regs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
 199 {
 200         mdb_tgt_gregset_t *k_regs = (mdb_tgt_gregset_t *)addr;
 201         const kreg_t *kregs = &k_regs->kregs[0];
 202 
 203         if (argc != 0 || (flags & DCMD_ADDRSPEC))
 204                 return (DCMD_USAGE);
 205 
 206 #define GETREG2(x) ((uintptr_t)kregs[(x)]), ((uintptr_t)kregs[(x)])
 207 
 208         mdb_printf("%%g0 = 0x%0?p %15A %%l0 = 0x%0?p %A\n",
 209             GETREG2(KREG_G0), GETREG2(KREG_L0));
 210 
 211         mdb_printf("%%g1 = 0x%0?p %15A %%l1 = 0x%0?p %A\n",
 212             GETREG2(KREG_G1), GETREG2(KREG_L1));
 213 
 214         mdb_printf("%%g2 = 0x%0?p %15A %%l2 = 0x%0?p %A\n",
 215             GETREG2(KREG_G2), GETREG2(KREG_L2));
 216 
 217         mdb_printf("%%g3 = 0x%0?p %15A %%l3 = 0x%0?p %A\n",
 218             GETREG2(KREG_G3), GETREG2(KREG_L3));
 219 
 220         mdb_printf("%%g4 = 0x%0?p %15A %%l4 = 0x%0?p %A\n",
 221             GETREG2(KREG_G4), GETREG2(KREG_L4));
 222 
 223         mdb_printf("%%g5 = 0x%0?p %15A %%l5 = 0x%0?p %A\n",
 224             GETREG2(KREG_G5), GETREG2(KREG_L5));
 225 
 226         mdb_printf("%%g6 = 0x%0?p %15A %%l6 = 0x%0?p %A\n",
 227             GETREG2(KREG_G6), GETREG2(KREG_L6));
 228 
 229         mdb_printf("%%g7 = 0x%0?p %15A %%l7 = 0x%0?p %A\n\n",
 230             GETREG2(KREG_G7), GETREG2(KREG_L7));
 231 
 232         mdb_printf("%%o0 = 0x%0?p %15A %%i0 = 0x%0?p %A\n",
 233             GETREG2(KREG_O0), GETREG2(KREG_I0));
 234 
 235         mdb_printf("%%o1 = 0x%0?p %15A %%i1 = 0x%0?p %A\n",
 236             GETREG2(KREG_O1), GETREG2(KREG_I1));
 237 
 238         mdb_printf("%%o2 = 0x%0?p %15A %%i2 = 0x%0?p %A\n",
 239             GETREG2(KREG_O2), GETREG2(KREG_I2));
 240 
 241         mdb_printf("%%o3 = 0x%0?p %15A %%i3 = 0x%0?p %A\n",
 242             GETREG2(KREG_O3), GETREG2(KREG_I3));
 243 
 244         mdb_printf("%%o4 = 0x%0?p %15A %%i4 = 0x%0?p %A\n",
 245             GETREG2(KREG_O4), GETREG2(KREG_I4));
 246 
 247         mdb_printf("%%o5 = 0x%0?p %15A %%i5 = 0x%0?p %A\n",
 248             GETREG2(KREG_O5), GETREG2(KREG_I5));
 249 
 250         mdb_printf("%%o6 = 0x%0?p %15A %%i6 = 0x%0?p %A\n",
 251             GETREG2(KREG_O6), GETREG2(KREG_I6));
 252 
 253         mdb_printf("%%o7 = 0x%0?p %15A %%i7 = 0x%0?p %A\n\n",
 254             GETREG2(KREG_O7), GETREG2(KREG_I7));
 255 
 256         mdb_printf(" %%psr = 0x%08x impl=0x%x ver=0x%x icc=%c%c%c%c\n"
 257             "                   ec=%u ef=%u pil=%u s=%u ps=%u et=%u cwp=0x%x\n",
 258             kregs[KREG_PSR],
 259             (kregs[KREG_PSR] & KREG_PSR_IMPL_MASK) >> KREG_PSR_IMPL_SHIFT,
 260             (kregs[KREG_PSR] & KREG_PSR_VER_MASK) >> KREG_PSR_VER_SHIFT,
 261             (kregs[KREG_PSR] & KREG_PSR_ICC_N_MASK) ? 'N' : 'n',
 262             (kregs[KREG_PSR] & KREG_PSR_ICC_Z_MASK) ? 'Z' : 'z',
 263             (kregs[KREG_PSR] & KREG_PSR_ICC_V_MASK) ? 'V' : 'v',
 264             (kregs[KREG_PSR] & KREG_PSR_ICC_C_MASK) ? 'C' : 'c',
 265             kregs[KREG_PSR] & KREG_PSR_EC_MASK,
 266             kregs[KREG_PSR] & KREG_PSR_EF_MASK,
 267             (kregs[KREG_PSR] & KREG_PSR_PIL_MASK) >> KREG_PSR_PIL_SHIFT,
 268             kregs[KREG_PSR] & KREG_PSR_S_MASK,
 269             kregs[KREG_PSR] & KREG_PSR_PS_MASK,
 270             kregs[KREG_PSR] & KREG_PSR_ET_MASK,
 271             (kregs[KREG_PSR] & KREG_PSR_CWP_MASK) >> KREG_PSR_CWP_SHIFT);
 272 
 273         mdb_printf("   %%y = 0x%0?p\n", kregs[KREG_Y]);
 274 
 275         mdb_printf("  %%pc = 0x%0?p %A\n", GETREG2(KREG_PC));
 276         mdb_printf(" %%npc = 0x%0?p %A\n", GETREG2(KREG_NPC));
 277 
 278         mdb_printf("  %%sp = 0x%0?p\n", kregs[KREG_SP]);
 279         mdb_printf("  %%fp = 0x%0?p\n\n", kregs[KREG_FP]);
 280 
 281         mdb_printf(" %%wim = 0x%08lx\n", kregs[KREG_WIM]);
 282         mdb_printf(" %%tbr = 0x%08lx\n", kregs[KREG_TBR]);
 283 
 284         return (DCMD_OK);
 285 }
 286 
 287 /*ARGSUSED*/
 288 static int
 289 kt_frame(void *arglim, uintptr_t pc, uint_t argc, const long *argv,
 290     const mdb_tgt_gregset_t *gregs)
 291 {
 292         argc = MIN(argc, (uint_t)arglim);
 293         mdb_printf("%a(", pc);
 294 
 295         if (argc != 0) {
 296                 mdb_printf("%lr", *argv++);
 297                 for (argc--; argc != 0; argc--)
 298                         mdb_printf(", %lr", *argv++);
 299         }
 300 
 301         mdb_printf(")\n");
 302         return (0);
 303 }
 304 
 305 static int
 306 kt_framev(void *arglim, uintptr_t pc, uint_t argc, const long *argv,
 307     const mdb_tgt_gregset_t *gregs)
 308 {
 309         argc = MIN(argc, (uint_t)arglim);
 310         mdb_printf("%0?lr %a(", gregs->kregs[KREG_SP], pc);
 311 
 312         if (argc != 0) {
 313                 mdb_printf("%lr", *argv++);
 314                 for (argc--; argc != 0; argc--)
 315                         mdb_printf(", %lr", *argv++);
 316         }
 317 
 318         mdb_printf(")\n");
 319         return (0);
 320 }
 321 
 322 static int
 323 kt_stack_common(uintptr_t addr, uint_t flags, int argc,
 324     const mdb_arg_t *argv, mdb_tgt_stack_f *func)
 325 {
 326         kt_data_t *kt = mdb.m_target->t_data;
 327         void *arg = (void *)mdb.m_nargs;
 328         mdb_tgt_gregset_t gregs, *grp;
 329 
 330         if (flags & DCMD_ADDRSPEC) {
 331                 bzero(&gregs, sizeof (gregs));
 332                 gregs.kregs[KREG_FP] = addr;
 333                 grp = &gregs;
 334         } else
 335                 grp = kt->k_regs;
 336 
 337         if (argc != 0) {
 338                 if (argv->a_type == MDB_TYPE_CHAR || argc > 1)
 339                         return (DCMD_USAGE);
 340 
 341                 if (argv->a_type == MDB_TYPE_STRING)
 342                         arg = (void *)(uint_t)mdb_strtoull(argv->a_un.a_str);
 343                 else
 344                         arg = (void *)(uint_t)argv->a_un.a_val;
 345         }
 346 
 347         (void) kt_stack_iter(mdb.m_target, grp, func, arg);
 348         return (DCMD_OK);
 349 }
 350 
 351 static int
 352 kt_stack(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
 353 {
 354         return (kt_stack_common(addr, flags, argc, argv, kt_frame));
 355 }
 356 
 357 static int
 358 kt_stackv(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
 359 {
 360         return (kt_stack_common(addr, flags, argc, argv, kt_framev));
 361 }
 362 
 363 /*ARGSUSED*/
 364 static int
 365 kt_notsup(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
 366 {
 367         errno = EMDB_TGTNOTSUP;
 368         return (DCMD_ERR);
 369 }
 370 
 371 const mdb_tgt_ops_t kt_sparcv7_ops = {
 372         kt_setflags,                            /* t_setflags */
 373         kt_setcontext,                          /* t_setcontext */
 374         kt_activate,                            /* t_activate */
 375         kt_deactivate,                          /* t_deactivate */
 376         (void (*)()) mdb_tgt_nop,               /* t_periodic */
 377         kt_destroy,                             /* t_destroy */
 378         kt_name,                                /* t_name */
 379         (const char *(*)()) mdb_conf_isa,       /* t_isa */
 380         kt_platform,                            /* t_platform */
 381         kt_uname,                               /* t_uname */
 382         kt_dmodel,                              /* t_dmodel */
 383         kt_aread,                               /* t_aread */
 384         kt_awrite,                              /* t_awrite */
 385         kt_vread,                               /* t_vread */
 386         kt_vwrite,                              /* t_vwrite */
 387         kt_pread,                               /* t_pread */
 388         kt_pwrite,                              /* t_pwrite */
 389         kt_fread,                               /* t_fread */
 390         kt_fwrite,                              /* t_fwrite */
 391         (ssize_t (*)()) mdb_tgt_notsup,         /* t_ioread */
 392         (ssize_t (*)()) mdb_tgt_notsup,         /* t_iowrite */
 393         kt_vtop,                                /* t_vtop */
 394         kt_lookup_by_name,                      /* t_lookup_by_name */
 395         kt_lookup_by_addr,                      /* t_lookup_by_addr */
 396         kt_symbol_iter,                         /* t_symbol_iter */
 397         kt_mapping_iter,                        /* t_mapping_iter */
 398         kt_object_iter,                         /* t_object_iter */
 399         kt_addr_to_map,                         /* t_addr_to_map */
 400         kt_name_to_map,                         /* t_name_to_map */
 401         kt_addr_to_ctf,                         /* t_addr_to_ctf */
 402         kt_name_to_ctf,                         /* t_name_to_ctf */
 403         kt_status,                              /* t_status */
 404         (int (*)()) mdb_tgt_notsup,             /* t_run */
 405         (int (*)()) mdb_tgt_notsup,             /* t_step */
 406         (int (*)()) mdb_tgt_notsup,             /* t_step_out */
 407         (int (*)()) mdb_tgt_notsup,             /* t_next */
 408         (int (*)()) mdb_tgt_notsup,             /* t_cont */
 409         (int (*)()) mdb_tgt_notsup,             /* t_signal */
 410         (int (*)()) mdb_tgt_null,               /* t_add_vbrkpt */
 411         (int (*)()) mdb_tgt_null,               /* t_add_sbrkpt */
 412         (int (*)()) mdb_tgt_null,               /* t_add_pwapt */
 413         (int (*)()) mdb_tgt_null,               /* t_add_vwapt */
 414         (int (*)()) mdb_tgt_null,               /* t_add_iowapt */
 415         (int (*)()) mdb_tgt_null,               /* t_add_sysenter */
 416         (int (*)()) mdb_tgt_null,               /* t_add_sysexit */
 417         (int (*)()) mdb_tgt_null,               /* t_add_signal */
 418         (int (*)()) mdb_tgt_null,               /* t_add_fault */
 419         kt_getareg,                             /* t_getareg */
 420         kt_putareg,                             /* t_putareg */
 421         kt_stack_iter,                          /* t_stack_iter */
 422         (int (*)()) mdb_tgt_notsup              /* t_auxv */
 423 };
 424 
 425 void
 426 kt_sparcv7_init(mdb_tgt_t *t)
 427 {
 428         kt_data_t *kt = t->t_data;
 429 
 430         struct rwindow rwin;
 431         panic_data_t pd;
 432         label_t label;
 433         kreg_t *kregs;
 434 
 435         /*
 436          * Initialize the machine-dependent parts of the kernel target
 437          * structure.  Once this is complete and we fill in the ops
 438          * vector, the target is now fully constructed and we can use
 439          * the target API itself to perform the rest of our initialization.
 440          */
 441         kt->k_rds = kt_sparcv7_regs;
 442         kt->k_regs = mdb_zalloc(sizeof (mdb_tgt_gregset_t), UM_SLEEP);
 443         kt->k_regsize = sizeof (mdb_tgt_gregset_t);
 444         kt->k_dcmd_regs = kt_regs;
 445         kt->k_dcmd_stack = kt_stack;
 446         kt->k_dcmd_stackv = kt_stackv;
 447         kt->k_dcmd_stackr = kt_stackv;
 448         kt->k_dcmd_cpustack = kt_notsup;
 449         kt->k_dcmd_cpuregs = kt_notsup;
 450 
 451         t->t_ops = &kt_sparcv7_ops;
 452         kregs = kt->k_regs->kregs;
 453 
 454         (void) mdb_dis_select("v8");
 455 
 456         /*
 457          * Don't attempt to load any thread or register information if
 458          * we're examining the live operating system.
 459          */
 460         if (strcmp(kt->k_symfile, "/dev/ksyms") == 0)
 461                 return;
 462 
 463         /*
 464          * If the panicbuf symbol is present and we can consume a panicbuf
 465          * header of the appropriate version from this address, then
 466          * we can initialize our current register set based on its contents:
 467          */
 468         if (mdb_tgt_readsym(t, MDB_TGT_AS_VIRT, &pd, sizeof (pd),
 469             MDB_TGT_OBJ_EXEC, "panicbuf") == sizeof (pd) &&
 470             pd.pd_version == PANICBUFVERS) {
 471 
 472                 size_t pd_size = MIN(PANICBUFSIZE, pd.pd_msgoff);
 473                 panic_data_t *pdp = mdb_zalloc(pd_size, UM_SLEEP);
 474                 uint_t i, n;
 475 
 476                 (void) mdb_tgt_readsym(t, MDB_TGT_AS_VIRT, pdp, pd_size,
 477                     MDB_TGT_OBJ_EXEC, "panicbuf");
 478 
 479                 n = (pd_size - (sizeof (panic_data_t) -
 480                     sizeof (panic_nv_t))) / sizeof (panic_nv_t);
 481 
 482                 for (i = 0; i < n; i++) {
 483                         (void) kt_putareg(t, kt->k_tid,
 484                             pdp->pd_nvdata[i].pnv_name,
 485                             pdp->pd_nvdata[i].pnv_value);
 486                 }
 487 
 488                 mdb_free(pdp, pd_size);
 489         }
 490 
 491         /*
 492          * Prior to the re-structuring of panicbuf, our only register data
 493          * was the panic_regs label_t, into which a setjmp() was performed.
 494          */
 495         if (kregs[KREG_PC] == 0 && kregs[KREG_SP] == 0 &&
 496             mdb_tgt_readsym(t, MDB_TGT_AS_VIRT, &label, sizeof (label),
 497             MDB_TGT_OBJ_EXEC, "panic_regs") == sizeof (label)) {
 498 
 499                 kregs[KREG_PC] = label.val[0];
 500                 kregs[KREG_SP] = label.val[1];
 501         }
 502 
 503         /*
 504          * If we can read a saved register window from the stack at %sp,
 505          * we can also fill in the locals and inputs.
 506          */
 507         if (kregs[KREG_SP] != 0 && mdb_tgt_vread(t, &rwin, sizeof (rwin),
 508             kregs[KREG_SP]) == sizeof (rwin)) {
 509 
 510                 kregs[KREG_L0] = rwin.rw_local[0];
 511                 kregs[KREG_L1] = rwin.rw_local[1];
 512                 kregs[KREG_L2] = rwin.rw_local[2];
 513                 kregs[KREG_L3] = rwin.rw_local[3];
 514                 kregs[KREG_L4] = rwin.rw_local[4];
 515                 kregs[KREG_L5] = rwin.rw_local[5];
 516                 kregs[KREG_L6] = rwin.rw_local[6];
 517                 kregs[KREG_L7] = rwin.rw_local[7];
 518 
 519                 kregs[KREG_I0] = rwin.rw_in[0];
 520                 kregs[KREG_I1] = rwin.rw_in[1];
 521                 kregs[KREG_I2] = rwin.rw_in[2];
 522                 kregs[KREG_I3] = rwin.rw_in[3];
 523                 kregs[KREG_I4] = rwin.rw_in[4];
 524                 kregs[KREG_I5] = rwin.rw_in[5];
 525                 kregs[KREG_I6] = rwin.rw_in[6];
 526                 kregs[KREG_I7] = rwin.rw_in[7];
 527 
 528         } else if (kregs[KREG_SP] != 0) {
 529                 warn("failed to read rwindow at %p -- current "
 530                     "frame inputs will be unavailable\n",
 531                     (void *)kregs[KREG_SP]);
 532         }
 533 }