OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [libmisc/] [monitor/] [mon-object.c] - Blame information for rev 279

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.