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 *) &_RTEMS_tasks_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 | /* XXX now that the driver name table is allocated from the */ |
---|
96 | /* XXX Workspace, this does not work */ |
---|
97 | (void *) 0, |
---|
98 | /* (void *) _IO_Driver_name_table, */ |
---|
99 | sizeof(rtems_monitor_dname_t), |
---|
100 | (rtems_monitor_object_next_fn) rtems_monitor_dname_next, |
---|
101 | (rtems_monitor_object_canonical_fn) rtems_monitor_dname_canonical, |
---|
102 | (rtems_monitor_object_dump_header_fn) rtems_monitor_dname_dump_header, |
---|
103 | (rtems_monitor_object_dump_fn) rtems_monitor_dname_dump, |
---|
104 | }, |
---|
105 | }; |
---|
106 | |
---|
107 | /* |
---|
108 | * Allow id's to be specified without the node number or |
---|
109 | * type for convenience. |
---|
110 | */ |
---|
111 | |
---|
112 | rtems_id |
---|
113 | rtems_monitor_id_fixup( |
---|
114 | rtems_id id, |
---|
115 | unsigned32 default_node, |
---|
116 | rtems_object_type_t type |
---|
117 | ) |
---|
118 | { |
---|
119 | unsigned32 node; |
---|
120 | |
---|
121 | node = rtems_get_node(id); |
---|
122 | if (node == 0) |
---|
123 | { |
---|
124 | #if 0 |
---|
125 | /* XXX Uncomment this when types are added to id's */ |
---|
126 | if (rtems_get_class(id) != OBJECTS_NO_CLASS) |
---|
127 | type = rtems_get_class(id); |
---|
128 | |
---|
129 | id = _Objects_Build_id(type, default_node, rtems_get_index(id)); |
---|
130 | #else |
---|
131 | #warning "TONY... FIX ME!!!!!" |
---|
132 | #if defined(hppa1_1) |
---|
133 | #warning "TONY... I SAID TO FIX ME!!!!! <HAHAHAHAHA>" |
---|
134 | #endif |
---|
135 | id = _Objects_Build_id(0, default_node, rtems_get_index(id)); |
---|
136 | #endif |
---|
137 | } |
---|
138 | return id; |
---|
139 | } |
---|
140 | |
---|
141 | |
---|
142 | rtems_monitor_object_info_t * |
---|
143 | rtems_monitor_object_lookup( |
---|
144 | rtems_object_type_t type |
---|
145 | ) |
---|
146 | { |
---|
147 | rtems_monitor_object_info_t *p; |
---|
148 | for (p = &rtems_monitor_object_info[0]; |
---|
149 | p < &rtems_monitor_object_info[NUMELEMS(rtems_monitor_object_info)]; |
---|
150 | p++) |
---|
151 | { |
---|
152 | if (p->type == type) |
---|
153 | return p; |
---|
154 | } |
---|
155 | return 0; |
---|
156 | } |
---|
157 | |
---|
158 | rtems_id |
---|
159 | rtems_monitor_object_canonical_next_remote( |
---|
160 | rtems_object_type_t type, |
---|
161 | rtems_id id, |
---|
162 | void *canonical |
---|
163 | ) |
---|
164 | { |
---|
165 | rtems_id next_id; |
---|
166 | rtems_status_code status; |
---|
167 | rtems_monitor_server_request_t request; |
---|
168 | rtems_monitor_server_response_t response; |
---|
169 | |
---|
170 | /* |
---|
171 | * Send request |
---|
172 | */ |
---|
173 | |
---|
174 | request.command = RTEMS_MONITOR_SERVER_CANONICAL; |
---|
175 | request.argument0 = (unsigned32) type; |
---|
176 | request.argument1 = (unsigned32) id; |
---|
177 | |
---|
178 | status = rtems_monitor_server_request(rtems_get_node(id), &request, &response); |
---|
179 | if (status != RTEMS_SUCCESSFUL) |
---|
180 | goto failed; |
---|
181 | |
---|
182 | /* |
---|
183 | * process response |
---|
184 | */ |
---|
185 | |
---|
186 | next_id = (rtems_id) response.result0; |
---|
187 | if (next_id != RTEMS_OBJECT_ID_FINAL) |
---|
188 | (void) memcpy(canonical, &response.payload, response.result1); |
---|
189 | |
---|
190 | return next_id; |
---|
191 | |
---|
192 | failed: |
---|
193 | return RTEMS_OBJECT_ID_FINAL; |
---|
194 | |
---|
195 | } |
---|
196 | |
---|
197 | |
---|
198 | rtems_id |
---|
199 | rtems_monitor_object_canonical_next( |
---|
200 | rtems_monitor_object_info_t *info, |
---|
201 | rtems_id id, |
---|
202 | void *canonical |
---|
203 | ) |
---|
204 | { |
---|
205 | rtems_id next_id; |
---|
206 | void *raw_item; |
---|
207 | |
---|
208 | if ( ! _Objects_Is_local_id(id)) |
---|
209 | next_id = rtems_monitor_object_canonical_next_remote(info->type, |
---|
210 | id, |
---|
211 | canonical); |
---|
212 | else |
---|
213 | { |
---|
214 | next_id = id; |
---|
215 | |
---|
216 | raw_item = (void *) info->next(info->object_information, |
---|
217 | canonical, |
---|
218 | &next_id); |
---|
219 | |
---|
220 | if (raw_item) |
---|
221 | { |
---|
222 | info->canonical(canonical, raw_item); |
---|
223 | _Thread_Enable_dispatch(); |
---|
224 | } |
---|
225 | } |
---|
226 | return next_id; |
---|
227 | } |
---|
228 | |
---|
229 | |
---|
230 | /* |
---|
231 | * this is routine server invokes locally to get the type |
---|
232 | */ |
---|
233 | |
---|
234 | rtems_id |
---|
235 | rtems_monitor_object_canonical_get( |
---|
236 | rtems_object_type_t type, |
---|
237 | rtems_id id, |
---|
238 | void *canonical, |
---|
239 | unsigned32 *size_p |
---|
240 | ) |
---|
241 | { |
---|
242 | rtems_monitor_object_info_t *info; |
---|
243 | rtems_id next_id; |
---|
244 | |
---|
245 | *size_p = 0; |
---|
246 | |
---|
247 | info = rtems_monitor_object_lookup(type); |
---|
248 | |
---|
249 | if (info == 0) |
---|
250 | return RTEMS_OBJECT_ID_FINAL; |
---|
251 | |
---|
252 | next_id = rtems_monitor_object_canonical_next(info, id, canonical); |
---|
253 | *size_p = info->size; |
---|
254 | |
---|
255 | return next_id; |
---|
256 | } |
---|
257 | |
---|
258 | |
---|
259 | void |
---|
260 | rtems_monitor_object_dump_1( |
---|
261 | rtems_monitor_object_info_t *info, |
---|
262 | rtems_id id, |
---|
263 | boolean verbose |
---|
264 | ) |
---|
265 | { |
---|
266 | rtems_id next_id; |
---|
267 | rtems_monitor_union_t canonical; |
---|
268 | |
---|
269 | if ((next_id = rtems_monitor_object_canonical_next( |
---|
270 | info, |
---|
271 | id, |
---|
272 | &canonical)) != RTEMS_OBJECT_ID_FINAL) |
---|
273 | { |
---|
274 | /* |
---|
275 | * If the one we actually got is the one we wanted, then |
---|
276 | * print it out. |
---|
277 | * For ones that have an id field, this works fine, |
---|
278 | * for all others, always dump it out. |
---|
279 | * |
---|
280 | * HACK: the way we determine whether there is an id is a hack. |
---|
281 | * |
---|
282 | * by the way: the reason we try to not have an id, is that some |
---|
283 | * of the canonical structures are almost too big for shared |
---|
284 | * memory driver (eg: mpci) |
---|
285 | */ |
---|
286 | |
---|
287 | if ((info->next != rtems_monitor_manager_next) || |
---|
288 | (id == canonical.generic.id)) |
---|
289 | info->dump(&canonical, verbose); |
---|
290 | } |
---|
291 | } |
---|
292 | |
---|
293 | void |
---|
294 | rtems_monitor_object_dump_all( |
---|
295 | rtems_monitor_object_info_t *info, |
---|
296 | boolean verbose |
---|
297 | ) |
---|
298 | { |
---|
299 | rtems_id next_id; |
---|
300 | rtems_monitor_union_t canonical; |
---|
301 | |
---|
302 | next_id = RTEMS_OBJECT_ID_INITIAL(rtems_monitor_default_node); |
---|
303 | |
---|
304 | while ((next_id = rtems_monitor_object_canonical_next( |
---|
305 | info, |
---|
306 | next_id, |
---|
307 | &canonical)) != RTEMS_OBJECT_ID_FINAL) |
---|
308 | { |
---|
309 | info->dump(&canonical, verbose); |
---|
310 | } |
---|
311 | } |
---|
312 | |
---|
313 | void |
---|
314 | rtems_monitor_object_cmd( |
---|
315 | int argc, |
---|
316 | char **argv, |
---|
317 | unsigned32 command_arg, |
---|
318 | boolean verbose |
---|
319 | ) |
---|
320 | { |
---|
321 | int arg; |
---|
322 | rtems_monitor_object_info_t *info = 0; |
---|
323 | rtems_object_type_t type = (rtems_object_type_t) command_arg; |
---|
324 | |
---|
325 | /* what is the default type? */ |
---|
326 | type = (rtems_object_type_t) command_arg; |
---|
327 | |
---|
328 | if (argc == 1) |
---|
329 | { |
---|
330 | if (type == RTEMS_OBJECT_INVALID) |
---|
331 | { |
---|
332 | printf("A type must be specified to \"dump all\"\n"); |
---|
333 | goto done; |
---|
334 | } |
---|
335 | |
---|
336 | info = rtems_monitor_object_lookup(type); |
---|
337 | if (info == 0) |
---|
338 | goto not_found; |
---|
339 | |
---|
340 | if (info->dump_header) |
---|
341 | info->dump_header(verbose); |
---|
342 | rtems_monitor_object_dump_all(info, verbose); |
---|
343 | } |
---|
344 | else |
---|
345 | { |
---|
346 | unsigned32 default_node = rtems_monitor_default_node; |
---|
347 | rtems_object_type_t last_type = RTEMS_OBJECT_INVALID; |
---|
348 | rtems_id id; |
---|
349 | |
---|
350 | for (arg=1; argv[arg]; arg++) |
---|
351 | { |
---|
352 | id = (rtems_id) strtoul(argv[arg], 0, 0); |
---|
353 | id = rtems_monitor_id_fixup(id, default_node, type); |
---|
354 | #if 0 |
---|
355 | type = rtems_get_type(id); |
---|
356 | #endif |
---|
357 | /* |
---|
358 | * Allow the item type to change in the middle |
---|
359 | * of the command. If the type changes, then |
---|
360 | * just dump out a new header and keep on going. |
---|
361 | */ |
---|
362 | if (type != last_type) |
---|
363 | { |
---|
364 | info = rtems_monitor_object_lookup(type); |
---|
365 | if (info == 0) |
---|
366 | { |
---|
367 | not_found: printf("Invalid or unsupported type %d\n", type); |
---|
368 | goto done; |
---|
369 | } |
---|
370 | |
---|
371 | if (info->dump_header) |
---|
372 | info->dump_header(verbose); |
---|
373 | } |
---|
374 | |
---|
375 | rtems_monitor_object_dump_1(info, id, verbose); |
---|
376 | |
---|
377 | default_node = rtems_get_node(id); |
---|
378 | |
---|
379 | last_type = type; |
---|
380 | } |
---|
381 | } |
---|
382 | done: |
---|
383 | } |
---|