xref: /titanic_52/usr/src/cmd/mdb/common/kmdb/kvm.h (revision ae115bc77f6fcde83175c75b4206dc2e50747966)
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
59acbbeafSnn35248  * Common Development and Distribution License (the "License").
69acbbeafSnn35248  * 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*ae115bc7Smrj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _KVM_H
277c478bd9Sstevel@tonic-gate #define	_KVM_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * The kmdb target
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
367c478bd9Sstevel@tonic-gate #include <mdb/mdb_target.h>
377c478bd9Sstevel@tonic-gate #include <kmdb/kmdb_dpi.h>
387c478bd9Sstevel@tonic-gate #include <kmdb/kvm_isadep.h>
397c478bd9Sstevel@tonic-gate #include <kmdb/kvm_cpu.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #include <sys/kobj.h>
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #ifdef __cplusplus
447c478bd9Sstevel@tonic-gate extern "C" {
457c478bd9Sstevel@tonic-gate #endif
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #define	KM_F_PRIMARY		1
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #define	KMT_TRAP_NOTENUM	-1	/* Glob for unnamed traps */
507c478bd9Sstevel@tonic-gate #define	KMT_TRAP_ALL		-2	/* Glob for all traps */
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate typedef struct kmt_module {
537c478bd9Sstevel@tonic-gate 	mdb_list_t	km_list;	/* List forward/back pointers */
547c478bd9Sstevel@tonic-gate 	char		*km_name;	/* Module name */
557c478bd9Sstevel@tonic-gate 	char		km_seen;
567c478bd9Sstevel@tonic-gate 	GElf_Ehdr	km_ehdr;
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	mdb_gelf_symtab_t *km_symtab;
597c478bd9Sstevel@tonic-gate 	Shdr		km_symtab_hdr;
607c478bd9Sstevel@tonic-gate 	Shdr		km_strtab_hdr;
617c478bd9Sstevel@tonic-gate 	const void	*km_symtab_va;
627c478bd9Sstevel@tonic-gate 	const void	*km_strtab_va;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	uintptr_t	km_text_va;
657c478bd9Sstevel@tonic-gate 	size_t		km_text_size;
667c478bd9Sstevel@tonic-gate 	uintptr_t	km_data_va;
677c478bd9Sstevel@tonic-gate 	size_t		km_data_size;
687c478bd9Sstevel@tonic-gate 	uintptr_t	km_bss_va;
697c478bd9Sstevel@tonic-gate 	size_t		km_bss_size;
707c478bd9Sstevel@tonic-gate 	const void	*km_ctf_va;
717c478bd9Sstevel@tonic-gate 	size_t		km_ctf_size;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	ctf_file_t	*km_ctfp;
747c478bd9Sstevel@tonic-gate 	struct modctl	km_modctl;
757c478bd9Sstevel@tonic-gate 	struct module	km_module;
767c478bd9Sstevel@tonic-gate 	int		km_flags;
777c478bd9Sstevel@tonic-gate } kmt_module_t;
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate typedef struct kmt_data {
807c478bd9Sstevel@tonic-gate 	const mdb_tgt_regdesc_t	*kmt_rds;	/* Register description table */
817c478bd9Sstevel@tonic-gate 	mdb_nv_t	kmt_modules;		/* Hash table of modules */
827c478bd9Sstevel@tonic-gate 	mdb_list_t	kmt_modlist;		/* List of mods in load order */
83*ae115bc7Smrj 	const char	*kmt_rtld_name;		/* Module containing krtld */
847c478bd9Sstevel@tonic-gate 	caddr_t		kmt_writemap;		/* Used to map PAs for writes */
857c478bd9Sstevel@tonic-gate 	size_t		kmt_writemapsz;		/* Size of same */
867c478bd9Sstevel@tonic-gate 	mdb_map_t	kmt_map;		/* Persistant map for callers */
877c478bd9Sstevel@tonic-gate 	ulong_t		*kmt_trapmap;
887c478bd9Sstevel@tonic-gate 	size_t		kmt_trapmax;
897c478bd9Sstevel@tonic-gate 	kmt_cpu_t	*kmt_cpu;		/* CPU-specific plugin */
907c478bd9Sstevel@tonic-gate 	int		kmt_cpu_retry;		/* Try CPU detect again? */
917c478bd9Sstevel@tonic-gate 	int		kmt_symavail;		/* Symbol resolution allowed */
927c478bd9Sstevel@tonic-gate 	uint_t		kmt_narmedbpts;		/* Number of armed brkpts */
937c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
947c478bd9Sstevel@tonic-gate 	struct {
957c478bd9Sstevel@tonic-gate 		GElf_Sym	_kmt_cmnint;
967c478bd9Sstevel@tonic-gate 		GElf_Sym	_kmt_cmntrap;
977c478bd9Sstevel@tonic-gate 		GElf_Sym	_kmt_sysenter;
989acbbeafSnn35248 		GElf_Sym	_kmt_brand_sysenter;
997c478bd9Sstevel@tonic-gate #if defined(__amd64)
1007c478bd9Sstevel@tonic-gate 		GElf_Sym	_kmt_syscall;
1019acbbeafSnn35248 		GElf_Sym	_kmt_brand_syscall;
1027c478bd9Sstevel@tonic-gate #endif
1037c478bd9Sstevel@tonic-gate 	} kmt_intrsyms;
1047c478bd9Sstevel@tonic-gate #endif
1057c478bd9Sstevel@tonic-gate } kmt_data_t;
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
1087c478bd9Sstevel@tonic-gate #define	kmt_cmnint	kmt_intrsyms._kmt_cmnint
1097c478bd9Sstevel@tonic-gate #define	kmt_cmntrap	kmt_intrsyms._kmt_cmntrap
1107c478bd9Sstevel@tonic-gate #endif
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate typedef struct kmt_defbp {
1137c478bd9Sstevel@tonic-gate 	mdb_list_t dbp_bplist;
1147c478bd9Sstevel@tonic-gate 	char *dbp_objname;
1157c478bd9Sstevel@tonic-gate 	char *dbp_symname;
1167c478bd9Sstevel@tonic-gate 	int dbp_ref;
1177c478bd9Sstevel@tonic-gate } kmt_defbp_t;
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate typedef struct kmt_brkpt {
1207c478bd9Sstevel@tonic-gate 	uintptr_t kb_addr;			/* Breakpoint address */
1217c478bd9Sstevel@tonic-gate 	mdb_instr_t kb_oinstr;			/* Replaced instruction */
1227c478bd9Sstevel@tonic-gate } kmt_brkpt_t;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate typedef struct kmt_bparg {
1257c478bd9Sstevel@tonic-gate 	uintptr_t ka_addr;			/* Explicit address */
1267c478bd9Sstevel@tonic-gate 	char *ka_symbol;			/* Symbolic name */
1277c478bd9Sstevel@tonic-gate 	kmt_defbp_t *ka_defbp;
1287c478bd9Sstevel@tonic-gate } kmt_bparg_t;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate extern void kmt_printregs(const mdb_tgt_gregset_t *gregs);
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate extern const char *kmt_def_dismode(void);
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate extern void kmt_init_isadep(mdb_tgt_t *);
1357c478bd9Sstevel@tonic-gate extern void kmt_startup_isadep(mdb_tgt_t *);
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate extern ssize_t kmt_write(mdb_tgt_t *, const void *, size_t, uintptr_t);
1387c478bd9Sstevel@tonic-gate extern ssize_t kmt_pwrite(mdb_tgt_t *, const void *, size_t, physaddr_t);
1397c478bd9Sstevel@tonic-gate extern ssize_t kmt_rw(mdb_tgt_t *, void *, size_t, uint64_t,
1407c478bd9Sstevel@tonic-gate     ssize_t (*)(void *, size_t, uint64_t));
1417c478bd9Sstevel@tonic-gate extern ssize_t kmt_writer(void *, size_t, uint64_t);
1427c478bd9Sstevel@tonic-gate extern ssize_t kmt_ioread(mdb_tgt_t *, void *, size_t, uintptr_t);
1437c478bd9Sstevel@tonic-gate extern ssize_t kmt_iowrite(mdb_tgt_t *, const void *, size_t, uintptr_t);
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate extern int kmt_step_out(mdb_tgt_t *, uintptr_t *);
1467c478bd9Sstevel@tonic-gate extern int kmt_step_branch(mdb_tgt_t *);
1477c478bd9Sstevel@tonic-gate extern int kmt_next(mdb_tgt_t *, uintptr_t *);
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate extern int kmt_stack(uintptr_t, uint_t, int, const mdb_arg_t *);
1507c478bd9Sstevel@tonic-gate extern int kmt_stackv(uintptr_t, uint_t, int, const mdb_arg_t *);
1517c478bd9Sstevel@tonic-gate extern int kmt_stackr(uintptr_t, uint_t, int, const mdb_arg_t *);
1527c478bd9Sstevel@tonic-gate extern int kmt_cpustack(uintptr_t, uint_t, int, const mdb_arg_t *, int, int);
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate extern const char *kmt_trapname(int);
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate #endif
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate #endif /* _KVM_H */
161