db_machdep.h revision 1.32 1 /* $NetBSD: db_machdep.h,v 1.32 2011/06/20 09:25:48 nakayama Exp $ */
2
3 /*
4 * Mach Operating System
5 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * All Rights Reserved.
7 *
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
13 *
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 *
18 * Carnegie Mellon requests users of this software to return to
19 *
20 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
24 *
25 * any improvements or extensions that they make and grant Carnegie Mellon
26 * the rights to redistribute these changes.
27 */
28
29 #ifndef _SPARC64_DB_MACHDEP_H_
30 #define _SPARC64_DB_MACHDEP_H_
31
32 /*
33 * Machine-dependent defines for new kernel debugger.
34 */
35
36 #include <sys/types.h>
37
38 #include <uvm/uvm_extern.h>
39
40 #ifndef SUN4U
41 #define SUN4U /* see .../sparc/include/frame.h for the reason */
42 #endif
43 #include <machine/frame.h>
44 #include <machine/pcb.h>
45 #include <machine/psl.h>
46 #include <machine/trap.h>
47 #include <machine/reg.h>
48
49
50 /* use 64-bit types explicitly for 32-bit kernels */
51 typedef vaddr_t db_addr_t; /* address - unsigned */
52 #ifdef __arch64__
53 #define DDB_EXPR_FMT "l" /* expression is int64_t (long) */
54 #else
55 #define DDB_EXPR_FMT "ll" /* expression is int64_t (long long) */
56 #endif
57 typedef int64_t db_expr_t; /* expression - signed */
58
59 struct trapstate {
60 int64_t tstate;
61 int64_t tpc;
62 int64_t tnpc;
63 int64_t tt;
64 };
65
66 typedef struct {
67 struct trapframe64 db_tf;
68 struct frame64 db_fr;
69 struct trapstate db_ts[5];
70 int db_tl;
71 struct fpstate64 db_fpstate __aligned(BLOCK_SIZE);
72 } db_regs_t;
73
74 /* Current CPU register state */
75 #define DDB_REGS ((db_regs_t*)__UNVOLATILE(curcpu()->ci_ddb_regs))
76 #define DDB_TF (&DDB_REGS->db_tf)
77 #define DDB_FP (&DDB_REGS->db_fpstate)
78
79 /* DDB commands not in db_interface.c */
80 void db_dump_ts(db_expr_t, bool, db_expr_t, const char *);
81 void db_dump_trap(db_expr_t, bool, db_expr_t, const char *);
82 void db_dump_fpstate(db_expr_t, bool, db_expr_t, const char *);
83 void db_dump_window(db_expr_t, bool, db_expr_t, const char *);
84 void db_dump_stack(db_expr_t, bool, db_expr_t, const char *);
85
86 #define PC_REGS(regs) ((regs)->db_tf.tf_pc)
87 #define PC_ADVANCE(regs) do { \
88 vaddr_t n = (regs)->db_tf.tf_npc; \
89 (regs)->db_tf.tf_pc = n; \
90 (regs)->db_tf.tf_npc = n + 4; \
91 } while(0)
92
93 #define BKPT_ADDR(addr) (addr) /* breakpoint address */
94 #define BKPT_INST 0x91d02001 /* breakpoint instruction */
95 #define BKPT_SIZE (4) /* size of breakpoint inst */
96 #define BKPT_SET(inst, addr) (BKPT_INST)
97
98 #define IS_BREAKPOINT_TRAP(type, code) \
99 ((type) == T_BREAKPOINT || (type) == T_KGDB_EXEC)
100 #define IS_WATCHPOINT_TRAP(type, code) \
101 ((type) ==T_PA_WATCHPT || (type) == T_VA_WATCHPT)
102
103 /*
104 * Sparc cpus have no hardware single-step.
105 */
106 #define SOFTWARE_SSTEP
107
108 bool db_inst_trap_return(int inst);
109 bool db_inst_return(int inst);
110 bool db_inst_call(int inst);
111 bool db_inst_branch(int inst);
112 int db_inst_load(int inst);
113 int db_inst_store(int inst);
114 bool db_inst_unconditional_flow_transfer(int inst);
115 db_addr_t db_branch_taken(int inst, db_addr_t pc, db_regs_t *regs);
116
117 #define inst_trap_return(ins) db_inst_trap_return(ins)
118 #define inst_return(ins) db_inst_return(ins)
119 #define inst_call(ins) db_inst_call(ins)
120 #define inst_branch(ins) db_inst_branch(ins)
121 #define inst_load(ins) db_inst_load(ins)
122 #define inst_store(ins) db_inst_store(ins)
123 #define inst_unconditional_flow_transfer(ins) \
124 db_inst_unconditional_flow_transfer(ins)
125 #define branch_taken(ins, pc, 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->db_tf.tf_npc)
131
132 #define DB_MACHINE_COMMANDS
133
134 int kdb_trap(int, struct trapframe64 *);
135
136 /*
137 * We use elf symbols in DDB.
138 */
139 #define DB_ELF_SYMBOLS
140 #ifdef __arch64__
141 #define DB_ELFSIZE 64
142 #else
143 #define DB_ELFSIZE 32
144 #endif
145
146 /*
147 * KGDB definitions
148 */
149 typedef u_long kgdb_reg_t;
150 #define KGDB_NUMREGS 125
151 #define KGDB_BUFLEN 2048
152
153 #endif /* _SPARC64_DB_MACHDEP_H_ */
154