| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: kgdb_stub.c,v 1.29 2015/06/26 14:26:38 christos Exp $ */ | | 1 | /* $NetBSD: kgdb_stub.c,v 1.30 2021/01/13 07:36:56 skrll Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1990, 1993 | | 4 | * Copyright (c) 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This software was developed by the Computer Systems Engineering group | | 7 | * This software was developed by the Computer Systems Engineering group |
8 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and | | 8 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and |
9 | * contributed to Berkeley. | | 9 | * contributed to Berkeley. |
10 | * | | 10 | * |
11 | * All advertising materials mentioning features or use of this software | | 11 | * All advertising materials mentioning features or use of this software |
12 | * must display the following acknowledgement: | | 12 | * must display the following acknowledgement: |
13 | * This product includes software developed by the University of | | 13 | * This product includes software developed by the University of |
14 | * California, Lawrence Berkeley Laboratories. | | 14 | * California, Lawrence Berkeley Laboratories. |
| @@ -35,27 +35,27 @@ | | | @@ -35,27 +35,27 @@ |
35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
37 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 37 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
38 | * SUCH DAMAGE. | | 38 | * SUCH DAMAGE. |
39 | * | | 39 | * |
40 | * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94 | | 40 | * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94 |
41 | */ | | 41 | */ |
42 | | | 42 | |
43 | /* | | 43 | /* |
44 | * "Stub" to allow remote CPU to debug over a serial line using gdb. | | 44 | * "Stub" to allow remote CPU to debug over a serial line using gdb. |
45 | */ | | 45 | */ |
46 | | | 46 | |
47 | #include <sys/cdefs.h> | | 47 | #include <sys/cdefs.h> |
48 | __KERNEL_RCSID(0, "$NetBSD: kgdb_stub.c,v 1.29 2015/06/26 14:26:38 christos Exp $"); | | 48 | __KERNEL_RCSID(0, "$NetBSD: kgdb_stub.c,v 1.30 2021/01/13 07:36:56 skrll Exp $"); |
49 | | | 49 | |
50 | #include "opt_ddb.h" | | 50 | #include "opt_ddb.h" |
51 | #include "opt_kgdb.h" | | 51 | #include "opt_kgdb.h" |
52 | | | 52 | |
53 | #include <sys/param.h> | | 53 | #include <sys/param.h> |
54 | #include <sys/systm.h> | | 54 | #include <sys/systm.h> |
55 | #include <sys/kgdb.h> | | 55 | #include <sys/kgdb.h> |
56 | | | 56 | |
57 | #undef DEBUG_KGDB | | 57 | #undef DEBUG_KGDB |
58 | | | 58 | |
59 | #ifdef DEBUG_KGDB | | 59 | #ifdef DEBUG_KGDB |
60 | #define DPRINTF(x) printf x | | 60 | #define DPRINTF(x) printf x |
61 | #else | | 61 | #else |
| @@ -154,76 +154,76 @@ digit2i(u_char c) | | | @@ -154,76 +154,76 @@ digit2i(u_char c) |
154 | if (c >= '0' && c <= '9') | | 154 | if (c >= '0' && c <= '9') |
155 | return (c - '0'); | | 155 | return (c - '0'); |
156 | else if (c >= 'a' && c <= 'f') | | 156 | else if (c >= 'a' && c <= 'f') |
157 | return (c - 'a' + 10); | | 157 | return (c - 'a' + 10); |
158 | else if (c >= 'A' && c <= 'F') | | 158 | else if (c >= 'A' && c <= 'F') |
159 | | | 159 | |
160 | return (c - 'A' + 10); | | 160 | return (c - 'A' + 10); |
161 | else | | 161 | else |
162 | return (-1); | | 162 | return (-1); |
163 | } | | 163 | } |
164 | | | 164 | |
165 | /* | | 165 | /* |
166 | * Convert the low 4 bits of an integer into | | 166 | * Convert the low 4 bits of an integer into |
167 | * an hex digit. | | 167 | * a hex digit. |
168 | */ | | 168 | */ |
169 | static u_char | | 169 | static u_char |
170 | i2digit(int n) | | 170 | i2digit(int n) |
171 | { | | 171 | { |
172 | return (hexdigits[n & 0x0f]); | | 172 | return (hexdigits[n & 0x0f]); |
173 | } | | 173 | } |
174 | | | 174 | |
175 | /* | | 175 | /* |
176 | * Convert a byte array into an hex string. | | 176 | * Convert a byte array into a hex string. |
177 | */ | | 177 | */ |
178 | static void | | 178 | static void |
179 | mem2hex(void *vdst, void *vsrc, int len) | | 179 | mem2hex(void *vdst, void *vsrc, int len) |
180 | { | | 180 | { |
181 | u_char *dst = vdst; | | 181 | u_char *dst = vdst; |
182 | u_char *src = vsrc; | | 182 | u_char *src = vsrc; |
183 | | | 183 | |
184 | while (len--) { | | 184 | while (len--) { |
185 | *dst++ = i2digit(*src >> 4); | | 185 | *dst++ = i2digit(*src >> 4); |
186 | *dst++ = i2digit(*src++); | | 186 | *dst++ = i2digit(*src++); |
187 | } | | 187 | } |
188 | *dst = '\0'; | | 188 | *dst = '\0'; |
189 | } | | 189 | } |
190 | | | 190 | |
191 | /* | | 191 | /* |
192 | * Convert an hex string into a byte array. | | 192 | * Convert a hex string into a byte array. |
193 | * This returns a pointer to the character following | | 193 | * This returns a pointer to the character following |
194 | * the last valid hex digit. If the string ends in | | 194 | * the last valid hex digit. If the string ends in |
195 | * the middle of a byte, NULL is returned. | | 195 | * the middle of a byte, NULL is returned. |
196 | */ | | 196 | */ |
197 | static u_char * | | 197 | static u_char * |
198 | hex2mem(void *vdst, u_char *src, int maxlen) | | 198 | hex2mem(void *vdst, u_char *src, int maxlen) |
199 | { | | 199 | { |
200 | u_char *dst = vdst; | | 200 | u_char *dst = vdst; |
201 | int msb, lsb; | | 201 | int msb, lsb; |
202 | | | 202 | |
203 | while (*src && maxlen--) { | | 203 | while (*src && maxlen--) { |
204 | msb = digit2i(*src++); | | 204 | msb = digit2i(*src++); |
205 | if (msb < 0) | | 205 | if (msb < 0) |
206 | return (src - 1); | | 206 | return (src - 1); |
207 | lsb = digit2i(*src++); | | 207 | lsb = digit2i(*src++); |
208 | if (lsb < 0) | | 208 | if (lsb < 0) |
209 | return (NULL); | | 209 | return (NULL); |
210 | *dst++ = (msb << 4) | lsb; | | 210 | *dst++ = (msb << 4) | lsb; |
211 | } | | 211 | } |
212 | return (src); | | 212 | return (src); |
213 | } | | 213 | } |
214 | | | 214 | |
215 | /* | | 215 | /* |
216 | * Convert an hex string into an integer. | | 216 | * Convert a hex string into an integer. |
217 | * This returns a pointer to the character following | | 217 | * This returns a pointer to the character following |
218 | * the last valid hex digit. | | 218 | * the last valid hex digit. |
219 | */ | | 219 | */ |
220 | static vaddr_t | | 220 | static vaddr_t |
221 | hex2i(u_char **srcp) | | 221 | hex2i(u_char **srcp) |
222 | { | | 222 | { |
223 | char *src = *srcp; | | 223 | char *src = *srcp; |
224 | vaddr_t r = 0; | | 224 | vaddr_t r = 0; |
225 | int nibble; | | 225 | int nibble; |
226 | | | 226 | |
227 | while ((nibble = digit2i(*src)) >= 0) { | | 227 | while ((nibble = digit2i(*src)) >= 0) { |
228 | r *= 16; | | 228 | r *= 16; |
229 | r += nibble; | | 229 | r += nibble; |