1292407Sbr/*- 2296614Sbr * Copyright (c) 2015-2016 Ruslan Bukin <br@bsdpad.com> 3292407Sbr * All rights reserved. 4292407Sbr * 5292407Sbr * Portions of this software were developed by SRI International and the 6292407Sbr * University of Cambridge Computer Laboratory under DARPA/AFRL contract 7292407Sbr * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. 8292407Sbr * 9292407Sbr * Portions of this software were developed by the University of Cambridge 10292407Sbr * Computer Laboratory as part of the CTSRD Project, with support from the 11292407Sbr * UK Higher Education Innovation Fund (HEIF). 12292407Sbr * 13292407Sbr * Redistribution and use in source and binary forms, with or without 14292407Sbr * modification, are permitted provided that the following conditions 15292407Sbr * are met: 16292407Sbr * 1. Redistributions of source code must retain the above copyright 17292407Sbr * notice, this list of conditions and the following disclaimer. 18292407Sbr * 2. Redistributions in binary form must reproduce the above copyright 19292407Sbr * notice, this list of conditions and the following disclaimer in the 20292407Sbr * documentation and/or other materials provided with the distribution. 21292407Sbr * 22292407Sbr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23292407Sbr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24292407Sbr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25292407Sbr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 26292407Sbr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27292407Sbr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28292407Sbr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29292407Sbr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30292407Sbr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31292407Sbr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32292407Sbr * SUCH DAMAGE. 33292407Sbr * 34292407Sbr * $FreeBSD$ 35292407Sbr */ 36292407Sbr 37292407Sbr#ifndef _MACHINE_DB_MACHDEP_H_ 38292407Sbr#define _MACHINE_DB_MACHDEP_H_ 39292407Sbr 40292407Sbr#include <machine/riscvreg.h> 41292407Sbr#include <machine/frame.h> 42292407Sbr#include <machine/trap.h> 43292407Sbr 44296614Sbr#define T_BREAKPOINT (EXCP_INSTR_BREAKPOINT) 45296614Sbr#define T_WATCHPOINT (0) 46296614Sbr 47292407Sbrtypedef vm_offset_t db_addr_t; 48292407Sbrtypedef long db_expr_t; 49292407Sbr 50296614Sbr#define PC_REGS() ((db_addr_t)kdb_thrctx->pcb_sepc) 51296614Sbr 52296614Sbr#define BKPT_INST (0x00100073) 53296614Sbr#define BKPT_SIZE (INSN_SIZE) 54296614Sbr#define BKPT_SET(inst) (BKPT_INST) 55296614Sbr 56296614Sbr#define BKPT_SKIP do { \ 57296614Sbr kdb_frame->tf_sepc += BKPT_SIZE; \ 58296614Sbr} while (0) 59296614Sbr 60296614Sbr#define db_clear_single_step kdb_cpu_clear_singlestep 61296614Sbr#define db_set_single_step kdb_cpu_set_singlestep 62296614Sbr 63296614Sbr#define IS_BREAKPOINT_TRAP(type, code) (type == T_BREAKPOINT) 64296614Sbr#define IS_WATCHPOINT_TRAP(type, code) (type == T_WATCHPOINT) 65296614Sbr 66296614Sbr#define inst_trap_return(ins) (ins == 0x10000073) /* eret */ 67296614Sbr#define inst_return(ins) (ins == 0x00008067) /* ret */ 68296614Sbr#define inst_call(ins) (((ins) & 0x7f) == 111 || \ 69296614Sbr ((ins) & 0x7f) == 103) /* jal, jalr */ 70296614Sbr 71296614Sbr#define inst_load(ins) ({ \ 72296614Sbr uint32_t tmp_instr = db_get_value(PC_REGS(), sizeof(uint32_t), FALSE); \ 73296614Sbr is_load_instr(tmp_instr); \ 74296614Sbr}) 75296614Sbr 76296614Sbr#define inst_store(ins) ({ \ 77296614Sbr uint32_t tmp_instr = db_get_value(PC_REGS(), sizeof(uint32_t), FALSE); \ 78296614Sbr is_store_instr(tmp_instr); \ 79296614Sbr}) 80296614Sbr 81296614Sbr#define is_load_instr(ins) (((ins) & 0x7f) == 3) 82296614Sbr#define is_store_instr(ins) (((ins) & 0x7f) == 35) 83296614Sbr 84296614Sbr#define next_instr_address(pc, bd) ((bd) ? (pc) : ((pc) + 4)) 85296614Sbr 86296614Sbr#define DB_SMALL_VALUE_MAX (0x7fffffff) 87296614Sbr#define DB_SMALL_VALUE_MIN (-0x40001) 88296614Sbr 89296614Sbr#define DB_ELFSIZE 64 90296614Sbr 91292407Sbr#endif /* !_MACHINE_DB_MACHDEP_H_ */ 92