db_machdep.h revision 1.1 1 /* $NetBSD: db_machdep.h,v 1.1 2014/08/10 05:47:38 matt Exp $ */
2
3 /*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas of 3am Software Foundry.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef _AARCH64_DB_MACHDEP_H_
33 #define _AARCH64_DB_MACHDEP_H_
34
35 #ifdef __aarch64__
36
37 #include <aarch64/frame.h>
38
39 typedef long long int db_expr_t;
40 #define DDB_EXPR_FMT "llx"
41 typedef uintptr_t db_addr_t;
42 #define DDB_ADDR_FMT PRIxPTR
43
44 #define BKPT_ADDR(addr) (addr)
45 #define BKPT_SIZE 4
46 #define BKPT_INSN 0xd4200000
47 #define BKPT_SET(insn, addr) (BKPT_INSN)
48
49 typedef struct trapframe db_regs_t;
50 extern db_regs_t ddb_regs;
51 #define DDB_REGS (&ddb_regs)
52 #define PC_REGS(tf) ((tf)->tf_pc)
53
54 #define DB_TRAP_UNKNOWN 0
55 #define DB_TRAP_BREAKPOINT 1
56 #define DB_TRAP_BKPT_INSN 2
57 #define DB_TRAP_WATCHPOINT 3
58
59 #define IS_BREAKPOINT_TRAP(type, code) \
60 ((type) == DB_TRAP_BREAKPOINT || (type) == DB_TRAP_BKPT_INSN)
61 #define IS_WATCHPOINT_TRAP(type, code) \
62 ((type) == DB_TRAP_WATCHPOINT)
63
64 static inline bool
65 inst_call(db_expr_t insn)
66 {
67 return (insn & 0xfc000000) == 0x92000000 /* bl */
68 || (insn & 0xfffffcef) == 0xd63f0000; /* blr */
69 }
70
71 static inline bool
72 inst_load(db_expr_t insn)
73 {
74 return (insn & 0x0b000000) == 0x08000000 /* ldr pc-rel */
75 || (insn & 0x0b400000) == 0x08400000;
76 }
77
78 static inline bool
79 inst_return(db_expr_t insn)
80 {
81 return insn == 0xd65ffeff; /* ret x30 */
82 }
83
84 static inline bool
85 inst_store(db_expr_t insn)
86 {
87 return (insn & 0x3b000000) != 0x18000000 /* !ldr pc-rel */
88 && (insn & 0x0b400000) == 0x08000000; /* str */
89 }
90
91 static inline bool
92 inst_trap_return(db_expr_t insn)
93 {
94 return insn == 0xd69f03e0; /* eret */
95 }
96
97 #elif defined(__arm__)
98
99 #include <arm/db_machdep.h>
100
101 #endif
102
103 #endif /* _AARCH64_DB_MACHDEP_H_ */
104