]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/db_machdep.h
xnu-792.17.14.tar.gz
[apple/xnu.git] / osfmk / i386 / db_machdep.h
CommitLineData
1c79356b 1/*
8f6c56a5 2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
8f6c56a5
A
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
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
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#include <i386/thread.h> /* for thread_status */
70#include <i386/eflags.h>
71#include <i386/trap.h>
72
8f6c56a5
A
73typedef vm_offset_t db_addr_t; /* address - unsigned */
74typedef int db_expr_t; /* expression - signed */
1c79356b 75
8f6c56a5 76typedef struct i386_saved_state db_regs_t;
1c79356b
A
77db_regs_t ddb_regs; /* register state */
78#define DDB_REGS (&ddb_regs)
79extern int db_active; /* ddb is active */
80
81#define PC_REGS(regs) ((db_addr_t)(regs)->eip)
82
83#define BKPT_INST 0xcc /* breakpoint instruction */
84#define BKPT_SIZE (1) /* size of breakpoint inst */
85#define BKPT_SET(inst) (BKPT_INST)
86
87#define FIXUP_PC_AFTER_BREAK ddb_regs.eip -= 1;
88
89#define db_clear_single_step(regs) ((regs)->efl &= ~EFL_TF)
90#define db_set_single_step(regs) ((regs)->efl |= EFL_TF)
91
92#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_INT3)
93#define IS_WATCHPOINT_TRAP(type, code) ((type) == T_WATCHPOINT)
94
95#define I_CALL 0xe8
96#define I_CALLI 0xff
97#define I_RET 0xc3
98#define I_IRET 0xcf
99
100#define inst_trap_return(ins) (((ins)&0xff) == I_IRET)
101#define inst_return(ins) (((ins)&0xff) == I_RET)
102#define inst_call(ins) (((ins)&0xff) == I_CALL || \
103 (((ins)&0xff) == I_CALLI && \
104 ((ins)&0x3800) == 0x1000))
105
106int db_inst_load(unsigned long);
107int db_inst_store(unsigned long);
108
109/* access capability and access macros */
110
111#define DB_ACCESS_LEVEL 2 /* access any space */
112#define DB_CHECK_ACCESS(addr,size,task) \
113 db_check_access(addr,size,task)
114#define DB_PHYS_EQ(task1,addr1,task2,addr2) \
115 db_phys_eq(task1,addr1,task2,addr2)
8f6c56a5
A
116#define DB_VALID_KERN_ADDR(addr) \
117 ((addr) >= VM_MIN_KERNEL_ADDRESS && \
118 (addr) < VM_MAX_KERNEL_ADDRESS)
1c79356b
A
119#define DB_VALID_ADDRESS(addr,user) \
120 ((!(user) && DB_VALID_KERN_ADDR(addr)) || \
121 ((user) && (addr) < VM_MAX_ADDRESS))
122
123/*
124 * Given pointer to i386_saved_state, determine if it represents
55e303ae 125 * a thread executing in user space.
1c79356b 126 */
55e303ae 127#define IS_USER_TRAP(regs, etext) (((regs)->cs & 3) != 0)
1c79356b
A
128
129extern boolean_t db_check_access(
130 vm_offset_t addr,
131 int size,
132 task_t task);
133extern boolean_t db_phys_eq(
134 task_t task1,
135 vm_offset_t addr1,
136 task_t task2,
137 vm_offset_t addr2);
138extern db_addr_t db_disasm(
139 db_addr_t loc,
140 boolean_t altfmt,
141 task_t task);
142extern void db_read_bytes(
143 vm_offset_t addr,
144 int size,
145 char *data,
146 task_t task);
147extern void db_write_bytes(
148 vm_offset_t addr,
149 int size,
150 char *data,
151 task_t task);
152extern void db_stack_trace_cmd(
153 db_expr_t addr,
154 boolean_t have_addr,
155 db_expr_t count,
156 char *modif);
157extern void db_reboot(
158 db_expr_t addr,
159 boolean_t have_addr,
160 db_expr_t count,
161 char *modif);
162
163/* macros for printing OS server dependent task name */
164
165#define DB_TASK_NAME(task) db_task_name(task)
166#define DB_TASK_NAME_TITLE "COMMAND "
167#define DB_TASK_NAME_LEN 23
168#define DB_NULL_TASK_NAME "? "
169
170extern void db_task_name(
171 task_t task);
172
173/* macro for checking if a thread has used floating-point */
174
8f6c56a5 175#define db_act_fp_used(act) (act && act->machine.pcb->ims.ifps)
1c79356b
A
176
177extern void db_tss_to_frame(
178 int tss_sel,
8f6c56a5 179 struct i386_saved_state *regs);
1c79356b
A
180extern int kdb_trap(
181 int type,
182 int code,
8f6c56a5 183 struct i386_saved_state *regs);
1c79356b 184extern boolean_t db_trap_from_asm(
8f6c56a5 185 struct i386_saved_state *regs);
1c79356b
A
186extern int dr6(void);
187extern void kdb_on(
188 int cpu);
8f6c56a5
A
189extern void cnpollc(
190 boolean_t on);
1c79356b
A
191
192#endif /* _I386_DB_MACHDEP_H_ */