1 /*	$OpenBSD: db_machdep.h,v 1.2 1997/03/21 00:48:48 niklas Exp $	*/
2 /*	$NetBSD: db_machdep.h,v 1.25 2015/01/23 07:27:05 nonaka Exp $	*/
3 
4 /*
5  * Mach Operating System
6  * Copyright (c) 1992 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 /*
31  * Machine-dependent defines for new kernel debugger.
32  */
33 #ifndef	_PPC_DB_MACHDEP_H_
34 #define	_PPC_DB_MACHDEP_H_
35 
36 #include <uvm/uvm_prot.h>
37 #include <uvm/uvm_param.h>
38 #include <machine/trap.h>
39 
40 #ifdef _KERNEL
41 #include "opt_ppcarch.h"
42 #endif
43 
44 #define	DB_ELF_SYMBOLS
45 #define	DB_ELFSIZE	32
46 
47 typedef	vaddr_t		db_addr_t;	/* address - unsigned */
48 #define	DDB_EXPR_FMT	"l"		/* expression is long */
49 typedef	long		db_expr_t;	/* expression - signed */
50 struct powerpc_saved_state {
51 	u_int32_t	r[32];		/* data registers */
52 	u_int32_t	iar;
53 	u_int32_t	msr;
54 	u_int32_t	lr;
55 	u_int32_t	ctr;
56 	u_int32_t	cr;
57 	u_int32_t	xer;
58 	u_int32_t	mq;
59 	u_int32_t	dear;
60 	u_int32_t	esr;
61 	u_int32_t	pid;
62 };
63 typedef struct powerpc_saved_state db_regs_t;
64 extern	db_regs_t	ddb_regs;		/* register state */
65 #define DDB_REGS	(&ddb_regs)
66 
67 #define	PC_REGS(regs)	(*(db_addr_t *)&(regs)->iar)
68 
69 #define	BKPT_ADDR(addr)	(addr)		/* breakpoint address */
70 #define	BKPT_ASM	"trap"		/* should match BKPT_INST */
71 #define	BKPT_INST	0x7fe00008	/* breakpoint instruction */
72 #define	BKPT_SIZE	(4)		/* size of breakpoint inst */
73 #define	BKPT_SET(inst, addr)	(BKPT_INST)
74 
75 #ifndef PPC_IBM4XX
76 #define SR_SINGLESTEP	0x400
77 #define	db_clear_single_step(regs)	((regs)->msr &= ~SR_SINGLESTEP)
78 #define	db_set_single_step(regs)	((regs)->msr |=  SR_SINGLESTEP)
79 #else
80 #define	SOFTWARE_SSTEP
81 #endif
82 
83 #define T_BREAKPOINT	0xffff
84 #define	IS_BREAKPOINT_TRAP(type, code)	((type) == T_BREAKPOINT)
85 
86 #define T_WATCHPOINT	0xeeee
87 #ifdef T_WATCHPOINT
88 #define	IS_WATCHPOINT_TRAP(type, code)	((type) == T_WATCHPOINT)
89 #else
90 #define	IS_WATCHPOINT_TRAP(type, code)	0
91 #endif
92 
93 #define	M_RTS		0xfc0007ff
94 #define I_RTS		0x4c000020
95 #define	I_BLRL		0x4c000021
96 #define M_BC		0xfc000001
97 #define I_BC		0x40000000
98 #define I_BCL		0x40000001
99 #define M_B		0xfc000001
100 #define I_B		0x48000000
101 #define I_BL		0x48000001
102 #define	M_BCTR		0xfc0007fe
103 #define	I_BCTR		0x4c000420
104 #define	I_BCTRL		0x4c000421
105 #define	M_RFI		0xfc0007fe
106 #define	I_RFI		0x4c000064
107 
108 #define	inst_trap_return(ins)	(((ins)&M_RFI) == I_RFI)
109 #define	inst_return(ins)	(((ins)&M_RTS) == I_RTS)
110 #define	inst_call(ins)		(((ins)&M_BC  ) == I_BCL   || \
111 				 ((ins)&M_B   ) == I_BL    || \
112 				 ((ins)&M_BCTR) == I_BCTRL || \
113 				 ((ins)&M_RTS ) == I_BLRL )
114 #define	inst_branch(ins)	(((ins)&M_BC  ) == I_BC || \
115 				 ((ins)&M_B   ) == I_B  || \
116 				 ((ins)&M_BCTR) == I_BCTR )
117 #define	inst_unconditional_flow_transfer(ins)	\
118 				(((ins)&M_B   ) == I_B    || \
119 				 ((ins)&M_BCTR) == I_BCTR )
120 #define inst_load(ins)		0
121 #define inst_store(ins)		0
122 #if defined(PPC_IBM4XX) || defined(PPC_BOOKE)
123 #define next_instr_address(v, b) ((db_addr_t) ((b) ? (v) : ((v) + 4)))
124 extern db_addr_t branch_taken(int, db_addr_t, db_regs_t *);
125 #endif
126 
127 /*
128  * GDB's register array is:
129  *  32 4-byte GPRs
130  *  32 8-byte FPRs
131  *   7 4-byte UISA special-purpose registers
132  *  16 4-byte segment registers
133  *  32 4-byte standard OEA special-purpose registers,
134  * and up to 64 4-byte non-standard OES special-purpose registers.
135  * GDB keeps some extra space, so the total size of the register array
136  * they use is 880 bytes (gdb-5.0).
137  * KGDB_NUMREGS 220
138  */
139 /*
140  * GDB's register array of gdb-6.0 is defined in
141  * usr/src/gnu/dist/gdb6/gdb/regformats/reg-ppc.dat
142  * GDB's register array is:
143  *  32 4-byte GPRs
144  *  32 8-byte FPRs
145  *   7 4-byte UISA special-purpose registers: pc, ps, cr, lr, ctr, xer, fpscr
146  * index of pc in array: 32 + 2*32 = 96
147  * size 32 * 4 + 32 * 8 + 7 * 4 = 103 * 4 = 412 bytes
148  * KGD_NUMREGS 103
149  */
150 typedef long	kgdb_reg_t;
151 #define KGDB_PPC_PC_REG		96	/* first UISA SP register */
152 #define KGDB_PPC_MSR_REG	97
153 #define KGDB_PPC_CR_REG		98
154 #define KGDB_PPC_LR_REG		99
155 #define KGDB_PPC_CTR_REG	100
156 #define KGDB_PPC_XER_REG	101
157 #define KGDB_PPC_FPSCR_REG	102
158 #define KGDB_NUMREGS		103	/* Treat all registers as 4-byte */
159 #define KGDB_BUFLEN		(2*KGDB_NUMREGS*sizeof(kgdb_reg_t)+1)
160 
161 #ifdef _KERNEL
162 
163 void	kdb_kintr(void *);
164 int	kdb_trap(int, void *);
165 
166 bool	ddb_running_on_this_cpu_p(void);
167 bool	ddb_running_on_any_cpu_p(void);
168 void	db_resume_others(void);
169 
170 /*
171  * We have machine-dependent commands.
172  */
173 #define	DB_MACHINE_COMMANDS
174 
175 #endif /* _KERNEL */
176 
177 #endif	/* _PPC_DB_MACHDEP_H_ */
178