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, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _KVM_H 28 #define _KVM_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 /* 33 * The kmdb target 34 */ 35 36 #include <mdb/mdb_modapi.h> 37 #include <mdb/mdb_target.h> 38 #include <kmdb/kmdb_dpi.h> 39 #include <kmdb/kvm_isadep.h> 40 #include <kmdb/kvm_cpu.h> 41 42 #include <sys/kobj.h> 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 #define KM_F_PRIMARY 1 49 50 #define KMT_TRAP_NOTENUM -1 /* Glob for unnamed traps */ 51 #define KMT_TRAP_ALL -2 /* Glob for all traps */ 52 53 typedef struct kmt_module { 54 mdb_list_t km_list; /* List forward/back pointers */ 55 char *km_name; /* Module name */ 56 char km_seen; 57 GElf_Ehdr km_ehdr; 58 59 mdb_gelf_symtab_t *km_symtab; 60 Shdr km_symtab_hdr; 61 Shdr km_strtab_hdr; 62 const void *km_symtab_va; 63 const void *km_strtab_va; 64 65 uintptr_t km_text_va; 66 size_t km_text_size; 67 uintptr_t km_data_va; 68 size_t km_data_size; 69 uintptr_t km_bss_va; 70 size_t km_bss_size; 71 const void *km_ctf_va; 72 size_t km_ctf_size; 73 74 ctf_file_t *km_ctfp; 75 struct modctl km_modctl; 76 struct module km_module; 77 int km_flags; 78 } kmt_module_t; 79 80 typedef struct kmt_data { 81 const mdb_tgt_regdesc_t *kmt_rds; /* Register description table */ 82 mdb_nv_t kmt_modules; /* Hash table of modules */ 83 mdb_list_t kmt_modlist; /* List of mods in load order */ 84 caddr_t kmt_writemap; /* Used to map PAs for writes */ 85 size_t kmt_writemapsz; /* Size of same */ 86 mdb_map_t kmt_map; /* Persistant map for callers */ 87 ulong_t *kmt_trapmap; 88 size_t kmt_trapmax; 89 kmt_cpu_t *kmt_cpu; /* CPU-specific plugin */ 90 int kmt_cpu_retry; /* Try CPU detect again? */ 91 int kmt_symavail; /* Symbol resolution allowed */ 92 uint_t kmt_narmedbpts; /* Number of armed brkpts */ 93 #if defined(__i386) || defined(__amd64) 94 struct { 95 GElf_Sym _kmt_cmnint; 96 GElf_Sym _kmt_cmntrap; 97 GElf_Sym _kmt_sysenter; 98 #if defined(__amd64) 99 GElf_Sym _kmt_syscall; 100 #endif 101 } kmt_intrsyms; 102 #endif 103 } kmt_data_t; 104 105 #if defined(__i386) || defined(__amd64) 106 #define kmt_cmnint kmt_intrsyms._kmt_cmnint 107 #define kmt_cmntrap kmt_intrsyms._kmt_cmntrap 108 #endif 109 110 typedef struct kmt_defbp { 111 mdb_list_t dbp_bplist; 112 char *dbp_objname; 113 char *dbp_symname; 114 int dbp_ref; 115 } kmt_defbp_t; 116 117 typedef struct kmt_brkpt { 118 uintptr_t kb_addr; /* Breakpoint address */ 119 mdb_instr_t kb_oinstr; /* Replaced instruction */ 120 } kmt_brkpt_t; 121 122 typedef struct kmt_bparg { 123 uintptr_t ka_addr; /* Explicit address */ 124 char *ka_symbol; /* Symbolic name */ 125 kmt_defbp_t *ka_defbp; 126 } kmt_bparg_t; 127 128 extern void kmt_printregs(const mdb_tgt_gregset_t *gregs); 129 130 extern const char *kmt_def_dismode(void); 131 132 extern void kmt_init_isadep(mdb_tgt_t *); 133 extern void kmt_startup_isadep(mdb_tgt_t *); 134 135 extern ssize_t kmt_write(mdb_tgt_t *, const void *, size_t, uintptr_t); 136 extern ssize_t kmt_pwrite(mdb_tgt_t *, const void *, size_t, physaddr_t); 137 extern ssize_t kmt_rw(mdb_tgt_t *, void *, size_t, uint64_t, 138 ssize_t (*)(void *, size_t, uint64_t)); 139 extern ssize_t kmt_writer(void *, size_t, uint64_t); 140 extern ssize_t kmt_ioread(mdb_tgt_t *, void *, size_t, uintptr_t); 141 extern ssize_t kmt_iowrite(mdb_tgt_t *, const void *, size_t, uintptr_t); 142 143 extern int kmt_step_out(mdb_tgt_t *, uintptr_t *); 144 extern int kmt_step_branch(mdb_tgt_t *); 145 extern int kmt_next(mdb_tgt_t *, uintptr_t *); 146 147 extern int kmt_stack(uintptr_t, uint_t, int, const mdb_arg_t *); 148 extern int kmt_stackv(uintptr_t, uint_t, int, const mdb_arg_t *); 149 extern int kmt_stackr(uintptr_t, uint_t, int, const mdb_arg_t *); 150 extern int kmt_cpustack(uintptr_t, uint_t, int, const mdb_arg_t *, int, int); 151 152 extern const char *kmt_trapname(int); 153 154 #ifdef __cplusplus 155 } 156 #endif 157 158 #endif /* _KVM_H */ 159