17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
5ae115bcmrj * Common Development and Distribution License (the "License").
6ae115bcmrj * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
217c478bdstevel@tonic-gate/*
22ae115bcmrj * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bdstevel@tonic-gate * Use is subject to license terms.
247c478bdstevel@tonic-gate */
257c478bdstevel@tonic-gate
267c478bdstevel@tonic-gate#ifndef	_MDB_KVM_H
277c478bdstevel@tonic-gate#define	_MDB_KVM_H
287c478bdstevel@tonic-gate
297c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bdstevel@tonic-gate
317c478bdstevel@tonic-gate#include <sys/types.h>
327c478bdstevel@tonic-gate#include <sys/machelf.h>
337c478bdstevel@tonic-gate#include <sys/dumphdr.h>
347c478bdstevel@tonic-gate#include <libctf.h>
357c478bdstevel@tonic-gate#include <kvm.h>
367c478bdstevel@tonic-gate
377c478bdstevel@tonic-gate#include <mdb/mdb_target.h>
387c478bdstevel@tonic-gate#include <mdb/mdb_list.h>
397c478bdstevel@tonic-gate#include <mdb/mdb_gelf.h>
40843e198johnlev#include <mdb/mdb_kb.h>
417c478bdstevel@tonic-gate
427c478bdstevel@tonic-gate#ifdef	__cplusplus
437c478bdstevel@tonic-gateextern "C" {
447c478bdstevel@tonic-gate#endif
457c478bdstevel@tonic-gate
467c478bdstevel@tonic-gate#ifdef _MDB
477c478bdstevel@tonic-gate
487c478bdstevel@tonic-gatetypedef struct kt_module {
497c478bdstevel@tonic-gate	mdb_list_t km_list;		/* List forward/back pointers */
507c478bdstevel@tonic-gate	char *km_name;			/* Module name */
517c478bdstevel@tonic-gate	void *km_data;			/* Data buffer (module->symspace) */
527c478bdstevel@tonic-gate	size_t km_datasz;		/* Size of km_data in bytes */
537c478bdstevel@tonic-gate	void *km_symbuf;		/* Base of symbol table in km_data */
547c478bdstevel@tonic-gate	char *km_strtab;		/* Base of string table in km_data */
557c478bdstevel@tonic-gate	mdb_gelf_symtab_t *km_symtab;	/* Symbol table for module */
567c478bdstevel@tonic-gate	uintptr_t km_symspace_va;	/* Kernel VA of krtld symspace */
577c478bdstevel@tonic-gate	uintptr_t km_symtab_va;		/* Kernel VA of krtld symtab */
587c478bdstevel@tonic-gate	uintptr_t km_strtab_va;		/* Kernel VA of krtld strtab */
597c478bdstevel@tonic-gate	Shdr km_symtab_hdr;		/* Native .symtab section header */
607c478bdstevel@tonic-gate	Shdr km_strtab_hdr;		/* Native .strtab section header */
617c478bdstevel@tonic-gate	uintptr_t km_text_va;		/* Kernel VA of start of module text */
627c478bdstevel@tonic-gate	size_t km_text_size;		/* Size of module text */
637c478bdstevel@tonic-gate	uintptr_t km_data_va;		/* Kernel VA of start of module data */
647c478bdstevel@tonic-gate	size_t km_data_size;		/* Size of module data */
657c478bdstevel@tonic-gate	uintptr_t km_bss_va;		/* Kernel VA of start of module BSS */
667c478bdstevel@tonic-gate	size_t km_bss_size;		/* Size of module BSS */
677c478bdstevel@tonic-gate	uintptr_t km_ctf_va;		/* Kernel VA of CTF data */
687c478bdstevel@tonic-gate	size_t km_ctf_size;		/* Size of CTF data */
697c478bdstevel@tonic-gate	void *km_ctf_buf;		/* CTF data for this module */
707c478bdstevel@tonic-gate	ctf_file_t *km_ctfp;		/* CTF container for this module */
717c478bdstevel@tonic-gate} kt_module_t;
727c478bdstevel@tonic-gate
737c478bdstevel@tonic-gatetypedef struct kt_data {
74843e198johnlev	mdb_kb_ops_t *k_kb_ops;		/* KVM backend ops */
757c478bdstevel@tonic-gate	void (*k_dump_print_content)();	/* mdb_ks dump_print_content routine */
767c478bdstevel@tonic-gate	int (*k_dump_find_curproc)();	/* mdb_ks dump_find_curproc routine */
777c478bdstevel@tonic-gate	char *k_symfile;		/* Symbol table pathname */
787c478bdstevel@tonic-gate	char *k_kvmfile;		/* Core file pathname */
79843e198johnlev	int k_xpv_domu;			/* Hypervisor domain dump? */
80ae115bcmrj	const char *k_rtld_name;	/* module containing krtld */
817c478bdstevel@tonic-gate	mdb_map_t k_map;		/* Persistant map for callers */
82843e198johnlev	void *k_cookie;			/* Cookie for libkvm routines */
837c478bdstevel@tonic-gate	struct as *k_as;		/* Kernel VA of kas struct */
847c478bdstevel@tonic-gate	mdb_io_t *k_fio;		/* File i/o backend */
857c478bdstevel@tonic-gate	mdb_gelf_file_t *k_file;	/* ELF file object */
867c478bdstevel@tonic-gate	mdb_gelf_symtab_t *k_symtab;	/* Standard symbol table */
877c478bdstevel@tonic-gate	mdb_gelf_symtab_t *k_dynsym;	/* Dynamic symbol table */
887c478bdstevel@tonic-gate	mdb_nv_t k_modules;		/* Hash table of modules */
897c478bdstevel@tonic-gate	mdb_list_t k_modlist;		/* List of modules in load order */
907c478bdstevel@tonic-gate	char k_platform[MAXNAMELEN];	/* Platform string */
917c478bdstevel@tonic-gate	const mdb_tgt_regdesc_t *k_rds;	/* Register description table */
927c478bdstevel@tonic-gate	mdb_tgt_gregset_t *k_regs;	/* Representative register set */
937c478bdstevel@tonic-gate	size_t k_regsize;		/* Size of k_regs in bytes */
947c478bdstevel@tonic-gate	mdb_tgt_tid_t k_tid;		/* Pointer to representative thread */
957c478bdstevel@tonic-gate	mdb_dcmd_f *k_dcmd_regs;	/* Dcmd to print registers */
967c478bdstevel@tonic-gate	mdb_dcmd_f *k_dcmd_stack;	/* Dcmd to print stack trace */
977c478bdstevel@tonic-gate	mdb_dcmd_f *k_dcmd_stackv;	/* Dcmd to print verbose stack trace */
987c478bdstevel@tonic-gate	mdb_dcmd_f *k_dcmd_stackr;	/* Dcmd to print stack trace and regs */
99843e198johnlev	mdb_dcmd_f *k_dcmd_cpustack;	/* Dcmd to print CPU stack trace */
100843e198johnlev	mdb_dcmd_f *k_dcmd_cpuregs;	/* Dcmd to print CPU registers */
1017c478bdstevel@tonic-gate	GElf_Sym k_intr_sym;		/* Kernel locore cmnint symbol */
1027c478bdstevel@tonic-gate	GElf_Sym k_trap_sym;		/* Kernel locore cmntrap symbol */
1037c478bdstevel@tonic-gate	struct dumphdr *k_dumphdr;	/* Dump header for post-mortem */
1047c478bdstevel@tonic-gate	pid_t k_dumpcontent;		/* The pid(s) (if any) in the dump */
1057c478bdstevel@tonic-gate	int k_activated;		/* Set if kt_activate called */
1067c478bdstevel@tonic-gate	int k_ctfvalid;			/* Set if kernel has a CTF arena */
1077c478bdstevel@tonic-gate} kt_data_t;
1087c478bdstevel@tonic-gate
1097c478bdstevel@tonic-gate/* values for k_dumpcontent */
1107c478bdstevel@tonic-gate#define	KT_DUMPCONTENT_KERNEL	0
1117c478bdstevel@tonic-gate#define	KT_DUMPCONTENT_INVALID	-1
1127c478bdstevel@tonic-gate#define	KT_DUMPCONTENT_ALL	-2
1137c478bdstevel@tonic-gate
1147c478bdstevel@tonic-gateextern int kt_setflags(mdb_tgt_t *, int);
1157c478bdstevel@tonic-gateextern int kt_setcontext(mdb_tgt_t *, void *);
1167c478bdstevel@tonic-gate
1177c478bdstevel@tonic-gateextern void kt_activate(mdb_tgt_t *);
1187c478bdstevel@tonic-gateextern void kt_deactivate(mdb_tgt_t *);
1197c478bdstevel@tonic-gateextern void kt_destroy(mdb_tgt_t *);
1207c478bdstevel@tonic-gate
1217c478bdstevel@tonic-gateextern const char *kt_name(mdb_tgt_t *);
1227c478bdstevel@tonic-gateextern const char *kt_platform(mdb_tgt_t *);
1237c478bdstevel@tonic-gateextern int kt_uname(mdb_tgt_t *, struct utsname *);
1247c478bdstevel@tonic-gateextern int kt_dmodel(mdb_tgt_t *);
1257c478bdstevel@tonic-gate
1267c478bdstevel@tonic-gateextern ssize_t kt_aread(mdb_tgt_t *, mdb_tgt_as_t,
1277c478bdstevel@tonic-gate    void *, size_t, mdb_tgt_addr_t);
1287c478bdstevel@tonic-gate
1297c478bdstevel@tonic-gateextern ssize_t kt_awrite(mdb_tgt_t *, mdb_tgt_as_t,
1307c478bdstevel@tonic-gate    const void *, size_t, mdb_tgt_addr_t);
1317c478bdstevel@tonic-gate
1327c478bdstevel@tonic-gateextern ssize_t kt_vread(mdb_tgt_t *, void *, size_t, uintptr_t);
1337c478bdstevel@tonic-gateextern ssize_t kt_vwrite(mdb_tgt_t *, const void *, size_t, uintptr_t);
1347c478bdstevel@tonic-gateextern ssize_t kt_pread(mdb_tgt_t *, void *, size_t, physaddr_t);
1357c478bdstevel@tonic-gateextern ssize_t kt_pwrite(mdb_tgt_t *, const void *, size_t, physaddr_t);
1367c478bdstevel@tonic-gateextern ssize_t kt_fread(mdb_tgt_t *, void *, size_t, uintptr_t);
1377c478bdstevel@tonic-gateextern ssize_t kt_fwrite(mdb_tgt_t *, const void *, size_t, uintptr_t);
1387c478bdstevel@tonic-gate
1397c478bdstevel@tonic-gateextern int kt_vtop(mdb_tgt_t *, mdb_tgt_as_t, uintptr_t, physaddr_t *);
1407c478bdstevel@tonic-gate
1417c478bdstevel@tonic-gateextern int kt_lookup_by_name(mdb_tgt_t *, const char *,
1427c478bdstevel@tonic-gate    const char *, GElf_Sym *, mdb_syminfo_t *);
1437c478bdstevel@tonic-gate
1447c478bdstevel@tonic-gateextern int kt_lookup_by_addr(mdb_tgt_t *, uintptr_t,
1457c478bdstevel@tonic-gate    uint_t, char *, size_t, GElf_Sym *, mdb_syminfo_t *);
1467c478bdstevel@tonic-gate
1477c478bdstevel@tonic-gateextern int kt_symbol_iter(mdb_tgt_t *, const char *, uint_t,
1487c478bdstevel@tonic-gate    uint_t, mdb_tgt_sym_f *, void *);
1497c478bdstevel@tonic-gate
1507c478bdstevel@tonic-gateextern int kt_mapping_iter(mdb_tgt_t *, mdb_tgt_map_f *, void *);
1517c478bdstevel@tonic-gateextern int kt_object_iter(mdb_tgt_t *, mdb_tgt_map_f *, void *);
1527c478bdstevel@tonic-gate
1537c478bdstevel@tonic-gateextern const mdb_map_t *kt_addr_to_map(mdb_tgt_t *, uintptr_t);
1547c478bdstevel@tonic-gateextern const mdb_map_t *kt_name_to_map(mdb_tgt_t *, const char *);
1557c478bdstevel@tonic-gate
1567c478bdstevel@tonic-gateextern struct ctf_file *kt_addr_to_ctf(mdb_tgt_t *, uintptr_t);
1577c478bdstevel@tonic-gateextern struct ctf_file *kt_name_to_ctf(mdb_tgt_t *, const char *);
1587c478bdstevel@tonic-gate
1597c478bdstevel@tonic-gateextern int kt_status(mdb_tgt_t *, mdb_tgt_status_t *);
1607c478bdstevel@tonic-gate
1617c478bdstevel@tonic-gate#ifdef __sparc
1627c478bdstevel@tonic-gateextern void kt_sparcv9_init(mdb_tgt_t *);
1637c478bdstevel@tonic-gateextern void kt_sparcv7_init(mdb_tgt_t *);
1647c478bdstevel@tonic-gate#else	/* __sparc */
1657c478bdstevel@tonic-gateextern void kt_ia32_init(mdb_tgt_t *);
1667c478bdstevel@tonic-gateextern void kt_amd64_init(mdb_tgt_t *);
1677c478bdstevel@tonic-gate#endif	/* __sparc */
1687c478bdstevel@tonic-gate
169843e198johnlevtypedef int (*mdb_name_lookup_fcn_t)(const char *, GElf_Sym *);
170843e198johnlevtypedef int (*mdb_addr_lookup_fcn_t)(uintptr_t, int, char *, size_t,
171843e198johnlev    GElf_Sym *);
172843e198johnlevextern void mdb_kvm_add_name_lookup(mdb_name_lookup_fcn_t);
173843e198johnlevextern void mdb_kvm_add_addr_lookup(mdb_addr_lookup_fcn_t);
174843e198johnlev
1757c478bdstevel@tonic-gate#endif	/* _MDB */
1767c478bdstevel@tonic-gate
1777c478bdstevel@tonic-gate#ifdef	__cplusplus
1787c478bdstevel@tonic-gate}
1797c478bdstevel@tonic-gate#endif
1807c478bdstevel@tonic-gate
1817c478bdstevel@tonic-gate#endif	/* _MDB_KVM_H */
182