[b06e68ef] | 1 | /* |
---|
| 2 | * @(#)object.c 1.7 - 95/08/02 |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | * RTEMS Monitor "object" support. |
---|
| 6 | * |
---|
| 7 | * Used to traverse object lists and print them out. |
---|
| 8 | * An object can be an RTEMS object (chain based stuff) or |
---|
| 9 | * a "misc" object such as a device driver. |
---|
| 10 | * |
---|
| 11 | * Each object has its own file in this directory (eg: extension.c) |
---|
| 12 | * That file provides routines to convert a "native" structure |
---|
| 13 | * to its canonical form, print a canonical structure, etc. |
---|
| 14 | * |
---|
| 15 | * TODO: |
---|
| 16 | * should allow for non-numeric id's??? |
---|
| 17 | * |
---|
| 18 | * $Id$ |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #include <rtems.h> |
---|
| 22 | #include "monitor.h" |
---|
| 23 | |
---|
| 24 | #include <stdio.h> |
---|
| 25 | #include <stdlib.h> /* strtoul() */ |
---|
| 26 | |
---|
| 27 | #include <monitor.h> |
---|
| 28 | |
---|
| 29 | #define NUMELEMS(arr) (sizeof(arr) / sizeof(arr[0])) |
---|
| 30 | |
---|
| 31 | /* |
---|
| 32 | * add: |
---|
| 33 | * next |
---|
| 34 | */ |
---|
| 35 | |
---|
| 36 | rtems_monitor_object_info_t rtems_monitor_object_info[] = |
---|
| 37 | { |
---|
| 38 | { RTEMS_OBJECT_CONFIG, |
---|
| 39 | (void *) 0, |
---|
| 40 | sizeof(rtems_monitor_config_t), |
---|
| 41 | (rtems_monitor_object_next_fn) rtems_monitor_config_next, |
---|
| 42 | (rtems_monitor_object_canonical_fn) rtems_monitor_config_canonical, |
---|
| 43 | (rtems_monitor_object_dump_header_fn) rtems_monitor_config_dump_header, |
---|
| 44 | (rtems_monitor_object_dump_fn) rtems_monitor_config_dump, |
---|
| 45 | }, |
---|
| 46 | { RTEMS_OBJECT_MPCI, |
---|
| 47 | (void *) 0, |
---|
| 48 | sizeof(rtems_monitor_mpci_t), |
---|
| 49 | (rtems_monitor_object_next_fn) rtems_monitor_mpci_next, |
---|
| 50 | (rtems_monitor_object_canonical_fn) rtems_monitor_mpci_canonical, |
---|
| 51 | (rtems_monitor_object_dump_header_fn) rtems_monitor_mpci_dump_header, |
---|
| 52 | (rtems_monitor_object_dump_fn) rtems_monitor_mpci_dump, |
---|
| 53 | }, |
---|
| 54 | { RTEMS_OBJECT_INIT_TASK, |
---|
| 55 | (void *) 0, |
---|
| 56 | sizeof(rtems_monitor_init_task_t), |
---|
| 57 | (rtems_monitor_object_next_fn) rtems_monitor_init_task_next, |
---|
| 58 | (rtems_monitor_object_canonical_fn) rtems_monitor_init_task_canonical, |
---|
| 59 | (rtems_monitor_object_dump_header_fn) rtems_monitor_init_task_dump_header, |
---|
| 60 | (rtems_monitor_object_dump_fn) rtems_monitor_init_task_dump, |
---|
| 61 | }, |
---|
| 62 | { RTEMS_OBJECT_TASK, |
---|
| 63 | (void *) &_Thread_Information, |
---|
| 64 | sizeof(rtems_monitor_task_t), |
---|
| 65 | (rtems_monitor_object_next_fn) rtems_monitor_manager_next, |
---|
| 66 | (rtems_monitor_object_canonical_fn) rtems_monitor_task_canonical, |
---|
| 67 | (rtems_monitor_object_dump_header_fn) rtems_monitor_task_dump_header, |
---|
| 68 | (rtems_monitor_object_dump_fn) rtems_monitor_task_dump, |
---|
| 69 | }, |
---|
| 70 | { RTEMS_OBJECT_QUEUE, |
---|
| 71 | (void *) &_Message_queue_Information, |
---|
| 72 | sizeof(rtems_monitor_queue_t), |
---|
| 73 | (rtems_monitor_object_next_fn) rtems_monitor_manager_next, |
---|
| 74 | (rtems_monitor_object_canonical_fn) rtems_monitor_queue_canonical, |
---|
| 75 | (rtems_monitor_object_dump_header_fn) rtems_monitor_queue_dump_header, |
---|
| 76 | (rtems_monitor_object_dump_fn) rtems_monitor_queue_dump, |
---|
| 77 | }, |
---|
| 78 | { RTEMS_OBJECT_EXTENSION, |
---|
| 79 | (void *) &_Extension_Information, |
---|
| 80 | sizeof(rtems_monitor_extension_t), |
---|
| 81 | (rtems_monitor_object_next_fn) rtems_monitor_manager_next, |
---|
| 82 | (rtems_monitor_object_canonical_fn) rtems_monitor_extension_canonical, |
---|
| 83 | (rtems_monitor_object_dump_header_fn) rtems_monitor_extension_dump_header, |
---|
| 84 | (rtems_monitor_object_dump_fn) rtems_monitor_extension_dump, |
---|
| 85 | }, |
---|
| 86 | { RTEMS_OBJECT_DRIVER, |
---|
| 87 | (void *) 0, |
---|
| 88 | sizeof(rtems_monitor_driver_t), |
---|
| 89 | (rtems_monitor_object_next_fn) rtems_monitor_driver_next, |
---|
| 90 | (rtems_monitor_object_canonical_fn) rtems_monitor_driver_canonical, |
---|
| 91 | (rtems_monitor_object_dump_header_fn) rtems_monitor_driver_dump_header, |
---|
| 92 | (rtems_monitor_object_dump_fn) rtems_monitor_driver_dump, |
---|
| 93 | }, |
---|
| 94 | { RTEMS_OBJECT_DNAME, |
---|
| 95 | (void *) &rtems_driver_name_table[0], |
---|
| 96 | sizeof(rtems_monitor_dname_t), |
---|
| 97 | (rtems_monitor_object_next_fn) rtems_monitor_dname_next, |
---|
| 98 | (rtems_monitor_object_canonical_fn) rtems_monitor_dname_canonical, |
---|
| 99 | (rtems_monitor_object_dump_header_fn) rtems_monitor_dname_dump_header, |
---|
| 100 | (rtems_monitor_object_dump_fn) rtems_monitor_dname_dump, |
---|
| 101 | }, |
---|
| 102 | }; |
---|
| 103 | |
---|
| 104 | /* |
---|
| 105 | * Allow id's to be specified without the node number or |
---|
| 106 | * type for convenience. |
---|
| 107 | */ |
---|
| 108 | |
---|
| 109 | rtems_id |
---|
| 110 | rtems_monitor_id_fixup( |
---|
| 111 | rtems_id id, |
---|
| 112 | unsigned32 default_node, |
---|
| 113 | rtems_object_type_t type |
---|
| 114 | ) |
---|
| 115 | { |
---|
| 116 | unsigned32 node; |
---|
| 117 | |
---|
| 118 | node = rtems_get_node(id); |
---|
| 119 | if (node == 0) |
---|
| 120 | { |
---|
| 121 | #if 0 |
---|
| 122 | /* XXX Uncomment this when types are added to id's */ |
---|
| 123 | if (rtems_get_type(id) != RTEMS_OBJECT_INVALID) |
---|
| 124 | type = rtems_get_type(id); |
---|
| 125 | |
---|
| 126 | id = _Objects_Build_id(type, default_node, rtems_get_index(id)); |
---|
| 127 | #else |
---|
| 128 | id = _Objects_Build_id(default_node, rtems_get_index(id)); |
---|
| 129 | #endif |
---|
| 130 | } |
---|
| 131 | return id; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | rtems_monitor_object_info_t * |
---|
| 136 | rtems_monitor_object_lookup( |
---|
| 137 | rtems_object_type_t type |
---|
| 138 | ) |
---|
| 139 | { |
---|
| 140 | rtems_monitor_object_info_t *p; |
---|
| 141 | for (p = &rtems_monitor_object_info[0]; |
---|
| 142 | p < &rtems_monitor_object_info[NUMELEMS(rtems_monitor_object_info)]; |
---|
| 143 | p++) |
---|
| 144 | { |
---|
| 145 | if (p->type == type) |
---|
| 146 | return p; |
---|
| 147 | } |
---|
| 148 | return 0; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | rtems_id |
---|
| 152 | rtems_monitor_object_canonical_next_remote( |
---|
| 153 | rtems_object_type_t type, |
---|
| 154 | rtems_id id, |
---|
| 155 | void *canonical |
---|
| 156 | ) |
---|
| 157 | { |
---|
| 158 | rtems_id next_id; |
---|
| 159 | rtems_status_code status; |
---|
| 160 | rtems_monitor_server_request_t request; |
---|
| 161 | rtems_monitor_server_response_t response; |
---|
| 162 | |
---|
| 163 | /* |
---|
| 164 | * Send request |
---|
| 165 | */ |
---|
| 166 | |
---|
| 167 | request.command = RTEMS_MONITOR_SERVER_CANONICAL; |
---|
| 168 | request.argument0 = (unsigned32) type; |
---|
| 169 | request.argument1 = (unsigned32) id; |
---|
| 170 | |
---|
| 171 | status = rtems_monitor_server_request(rtems_get_node(id), &request, &response); |
---|
| 172 | if (status != RTEMS_SUCCESSFUL) |
---|
| 173 | goto failed; |
---|
| 174 | |
---|
| 175 | /* |
---|
| 176 | * process response |
---|
| 177 | */ |
---|
| 178 | |
---|
| 179 | next_id = (rtems_id) response.result0; |
---|
| 180 | if (next_id != RTEMS_OBJECT_ID_FINAL) |
---|
| 181 | (void) memcpy(canonical, &response.payload, response.result1); |
---|
| 182 | |
---|
| 183 | return next_id; |
---|
| 184 | |
---|
| 185 | failed: |
---|
| 186 | return RTEMS_OBJECT_ID_FINAL; |
---|
| 187 | |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | rtems_id |
---|
| 192 | rtems_monitor_object_canonical_next( |
---|
| 193 | rtems_monitor_object_info_t *info, |
---|
| 194 | rtems_id id, |
---|
| 195 | void *canonical |
---|
| 196 | ) |
---|
| 197 | { |
---|
| 198 | rtems_id next_id; |
---|
| 199 | void *raw_item; |
---|
| 200 | |
---|
| 201 | if ( ! _Objects_Is_local_id(id)) |
---|
| 202 | next_id = rtems_monitor_object_canonical_next_remote(info->type, |
---|
| 203 | id, |
---|
| 204 | canonical); |
---|
| 205 | else |
---|
| 206 | { |
---|
| 207 | next_id = id; |
---|
| 208 | |
---|
| 209 | raw_item = (void *) info->next(info->object_information, |
---|
| 210 | canonical, |
---|
| 211 | &next_id); |
---|
| 212 | |
---|
| 213 | if (raw_item) |
---|
| 214 | { |
---|
| 215 | info->canonical(canonical, raw_item); |
---|
| 216 | _Thread_Enable_dispatch(); |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | return next_id; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | /* |
---|
| 224 | * this is routine server invokes locally to get the type |
---|
| 225 | */ |
---|
| 226 | |
---|
| 227 | rtems_id |
---|
| 228 | rtems_monitor_object_canonical_get( |
---|
| 229 | rtems_object_type_t type, |
---|
| 230 | rtems_id id, |
---|
| 231 | void *canonical, |
---|
| 232 | unsigned32 *size_p |
---|
| 233 | ) |
---|
| 234 | { |
---|
| 235 | rtems_monitor_object_info_t *info; |
---|
| 236 | rtems_id next_id; |
---|
| 237 | |
---|
| 238 | *size_p = 0; |
---|
| 239 | |
---|
| 240 | info = rtems_monitor_object_lookup(type); |
---|
| 241 | |
---|
| 242 | if (info == 0) |
---|
| 243 | return RTEMS_OBJECT_ID_FINAL; |
---|
| 244 | |
---|
| 245 | next_id = rtems_monitor_object_canonical_next(info, id, canonical); |
---|
| 246 | *size_p = info->size; |
---|
| 247 | |
---|
| 248 | return next_id; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | |
---|
| 252 | void |
---|
| 253 | rtems_monitor_object_dump_1( |
---|
| 254 | rtems_monitor_object_info_t *info, |
---|
| 255 | rtems_id id, |
---|
| 256 | boolean verbose |
---|
| 257 | ) |
---|
| 258 | { |
---|
| 259 | rtems_id next_id; |
---|
| 260 | rtems_monitor_union_t canonical; |
---|
| 261 | |
---|
| 262 | if ((next_id = rtems_monitor_object_canonical_next( |
---|
| 263 | info, |
---|
| 264 | id, |
---|
| 265 | &canonical)) != RTEMS_OBJECT_ID_FINAL) |
---|
| 266 | { |
---|
| 267 | /* |
---|
| 268 | * If the one we actually got is the one we wanted, then |
---|
| 269 | * print it out. |
---|
| 270 | * For ones that have an id field, this works fine, |
---|
| 271 | * for all others, always dump it out. |
---|
| 272 | * |
---|
| 273 | * HACK: the way we determine whether there is an id is a hack. |
---|
| 274 | * |
---|
| 275 | * by the way: the reason we try to not have an id, is that some |
---|
| 276 | * of the canonical structures are almost too big for shared |
---|
| 277 | * memory driver (eg: mpci) |
---|
| 278 | */ |
---|
| 279 | |
---|
| 280 | if ((info->next != rtems_monitor_manager_next) || |
---|
| 281 | (id == canonical.generic.id)) |
---|
| 282 | info->dump(&canonical, verbose); |
---|
| 283 | } |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | void |
---|
| 287 | rtems_monitor_object_dump_all( |
---|
| 288 | rtems_monitor_object_info_t *info, |
---|
| 289 | boolean verbose |
---|
| 290 | ) |
---|
| 291 | { |
---|
| 292 | rtems_id next_id; |
---|
| 293 | rtems_monitor_union_t canonical; |
---|
| 294 | |
---|
| 295 | next_id = RTEMS_OBJECT_ID_INITIAL(rtems_monitor_default_node); |
---|
| 296 | |
---|
| 297 | while ((next_id = rtems_monitor_object_canonical_next( |
---|
| 298 | info, |
---|
| 299 | next_id, |
---|
| 300 | &canonical)) != RTEMS_OBJECT_ID_FINAL) |
---|
| 301 | { |
---|
| 302 | info->dump(&canonical, verbose); |
---|
| 303 | } |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | void |
---|
| 307 | rtems_monitor_object_cmd( |
---|
| 308 | int argc, |
---|
| 309 | char **argv, |
---|
| 310 | unsigned32 command_arg, |
---|
| 311 | boolean verbose |
---|
| 312 | ) |
---|
| 313 | { |
---|
| 314 | int arg; |
---|
| 315 | rtems_monitor_object_info_t *info = 0; |
---|
| 316 | rtems_object_type_t type = (rtems_object_type_t) command_arg; |
---|
| 317 | |
---|
| 318 | /* what is the default type? */ |
---|
| 319 | type = (rtems_object_type_t) command_arg; |
---|
| 320 | |
---|
| 321 | if (argc == 1) |
---|
| 322 | { |
---|
| 323 | if (type == RTEMS_OBJECT_INVALID) |
---|
| 324 | { |
---|
| 325 | printf("A type must be specified to \"dump all\"\n"); |
---|
| 326 | goto done; |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | info = rtems_monitor_object_lookup(type); |
---|
| 330 | if (info == 0) |
---|
| 331 | goto not_found; |
---|
| 332 | |
---|
| 333 | if (info->dump_header) |
---|
| 334 | info->dump_header(verbose); |
---|
| 335 | rtems_monitor_object_dump_all(info, verbose); |
---|
| 336 | } |
---|
| 337 | else |
---|
| 338 | { |
---|
| 339 | unsigned32 default_node = rtems_monitor_default_node; |
---|
| 340 | rtems_object_type_t last_type = RTEMS_OBJECT_INVALID; |
---|
| 341 | rtems_id id; |
---|
| 342 | |
---|
| 343 | for (arg=1; argv[arg]; arg++) |
---|
| 344 | { |
---|
| 345 | id = (rtems_id) strtoul(argv[arg], 0, 0); |
---|
| 346 | id = rtems_monitor_id_fixup(id, default_node, type); |
---|
| 347 | #if 0 |
---|
| 348 | type = rtems_get_type(id); |
---|
| 349 | #endif |
---|
| 350 | /* |
---|
| 351 | * Allow the item type to change in the middle |
---|
| 352 | * of the command. If the type changes, then |
---|
| 353 | * just dump out a new header and keep on going. |
---|
| 354 | */ |
---|
| 355 | if (type != last_type) |
---|
| 356 | { |
---|
| 357 | info = rtems_monitor_object_lookup(type); |
---|
| 358 | if (info == 0) |
---|
| 359 | { |
---|
| 360 | not_found: printf("Invalid or unsupported type %d\n", type); |
---|
| 361 | goto done; |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | if (info->dump_header) |
---|
| 365 | info->dump_header(verbose); |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | rtems_monitor_object_dump_1(info, id, verbose); |
---|
| 369 | |
---|
| 370 | default_node = rtems_get_node(id); |
---|
| 371 | |
---|
| 372 | last_type = type; |
---|
| 373 | } |
---|
| 374 | } |
---|
| 375 | done: |
---|
| 376 | } |
---|