1 /* $OpenBSD: db_machdep.h,v 1.23 2022/02/15 00:27:11 jsg Exp $ */
2
3 /*
4 * Copyright (c) 1998-2005 Michael Shalayeff
5 * All rights reserved.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
16 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 #ifndef _MACHINE_DB_MACHDEP_H_
21 #define _MACHINE_DB_MACHDEP_H_
22
23 #include <uvm/uvm_extern.h>
24
25 /* types the generic ddb module needs */
26 typedef long db_expr_t;
27
28 typedef struct trapframe db_regs_t;
29 extern db_regs_t ddb_regs;
30
31 #define PC_REGS(regs) ((vaddr_t)(regs)->tf_iioq_head)
32 #define SET_PC_REGS(regs, value) \
33 do { \
34 (regs)->tf_iioq_tail = 4 + \
35 ((regs)->tf_iioq_head = (value)); \
36 } while (0)
37
38 /* Breakpoint related definitions */
39 #define BKPT_INST 0x00010000 /* break 0,8 */
40 #define BKPT_SIZE sizeof(int)
41 #define BKPT_SET(inst) BKPT_INST
42
43 #define IS_BREAKPOINT_TRAP(type, code) ((type) == T_IBREAK)
44 #define IS_WATCHPOINT_TRAP(type, code) ((type) == T_DBREAK)
45
46 #define FIXUP_PC_AFTER_BREAK(regs) ((regs)->tf_iioq_head -= sizeof(int))
47
48 #define DB_VALID_BREAKPOINT(addr) db_valid_breakpoint(addr)
49
inst_call(u_int ins)50 static __inline int inst_call(u_int ins) {
51 return (ins & 0xfc00e000) == 0xe8000000 ||
52 (ins & 0xfc00e000) == 0xe8004000 ||
53 (ins & 0xfc000000) == 0xe4000000;
54 }
inst_branch(u_int ins)55 static __inline int inst_branch(u_int ins) {
56 return (ins & 0xf0000000) == 0xe0000000 ||
57 (ins & 0xf0000000) == 0xc0000000 ||
58 (ins & 0xf0000000) == 0xa0000000 ||
59 (ins & 0xf0000000) == 0x80000000;
60 }
inst_return(u_int ins)61 static __inline int inst_return(u_int ins) {
62 return (ins & 0xfc00e000) == 0xe800c000 ||
63 (ins & 0xfc000000) == 0xe0000000;
64 }
inst_trap_return(u_int ins)65 static __inline int inst_trap_return(u_int ins) {
66 return (ins & 0xfc001fff) == 0x00000c00 || /* rfi */
67 (ins & 0xfc001fff) == 0x00000ca0; /* rfir */
68 }
69
70 #if 0
71 #define db_clear_single_step(r) ((r)->tf_flags &= ~(PSL_Z))
72 #define db_set_single_step(r) ((r)->tf_flags |= (PSL_Z))
73 #else
74 #define SOFTWARE_SSTEP 1
75 #define SOFTWARE_SSTEP_EMUL 1
76
77 static __inline vaddr_t
next_instr_address(vaddr_t addr,int b)78 next_instr_address(vaddr_t addr, int b) {
79 return (addr + 4);
80 }
81
82 #define branch_taken(ins,pc,f,regs) branch_taken1(ins, pc, regs)
83 static __inline vaddr_t
branch_taken1(int ins,vaddr_t pc,db_regs_t * regs)84 branch_taken1(int ins, vaddr_t pc, db_regs_t *regs) {
85 return (pc);
86 }
87
88 #endif
89
90 int db_valid_breakpoint(vaddr_t);
91 int db_ktrap(int, int, db_regs_t *);
92
93 #endif /* _MACHINE_DB_MACHDEP_H_ */
94