xref: /openbsd/sys/arch/hppa/include/db_machdep.h (revision 274d7c50)
1 /*	$OpenBSD: db_machdep.h,v 1.21 2019/11/07 14:44:53 mpi 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	vaddr_t db_addr_t;
27 typedef	long db_expr_t;
28 
29 typedef struct trapframe db_regs_t;
30 extern db_regs_t	ddb_regs;
31 
32 #define	PC_REGS(regs)	((vaddr_t)(regs)->tf_iioq_head)
33 #define	SET_PC_REGS(regs, value)					\
34 do {									\
35 	(regs)->tf_iioq_tail = 4 +					\
36 	    ((regs)->tf_iioq_head = (value));				\
37 } while (0)
38 
39 /* Breakpoint related definitions */
40 #define	BKPT_INST	0x00010000	/* break 0,8 */
41 #define	BKPT_SIZE	sizeof(int)
42 #define	BKPT_SET(inst)	BKPT_INST
43 
44 #define	IS_BREAKPOINT_TRAP(type, code) ((type) == T_IBREAK)
45 #define	IS_WATCHPOINT_TRAP(type, code) ((type) == T_DBREAK)
46 
47 #define	FIXUP_PC_AFTER_BREAK(regs) ((regs)->tf_iioq_head -= sizeof(int))
48 
49 #define DB_VALID_BREAKPOINT(addr) db_valid_breakpoint(addr)
50 
51 static __inline int inst_call(u_int ins) {
52 	return (ins & 0xfc00e000) == 0xe8000000 ||
53 	       (ins & 0xfc00e000) == 0xe8004000 ||
54 	       (ins & 0xfc000000) == 0xe4000000;
55 }
56 static __inline int inst_branch(u_int ins) {
57 	return (ins & 0xf0000000) == 0xe0000000 ||
58 	       (ins & 0xf0000000) == 0xc0000000 ||
59 	       (ins & 0xf0000000) == 0xa0000000 ||
60 	       (ins & 0xf0000000) == 0x80000000;
61 }
62 static __inline int inst_return(u_int ins) {
63 	return (ins & 0xfc00e000) == 0xe800c000 ||
64 	       (ins & 0xfc000000) == 0xe0000000;
65 }
66 static __inline int inst_trap_return(u_int ins)	{
67 	return (ins & 0xfc001fc0) == 0x00000ca0;
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
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
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