| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: db_access.c,v 1.19 2009/03/07 22:02:17 ad Exp $ */ | | 1 | /* $NetBSD: db_access.c,v 1.20 2009/09/27 18:24:23 bsh Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Mach Operating System | | 4 | * Mach Operating System |
5 | * Copyright (c) 1991,1990 Carnegie Mellon University | | 5 | * Copyright (c) 1991,1990 Carnegie Mellon University |
6 | * All Rights Reserved. | | 6 | * All Rights Reserved. |
7 | * | | 7 | * |
8 | * Permission to use, copy, modify and distribute this software and its | | 8 | * Permission to use, copy, modify and distribute this software and its |
9 | * documentation is hereby granted, provided that both the copyright | | 9 | * documentation is hereby granted, provided that both the copyright |
10 | * notice and this permission notice appear in all copies of the | | 10 | * notice and this permission notice appear in all copies of the |
11 | * software, derivative works or modified versions, and any portions | | 11 | * software, derivative works or modified versions, and any portions |
12 | * thereof, and that both notices appear in supporting documentation. | | 12 | * thereof, and that both notices appear in supporting documentation. |
13 | * | | 13 | * |
14 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | | 14 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" |
| @@ -20,39 +20,45 @@ | | | @@ -20,39 +20,45 @@ |
20 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | | 20 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU |
21 | * School of Computer Science | | 21 | * School of Computer Science |
22 | * Carnegie Mellon University | | 22 | * Carnegie Mellon University |
23 | * Pittsburgh PA 15213-3890 | | 23 | * Pittsburgh PA 15213-3890 |
24 | * | | 24 | * |
25 | * any improvements or extensions that they make and grant Carnegie the | | 25 | * any improvements or extensions that they make and grant Carnegie the |
26 | * rights to redistribute these changes. | | 26 | * rights to redistribute these changes. |
27 | * | | 27 | * |
28 | * Author: David B. Golub, Carnegie Mellon University | | 28 | * Author: David B. Golub, Carnegie Mellon University |
29 | * Date: 7/90 | | 29 | * Date: 7/90 |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __KERNEL_RCSID(0, "$NetBSD: db_access.c,v 1.19 2009/03/07 22:02:17 ad Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: db_access.c,v 1.20 2009/09/27 18:24:23 bsh Exp $"); |
| | | 34 | |
| | | 35 | #include "opt_kgdb.h" |
34 | | | 36 | |
35 | #include <sys/param.h> | | 37 | #include <sys/param.h> |
36 | #include <sys/proc.h> | | 38 | #include <sys/proc.h> |
37 | #include <sys/endian.h> | | 39 | #include <sys/endian.h> |
38 | | | 40 | |
39 | #include <ddb/ddb.h> | | 41 | #include <ddb/ddb.h> |
40 | | | 42 | |
41 | /* | | 43 | /* |
42 | * Access unaligned data items on aligned (longword) | | 44 | * Access unaligned data items on aligned (longword) |
43 | * boundaries. | | 45 | * boundaries. |
| | | 46 | * |
| | | 47 | * This file is shared by ddb and kgdb. |
44 | */ | | 48 | */ |
45 | | | 49 | |
| | | 50 | #if defined(DDB) || defined(KGDB) && defined(SOFTWARE_SSTEP) |
| | | 51 | |
46 | const int db_extend[] = { /* table for sign-extending */ | | 52 | const int db_extend[] = { /* table for sign-extending */ |
47 | 0, | | 53 | 0, |
48 | 0xFFFFFF80, | | 54 | 0xFFFFFF80, |
49 | 0xFFFF8000, | | 55 | 0xFFFF8000, |
50 | 0xFF800000 | | 56 | 0xFF800000 |
51 | }; | | 57 | }; |
52 | | | 58 | |
53 | db_expr_t | | 59 | db_expr_t |
54 | db_get_value(db_addr_t addr, size_t size, bool is_signed) | | 60 | db_get_value(db_addr_t addr, size_t size, bool is_signed) |
55 | { | | 61 | { |
56 | char data[sizeof(db_expr_t)]; | | 62 | char data[sizeof(db_expr_t)]; |
57 | db_expr_t value; | | 63 | db_expr_t value; |
58 | size_t i; | | 64 | size_t i; |
| @@ -81,26 +87,30 @@ db_put_value(db_addr_t addr, size_t size | | | @@ -81,26 +87,30 @@ db_put_value(db_addr_t addr, size_t size |
81 | #if BYTE_ORDER == LITTLE_ENDIAN | | 87 | #if BYTE_ORDER == LITTLE_ENDIAN |
82 | for (i = 0; i < size; i++) | | 88 | for (i = 0; i < size; i++) |
83 | #else /* BYTE_ORDER == BIG_ENDIAN */ | | 89 | #else /* BYTE_ORDER == BIG_ENDIAN */ |
84 | for (i = size; i-- > 0;) | | 90 | for (i = size; i-- > 0;) |
85 | #endif /* BYTE_ORDER */ | | 91 | #endif /* BYTE_ORDER */ |
86 | { | | 92 | { |
87 | data[i] = value & 0xFF; | | 93 | data[i] = value & 0xFF; |
88 | value >>= 8; | | 94 | value >>= 8; |
89 | } | | 95 | } |
90 | | | 96 | |
91 | db_write_bytes(addr, size, data); | | 97 | db_write_bytes(addr, size, data); |
92 | } | | 98 | } |
93 | | | 99 | |
| | | 100 | #endif /* DDB || KGDB && SOFTWARE_SSTEP */ |
| | | 101 | |
| | | 102 | #ifdef DDB |
| | | 103 | |
94 | void * | | 104 | void * |
95 | db_read_ptr(const char *name) | | 105 | db_read_ptr(const char *name) |
96 | { | | 106 | { |
97 | db_expr_t val; | | 107 | db_expr_t val; |
98 | void *p; | | 108 | void *p; |
99 | | | 109 | |
100 | if (!db_value_of_name(name, &val)) { | | 110 | if (!db_value_of_name(name, &val)) { |
101 | db_printf("db_read_ptr: cannot find `%s'\n", name); | | 111 | db_printf("db_read_ptr: cannot find `%s'\n", name); |
102 | db_error(NULL); | | 112 | db_error(NULL); |
103 | /* NOTREACHED */ | | 113 | /* NOTREACHED */ |
104 | } | | 114 | } |
105 | db_read_bytes((db_addr_t)val, sizeof(p), (char *)&p); | | 115 | db_read_bytes((db_addr_t)val, sizeof(p), (char *)&p); |
106 | return p; | | 116 | return p; |
| @@ -110,13 +120,15 @@ int | | | @@ -110,13 +120,15 @@ int |
110 | db_read_int(const char *name) | | 120 | db_read_int(const char *name) |
111 | { | | 121 | { |
112 | db_expr_t val; | | 122 | db_expr_t val; |
113 | int p; | | 123 | int p; |
114 | | | 124 | |
115 | if (!db_value_of_name(name, &val)) { | | 125 | if (!db_value_of_name(name, &val)) { |
116 | db_printf("db_read_int: cannot find `%s'\n", name); | | 126 | db_printf("db_read_int: cannot find `%s'\n", name); |
117 | db_error(NULL); | | 127 | db_error(NULL); |
118 | /* NOTREACHED */ | | 128 | /* NOTREACHED */ |
119 | } | | 129 | } |
120 | db_read_bytes((db_addr_t)val, sizeof(p), (char *)&p); | | 130 | db_read_bytes((db_addr_t)val, sizeof(p), (char *)&p); |
121 | return p; | | 131 | return p; |
122 | } | | 132 | } |
| | | 133 | |
| | | 134 | #endif /* DDB */ |