1 /*        $NetBSD: db_machdep.h,v 1.28 2020/12/01 02:48:29 rin Exp $  */
2 
3 /*
4  * Copyright (c) 1996 Scott K Stevens
5  *
6  * Mach Operating System
7  * Copyright (c) 1991,1990 Carnegie Mellon University
8  * All Rights Reserved.
9  *
10  * Permission to use, copy, modify and distribute this software and its
11  * documentation is hereby granted, provided that both the copyright
12  * notice and this permission notice appear in all copies of the
13  * software, derivative works or modified versions, and any portions
14  * thereof, and that both notices appear in supporting documentation.
15  *
16  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
18  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19  *
20  * Carnegie Mellon requests users of this software to return to
21  *
22  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
23  *  School of Computer Science
24  *  Carnegie Mellon University
25  *  Pittsburgh PA 15213-3890
26  *
27  * any improvements or extensions that they make and grant Carnegie Mellon
28  * the rights to redistribute these changes.
29  */
30 
31 #ifndef   _ARM_DB_MACHDEP_H_
32 #define   _ARM_DB_MACHDEP_H_
33 
34 #if defined(__arm__)
35 
36 /*
37  * Machine-dependent defines for new kernel debugger.
38  */
39 #include <sys/types.h>
40 #include <uvm/uvm_extern.h>
41 #include <arm/armreg.h>
42 #include <arm/cdefs.h>
43 #include <machine/frame.h>
44 #include <machine/trap.h>
45 
46 /* end of mangling */
47 
48 typedef   vaddr_t             db_addr_t;          /* address - unsigned */
49 #define   DDB_EXPR_FMT        "l"                 /* expression is long */
50 typedef   long                db_expr_t;          /* expression - signed */
51 
52 typedef trapframe_t db_regs_t;
53 
54 #ifndef MULTIPROCESSOR
55 extern db_regs_t ddb_regs;    /* register state */
56 #define   DDB_REGS  (&ddb_regs)
57 #else
58 extern db_regs_t *ddb_regp;
59 #define DDB_REGS    (ddb_regp)
60 #define ddb_regs    (*ddb_regp)
61 #endif
62 
63 #define   PC_REGS(regs)       ((regs)->tf_pc)
64 #define PC_ADVANCE(r)   ((r)->tf_r15 += BKPT_SIZE)
65 
66 #define   BKPT_ADDR(addr)     (addr)                        /* breakpoint address */
67 #if defined(DDB)
68 #define   BKPT_INST (KERNEL_BREAKPOINT) /* breakpoint instruction */
69 #else
70 /* breakpoint instruction if we use KGDB, this is used in db_set_temp_breakpoint() */
71 #define BKPT_INST   (GDB5_BREAKPOINT)
72 #endif
73 #define   BKPT_SIZE (INSN_SIZE)                   /* size of breakpoint inst */
74 #ifdef __ARM_ARCH_BE8
75 #define   BKPT_SET(inst, addr)          (bswap32(BKPT_INST))
76 #else
77 #define   BKPT_SET(inst, addr)          (BKPT_INST)
78 #endif
79 
80 /*#define FIXUP_PC_AFTER_BREAK(regs)    ((regs)->tf_pc -= BKPT_SIZE)*/
81 
82 #define   T_FAULT                                 (0)
83 #define T_BREAKPOINT                              (1)
84 
85 #define   IS_BREAKPOINT_TRAP(type, code)          ((type) == T_BREAKPOINT)
86 #define   IS_WATCHPOINT_TRAP(type, code)          (0)
87 
88 #define   inst_trap_return(ins)         (0)
89 /* ldmxx reg, {..., pc}
90                                                       01800000  stack mode
91                                                       000f0000  register
92                                                       0000ffff  register list */
93 /* mov pc, reg
94                                                       0000000f  register */
95 #define   inst_return(ins)    (((ins) & 0x0e108000) == 0x08108000 || \
96                                          ((ins) & 0x0ff0fff0) == 0x01a0f000)
97 /* bl ...
98                                                       00ffffff  offset>>2 */
99 #define   inst_call(ins)                (((ins) & 0x0f000000) == 0x0b000000)
100 /* b ...
101                                                       00ffffff  offset>>2 */
102 /* ldr pc, [pc, reg, lsl #2]
103                                                       0000000f  register */
104 #define   inst_branch(ins)    (((ins) & 0x0f000000) == 0x0a000000 || \
105                                          ((ins) & 0x0fdffff0) == 0x079ff100 || \
106                                          ((ins) & 0x0ff0f000) == 0x0590f000)
107 #define inst_load(ins)                  (0)
108 #define inst_store(ins)                 (0)
109 #define inst_unconditional_flow_transfer(ins)     \
110           (__SHIFTOUT((ins), INSN_COND_MASK) == INSN_COND_AL \
111            && (inst_branch(ins) || inst_call(ins) || inst_return(ins)))
112 
113 #define getreg_val                      (0)
114 #define next_instr_address(pc, bd)      ((bd) ? (pc) : ((pc) + INSN_SIZE))
115 
116 #define DB_MACHINE_COMMANDS
117 
118 #define SOFTWARE_SSTEP
119 
120 u_int branch_taken(u_int insn, u_int pc, db_regs_t *db_regs);
121 int kdb_trap(int, db_regs_t *);
122 void db_machine_init(void);
123 int db_validate_address(vaddr_t addr);
124 
125 #define DB_ELF_SYMBOLS
126 
127 /*
128  * kgdb
129  */
130 typedef register_t  kgdb_reg_t;
131 #define KGDB_NUMREGS          (16 + 8*3 + 2)      /* r0..r15, f0..f7, fps, cpsr
132                                                    * fp-registers are 12 bytes wide */
133 #define KGDB_REGNUM_R0                  0
134 #define KGDB_REGNUM_SPSR      16 + 8*3 + 1
135 #define KGDB_BUFLEN           1024
136 
137 /*
138  * MP stuff
139  */
140 extern volatile struct cpu_info *db_onproc;
141 extern volatile struct cpu_info *db_newcpu;
142 
143 #elif defined(__aarch64__)
144 
145 #include <aarch64/db_machdep.h>
146 
147 #endif
148 
149 #endif    /* _ARM_DB_MACHDEP_H_ */
150