xref: /openbsd/sys/arch/riscv64/include/db_machdep.h (revision 771fbea0)
1 /*	$OpenBSD: db_machdep.h,v 1.3 2021/05/12 01:20:52 jsg Exp $	*/
2 
3 /*
4  * Copyright (c) 2019 Brian Bamsch <bbamsch@google.com>
5  * Copyright (c) 2015-2016 Ruslan Bukin <br@bsdpad.com>
6  * All rights reserved.
7  *
8  * Portions of this software were developed by SRI International and the
9  * University of Cambridge Computer Laboratory under DARPA/AFRL contract
10  * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.
11  *
12  * Portions of this software were developed by the University of Cambridge
13  * Computer Laboratory as part of the CTSRD Project, with support from the
14  * UK Higher Education Innovation Fund (HEIF).
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  *    notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  * $FreeBSD$
38  */
39 
40 #ifndef	_MACHINE_DB_MACHDEP_H_
41 #define	_MACHINE_DB_MACHDEP_H_
42 
43 #include <sys/param.h>
44 #include <uvm/uvm_extern.h>
45 #include <machine/riscvreg.h>
46 #include <machine/frame.h>
47 #include <machine/trap.h>
48 
49 #define	T_BREAKPOINT	(EXCP_BREAKPOINT)
50 #define	T_WATCHPOINT	(0)
51 
52 typedef vaddr_t		db_addr_t;
53 typedef long		db_expr_t;
54 
55 typedef trapframe_t	db_regs_t;
56 
57 extern db_regs_t	ddb_regs;
58 #define DDB_REGS	(&ddb_regs)
59 
60 #define	PC_REGS(regs)			((db_addr_t)(regs)->tf_ra)
61 #define	SET_PC_REGS(regs, value)	(regs)->tf_ra = (register_t)(value)
62 
63 #define	BKPT_INST	(KERNEL_BREAKPOINT)
64 #define	BKPT_SIZE	(INSN_SIZE)
65 #define	BKPT_SET(inst)	(BKPT_INST)
66 
67 #define	IS_BREAKPOINT_TRAP(type, code)	((type) == T_BREAKPOINT)
68 #define	IS_WATCHPOINT_TRAP(type, code)	((type) == T_WATCHPOINT)
69 
70 #define	inst_trap_return(ins)	(ins == 0x10000073)	/* eret */
71 #define	inst_return(ins)	(ins == 0x00008067)	/* ret */
72 #define	inst_call(ins)		(((ins) & 0x7f) == 0x6f || \
73 				 ((ins) & 0x7f) == 0x67)	/* jal, jalr */
74 #define	inst_branch(ins)	(((ins) & 0x7f) == 0x63)	/* branch */
75 
76 #define	next_instr_address(pc, bd)	((bd) ? (pc) : ((pc) + INSN_SIZE))
77 
78 #define DB_MACHINE_COMMANDS
79 
80 #define SOFTWARE_SSTEP
81 
82 int db_trapper(vaddr_t, u_int, trapframe_t *, int);
83 void db_machine_init (void);
84 db_addr_t db_branch_taken(u_int inst, db_addr_t pc, db_regs_t *regs);
85 
86 #define branch_taken(ins, pc, fun, regs) \
87 	db_branch_taken((ins), (pc), (regs))
88 
89 /* For ddb_state */
90 #define DDB_STATE_NOT_RUNNING	0
91 #define DDB_STATE_RUNNING	1
92 #define DDB_STATE_EXITING	2
93 
94 #endif /* !_MACHINE_DB_MACHDEP_H_ */
95