xref: /openbsd/sys/arch/sparc64/include/db_machdep.h (revision 3d8817e4)
1 /*	$OpenBSD: db_machdep.h,v 1.13 2011/03/23 16:54:37 pirofti Exp $	*/
2 /*	$NetBSD: db_machdep.h,v 1.12 2001/07/07 15:16:13 eeh Exp $ */
3 
4 /*
5  * Mach Operating System
6  * Copyright (c) 1991,1990 Carnegie Mellon University
7  * All Rights Reserved.
8  *
9  * Permission to use, copy, modify and distribute this software and its
10  * documentation is hereby granted, provided that both the copyright
11  * notice and this permission notice appear in all copies of the
12  * software, derivative works or modified versions, and any portions
13  * thereof, and that both notices appear in supporting documentation.
14  *
15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
17  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18  *
19  * Carnegie Mellon requests users of this software to return to
20  *
21  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
22  *  School of Computer Science
23  *  Carnegie Mellon University
24  *  Pittsburgh PA 15213-3890
25  *
26  * any improvements or extensions that they make and grant Carnegie Mellon
27  * the rights to redistribute these changes.
28  */
29 
30 #ifndef	_MACHINE_DB_MACHDEP_H_
31 #define	_MACHINE_DB_MACHDEP_H_
32 
33 /*
34  * Machine-dependent defines for new kernel debugger.
35  */
36 
37 #include <uvm/uvm_extern.h>
38 
39 #include <machine/frame.h>
40 #include <machine/psl.h>
41 #include <machine/trap.h>
42 #include <machine/reg.h>
43 
44 /* end of mangling */
45 
46 typedef	vaddr_t		db_addr_t;	/* address - unsigned */
47 typedef	long		db_expr_t;	/* expression - signed */
48 
49 struct trapstate {
50 	int64_t tstate;
51 	int64_t tpc;
52 	int64_t	tnpc;
53 	int64_t	tt;
54 };
55 #if 1
56 typedef struct {
57 	struct trapframe64	ddb_tf;
58 	struct frame64		ddb_fr;
59 	struct trapstate	ddb_ts[5];
60 	int			ddb_tl;
61 	struct fpstate64	ddb_fpstate;
62 } db_regs_t;
63 #else
64 typedef struct db_regs {
65 	struct trapregs dbr_traps[4];
66 	int		dbr_y;
67 	char		dbr_tl;
68 	char		dbr_canrestore;
69 	char		dbr_cansave;
70 	char		dbr_cleanwin;
71 	char		dbr_cwp;
72 	char		dbr_wstate;
73 	int64_t		dbr_g[8];
74 	int64_t		dbr_ag[8];
75 	int64_t		dbr_ig[8];
76 	int64_t		dbr_mg[8];
77 	int64_t		dbr_out[8];
78 	int64_t		dbr_local[8];
79 	int64_t		dbr_in[8];
80 } db_regs_t;
81 #endif
82 
83 extern	db_regs_t ddb_regs;	/* register state */
84 #define	DDB_REGS	(&ddb_regs)
85 #define	DDB_TF		(&ddb_regs.ddb_tf)
86 #define	DDB_FR		(&ddb_regs.ddb_fr)
87 #define	DDB_FP		(&ddb_regs.ddb_fpstate)
88 
89 #define	PC_REGS(regs)	((db_addr_t)(regs)->ddb_tf.tf_pc)
90 #define	SET_PC_REGS(regs, value)	(regs)->ddb_tf.tf_pc = (int32_t)(value)
91 #define	PC_ADVANCE(regs) do {				\
92 	vaddr_t n = (regs)->ddb_tf.tf_npc;		\
93 	(regs)->ddb_tf.tf_pc = n;			\
94 	(regs)->ddb_tf.tf_npc = n + 4;			\
95 } while(0)
96 
97 #define	BKPT_INST	0x91d02001	/* breakpoint instruction */
98 #define	BKPT_SIZE	(4)		/* size of breakpoint inst */
99 #define	BKPT_SET(inst)	(BKPT_INST)
100 
101 #define	IS_BREAKPOINT_TRAP(type, code)	\
102 	((type) == T_BREAKPOINT || (type) == T_KGDB_EXEC)
103 #define IS_WATCHPOINT_TRAP(type, code)	\
104 	((type) ==T_PA_WATCHPT || (type) == T_VA_WATCHPT)
105 
106 /*
107  * Sparc cpus have no hardware single-step.
108  */
109 #define SOFTWARE_SSTEP
110 
111 boolean_t	db_inst_trap_return(int inst);
112 boolean_t	db_inst_return(int inst);
113 boolean_t	db_inst_call(int inst);
114 boolean_t	db_inst_branch(int inst);
115 boolean_t	db_inst_unconditional_flow_transfer(int inst);
116 db_addr_t	db_branch_taken(int inst, db_addr_t pc, db_regs_t *regs);
117 void		db_machine_init(void);
118 
119 #define inst_trap_return(ins)	db_inst_trap_return(ins)
120 #define inst_return(ins)	db_inst_return(ins)
121 #define inst_call(ins)		db_inst_call(ins)
122 #define inst_branch(ins)	db_inst_branch(ins)
123 #define	inst_unconditional_flow_transfer(ins) \
124 				db_inst_unconditional_flow_transfer(ins)
125 #define branch_taken(ins, pc, fun, regs) \
126 				db_branch_taken((ins), (pc), (regs))
127 
128 /* see note in db_interface.c about reversed breakpoint addrs */
129 #define next_instr_address(pc, bd) \
130 	((bd) ? (pc) : ddb_regs.ddb_tf.tf_npc)
131 
132 #define DB_MACHINE_COMMANDS
133 
134 void db_machine_init(void);
135 int kdb_trap(int, struct trapframe64 *);
136 
137 /*
138  * We will use elf symbols in DDB when they work.
139  */
140 #define	DB_ELF_SYMBOLS
141 #define DB_ELFSIZE	64
142 
143 /* Register device-specific method for triggering XIRs. */
144 void db_register_xir(void (*)(void *, int), void *);
145 
146 #endif	/* _MACHINE_DB_MACHDEP_H_ */
147