db_machdep.h revision 308418
1178825Sdfr/*-
2178825Sdfr * Mach Operating System
3178825Sdfr * Copyright (c) 1991,1990 Carnegie Mellon University
4178825Sdfr * All Rights Reserved.
5178825Sdfr *
6178825Sdfr * Permission to use, copy, modify and distribute this software and its
7178825Sdfr * documentation is hereby granted, provided that both the copyright
8178825Sdfr * notice and this permission notice appear in all copies of the
9178825Sdfr * software, derivative works or modified versions, and any portions
10178825Sdfr * thereof, and that both notices appear in supporting documentation.
11178825Sdfr *
12178825Sdfr * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13178825Sdfr * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14178825Sdfr * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15178825Sdfr *
16178825Sdfr * Carnegie Mellon requests users of this software to return to
17178825Sdfr *
18178825Sdfr *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
19178825Sdfr *  School of Computer Science
20178825Sdfr *  Carnegie Mellon University
21178825Sdfr *  Pittsburgh PA 15213-3890
22178825Sdfr *
23178825Sdfr * any improvements or extensions that they make and grant Carnegie Mellon
24178825Sdfr * the rights to redistribute these changes.
25178825Sdfr *
26178825Sdfr * $FreeBSD: stable/11/sys/i386/include/db_machdep.h 308418 2016-11-07 12:10:17Z kib $
27178825Sdfr */
28178825Sdfr
29178825Sdfr#ifndef _MACHINE_DB_MACHDEP_H_
30178825Sdfr#define	_MACHINE_DB_MACHDEP_H_
31178825Sdfr
32178825Sdfr#include <machine/frame.h>
33178825Sdfr#include <machine/trap.h>
34178825Sdfr
35178825Sdfrtypedef	vm_offset_t	db_addr_t;	/* address - unsigned */
36178825Sdfrtypedef	int		db_expr_t;	/* expression - signed */
37178825Sdfr
38178825Sdfr#define	PC_REGS()	((db_addr_t)(kdb_frame->tf_eflags & PSL_VM ?	\
39178825Sdfr			    (kdb_frame->tf_eip & 0xffff) +		\
40178825Sdfr			    ((kdb_frame->tf_cs & 0xffff) << 4) :	\
41178825Sdfr			    kdb_frame->tf_eip))
42178825Sdfr
43178825Sdfr#define	BKPT_INST	0xcc		/* breakpoint instruction */
44178825Sdfr#define	BKPT_SIZE	(1)		/* size of breakpoint inst */
45178825Sdfr#define	BKPT_SET(inst)	(BKPT_INST)
46178825Sdfr
47178825Sdfr#define BKPT_SKIP				\
48178825Sdfrdo {						\
49178825Sdfr	kdb_frame->tf_eip += 1;			\
50178825Sdfr	kdb_thrctx->pcb_eip += 1;		\
51178825Sdfr} while(0)
52178825Sdfr
53178825Sdfr#define	FIXUP_PC_AFTER_BREAK			\
54178825Sdfrdo {						\
55178825Sdfr	kdb_frame->tf_eip -= 1;			\
56178825Sdfr	kdb_thrctx->pcb_eip -= 1;		\
57178825Sdfr} while(0);
58178825Sdfr
59178825Sdfr#define	db_clear_single_step	kdb_cpu_clear_singlestep
60178825Sdfr#define	db_set_single_step	kdb_cpu_set_singlestep
61178825Sdfr
62178825Sdfr/*
63178825Sdfr * The debug exception type is copied from %dr6 to 'code' and used to
64178825Sdfr * disambiguate single step traps.  Watchpoints have no special support.
65178825Sdfr * Our hardware breakpoints are not well integrated with ddb and are too
66178825Sdfr * different from watchpoints.  ddb treats them as unknown traps with
67178825Sdfr * unknown addresses and doesn't turn them off while it is running.
68178825Sdfr */
69178825Sdfr#define	IS_BREAKPOINT_TRAP(type, code)	((type) == T_BPTFLT)
70178825Sdfr#define	IS_SSTEP_TRAP(type, code)	((type) == T_TRCTRAP && (code) & 0x4000)
71178825Sdfr#define	IS_WATCHPOINT_TRAP(type, code)	0
72178825Sdfr
73178825Sdfr#define	I_CALL		0xe8
74178825Sdfr#define	I_CALLI		0xff
75178825Sdfr#define	I_RET		0xc3
76178825Sdfr#define	I_IRET		0xcf
77178825Sdfr
78178825Sdfr#define	inst_trap_return(ins)	(((ins)&0xff) == I_IRET)
79#define	inst_return(ins)	(((ins)&0xff) == I_RET)
80#define	inst_call(ins)		(((ins)&0xff) == I_CALL || \
81				 (((ins)&0xff) == I_CALLI && \
82				  ((ins)&0x3800) == 0x1000))
83#define inst_load(ins)		0
84#define inst_store(ins)		0
85
86/*
87 * There no interesting addresses below _kstack = 0xefbfe000.  There
88 * are small absolute values for GUPROF, but we don't want to see them.
89 * Treat "negative" addresses below _kstack as non-small to allow for
90 * future reductions of _kstack and to avoid sign extension problems.
91 *
92 * There is one interesting symbol above -db_maxoff = 0xffff0000,
93 * namely _APTD = 0xfffff000.  Accepting this would mess up the
94 * printing of small negative offsets.  The next largest symbol is
95 * _APTmap = 0xffc00000.  Accepting this is OK (unless db_maxoff is
96 * set to >= 0x400000 - (max stack offset)).
97 */
98#define	DB_SMALL_VALUE_MAX	0x7fffffff
99#define	DB_SMALL_VALUE_MIN	(-0x400001)
100
101int	db_segsize(struct trapframe *tfp);
102
103#endif /* !_MACHINE_DB_MACHDEP_H_ */
104