Home | History | Annotate | Line # | Download | only in include
db_machdep.h revision 1.2.16.1
      1  1.2.16.1  pgoyette /* $NetBSD: db_machdep.h,v 1.2.16.1 2018/04/07 04:12:11 pgoyette Exp $ */
      2       1.1      matt 
      3       1.1      matt /*-
      4       1.1      matt  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      5       1.1      matt  * All rights reserved.
      6       1.1      matt  *
      7       1.1      matt  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1      matt  * by Matt Thomas of 3am Software Foundry.
      9       1.1      matt  *
     10       1.1      matt  * Redistribution and use in source and binary forms, with or without
     11       1.1      matt  * modification, are permitted provided that the following conditions
     12       1.1      matt  * are met:
     13       1.1      matt  * 1. Redistributions of source code must retain the above copyright
     14       1.1      matt  *    notice, this list of conditions and the following disclaimer.
     15       1.1      matt  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1      matt  *    notice, this list of conditions and the following disclaimer in the
     17       1.1      matt  *    documentation and/or other materials provided with the distribution.
     18       1.1      matt  *
     19       1.1      matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1      matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1      matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1      matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1      matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1      matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1      matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1      matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1      matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1      matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1      matt  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1      matt  */
     31       1.1      matt 
     32  1.2.16.1  pgoyette /*-
     33  1.2.16.1  pgoyette  * Copyright (c) 2014 Andrew Turner
     34  1.2.16.1  pgoyette  * Copyright (c) 2014-2015 The FreeBSD Foundation
     35  1.2.16.1  pgoyette  * All rights reserved.
     36  1.2.16.1  pgoyette  *
     37  1.2.16.1  pgoyette  * This software was developed by Semihalf under
     38  1.2.16.1  pgoyette  * sponsorship from the FreeBSD Foundation.
     39  1.2.16.1  pgoyette  *
     40  1.2.16.1  pgoyette  * Redistribution and use in source and binary forms, with or without
     41  1.2.16.1  pgoyette  * modification, are permitted provided that the following conditions
     42  1.2.16.1  pgoyette  * are met:
     43  1.2.16.1  pgoyette  * 1. Redistributions of source code must retain the above copyright
     44  1.2.16.1  pgoyette  *    notice, this list of conditions and the following disclaimer.
     45  1.2.16.1  pgoyette  * 2. Redistributions in binary form must reproduce the above copyright
     46  1.2.16.1  pgoyette  *    notice, this list of conditions and the following disclaimer in the
     47  1.2.16.1  pgoyette  *    documentation and/or other materials provided with the distribution.
     48  1.2.16.1  pgoyette  *
     49  1.2.16.1  pgoyette  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     50  1.2.16.1  pgoyette  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     51  1.2.16.1  pgoyette  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     52  1.2.16.1  pgoyette  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     53  1.2.16.1  pgoyette  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     54  1.2.16.1  pgoyette  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     55  1.2.16.1  pgoyette  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     56  1.2.16.1  pgoyette  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     57  1.2.16.1  pgoyette  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     58  1.2.16.1  pgoyette  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     59  1.2.16.1  pgoyette  * SUCH DAMAGE.
     60  1.2.16.1  pgoyette  *
     61  1.2.16.1  pgoyette  * $FreeBSD: head/sys/arm64/include/db_machdep.h 316001 2017-03-26 18:46:35Z bde $
     62  1.2.16.1  pgoyette  */
     63  1.2.16.1  pgoyette 
     64       1.1      matt #ifndef _AARCH64_DB_MACHDEP_H_
     65       1.1      matt #define _AARCH64_DB_MACHDEP_H_
     66       1.1      matt 
     67       1.1      matt #ifdef __aarch64__
     68       1.1      matt 
     69  1.2.16.1  pgoyette #include <sys/types.h>
     70       1.1      matt #include <aarch64/frame.h>
     71       1.1      matt 
     72       1.1      matt typedef long long int db_expr_t;
     73  1.2.16.1  pgoyette #define DDB_EXPR_FMT "ll"
     74       1.1      matt typedef uintptr_t db_addr_t;
     75       1.1      matt 
     76       1.1      matt #define BKPT_ADDR(addr)		(addr)
     77       1.1      matt #define BKPT_SIZE		4
     78  1.2.16.1  pgoyette #define BKPT_INSN		0xd4200000	/* brk #0 */
     79  1.2.16.1  pgoyette #define BKPT_SET(insn, addr)	(BKPT_INSN)
     80       1.1      matt 
     81       1.1      matt typedef struct trapframe db_regs_t;
     82       1.1      matt extern db_regs_t ddb_regs;
     83       1.1      matt #define DDB_REGS		(&ddb_regs)
     84       1.1      matt #define PC_REGS(tf)		((tf)->tf_pc)
     85       1.1      matt 
     86  1.2.16.1  pgoyette int kdb_trap(int, struct trapframe *);
     87  1.2.16.1  pgoyette #define DB_TRAP_UNKNOWN		0
     88  1.2.16.1  pgoyette #define DB_TRAP_BREAKPOINT	1
     89  1.2.16.1  pgoyette #define DB_TRAP_BKPT_INSN	2
     90  1.2.16.1  pgoyette #define DB_TRAP_WATCHPOINT	3
     91  1.2.16.1  pgoyette #define DB_TRAP_SW_STEP		4
     92       1.1      matt 
     93       1.1      matt #define IS_BREAKPOINT_TRAP(type, code) \
     94       1.1      matt 	((type) == DB_TRAP_BREAKPOINT || (type) == DB_TRAP_BKPT_INSN)
     95       1.1      matt #define IS_WATCHPOINT_TRAP(type, code) \
     96       1.1      matt 	((type) == DB_TRAP_WATCHPOINT)
     97       1.1      matt 
     98  1.2.16.1  pgoyette static inline bool
     99  1.2.16.1  pgoyette inst_return(db_expr_t insn)
    100       1.1      matt {
    101  1.2.16.1  pgoyette 	return ((insn & 0xfffffc1f) == 0xd65f0000);	/* ret xN */
    102       1.1      matt }
    103       1.1      matt 
    104       1.1      matt static inline bool
    105  1.2.16.1  pgoyette inst_trap_return(db_expr_t insn)
    106       1.1      matt {
    107  1.2.16.1  pgoyette 	return insn == 0xd69f03e0;			/* eret */
    108       1.1      matt }
    109       1.1      matt 
    110       1.1      matt static inline bool
    111  1.2.16.1  pgoyette inst_call(db_expr_t insn)
    112  1.2.16.1  pgoyette {
    113  1.2.16.1  pgoyette 	return ((insn & 0xfc000000) == 0x94000000)	/* bl */
    114  1.2.16.1  pgoyette 	    || ((insn & 0xfffffc1f) == 0xd63f0000);	/* blr */
    115  1.2.16.1  pgoyette }
    116  1.2.16.1  pgoyette 
    117  1.2.16.1  pgoyette static inline bool
    118  1.2.16.1  pgoyette inst_load(db_expr_t insn)
    119       1.1      matt {
    120  1.2.16.1  pgoyette 	return
    121  1.2.16.1  pgoyette 	    ((((insn) & 0x3b000000) == 0x18000000) || /* literal */
    122  1.2.16.1  pgoyette 	     (((insn) & 0x3f400000) == 0x08400000) || /* exclusive */
    123  1.2.16.1  pgoyette 	     (((insn) & 0x3bc00000) == 0x28400000) || /* no-allocate pair */
    124  1.2.16.1  pgoyette 	     ((((insn) & 0x3b200c00) == 0x38000400) &&
    125  1.2.16.1  pgoyette 	      (((insn) & 0x3be00c00) != 0x38000400) &&
    126  1.2.16.1  pgoyette 	      (((insn) & 0xffe00c00) != 0x3c800400)) || /* imm post-indexed */
    127  1.2.16.1  pgoyette 	     ((((insn) & 0x3b200c00) == 0x38000c00) &&
    128  1.2.16.1  pgoyette 	      (((insn) & 0x3be00c00) != 0x38000c00) &&
    129  1.2.16.1  pgoyette 	      (((insn) & 0xffe00c00) != 0x3c800c00)) || /* imm pre-indexed */
    130  1.2.16.1  pgoyette 	     ((((insn) & 0x3b200c00) == 0x38200800) &&
    131  1.2.16.1  pgoyette 	      (((insn) & 0x3be00c00) != 0x38200800) &&
    132  1.2.16.1  pgoyette 	      (((insn) & 0xffe00c00) != 0x3ca00c80)) || /* register offset */
    133  1.2.16.1  pgoyette 	     ((((insn) & 0x3b200c00) == 0x38000800) &&
    134  1.2.16.1  pgoyette 	      (((insn) & 0x3be00c00) != 0x38000800)) || /* unprivileged */
    135  1.2.16.1  pgoyette 	     ((((insn) & 0x3b200c00) == 0x38000000) &&
    136  1.2.16.1  pgoyette 	      (((insn) & 0x3be00c00) != 0x38000000) &&
    137  1.2.16.1  pgoyette 	      (((insn) & 0xffe00c00) != 0x3c800000)) || /* unscaled imm */
    138  1.2.16.1  pgoyette 	     ((((insn) & 0x3b000000) == 0x39000000) &&
    139  1.2.16.1  pgoyette 	      (((insn) & 0x3bc00000) != 0x39000000) &&
    140  1.2.16.1  pgoyette 	      (((insn) & 0xffc00000) != 0x3d800000)) || /* unsigned imm */
    141  1.2.16.1  pgoyette 	     (((insn) & 0x3bc00000) == 0x28400000) || /* pair (offset) */
    142  1.2.16.1  pgoyette 	     (((insn) & 0x3bc00000) == 0x28c00000) || /* pair (post-indexed) */
    143  1.2.16.1  pgoyette 	     (((insn) & 0x3bc00000) == 0x29800000)); /* pair (pre-indexed) */
    144       1.1      matt }
    145       1.1      matt 
    146       1.1      matt static inline bool
    147       1.1      matt inst_store(db_expr_t insn)
    148       1.1      matt {
    149  1.2.16.1  pgoyette 	return
    150  1.2.16.1  pgoyette 	    ((((insn) & 0x3f400000) == 0x08000000) || /* exclusive */
    151  1.2.16.1  pgoyette 	     (((insn) & 0x3bc00000) == 0x28000000) || /* no-allocate pair */
    152  1.2.16.1  pgoyette 	     ((((insn) & 0x3be00c00) == 0x38000400) ||
    153  1.2.16.1  pgoyette 	      (((insn) & 0xffe00c00) == 0x3c800400)) || /* imm post-indexed */
    154  1.2.16.1  pgoyette 	     ((((insn) & 0x3be00c00) == 0x38000c00) ||
    155  1.2.16.1  pgoyette 	      (((insn) & 0xffe00c00) == 0x3c800c00)) || /* imm pre-indexed */
    156  1.2.16.1  pgoyette 	     ((((insn) & 0x3be00c00) == 0x38200800) ||
    157  1.2.16.1  pgoyette 	      (((insn) & 0xffe00c00) == 0x3ca00800)) || /* register offset */
    158  1.2.16.1  pgoyette 	     (((insn) & 0x3be00c00) == 0x38000800) ||  /* unprivileged */
    159  1.2.16.1  pgoyette 	     ((((insn) & 0x3be00c00) == 0x38000000) ||
    160  1.2.16.1  pgoyette 	      (((insn) & 0xffe00c00) == 0x3c800000)) || /* unscaled imm */
    161  1.2.16.1  pgoyette 	     ((((insn) & 0x3bc00000) == 0x39000000) ||
    162  1.2.16.1  pgoyette 	      (((insn) & 0xffc00000) == 0x3d800000)) || /* unsigned imm */
    163  1.2.16.1  pgoyette 	     (((insn) & 0x3bc00000) == 0x28000000) || /* pair (offset) */
    164  1.2.16.1  pgoyette 	     (((insn) & 0x3bc00000) == 0x28800000) || /* pair (post-indexed) */
    165  1.2.16.1  pgoyette 	     (((insn) & 0x3bc00000) == 0x29800000)); /* pair (pre-indexed) */
    166       1.1      matt }
    167       1.1      matt 
    168  1.2.16.1  pgoyette #define SOFTWARE_SSTEP
    169  1.2.16.1  pgoyette 
    170  1.2.16.1  pgoyette #ifdef SOFTWARE_SSTEP
    171  1.2.16.1  pgoyette 
    172       1.1      matt static inline bool
    173  1.2.16.1  pgoyette inst_branch(db_expr_t insn)
    174       1.1      matt {
    175  1.2.16.1  pgoyette 	return
    176  1.2.16.1  pgoyette 	    ((insn & 0xff000010) == 0x54000000) ||	/* b.cond */
    177  1.2.16.1  pgoyette 	    ((insn & 0xfc000000) == 0x14000000) ||	/* b imm */
    178  1.2.16.1  pgoyette 	    ((insn & 0xfffffc1f) == 0xd61f0000) ||	/* br */
    179  1.2.16.1  pgoyette 	    ((insn & 0x7f000000) == 0x35000000) ||	/* cbnz */
    180  1.2.16.1  pgoyette 	    ((insn & 0x7f000000) == 0x34000000) ||	/* cbz */
    181  1.2.16.1  pgoyette 	    ((insn & 0x7f000000) == 0x37000000) ||	/* tbnz */
    182  1.2.16.1  pgoyette 	    ((insn & 0x7f000000) == 0x36000000);	/* tbz */
    183       1.1      matt }
    184       1.1      matt 
    185  1.2.16.1  pgoyette bool db_inst_unconditional_flow_transfer(db_expr_t);
    186  1.2.16.1  pgoyette db_addr_t db_branch_taken(db_expr_t, db_addr_t, db_regs_t *);
    187  1.2.16.1  pgoyette 
    188  1.2.16.1  pgoyette #define next_instr_address(pc, bd)		\
    189  1.2.16.1  pgoyette 	    ((bd) ? (pc) : ((pc) + 4))
    190  1.2.16.1  pgoyette #define branch_taken(ins, pc, regs)		\
    191  1.2.16.1  pgoyette 	    db_branch_taken((ins), (pc), (regs))
    192  1.2.16.1  pgoyette #define inst_unconditional_flow_transfer(ins)	\
    193  1.2.16.1  pgoyette 	    db_inst_unconditional_flow_transfer(ins)
    194  1.2.16.1  pgoyette 
    195  1.2.16.1  pgoyette #endif /* SOFTWARE_SSTEP */
    196  1.2.16.1  pgoyette 
    197  1.2.16.1  pgoyette #define DB_MACHINE_COMMANDS
    198  1.2.16.1  pgoyette void dump_trapframe(struct trapframe *, void (*)(const char *, ...));
    199  1.2.16.1  pgoyette 
    200  1.2.16.1  pgoyette 
    201  1.2.16.1  pgoyette 
    202  1.2.16.1  pgoyette void db_machdep_init(void);
    203  1.2.16.1  pgoyette 
    204  1.2.16.1  pgoyette /* hardware breakpoint/watchpoint functions */
    205  1.2.16.1  pgoyette void aarch64_breakpoint_clear(int);
    206  1.2.16.1  pgoyette void aarch64_breakpoint_set(int, vaddr_t);
    207  1.2.16.1  pgoyette void aarch64_watchpoint_clear(int);
    208  1.2.16.1  pgoyette void aarch64_watchpoint_set(int, vaddr_t, int, int);
    209  1.2.16.1  pgoyette #define WATCHPOINT_ACCESS_LOAD		0x01
    210  1.2.16.1  pgoyette #define WATCHPOINT_ACCESS_STORE		0x02
    211  1.2.16.1  pgoyette #define WATCHPOINT_ACCESS_LOADSTORE	0x03
    212  1.2.16.1  pgoyette #define WATCHPOINT_ACCESS_MASK		0x03
    213  1.2.16.1  pgoyette 
    214  1.2.16.1  pgoyette 
    215       1.1      matt #elif defined(__arm__)
    216       1.1      matt 
    217       1.1      matt #include <arm/db_machdep.h>
    218       1.1      matt 
    219       1.1      matt #endif
    220       1.1      matt 
    221       1.1      matt #endif /* _AARCH64_DB_MACHDEP_H_ */
    222