| 1 | /*	$OpenBSD: db_machdep.h,v 1.5 2021/08/30 08:11:12 jasper 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 long		db_expr_t; |
| 53 | |
| 54 | typedef trapframe_t	db_regs_t; |
| 55 | |
| 56 | extern db_regs_t	ddb_regs; |
| 57 | #define DDB_REGS	(&ddb_regs) |
| 58 | |
| 59 | #define	PC_REGS(regs)			((vaddr_t)(regs)->tf_ra) |
| 60 | #define	SET_PC_REGS(regs, value)	(regs)->tf_ra = (register_t)(value) |
| 61 | |
| 62 | #define	BKPT_INST	(KERNEL_BREAKPOINT) |
| 63 | #define	BKPT_SIZE	(INSN_SIZE) |
| 64 | #define	BKPT_SET(inst)	(BKPT_INST) |
| 65 | |
| 66 | #define	IS_BREAKPOINT_TRAP(type, code)	((type) == T_BREAKPOINT) |
| 67 | #define	IS_WATCHPOINT_TRAP(type, code)	((type) == T_WATCHPOINT) |
| 68 | |
| 69 | #define	inst_trap_return(ins)	(ins == 0x10000073)	/* eret */ |
| 70 | #define	inst_return(ins)	(ins == 0x00008067)	/* ret */ |
| 71 | #define	inst_call(ins)		(((ins) & 0x7f) == 0x6f || \ |
| 72 | 				 ((ins) & 0x7f) == 0x67)	/* jal, jalr */ |
| 73 | #define	inst_branch(ins)	(((ins) & 0x7f) == 0x63)	/* branch */ |
| 74 | |
| 75 | #define	next_instr_address(pc, bd)	((bd) ? (pc) : ((pc) + INSN_SIZE)) |
| 76 | |
| 77 | #define DB_MACHINE_COMMANDS |
| 78 | |
| 79 | #define SOFTWARE_SSTEP |
| 80 | |
| 81 | int db_trapper(vaddr_t, u_int, trapframe_t *, int); |
| 82 | void db_machine_init (void); |
| 83 | vaddr_t db_branch_taken(u_int inst, vaddr_t pc, db_regs_t *regs); |
| 84 | |
| 85 | #define branch_taken(ins, pc, fun, regs) \ |
| 86 | 	db_branch_taken((ins), (pc), (regs)) |
| 87 | |
| 88 | /* For ddb_state */ |
| 89 | #define DDB_STATE_NOT_RUNNING	0 |
| 90 | #define DDB_STATE_RUNNING	1 |
| 91 | #define DDB_STATE_EXITING	2 |
| 92 | |
| 93 | #endif /* !_MACHINE_DB_MACHDEP_H_ */ |