17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*80148899SSurya Prakki * Common Development and Distribution License (the "License"). 6*80148899SSurya Prakki * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*80148899SSurya Prakki * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h> 277c478bd9Sstevel@tonic-gate #include <sys/utsname.h> 287c478bd9Sstevel@tonic-gate #include <strings.h> 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #include <kmdb/kmdb_dpi.h> 317c478bd9Sstevel@tonic-gate #include <kmdb/kmdb_kdi.h> 327c478bd9Sstevel@tonic-gate #include <mdb/mdb_err.h> 337c478bd9Sstevel@tonic-gate #include <mdb/mdb.h> 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate static const char _mdb_version[] = KMDB_VERSION; 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate const char * 387c478bd9Sstevel@tonic-gate mdb_conf_version(void) 397c478bd9Sstevel@tonic-gate { 407c478bd9Sstevel@tonic-gate return (_mdb_version); 417c478bd9Sstevel@tonic-gate } 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate const char * 447c478bd9Sstevel@tonic-gate mdb_conf_isa(void) 457c478bd9Sstevel@tonic-gate { 467c478bd9Sstevel@tonic-gate #if defined(__sparc) 477c478bd9Sstevel@tonic-gate #if defined(__sparcv9) 487c478bd9Sstevel@tonic-gate return ("sparcv9"); 497c478bd9Sstevel@tonic-gate #else /* __sparcv9 */ 507c478bd9Sstevel@tonic-gate return ("sparc"); 517c478bd9Sstevel@tonic-gate #endif /* __sparcv9 */ 527c478bd9Sstevel@tonic-gate #elif defined(__amd64) 537c478bd9Sstevel@tonic-gate return ("amd64"); 547c478bd9Sstevel@tonic-gate #elif defined(__i386) 557c478bd9Sstevel@tonic-gate return ("i386"); 567c478bd9Sstevel@tonic-gate #else 577c478bd9Sstevel@tonic-gate #error "unknown ISA" 587c478bd9Sstevel@tonic-gate #endif 597c478bd9Sstevel@tonic-gate } 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate /* 627c478bd9Sstevel@tonic-gate * These functions are needed for path evaluation, and must be run prior to 637c478bd9Sstevel@tonic-gate * target initialization. The kmdb symbol resolution machinery hasn't been 647c478bd9Sstevel@tonic-gate * initialized at this point, so we have to rely on the kernel to look up 657c478bd9Sstevel@tonic-gate * utsname and platform for us. 667c478bd9Sstevel@tonic-gate */ 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate void 697c478bd9Sstevel@tonic-gate mdb_conf_uname(struct utsname *utsp) 707c478bd9Sstevel@tonic-gate { 717c478bd9Sstevel@tonic-gate bzero(utsp, sizeof (struct utsname)); 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate if (kmdb_dpi_get_state(NULL) == DPI_STATE_INIT) { 747c478bd9Sstevel@tonic-gate struct utsname *utsaddr; 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate /* 777c478bd9Sstevel@tonic-gate * The kernel is running during DPI initialization, so we'll ask 787c478bd9Sstevel@tonic-gate * it to do the lookup. Our own symbol resolution facilities 797c478bd9Sstevel@tonic-gate * won't be available until after the debugger starts. 807c478bd9Sstevel@tonic-gate */ 817c478bd9Sstevel@tonic-gate if ((utsaddr = (struct utsname *)kmdb_kdi_lookup_by_name("unix", 827c478bd9Sstevel@tonic-gate "utsname")) == NULL) { 837c478bd9Sstevel@tonic-gate warn("'utsname' symbol is missing from kernel\n"); 84*80148899SSurya Prakki (void) strcpy(utsp->sysname, "unknown"); 857c478bd9Sstevel@tonic-gate return; 867c478bd9Sstevel@tonic-gate } 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate bcopy(utsaddr, utsp, sizeof (struct utsname)); 897c478bd9Sstevel@tonic-gate } else 907c478bd9Sstevel@tonic-gate (void) mdb_tgt_uname(mdb.m_target, utsp); 917c478bd9Sstevel@tonic-gate } 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate const char * 947c478bd9Sstevel@tonic-gate mdb_conf_platform(void) 957c478bd9Sstevel@tonic-gate { 967c478bd9Sstevel@tonic-gate if (kmdb_dpi_get_state(NULL) == DPI_STATE_INIT) { 977c478bd9Sstevel@tonic-gate static char plat[SYS_NMLN]; 987c478bd9Sstevel@tonic-gate caddr_t plataddr; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate /* 1017c478bd9Sstevel@tonic-gate * The kernel is running during DPI initialization, so we'll ask 1027c478bd9Sstevel@tonic-gate * it to do the lookup. Our own symbol resolution facilities 1037c478bd9Sstevel@tonic-gate * won't be available until after the debugger starts. 1047c478bd9Sstevel@tonic-gate */ 1057c478bd9Sstevel@tonic-gate if ((plataddr = (caddr_t)kmdb_kdi_lookup_by_name("unix", 1067c478bd9Sstevel@tonic-gate "platform")) == NULL) { 1077c478bd9Sstevel@tonic-gate warn("conf: 'platform' symbol is missing from " 1087c478bd9Sstevel@tonic-gate "kernel\n"); 1097c478bd9Sstevel@tonic-gate return ("unknown"); 1107c478bd9Sstevel@tonic-gate } 1117c478bd9Sstevel@tonic-gate 112*80148899SSurya Prakki (void) strncpy(plat, plataddr, sizeof (plat)); 1137c478bd9Sstevel@tonic-gate plat[sizeof (plat) - 1] = '\0'; 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate return (plat); 1167c478bd9Sstevel@tonic-gate } else 1177c478bd9Sstevel@tonic-gate return (mdb_tgt_platform(mdb.m_target)); 1187c478bd9Sstevel@tonic-gate } 119