db_machdep.h revision 1.27 1 1.1 sakamoto /* $OpenBSD: db_machdep.h,v 1.2 1997/03/21 00:48:48 niklas Exp $ */
2 1.27 rin /* $NetBSD: db_machdep.h,v 1.27 2019/12/15 06:05:00 rin Exp $ */
3 1.1 sakamoto
4 1.1 sakamoto /*
5 1.1 sakamoto * Mach Operating System
6 1.1 sakamoto * Copyright (c) 1992 Carnegie Mellon University
7 1.1 sakamoto * All Rights Reserved.
8 1.1 sakamoto *
9 1.1 sakamoto * Permission to use, copy, modify and distribute this software and its
10 1.1 sakamoto * documentation is hereby granted, provided that both the copyright
11 1.1 sakamoto * notice and this permission notice appear in all copies of the
12 1.1 sakamoto * software, derivative works or modified versions, and any portions
13 1.1 sakamoto * thereof, and that both notices appear in supporting documentation.
14 1.1 sakamoto *
15 1.1 sakamoto * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 1.1 sakamoto * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
17 1.1 sakamoto * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 1.1 sakamoto *
19 1.1 sakamoto * Carnegie Mellon requests users of this software to return to
20 1.1 sakamoto *
21 1.1 sakamoto * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 1.1 sakamoto * School of Computer Science
23 1.1 sakamoto * Carnegie Mellon University
24 1.1 sakamoto * Pittsburgh PA 15213-3890
25 1.1 sakamoto *
26 1.1 sakamoto * any improvements or extensions that they make and grant Carnegie Mellon
27 1.1 sakamoto * the rights to redistribute these changes.
28 1.1 sakamoto */
29 1.1 sakamoto
30 1.1 sakamoto /*
31 1.1 sakamoto * Machine-dependent defines for new kernel debugger.
32 1.1 sakamoto */
33 1.1 sakamoto #ifndef _PPC_DB_MACHDEP_H_
34 1.1 sakamoto #define _PPC_DB_MACHDEP_H_
35 1.1 sakamoto
36 1.5 mrg #include <uvm/uvm_prot.h>
37 1.7 mrg #include <uvm/uvm_param.h>
38 1.1 sakamoto #include <machine/trap.h>
39 1.1 sakamoto
40 1.9 simonb #ifdef _KERNEL
41 1.9 simonb #include "opt_ppcarch.h"
42 1.9 simonb #endif
43 1.9 simonb
44 1.1 sakamoto #define DB_ELF_SYMBOLS
45 1.1 sakamoto
46 1.4 tsubai typedef vaddr_t db_addr_t; /* address - unsigned */
47 1.23 joerg #define DDB_EXPR_FMT "l" /* expression is long */
48 1.3 tsubai typedef long db_expr_t; /* expression - signed */
49 1.1 sakamoto struct powerpc_saved_state {
50 1.2 mycroft u_int32_t r[32]; /* data registers */
51 1.1 sakamoto u_int32_t iar;
52 1.1 sakamoto u_int32_t msr;
53 1.9 simonb u_int32_t lr;
54 1.9 simonb u_int32_t ctr;
55 1.9 simonb u_int32_t cr;
56 1.9 simonb u_int32_t xer;
57 1.15 kleink u_int32_t mq;
58 1.9 simonb u_int32_t dear;
59 1.9 simonb u_int32_t esr;
60 1.9 simonb u_int32_t pid;
61 1.1 sakamoto };
62 1.1 sakamoto typedef struct powerpc_saved_state db_regs_t;
63 1.13 matt extern db_regs_t ddb_regs; /* register state */
64 1.1 sakamoto #define DDB_REGS (&ddb_regs)
65 1.1 sakamoto
66 1.16 matt #define PC_REGS(regs) (*(db_addr_t *)&(regs)->iar)
67 1.1 sakamoto
68 1.17 scw #define BKPT_ADDR(addr) (addr) /* breakpoint address */
69 1.14 scw #define BKPT_ASM "trap" /* should match BKPT_INST */
70 1.12 dbj #define BKPT_INST 0x7fe00008 /* breakpoint instruction */
71 1.1 sakamoto #define BKPT_SIZE (4) /* size of breakpoint inst */
72 1.18 cherry #define BKPT_SET(inst, addr) (BKPT_INST)
73 1.1 sakamoto
74 1.14 scw #ifndef PPC_IBM4XX
75 1.1 sakamoto #define SR_SINGLESTEP 0x400
76 1.1 sakamoto #define db_clear_single_step(regs) ((regs)->msr &= ~SR_SINGLESTEP)
77 1.1 sakamoto #define db_set_single_step(regs) ((regs)->msr |= SR_SINGLESTEP)
78 1.14 scw #else
79 1.14 scw #define SOFTWARE_SSTEP
80 1.14 scw #endif
81 1.1 sakamoto
82 1.12 dbj #define T_BREAKPOINT 0xffff
83 1.1 sakamoto #define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BREAKPOINT)
84 1.1 sakamoto
85 1.1 sakamoto #define T_WATCHPOINT 0xeeee
86 1.1 sakamoto #ifdef T_WATCHPOINT
87 1.1 sakamoto #define IS_WATCHPOINT_TRAP(type, code) ((type) == T_WATCHPOINT)
88 1.1 sakamoto #else
89 1.1 sakamoto #define IS_WATCHPOINT_TRAP(type, code) 0
90 1.1 sakamoto #endif
91 1.1 sakamoto
92 1.14 scw #define M_RTS 0xfc0007ff
93 1.1 sakamoto #define I_RTS 0x4c000020
94 1.14 scw #define I_BLRL 0x4c000021
95 1.14 scw #define M_BC 0xfc000001
96 1.1 sakamoto #define I_BC 0x40000000
97 1.14 scw #define I_BCL 0x40000001
98 1.14 scw #define M_B 0xfc000001
99 1.14 scw #define I_B 0x48000000
100 1.14 scw #define I_BL 0x48000001
101 1.27 rin #define M_BCTR 0xfc0007ff
102 1.14 scw #define I_BCTR 0x4c000420
103 1.14 scw #define I_BCTRL 0x4c000421
104 1.1 sakamoto #define M_RFI 0xfc0007fe
105 1.1 sakamoto #define I_RFI 0x4c000064
106 1.1 sakamoto
107 1.1 sakamoto #define inst_trap_return(ins) (((ins)&M_RFI) == I_RFI)
108 1.1 sakamoto #define inst_return(ins) (((ins)&M_RTS) == I_RTS)
109 1.14 scw #define inst_call(ins) (((ins)&M_BC ) == I_BCL || \
110 1.14 scw ((ins)&M_B ) == I_BL || \
111 1.14 scw ((ins)&M_BCTR) == I_BCTRL || \
112 1.14 scw ((ins)&M_RTS ) == I_BLRL )
113 1.14 scw #define inst_branch(ins) (((ins)&M_BC ) == I_BC || \
114 1.14 scw ((ins)&M_B ) == I_B || \
115 1.14 scw ((ins)&M_BCTR) == I_BCTR )
116 1.14 scw #define inst_unconditional_flow_transfer(ins) \
117 1.14 scw (((ins)&M_B ) == I_B || \
118 1.14 scw ((ins)&M_BCTR) == I_BCTR )
119 1.1 sakamoto #define inst_load(ins) 0
120 1.1 sakamoto #define inst_store(ins) 0
121 1.22 matt #if defined(PPC_IBM4XX) || defined(PPC_BOOKE)
122 1.14 scw #define next_instr_address(v, b) ((db_addr_t) ((b) ? (v) : ((v) + 4)))
123 1.14 scw extern db_addr_t branch_taken(int, db_addr_t, db_regs_t *);
124 1.14 scw #endif
125 1.10 briggs
126 1.10 briggs /*
127 1.10 briggs * GDB's register array is:
128 1.10 briggs * 32 4-byte GPRs
129 1.10 briggs * 32 8-byte FPRs
130 1.10 briggs * 7 4-byte UISA special-purpose registers
131 1.10 briggs * 16 4-byte segment registers
132 1.10 briggs * 32 4-byte standard OEA special-purpose registers,
133 1.10 briggs * and up to 64 4-byte non-standard OES special-purpose registers.
134 1.10 briggs * GDB keeps some extra space, so the total size of the register array
135 1.10 briggs * they use is 880 bytes (gdb-5.0).
136 1.24 matt * KGDB_NUMREGS 220
137 1.24 matt */
138 1.24 matt /*
139 1.24 matt * GDB's register array of gdb-6.0 is defined in
140 1.24 matt * usr/src/gnu/dist/gdb6/gdb/regformats/reg-ppc.dat
141 1.24 matt * GDB's register array is:
142 1.24 matt * 32 4-byte GPRs
143 1.24 matt * 32 8-byte FPRs
144 1.24 matt * 7 4-byte UISA special-purpose registers: pc, ps, cr, lr, ctr, xer, fpscr
145 1.24 matt * index of pc in array: 32 + 2*32 = 96
146 1.24 matt * size 32 * 4 + 32 * 8 + 7 * 4 = 103 * 4 = 412 bytes
147 1.24 matt * KGD_NUMREGS 103
148 1.10 briggs */
149 1.10 briggs typedef long kgdb_reg_t;
150 1.10 briggs #define KGDB_PPC_PC_REG 96 /* first UISA SP register */
151 1.10 briggs #define KGDB_PPC_MSR_REG 97
152 1.10 briggs #define KGDB_PPC_CR_REG 98
153 1.10 briggs #define KGDB_PPC_LR_REG 99
154 1.10 briggs #define KGDB_PPC_CTR_REG 100
155 1.10 briggs #define KGDB_PPC_XER_REG 101
156 1.24 matt #define KGDB_PPC_FPSCR_REG 102
157 1.24 matt #define KGDB_NUMREGS 103 /* Treat all registers as 4-byte */
158 1.24 matt #define KGDB_BUFLEN (2*KGDB_NUMREGS*sizeof(kgdb_reg_t)+1)
159 1.1 sakamoto
160 1.1 sakamoto #ifdef _KERNEL
161 1.1 sakamoto
162 1.20 dsl void kdb_kintr(void *);
163 1.20 dsl int kdb_trap(int, void *);
164 1.9 simonb
165 1.25 nonaka bool ddb_running_on_this_cpu_p(void);
166 1.25 nonaka bool ddb_running_on_any_cpu_p(void);
167 1.25 nonaka void db_resume_others(void);
168 1.25 nonaka
169 1.9 simonb /*
170 1.9 simonb * We have machine-dependent commands.
171 1.9 simonb */
172 1.9 simonb #define DB_MACHINE_COMMANDS
173 1.1 sakamoto
174 1.1 sakamoto #endif /* _KERNEL */
175 1.1 sakamoto
176 1.1 sakamoto #endif /* _PPC_DB_MACHDEP_H_ */
177