xref: /netbsd/sys/arch/amd64/include/db_machdep.h (revision 6550d01e)
1 /*	$NetBSD: db_machdep.h,v 1.9 2009/03/14 14:45:54 dsl Exp $	*/
2 
3 /*
4  * Mach Operating System
5  * Copyright (c) 1991,1990 Carnegie Mellon University
6  * All Rights Reserved.
7  *
8  * Permission to use, copy, modify and distribute this software and its
9  * documentation is hereby granted, provided that both the copyright
10  * notice and this permission notice appear in all copies of the
11  * software, derivative works or modified versions, and any portions
12  * thereof, and that both notices appear in supporting documentation.
13  *
14  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17  *
18  * Carnegie Mellon requests users of this software to return to
19  *
20  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
21  *  School of Computer Science
22  *  Carnegie Mellon University
23  *  Pittsburgh PA 15213-3890
24  *
25  * any improvements or extensions that they make and grant Carnegie Mellon
26  * the rights to redistribute these changes.
27  */
28 
29 #ifndef	_X86_64_DB_MACHDEP_H_
30 #define	_X86_64_DB_MACHDEP_H_
31 
32 /*
33  * Machine-dependent defines for new kernel debugger.
34  */
35 
36 #if defined(_KERNEL_OPT)
37 #include "opt_multiprocessor.h"
38 #endif /* defined(_KERNEL_OPT) */
39 #include <sys/param.h>
40 #include <uvm/uvm_extern.h>
41 #include <machine/trap.h>
42 
43 typedef	vaddr_t		db_addr_t;	/* address - unsigned */
44 typedef	long		db_expr_t;	/* expression - signed */
45 
46 typedef struct trapframe db_regs_t;
47 #ifndef MULTIPROCESSOR
48 extern db_regs_t ddb_regs;	/* register state */
49 #define	DDB_REGS	(&ddb_regs)
50 #else
51 extern db_regs_t *ddb_regp;
52 #define DDB_REGS	(ddb_regp)
53 #define ddb_regs	(*ddb_regp)
54 #endif
55 
56 #define	PC_REGS(regs)	((regs)->tf_rip)
57 #define PC_ADVANCE(r)  ((r)->tf_rip += BKPT_SIZE)
58 
59 #define	BKPT_ADDR(addr)	(addr)		/* breakpoint address */
60 #define	BKPT_INST	0xcc		/* breakpoint instruction */
61 #define	BKPT_SIZE	(1)		/* size of breakpoint inst */
62 #define	BKPT_SET(inst, addr)	(BKPT_INST)
63 
64 #define	FIXUP_PC_AFTER_BREAK(regs)	((regs)->tf_rip -= BKPT_SIZE)
65 
66 #define	db_clear_single_step(regs)	((regs)->tf_rflags &= ~PSL_T)
67 #define	db_set_single_step(regs)	((regs)->tf_rflags |=  PSL_T)
68 
69 #define	IS_BREAKPOINT_TRAP(type, code)	((type) == T_BPTFLT)
70 #define IS_WATCHPOINT_TRAP(type, code)	((type) == T_TRCTRAP && (code) & 15)
71 
72 #define	I_CALL		0xe8
73 #define	I_CALLI		0xff
74 #define	I_RET		0xc3
75 #define	I_IRET		0xcf
76 
77 #define	inst_trap_return(ins)	(((ins)&0xff) == I_IRET)
78 #define	inst_return(ins)	(((ins)&0xff) == I_RET)
79 #define	inst_call(ins)		(((ins)&0xff) == I_CALL || \
80 				 (((ins)&0xff) == I_CALLI && \
81 				  ((ins)&0x3800) == 0x1000))
82 #define inst_load(ins)		0
83 #define inst_store(ins)		0
84 
85 /* access capability and access macros */
86 
87 #define DB_ACCESS_LEVEL		2	/* access any space */
88 #define DB_CHECK_ACCESS(addr,size,task)				\
89 	db_check_access(addr,size,task)
90 #define DB_PHYS_EQ(task1,addr1,task2,addr2)			\
91 	db_phys_eq(task1,addr1,task2,addr2)
92 #define DB_VALID_KERN_ADDR(addr)				\
93 	((addr) >= VM_MIN_KERNEL_ADDRESS && 			\
94 	 (addr) < VM_MAX_KERNEL_ADDRESS)
95 #define DB_VALID_ADDRESS(addr,user)				\
96 	((!(user) && DB_VALID_KERN_ADDR(addr)) ||		\
97 	 ((user) && (addr) < VM_MAX_ADDRESS))
98 
99 #if 0
100 bool	 	db_check_access(vaddr_t, int, task_t);
101 bool		db_phys_eq(task_t, vaddr_t, task_t, vaddr_t);
102 #endif
103 
104 /* macros for printing OS server dependent task name */
105 
106 #define DB_TASK_NAME(task)	db_task_name(task)
107 #define DB_TASK_NAME_TITLE	"COMMAND                "
108 #define DB_TASK_NAME_LEN	23
109 #define DB_NULL_TASK_NAME	"?                      "
110 
111 /*
112  * Constants for KGDB.
113  */
114 typedef	long		kgdb_reg_t;
115 #define	KGDB_NUMREGS	16
116 #define	KGDB_BUFLEN	512
117 
118 #if 0
119 void		db_task_name(/* task_t */);
120 #endif
121 
122 /* macro for checking if a thread has used floating-point */
123 
124 #define db_thread_fp_used(thread)	((thread)->pcb->ims.ifps != 0)
125 
126 int kdb_trap(int, int, db_regs_t *);
127 
128 /*
129  * We define some of our own commands
130  */
131 #define DB_MACHINE_COMMANDS
132 
133 #define	DB_ELF_SYMBOLS
134 #define	DB_ELFSIZE	64
135 
136 extern void db_machine_init(void);
137 
138 extern void cpu_debug_dump(void);
139 
140 #endif	/* _X86_64_DB_MACHDEP_H_ */
141