]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/db_machdep.h
xnu-792.25.20.tar.gz
[apple/xnu.git] / osfmk / i386 / db_machdep.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 /*
51 */
52
53 #ifndef _I386_DB_MACHDEP_H_
54 #define _I386_DB_MACHDEP_H_
55
56 /*
57 * Machine-dependent defines for new kernel debugger.
58 */
59
60 #include <kern/kern_types.h>
61 #include <mach/i386/vm_types.h>
62 #include <mach/i386/vm_param.h>
63 #include <i386/thread.h> /* for thread_status */
64 #include <i386/eflags.h>
65 #include <i386/trap.h>
66 #include <i386/pmCPU.h>
67 #include <i386/hpet.h>
68
69 typedef addr64_t db_addr_t; /* address - unsigned */
70 typedef uint64_t db_expr_t; /* expression */
71
72 typedef struct x86_saved_state32 db_regs_t;
73 db_regs_t ddb_regs; /* register state */
74 #define DDB_REGS (&ddb_regs)
75 extern int db_active; /* ddb is active */
76
77 #define PC_REGS(regs) ((db_addr_t)(regs)->eip)
78
79 #define BKPT_INST 0xcc /* breakpoint instruction */
80 #define BKPT_SIZE (1) /* size of breakpoint inst */
81 #define BKPT_SET(inst) (BKPT_INST)
82
83 #define FIXUP_PC_AFTER_BREAK ddb_regs.eip -= 1;
84
85 #define db_clear_single_step(regs) ((regs)->efl &= ~EFL_TF)
86 #define db_set_single_step(regs) ((regs)->efl |= EFL_TF)
87
88 #define IS_BREAKPOINT_TRAP(type, code) ((type) == T_INT3)
89 #define IS_WATCHPOINT_TRAP(type, code) ((type) == T_WATCHPOINT)
90
91 #define I_CALL 0xe8
92 #define I_CALLI 0xff
93 #define I_RET 0xc3
94 #define I_IRET 0xcf
95
96 #define inst_trap_return(ins) (((ins)&0xff) == I_IRET)
97 #define inst_return(ins) (((ins)&0xff) == I_RET)
98 #define inst_call(ins) (((ins)&0xff) == I_CALL || \
99 (((ins)&0xff) == I_CALLI && \
100 ((ins)&0x3800) == 0x1000))
101
102 int db_inst_load(unsigned long);
103 int db_inst_store(unsigned long);
104
105 /* access capability and access macros */
106
107 #define DB_ACCESS_LEVEL 2 /* access any space */
108 #define DB_CHECK_ACCESS(addr,size,task) \
109 db_check_access(addr,size,task)
110 #define DB_PHYS_EQ(task1,addr1,task2,addr2) \
111 db_phys_eq(task1,addr1,task2,addr2)
112 #define DB_VALID_KERN_ADDR(addr) (1)
113 #define DB_VALID_ADDRESS(addr,user) \
114 ((!(user) && DB_VALID_KERN_ADDR(addr)) || \
115 ((user) && (addr) < VM_MAX_ADDRESS))
116
117 /*
118 * Given pointer to i386_saved_state, determine if it represents
119 * a thread executing in user space.
120 */
121 #define IS_USER_TRAP(regs, etext) (((regs)->cs & 3) != 0)
122
123 extern boolean_t db_check_access(
124 vm_offset_t addr,
125 int size,
126 task_t task);
127 extern boolean_t db_phys_eq(
128 task_t task1,
129 vm_offset_t addr1,
130 task_t task2,
131 vm_offset_t addr2);
132 extern db_addr_t db_disasm(
133 db_addr_t loc,
134 boolean_t altfmt,
135 task_t task);
136 extern void db_read_bytes(
137 vm_offset_t addr,
138 int size,
139 char *data,
140 task_t task);
141 extern void db_write_bytes(
142 vm_offset_t addr,
143 int size,
144 char *data,
145 task_t task);
146 extern void db_stack_trace_cmd(
147 db_expr_t addr,
148 boolean_t have_addr,
149 db_expr_t count,
150 char *modif);
151 extern void db_reboot(
152 db_expr_t addr,
153 boolean_t have_addr,
154 db_expr_t count,
155 char *modif);
156
157 extern void db_display_kmod(db_expr_t addr, int have_addr, db_expr_t count, char * modif);
158 extern void db_display_real(db_expr_t addr, int have_addr, db_expr_t count, char * modif);
159 extern void db_display_iokit(db_expr_t addr, int have_addr, db_expr_t count, char * modif);
160 extern void db_cpuid(db_expr_t addr, int have_addr, db_expr_t count, char * modif);
161 extern void db_msr(db_expr_t addr, int have_addr, db_expr_t count, char * modif);
162 extern void db_apic(db_expr_t addr, int have_addr, db_expr_t count, char * modif);
163 extern void db_test(db_expr_t addr, int have_addr, db_expr_t count, char * modif);
164 extern void db_intcnt(db_expr_t addr, int have_addr, db_expr_t count, char * modif);
165 extern void db_display_hpet(hpetReg_t *hpt);
166 extern void db_hpet(db_expr_t addr, int have_addr, db_expr_t count, char * modif);
167 extern void db_cfg(db_expr_t addr, int have_addr, db_expr_t count, char * modif);
168 extern void db_dtimers(db_expr_t addr, int have_addr, db_expr_t count, char * modif);
169
170 /* macros for printing OS server dependent task name */
171
172 #define DB_TASK_NAME(task) db_task_name(task)
173 #define DB_TASK_NAME_TITLE "COMMAND "
174 #define DB_TASK_NAME_LEN 23
175 #define DB_NULL_TASK_NAME "? "
176
177 extern void db_task_name(
178 task_t task);
179
180 /* macro for checking if a thread has used floating-point */
181
182 #define db_act_fp_used(act) (act && act->machine.pcb->ifps)
183
184 extern void db_tss_to_frame(
185 int tss_sel,
186 x86_saved_state32_t *regs);
187 extern int kdb_trap(
188 int type,
189 int code,
190 x86_saved_state32_t *regs);
191 extern boolean_t db_trap_from_asm(
192 x86_saved_state32_t *regs);
193 extern int dr6(void);
194 extern void kdb_on(
195 int cpu);
196
197 #if MACH_KDB
198 extern void db_getpmgr(pmData_t *pmj);
199 extern void db_chkpmgr(void);
200 #endif /* MACH_KDB */
201 extern void db_pmgr(db_expr_t addr, int have_addr, db_expr_t count, char * modif);
202 extern void db_nap(db_expr_t addr, int have_addr, db_expr_t count, char * modif);
203
204 #endif /* _I386_DB_MACHDEP_H_ */