]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm64/arm64/db_interface.c
FEATURE compat_freebsd_32bit: only report on arm64 when support is present
[FreeBSD/FreeBSD.git] / sys / arm64 / arm64 / db_interface.c
1 /*-
2  * Copyright (c) 2015 The FreeBSD Foundation
3  *
4  * This software was developed by Semihalf under
5  * the sponsorship of the FreeBSD Foundation.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28
29 #include <sys/cdefs.h>
30 #include <sys/param.h>
31 #include <sys/proc.h>
32 #include <vm/vm.h>
33 #include <vm/pmap.h>
34 #include <vm/vm_map.h>
35
36 #ifdef KDB
37 #include <sys/kdb.h>
38 #endif
39
40 #include <ddb/ddb.h>
41 #include <ddb/db_variables.h>
42
43 #include <machine/cpu.h>
44 #include <machine/pcb.h>
45 #include <machine/stack.h>
46 #include <machine/vmparam.h>
47
48 static int
49 db_frame(struct db_variable *vp, db_expr_t *valuep, int op)
50 {
51         long *reg;
52
53         if (kdb_frame == NULL)
54                 return (0);
55
56         reg = (long *)((uintptr_t)kdb_frame + (db_expr_t)vp->valuep);
57         if (op == DB_VAR_GET)
58                 *valuep = *reg;
59         else
60                 *reg = *valuep;
61         return (1);
62 }
63
64 #define DB_OFFSET(x)    (db_expr_t *)offsetof(struct trapframe, x)
65 struct db_variable db_regs[] = {
66         { "spsr", DB_OFFSET(tf_spsr),   db_frame },
67         { "x0", DB_OFFSET(tf_x[0]),     db_frame },
68         { "x1", DB_OFFSET(tf_x[1]),     db_frame },
69         { "x2", DB_OFFSET(tf_x[2]),     db_frame },
70         { "x3", DB_OFFSET(tf_x[3]),     db_frame },
71         { "x4", DB_OFFSET(tf_x[4]),     db_frame },
72         { "x5", DB_OFFSET(tf_x[5]),     db_frame },
73         { "x6", DB_OFFSET(tf_x[6]),     db_frame },
74         { "x7", DB_OFFSET(tf_x[7]),     db_frame },
75         { "x8", DB_OFFSET(tf_x[8]),     db_frame },
76         { "x9", DB_OFFSET(tf_x[9]),     db_frame },
77         { "x10", DB_OFFSET(tf_x[10]),   db_frame },
78         { "x11", DB_OFFSET(tf_x[11]),   db_frame },
79         { "x12", DB_OFFSET(tf_x[12]),   db_frame },
80         { "x13", DB_OFFSET(tf_x[13]),   db_frame },
81         { "x14", DB_OFFSET(tf_x[14]),   db_frame },
82         { "x15", DB_OFFSET(tf_x[15]),   db_frame },
83         { "x16", DB_OFFSET(tf_x[16]),   db_frame },
84         { "x17", DB_OFFSET(tf_x[17]),   db_frame },
85         { "x18", DB_OFFSET(tf_x[18]),   db_frame },
86         { "x19", DB_OFFSET(tf_x[19]),   db_frame },
87         { "x20", DB_OFFSET(tf_x[20]),   db_frame },
88         { "x21", DB_OFFSET(tf_x[21]),   db_frame },
89         { "x22", DB_OFFSET(tf_x[22]),   db_frame },
90         { "x23", DB_OFFSET(tf_x[23]),   db_frame },
91         { "x24", DB_OFFSET(tf_x[24]),   db_frame },
92         { "x25", DB_OFFSET(tf_x[25]),   db_frame },
93         { "x26", DB_OFFSET(tf_x[26]),   db_frame },
94         { "x27", DB_OFFSET(tf_x[27]),   db_frame },
95         { "x28", DB_OFFSET(tf_x[28]),   db_frame },
96         { "x29", DB_OFFSET(tf_x[29]),   db_frame },
97         { "lr", DB_OFFSET(tf_lr),       db_frame },
98         { "elr", DB_OFFSET(tf_elr),     db_frame },
99         { "sp", DB_OFFSET(tf_sp), db_frame },
100 };
101
102 struct db_variable *db_eregs = db_regs + nitems(db_regs);
103
104 void
105 db_show_mdpcpu(struct pcpu *pc)
106 {
107 }
108
109 /*
110  * Read bytes from kernel address space for debugger.
111  */
112 int
113 db_read_bytes(vm_offset_t addr, size_t size, char *data)
114 {
115         jmp_buf jb;
116         void *prev_jb;
117         const char *src;
118         int ret;
119         uint64_t tmp64;
120         uint32_t tmp32;
121         uint16_t tmp16;
122
123         prev_jb = kdb_jmpbuf(jb);
124         ret = setjmp(jb);
125
126         if (ret == 0) {
127                 src = (const char *)addr;
128                 if (size == 8 && (addr & 7) == 0) {
129                         tmp64 = *((const int *)src);
130                         src = (const char *)&tmp64;
131                 } else if (size == 4 && (addr & 3) == 0) {
132                         tmp32 = *((const int *)src);
133                         src = (const char *)&tmp32;
134                 } else if (size == 2 && (addr & 1) == 0) {
135                         tmp16 = *((const short *)src);
136                         src = (const char *)&tmp16;
137                 }
138                 while (size-- > 0)
139                         *data++ = *src++;
140         }
141         (void)kdb_jmpbuf(prev_jb);
142
143         return (ret);
144 }
145
146 /*
147  * Write bytes to kernel address space for debugger.
148  */
149 int
150 db_write_bytes(vm_offset_t addr, size_t size, char *data)
151 {
152         jmp_buf jb;
153         void *prev_jb;
154         char *dst;
155         size_t i;
156         int ret;
157
158         prev_jb = kdb_jmpbuf(jb);
159         ret = setjmp(jb);
160         if (ret == 0) {
161                 if (!arm64_get_writable_addr(addr, &addr)) {
162                         ret = 1;
163                 } else {
164                         dst = (char *)addr;
165                         for (i = 0; i < size; i++)
166                                 *dst++ = *data++;
167                         dsb(ish);
168
169                         /*
170                          * Ensure the I & D cache are in sync if we wrote
171                          * to executable memory.
172                          */
173                         cpu_icache_sync_range(addr, (vm_size_t)size);
174                 }
175         }
176         (void)kdb_jmpbuf(prev_jb);
177
178         return (ret);
179 }