#ifndef _AARCH64_DB_MACHDEP_H_
#define _AARCH64_DB_MACHDEP_H_
#ifdef __aarch64__
#include <sys/types.h>
#include <sys/endian.h>
#include <uvm/uvm.h>
#include <aarch64/frame.h>
#include <aarch64/pmap.h>
#include <ddb/db_user.h>
typedef long long int db_expr_t;
#define DDB_EXPR_FMT "ll"
typedef uintptr_t db_addr_t;
#define BKPT_ADDR(addr) (addr)
#define BKPT_SIZE 4
#ifdef __AARCH64EB__
#define BKPT_INSN 0x000020d4
#else
#define BKPT_INSN 0xd4200000
#endif
#define BKPT_SET(insn, addr) (BKPT_INSN)
typedef struct trapframe db_regs_t;
extern db_regs_t ddb_regs;
#define DDB_REGS (&ddb_regs)
#define PC_REGS(tf) ((tf)->tf_pc)
int kdb_trap(int, struct trapframe *);
#define DB_TRAP_UNKNOWN 0
#define DB_TRAP_BREAKPOINT 1
#define DB_TRAP_BKPT_INSN 2
#define DB_TRAP_WATCHPOINT 3
#define DB_TRAP_SW_STEP 4
#define IS_BREAKPOINT_TRAP(type, code) \
((type) == DB_TRAP_BKPT_INSN)
#define IS_WATCHPOINT_TRAP(type, code) \
((type) == DB_TRAP_BREAKPOINT || (type) == DB_TRAP_WATCHPOINT)
static inline bool
inst_return(db_expr_t insn)
{
LE32TOH(insn);
return ((insn & 0xfffffc1f) == 0xd65f0000);
}
static inline bool
inst_trap_return(db_expr_t insn)
{
LE32TOH(insn);
return insn == 0xd69f03e0;
}
static inline bool
inst_call(db_expr_t insn)
{
LE32TOH(insn);
return ((insn & 0xfc000000) == 0x94000000)
|| ((insn & 0xfffffc1f) == 0xd63f0000);
}
static inline bool
inst_load(db_expr_t insn)
{
LE32TOH(insn);
return
((insn & 0xffe00c00) == 0xb8800000) ||
((insn & 0xffe00400) == 0xb8800400) ||
((insn & 0xffc00c00) == 0xb8800800) ||
((insn & 0xffc00000) == 0xb9800000) ||
((insn & 0xffc00000) == 0x39400000) ||
((insn & 0xff000000) == 0x98000000) ||
((insn & 0xfec00000) == 0x68c00000) ||
((insn & 0xefc00000) == 0x69400000) ||
((insn & 0xbfff0000) == 0x887f0000) ||
((insn & 0xbfc00000) == 0xb9400000) ||
((insn & 0xbfa00c00) == 0x38800000) ||
((insn & 0xbfa00400) == 0x38800400) ||
((insn & 0xbf800c00) == 0x38800800) ||
((insn & 0xbf800000) == 0x39800000) ||
((insn & 0xbf000000) == 0x18000000) ||
((insn & 0x7e400000) == 0x28400000) ||
((insn & 0x3ffffc00) == 0x085f7c00) ||
((insn & 0x3fe00c00) == 0x38400000) ||
((insn & 0x3fe00400) == 0x38400400) ||
((insn & 0x3fc00c00) == 0x38400800) ||
((insn & 0x3f7ffc00) == 0x085ffc00);
}
static inline bool
inst_store(db_expr_t insn)
{
LE32TOH(insn);
return
((insn & 0xbfe00000) == 0x88200000) ||
((insn & 0x7e400000) == 0x28000000) ||
((insn & 0x3ffffc00) == 0x089ffc00) ||
((insn & 0x3fe07c00) == 0x08007c00) ||
((insn & 0x3fe00c00) == 0x38000000) ||
((insn & 0x3fe00400) == 0x38000400) ||
((insn & 0x3fc00c00) == 0x38000800) ||
((insn & 0x3fc00000) == 0x39000000);
}
#define SOFTWARE_SSTEP
#ifdef SOFTWARE_SSTEP
static inline bool
inst_branch(db_expr_t insn)
{
LE32TOH(insn);
return
((insn & 0xff000010) == 0x54000000) ||
((insn & 0xfc000000) == 0x14000000) ||
((insn & 0xfffffc1f) == 0xd61f0000) ||
((insn & 0x7f000000) == 0x35000000) ||
((insn & 0x7f000000) == 0x34000000) ||
((insn & 0x7f000000) == 0x37000000) ||
((insn & 0x7f000000) == 0x36000000);
}
bool db_inst_unconditional_flow_transfer(db_expr_t);
db_addr_t db_branch_taken(db_expr_t, db_addr_t, db_regs_t *);
#define next_instr_address(pc, bd) \
((bd) ? (pc) : ((pc) + 4))
#define branch_taken(ins, pc, regs) \
db_branch_taken((ins), (pc), (regs))
#define inst_unconditional_flow_transfer(ins) \
db_inst_unconditional_flow_transfer(ins)
#endif
#define DB_MACHINE_COMMANDS
#ifdef _KERNEL
void db_pteinfo(vaddr_t, void (*)(const char *, ...) __printflike(1, 2));
void db_pte_print(pt_entry_t, int, void (*)(const char *, ...) __printflike(1, 2));
void db_ttbrdump(bool, vaddr_t, void (*pr)(const char *, ...) __printflike(1, 2));
void db_machdep_cpu_init(void);
void db_machdep_init(struct cpu_info * const);
void aarch64_breakpoint_set(int, vaddr_t);
void aarch64_watchpoint_set(int, vaddr_t, u_int, u_int);
#define WATCHPOINT_ACCESS_LOAD 0x01
#define WATCHPOINT_ACCESS_STORE 0x02
#define WATCHPOINT_ACCESS_LOADSTORE 0x03
#define WATCHPOINT_ACCESS_MASK 0x03
#endif
void dump_trapframe(struct trapframe *, void (*)(const char *, ...) __printflike(1, 2));
void dump_switchframe(struct trapframe *, void (*)(const char *, ...) __printflike(1, 2));
const char *strdisasm(vaddr_t, uint64_t);
#define DB_ELF_SYMBOLS
#elif defined(__arm__)
#include <arm/db_machdep.h>
#endif
#endif