Home | History | Annotate | Line # | Download | only in include
      1  1.16     skrll /* $NetBSD: db_machdep.h,v 1.16 2021/10/31 22:06:32 skrll 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.3       ryo /*-
     33   1.3       ryo  * Copyright (c) 2014 Andrew Turner
     34   1.3       ryo  * Copyright (c) 2014-2015 The FreeBSD Foundation
     35   1.3       ryo  * All rights reserved.
     36   1.3       ryo  *
     37   1.3       ryo  * This software was developed by Semihalf under
     38   1.3       ryo  * sponsorship from the FreeBSD Foundation.
     39   1.3       ryo  *
     40   1.3       ryo  * Redistribution and use in source and binary forms, with or without
     41   1.3       ryo  * modification, are permitted provided that the following conditions
     42   1.3       ryo  * are met:
     43   1.3       ryo  * 1. Redistributions of source code must retain the above copyright
     44   1.3       ryo  *    notice, this list of conditions and the following disclaimer.
     45   1.3       ryo  * 2. Redistributions in binary form must reproduce the above copyright
     46   1.3       ryo  *    notice, this list of conditions and the following disclaimer in the
     47   1.3       ryo  *    documentation and/or other materials provided with the distribution.
     48   1.3       ryo  *
     49   1.3       ryo  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     50   1.3       ryo  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     51   1.3       ryo  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     52   1.3       ryo  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     53   1.3       ryo  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     54   1.3       ryo  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     55   1.3       ryo  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     56   1.3       ryo  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     57   1.3       ryo  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     58   1.3       ryo  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     59   1.3       ryo  * SUCH DAMAGE.
     60   1.3       ryo  *
     61   1.3       ryo  * $FreeBSD: head/sys/arm64/include/db_machdep.h 316001 2017-03-26 18:46:35Z bde $
     62   1.3       ryo  */
     63   1.3       ryo 
     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.3       ryo #include <sys/types.h>
     70  1.14     skrll 
     71  1.14     skrll #include <uvm/uvm.h>
     72  1.14     skrll 
     73   1.1      matt #include <aarch64/frame.h>
     74  1.14     skrll #include <aarch64/pmap.h>
     75  1.14     skrll 
     76   1.7  jakllsch #include <ddb/db_user.h>
     77   1.1      matt 
     78   1.1      matt typedef long long int db_expr_t;
     79   1.3       ryo #define DDB_EXPR_FMT "ll"
     80   1.1      matt typedef uintptr_t db_addr_t;
     81   1.1      matt 
     82   1.1      matt #define BKPT_ADDR(addr)		(addr)
     83   1.1      matt #define BKPT_SIZE		4
     84  1.11       ryo #ifdef __AARCH64EB__
     85  1.11       ryo #define BKPT_INSN		0x000020d4	/* brk #0 */
     86  1.11       ryo #else
     87   1.3       ryo #define BKPT_INSN		0xd4200000	/* brk #0 */
     88  1.11       ryo #endif
     89   1.3       ryo #define BKPT_SET(insn, addr)	(BKPT_INSN)
     90   1.1      matt 
     91   1.1      matt typedef struct trapframe db_regs_t;
     92   1.1      matt extern db_regs_t ddb_regs;
     93   1.1      matt #define DDB_REGS		(&ddb_regs)
     94   1.1      matt #define PC_REGS(tf)		((tf)->tf_pc)
     95   1.1      matt 
     96   1.3       ryo int kdb_trap(int, struct trapframe *);
     97   1.3       ryo #define DB_TRAP_UNKNOWN		0
     98   1.3       ryo #define DB_TRAP_BREAKPOINT	1
     99   1.3       ryo #define DB_TRAP_BKPT_INSN	2
    100   1.3       ryo #define DB_TRAP_WATCHPOINT	3
    101   1.3       ryo #define DB_TRAP_SW_STEP		4
    102   1.1      matt 
    103   1.1      matt #define IS_BREAKPOINT_TRAP(type, code) \
    104  1.12       ryo 	((type) == DB_TRAP_BKPT_INSN)
    105   1.1      matt #define IS_WATCHPOINT_TRAP(type, code) \
    106  1.12       ryo 	((type) == DB_TRAP_BREAKPOINT || (type) == DB_TRAP_WATCHPOINT)
    107   1.1      matt 
    108   1.3       ryo static inline bool
    109   1.3       ryo inst_return(db_expr_t insn)
    110   1.3       ryo {
    111  1.11       ryo 	LE32TOH(insn);
    112   1.3       ryo 	return ((insn & 0xfffffc1f) == 0xd65f0000);	/* ret xN */
    113   1.3       ryo }
    114   1.3       ryo 
    115   1.3       ryo static inline bool
    116   1.3       ryo inst_trap_return(db_expr_t insn)
    117   1.1      matt {
    118  1.11       ryo 	LE32TOH(insn);
    119   1.3       ryo 	return insn == 0xd69f03e0;			/* eret */
    120   1.1      matt }
    121   1.1      matt 
    122   1.1      matt static inline bool
    123   1.3       ryo inst_call(db_expr_t insn)
    124   1.1      matt {
    125  1.11       ryo 	LE32TOH(insn);
    126   1.3       ryo 	return ((insn & 0xfc000000) == 0x94000000)	/* bl */
    127   1.3       ryo 	    || ((insn & 0xfffffc1f) == 0xd63f0000);	/* blr */
    128   1.1      matt }
    129   1.1      matt 
    130   1.1      matt static inline bool
    131   1.3       ryo inst_load(db_expr_t insn)
    132   1.1      matt {
    133  1.11       ryo 	LE32TOH(insn);
    134   1.3       ryo 	return
    135   1.4       ryo 	    ((insn & 0xffe00c00) == 0xb8800000) ||	/* ldursw */
    136   1.5       ryo 	    /* ldrsw imm{pre,post}idx */
    137   1.5       ryo 	    ((insn & 0xffe00400) == 0xb8800400) ||
    138   1.5       ryo 	    ((insn & 0xffc00c00) == 0xb8800800) ||	/* ldrsw reg,ldtrsw */
    139   1.4       ryo 	    ((insn & 0xffc00000) == 0xb9800000) ||	/* ldrsw immunsign */
    140   1.4       ryo 	    ((insn & 0xffc00000) == 0x39400000) ||	/* ldrb immunsign */
    141   1.4       ryo 	    ((insn & 0xff000000) == 0x98000000) ||	/* ldrsw literal */
    142   1.5       ryo 	    /* ldpsw {pre,post}idx */
    143   1.5       ryo 	    ((insn & 0xfec00000) == 0x68c00000) ||
    144   1.4       ryo 	    /* ldrh immunsign,ldpsw signed */
    145   1.5       ryo 	    ((insn & 0xefc00000) == 0x69400000) ||
    146   1.5       ryo 	    ((insn & 0xbfff0000) == 0x887f0000) ||	/* ldaxp,ldxp */
    147   1.4       ryo 	    ((insn & 0xbfc00000) == 0xb9400000) ||	/* ldr immunsign */
    148   1.5       ryo 	    ((insn & 0xbfa00c00) == 0x38800000) ||	/* ldursh,ldursb */
    149   1.5       ryo 	    /* ldrsh imm{pre,post}idx,ldrsb imm{pre,post}idx */
    150   1.5       ryo 	    ((insn & 0xbfa00400) == 0x38800400) ||
    151   1.4       ryo 	    /* ldrs[bh] reg,ldtrs[bh] */
    152   1.5       ryo 	    ((insn & 0xbf800c00) == 0x38800800) ||
    153   1.5       ryo 	    /* ldrsh immunsign,ldrsb immunsign */
    154   1.5       ryo 	    ((insn & 0xbf800000) == 0x39800000) ||
    155   1.4       ryo 	    ((insn & 0xbf000000) == 0x18000000) ||	/* ldr literal */
    156   1.5       ryo 	    /* ldp {pre,post}idx,ldp signed,ldnp */
    157   1.5       ryo 	    ((insn & 0x7e400000) == 0x28400000) ||
    158   1.5       ryo 	    ((insn & 0x3ffffc00) == 0x085f7c00) ||	/* ldxr,ldxr[bh] */
    159   1.5       ryo 	    ((insn & 0x3fe00c00) == 0x38400000) ||	/* ldur,ldur[bh] */
    160   1.5       ryo 	    /* ldr imm{pre,post}idx,ldr[bh]_imm{pre,post}idx */
    161   1.5       ryo 	    ((insn & 0x3fe00400) == 0x38400400) ||
    162   1.5       ryo 	    /* ldtr,ldtr[bh],ldr_reg,ldr[bh]_reg */
    163   1.5       ryo 	    ((insn & 0x3fc00c00) == 0x38400800) ||
    164   1.5       ryo 	    /* ldaxr,ldaxr[bh],ldar,ldar[bh] */
    165   1.5       ryo 	    ((insn & 0x3f7ffc00) == 0x085ffc00);
    166   1.1      matt }
    167   1.1      matt 
    168   1.1      matt static inline bool
    169   1.1      matt inst_store(db_expr_t insn)
    170   1.1      matt {
    171  1.11       ryo 	LE32TOH(insn);
    172   1.3       ryo 	return
    173   1.5       ryo 	    ((insn & 0xbfe00000) == 0x88200000) ||	/* stlxp,stxp */
    174   1.5       ryo 	    /* stp {pre,post}idx,stp signed,stnp */
    175   1.5       ryo 	    ((insn & 0x7e400000) == 0x28000000) ||
    176   1.5       ryo 	    ((insn & 0x3ffffc00) == 0x089ffc00) ||	/* stlr,stlr[bh] */
    177   1.5       ryo 	    /* stlxr,stlxr[bh],stxr,stxr[bh] */
    178   1.5       ryo 	    ((insn & 0x3fe07c00) == 0x08007c00) ||
    179   1.5       ryo 	    ((insn & 0x3fe00c00) == 0x38000000) ||	/* stur,stur[bh] */
    180   1.5       ryo 	    /* str imm{pre,post}idx,str[bh] imm{pre,post}idx */
    181   1.5       ryo 	    ((insn & 0x3fe00400) == 0x38000400) ||
    182   1.5       ryo 	    /* str reg,str[bh] reg,sttr,sttr[bh] */
    183   1.5       ryo 	    ((insn & 0x3fc00c00) == 0x38000800) ||
    184   1.5       ryo 	    /* str immunsign,str[bh] immunsign */
    185   1.5       ryo 	    ((insn & 0x3fc00000) == 0x39000000);
    186   1.1      matt }
    187   1.1      matt 
    188   1.3       ryo #define SOFTWARE_SSTEP
    189   1.3       ryo 
    190   1.3       ryo #ifdef SOFTWARE_SSTEP
    191   1.3       ryo 
    192   1.1      matt static inline bool
    193   1.3       ryo inst_branch(db_expr_t insn)
    194   1.1      matt {
    195  1.11       ryo 	LE32TOH(insn);
    196   1.3       ryo 	return
    197   1.3       ryo 	    ((insn & 0xff000010) == 0x54000000) ||	/* b.cond */
    198   1.3       ryo 	    ((insn & 0xfc000000) == 0x14000000) ||	/* b imm */
    199   1.3       ryo 	    ((insn & 0xfffffc1f) == 0xd61f0000) ||	/* br */
    200   1.3       ryo 	    ((insn & 0x7f000000) == 0x35000000) ||	/* cbnz */
    201   1.3       ryo 	    ((insn & 0x7f000000) == 0x34000000) ||	/* cbz */
    202   1.3       ryo 	    ((insn & 0x7f000000) == 0x37000000) ||	/* tbnz */
    203   1.3       ryo 	    ((insn & 0x7f000000) == 0x36000000);	/* tbz */
    204   1.1      matt }
    205   1.1      matt 
    206   1.3       ryo bool db_inst_unconditional_flow_transfer(db_expr_t);
    207   1.3       ryo db_addr_t db_branch_taken(db_expr_t, db_addr_t, db_regs_t *);
    208   1.3       ryo 
    209   1.3       ryo #define next_instr_address(pc, bd)		\
    210   1.3       ryo 	    ((bd) ? (pc) : ((pc) + 4))
    211   1.3       ryo #define branch_taken(ins, pc, regs)		\
    212   1.3       ryo 	    db_branch_taken((ins), (pc), (regs))
    213   1.3       ryo #define inst_unconditional_flow_transfer(ins)	\
    214   1.3       ryo 	    db_inst_unconditional_flow_transfer(ins)
    215   1.3       ryo 
    216   1.3       ryo #endif /* SOFTWARE_SSTEP */
    217   1.3       ryo 
    218   1.3       ryo #define DB_MACHINE_COMMANDS
    219  1.14     skrll 
    220  1.14     skrll #ifdef _KERNEL
    221  1.14     skrll void db_pteinfo(vaddr_t, void (*)(const char *, ...) __printflike(1, 2));
    222  1.14     skrll void db_pte_print(pt_entry_t, int, void (*)(const char *, ...) __printflike(1, 2));
    223  1.14     skrll void db_ttbrdump(bool, vaddr_t, void (*pr)(const char *, ...) __printflike(1, 2));
    224  1.15     skrll void db_machdep_cpu_init(void);
    225  1.15     skrll void db_machdep_init(struct cpu_info * const);
    226   1.3       ryo 
    227   1.3       ryo /* hardware breakpoint/watchpoint functions */
    228   1.3       ryo void aarch64_breakpoint_set(int, vaddr_t);
    229  1.13       ryo void aarch64_watchpoint_set(int, vaddr_t, u_int, u_int);
    230   1.3       ryo #define WATCHPOINT_ACCESS_LOAD		0x01
    231   1.3       ryo #define WATCHPOINT_ACCESS_STORE		0x02
    232   1.3       ryo #define WATCHPOINT_ACCESS_LOADSTORE	0x03
    233   1.3       ryo #define WATCHPOINT_ACCESS_MASK		0x03
    234  1.16     skrll #endif
    235  1.16     skrll 
    236  1.16     skrll void dump_trapframe(struct trapframe *, void (*)(const char *, ...) __printflike(1, 2));
    237  1.16     skrll 
    238  1.16     skrll void dump_switchframe(struct trapframe *, void (*)(const char *, ...) __printflike(1, 2));
    239  1.16     skrll const char *strdisasm(vaddr_t, uint64_t);
    240   1.3       ryo 
    241   1.7  jakllsch #define DB_ELF_SYMBOLS
    242   1.3       ryo 
    243   1.1      matt #elif defined(__arm__)
    244   1.1      matt 
    245   1.1      matt #include <arm/db_machdep.h>
    246   1.1      matt 
    247   1.1      matt #endif
    248   1.1      matt 
    249   1.1      matt #endif /* _AARCH64_DB_MACHDEP_H_ */
    250