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