1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
/* $NetBSD: db_machdep.h,v 1.38 2021/05/18 06:38:24 skrll Exp $ */
/*
* Copyright (c) 1997 Jonathan Stone (hereinafter referred to as the author)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Jonathan Stone for
* the NetBSD Project.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _MIPS_DB_MACHDEP_H_
#define _MIPS_DB_MACHDEP_H_
#include <sys/types.h>
#include <sys/stdbool.h>
#include <uvm/uvm_param.h> /* XXX boolean_t */
#include <mips/trap.h> /* T_BREAK */
#include <mips/reg.h> /* register state */
#include <mips/regnum.h> /* symbolic register indices */
#include <mips/pcb.h>
#define DB_ELF_SYMBOLS
typedef vaddr_t db_addr_t; /* address - unsigned */
#ifdef __mips_n32
#define DDB_EXPR_FMT "ll" /* expression is long long */
typedef int64_t db_expr_t; /* expression - signed */
#else
#define DDB_EXPR_FMT "l" /* expression is long */
typedef long db_expr_t; /* expression - signed */
#endif
typedef struct reg db_regs_t;
extern db_regs_t ddb_regs; /* register state */
#define DDB_REGS (&ddb_regs)
#define PC_REGS(regs) ((regs)->r_regs[_R_PC])
#define PC_ADVANCE(regs) do { \
if ((db_get_value((regs)->r_regs[_R_PC], sizeof(int), false) &\
0xfc00003f) == 0xd) \
(regs)->r_regs[_R_PC] += BKPT_SIZE; \
} while(0)
/* Similar to PC_ADVANCE(), except only advance on cpu_Debugger()'s bpt */
#define PC_BREAK_ADVANCE(regs) do { \
if (db_get_value((regs)->r_regs[_R_PC], sizeof(int), false) == 0xd) \
(regs)->r_regs[_R_PC] += BKPT_SIZE; \
} while(0)
#define BKPT_ADDR(addr) (addr) /* breakpoint address */
#define BKPT_INST 0x0001000D
#define BKPT_SIZE (4) /* size of breakpoint inst */
#define BKPT_SET(inst, addr) (BKPT_INST)
#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BREAK)
#define IS_WATCHPOINT_TRAP(type, code) (0) /* XXX mips3 watchpoint */
/*
* Interface to disassembly (shared with mdb)
*/
db_addr_t db_disasm_insn(int insn, db_addr_t loc, bool altfmt);
/*
* Entrypoints to DDB for kernel, keyboard drivers, init hook
*/
void kdb_kbd_trap(db_regs_t *);
int kdb_trap(int, struct reg *);
static inline void
db_set_ddb_regs(int type, struct reg *regs)
{
ddb_regs = *regs;
}
/*
* Helper functions for fetching 32-bit and 64-bit kernel memory.
*/
bool kdbpeek(vaddr_t, unsigned *);
mips_reg_t kdbrpeek(vaddr_t, size_t);
/*
* Constants for KGDB.
*/
typedef mips_reg_t kgdb_reg_t;
#define KGDB_NUMREGS 90
#define KGDB_BUFLEN 1024
/*
* MIPS cpus have no hardware single-step.
*/
#define SOFTWARE_SSTEP
#define inst_trap_return(ins) ((ins)&0)
bool inst_branch(int inst);
bool inst_call(int inst);
bool inst_return(int inst);
bool inst_load(int inst);
bool inst_store(int inst);
bool inst_unconditional_flow_transfer(int inst);
db_addr_t branch_taken(int inst, db_addr_t pc, db_regs_t *regs);
db_addr_t next_instr_address(db_addr_t pc, bool bd);
bool ddb_running_on_this_cpu_p(void);
bool ddb_running_on_any_cpu_p(void);
void db_resume_others(void);
void db_mips_stack_trace(void *, void *, void (*pr)(const char *, ...));
#ifdef _KERNEL
/*
* Optional function to perform machine- or cpu-specific reset.
* Called from ddb "machine reset".
*/
extern void (*cpu_reset_address)(void);
/*
* We have machine-dependent commands.
*/
#define DB_MACHINE_COMMANDS
#endif
#define db_stacktrace_print(prfunc) \
db_mips_stack_trace(__builtin_return_address(0), \
__builtin_frame_address(0), prfunc)
#endif /* _MIPS_DB_MACHDEP_H_ */
|