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