Mercurial > ecos-v3_0-branch
comparison packages/hal/common/current/src/bplist-dynamic.c @ 112:02ea4320376c ecos-sw-2000-07-21
Merge from eCos master repository on 2000-07-21-21:01:39-BST
| author | jlarmour |
|---|---|
| date | Fri, 21 Jul 2000 21:34:11 +0000 |
| parents | |
| children | 5ad2b71d525e |
comparison
equal
deleted
inserted
replaced
| 111:211b8a635ce9 | 112:02ea4320376c |
|---|---|
| 1 //========================================================================== | |
| 2 // | |
| 3 // bplist-dynamic.c | |
| 4 // | |
| 5 // Dynamic breakpoint list. | |
| 6 // Currently only statically allocated. (ie NO_MALLOC is assumed) | |
| 7 // | |
| 8 //========================================================================== | |
| 9 //####COPYRIGHTBEGIN#### | |
| 10 // | |
| 11 // ------------------------------------------- | |
| 12 // The contents of this file are subject to the Red Hat eCos Public License | |
| 13 // Version 1.1 (the "License"); you may not use this file except in | |
| 14 // compliance with the License. You may obtain a copy of the License at | |
| 15 // http://www.redhat.com/ | |
| 16 // | |
| 17 // Software distributed under the License is distributed on an "AS IS" | |
| 18 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 19 // License for the specific language governing rights and limitations under | |
| 20 // the License. | |
| 21 // | |
| 22 // The Original Code is eCos - Embedded Configurable Operating System, | |
| 23 // released September 30, 1998. | |
| 24 // | |
| 25 // The Initial Developer of the Original Code is Red Hat. | |
| 26 // Portions created by Red Hat are | |
| 27 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. | |
| 28 // All Rights Reserved. | |
| 29 // ------------------------------------------- | |
| 30 // | |
| 31 //####COPYRIGHTEND#### | |
| 32 //========================================================================== | |
| 33 //#####DESCRIPTIONBEGIN#### | |
| 34 // | |
| 35 // Author(s): | |
| 36 // Contributors: dmoseley | |
| 37 // Date: 2000-07-11 | |
| 38 // Purpose: Dynamic breakpoint list. | |
| 39 // Description: | |
| 40 // | |
| 41 // | |
| 42 //####DESCRIPTIONEND#### | |
| 43 // | |
| 44 //========================================================================= | |
| 45 | |
| 46 #include <cyg/hal/hal_stub.h> | |
| 47 | |
| 48 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS | |
| 49 | |
| 50 #if defined(CYGNUM_HAL_BREAKPOINT_LIST_SIZE) && (CYGNUM_HAL_BREAKPOINT_LIST_SIZE > 0) | |
| 51 | |
| 52 /* | |
| 53 * A simple target breakpoint list without using malloc. | |
| 54 * To use this package, you must define HAL_BREAKINST_SIZE to be the size | |
| 55 * in bytes of a trap instruction (max if there's more than one), | |
| 56 * HAL_BREAKINST to the opcode value of the instruction, and | |
| 57 * HAL_BREAKINST_TYPE to be the type necessary to hold the opcode value. | |
| 58 */ | |
| 59 | |
| 60 struct breakpoint_list { | |
| 61 target_register_t addr; | |
| 62 char old_contents [HAL_BREAKINST_SIZE]; | |
| 63 struct breakpoint_list *next; | |
| 64 char in_memory; | |
| 65 } *breakpoint_list = NULL; | |
| 66 | |
| 67 static HAL_BREAKINST_TYPE break_inst = HAL_BREAKINST; | |
| 68 static void *_break_inst = &break_inst; | |
| 69 | |
| 70 static struct breakpoint_list bp_list [CYGNUM_HAL_BREAKPOINT_LIST_SIZE]; | |
| 71 static struct breakpoint_list *free_bp_list = NULL; | |
| 72 static int curr_bp_num = 0; | |
| 73 | |
| 74 int | |
| 75 __set_breakpoint (target_register_t addr) | |
| 76 { | |
| 77 struct breakpoint_list **addent = &breakpoint_list; | |
| 78 struct breakpoint_list *l = breakpoint_list; | |
| 79 struct breakpoint_list *newent; | |
| 80 | |
| 81 while (l != NULL && l->addr < addr) | |
| 82 { | |
| 83 addent = &l->next; | |
| 84 l = l->next; | |
| 85 } | |
| 86 | |
| 87 if (l != NULL && l->addr == addr) | |
| 88 return 2; | |
| 89 | |
| 90 if (free_bp_list != NULL) | |
| 91 { | |
| 92 newent = free_bp_list; | |
| 93 free_bp_list = free_bp_list->next; | |
| 94 } | |
| 95 else | |
| 96 { | |
| 97 if (curr_bp_num < CYGNUM_HAL_BREAKPOINT_LIST_SIZE) | |
| 98 { | |
| 99 newent = &bp_list[curr_bp_num++]; | |
| 100 } | |
| 101 else | |
| 102 { | |
| 103 return 1; | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 newent->addr = addr; | |
| 108 newent->in_memory = 0; | |
| 109 newent->next = l; | |
| 110 *addent = newent; | |
| 111 return 0; | |
| 112 } | |
| 113 | |
| 114 int | |
| 115 __remove_breakpoint (target_register_t addr) | |
| 116 { | |
| 117 struct breakpoint_list *l = breakpoint_list; | |
| 118 struct breakpoint_list *prev = NULL; | |
| 119 | |
| 120 while (l != NULL && l->addr < addr) | |
| 121 { | |
| 122 prev = l; | |
| 123 l = l->next; | |
| 124 } | |
| 125 | |
| 126 if ((l == NULL) || (l->addr != addr)) | |
| 127 return 1; | |
| 128 | |
| 129 if (l->in_memory) | |
| 130 { | |
| 131 __write_mem_safe (&l->old_contents[0], | |
| 132 (void*)l->addr, | |
| 133 sizeof (l->old_contents)); | |
| 134 } | |
| 135 | |
| 136 if (prev == NULL) | |
| 137 breakpoint_list = l->next; | |
| 138 else | |
| 139 prev->next = l->next; | |
| 140 | |
| 141 l->next = free_bp_list; | |
| 142 free_bp_list = l; | |
| 143 | |
| 144 return 0; | |
| 145 } | |
| 146 | |
| 147 void | |
| 148 __install_breakpoint_list (void) | |
| 149 { | |
| 150 struct breakpoint_list *l = breakpoint_list; | |
| 151 | |
| 152 while (l != NULL) | |
| 153 { | |
| 154 if (! l->in_memory) | |
| 155 { | |
| 156 int len = sizeof (l->old_contents); | |
| 157 if (__read_mem_safe (&l->old_contents[0], (void*)l->addr, len) == len) | |
| 158 { | |
| 159 if (__write_mem_safe (_break_inst, (void*)l->addr, len) == len) | |
| 160 { | |
| 161 l->in_memory = 1; | |
| 162 } | |
| 163 } | |
| 164 | |
| 165 } | |
| 166 l = l->next; | |
| 167 } | |
| 168 flush_i_cache (); | |
| 169 } | |
| 170 | |
| 171 void | |
| 172 __clear_breakpoint_list () | |
| 173 { | |
| 174 struct breakpoint_list *l = breakpoint_list; | |
| 175 | |
| 176 while (l != NULL) | |
| 177 { | |
| 178 if (l->in_memory) | |
| 179 { | |
| 180 int len = sizeof (l->old_contents); | |
| 181 if (__write_mem_safe (&l->old_contents[0], (void*)l->addr, len) == len) | |
| 182 { | |
| 183 l->in_memory = 0; | |
| 184 } | |
| 185 } | |
| 186 l = l->next; | |
| 187 } | |
| 188 flush_i_cache (); | |
| 189 } | |
| 190 | |
| 191 int | |
| 192 __display_breakpoint_list (void (*print_func)(target_register_t)) | |
| 193 { | |
| 194 struct breakpoint_list *l = breakpoint_list; | |
| 195 | |
| 196 while (l != NULL) | |
| 197 { | |
| 198 print_func(l->addr); | |
| 199 l = l->next; | |
| 200 } | |
| 201 | |
| 202 return 0; | |
| 203 } | |
| 204 | |
| 205 #else // (CYGNUM_HAL_BREAKPOINT_LIST_SIZE == 0) or UNDEFINED | |
| 206 | |
| 207 #include <cyg/hal/hal_stub.h> // Our header | |
| 208 | |
| 209 int | |
| 210 __set_breakpoint (target_register_t addr) | |
| 211 { | |
| 212 return 1; | |
| 213 } | |
| 214 | |
| 215 int | |
| 216 __remove_breakpoint (target_register_t addr) | |
| 217 { | |
| 218 return 1; | |
| 219 } | |
| 220 | |
| 221 void | |
| 222 __install_breakpoint_list (void) | |
| 223 { | |
| 224 } | |
| 225 | |
| 226 void | |
| 227 __clear_breakpoint_list (void) | |
| 228 { | |
| 229 } | |
| 230 | |
| 231 int | |
| 232 __display_breakpoint_list (void (*print_func)(target_register_t)) | |
| 233 { | |
| 234 } | |
| 235 #endif // (CYGNUM_HAL_BREAKPOINT_LIST_SIZE > 0) | |
| 236 | |
| 237 #endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS | |
| 238 |
