summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/monitor/mon-prmisc.c
blob: ecf17b08b7afcce5f9aa2fc8bc277472fa38203b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
 * Print misc stuff for the monitor dump routines
 * Each routine returns the number of characters it output.
 *
 * TODO:
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <rtems.h>
#include <rtems/monitor.h>
#include <rtems/assoc.h>

#include <stdio.h>
#include <ctype.h>
#include <inttypes.h>

void
rtems_monitor_separator(void)
{
    fprintf(stdout,"------------------------------------------------------------------------------\n");
}

uint32_t
rtems_monitor_pad(
    uint32_t    destination_column,
    uint32_t    current_column
)
{
    int pad_length;

    if (destination_column <= current_column)
        pad_length = 1;
    else
        pad_length = destination_column - current_column;

    return fprintf(stdout,"%*s", pad_length, "");
}

int
rtems_monitor_dump_decimal(uint32_t   num)
{
    return fprintf(stdout,"%4" PRId32, num);
}

int
rtems_monitor_dump_addr(const void *addr)
{
    return fprintf(stdout,"%08" PRIxPTR, (intptr_t) addr);
}

int
rtems_monitor_dump_hex(uint32_t   num)
{
    return fprintf(stdout,"0x%" PRIx32, num);
}

static int
rtems_monitor_dump_assoc_bitfield(
    const rtems_assoc_t *ap,
    const char          *separator,
    uint32_t             value
  )
{
    uint32_t   b;
    uint32_t   length = 0;
    const char *name;

    for (b = 1; b; b <<= 1)
        if (b & value)
        {
            if (length)
                length += fprintf(stdout,"%s", separator);

            name = rtems_assoc_name_by_local(ap, b);

            if (name)
                length += fprintf(stdout,"%s", name);
            else
                length += fprintf(stdout,"0x%" PRIx32, b);
        }

    return length;
}

int
rtems_monitor_dump_id(rtems_id id)
{
#if defined(RTEMS_USE_16_BIT_OBJECT)
    return fprintf(stdout,"%08" PRIx16, id);
#else
    return fprintf(stdout,"%08" PRIx32, id);
#endif
}

int
rtems_monitor_dump_name(rtems_id id)
{
    char name_buffer[18] = "????";

    rtems_object_get_name( id, sizeof(name_buffer), name_buffer );

    return fprintf(stdout, "%s", name_buffer);
}

int
rtems_monitor_dump_priority(rtems_task_priority priority)
{
    return fprintf(stdout,"%3" PRId32, priority);
}

int
rtems_monitor_dump_state(States_Control state)
{
    char buf[16];

    rtems_assoc_thread_states_to_string(state, buf, sizeof(buf));
    return fprintf(stdout, "%s", buf);
}

static const rtems_assoc_t rtems_monitor_attribute_assoc[] = {
    { "GL",  RTEMS_GLOBAL, 0 },
    { "PR",  RTEMS_PRIORITY, 0 },
    { "FL",  RTEMS_FLOATING_POINT, 0 },
    { "BI",  RTEMS_BINARY_SEMAPHORE, 0 },
    { "SB",  RTEMS_SIMPLE_BINARY_SEMAPHORE, 0 },
    { "IN",  RTEMS_INHERIT_PRIORITY, 0 },
    { "CE",  RTEMS_PRIORITY_CEILING, 0 },
    { "AR",  RTEMS_BARRIER_AUTOMATIC_RELEASE, 0 },
    { "ST",  RTEMS_SYSTEM_TASK, 0 },
    { 0, 0, 0 },
};

int
rtems_monitor_dump_attributes(rtems_attribute attributes)
{
    int   length = 0;

    if (attributes == RTEMS_DEFAULT_ATTRIBUTES)  /* value is 0 */
        length += fprintf(stdout,"DEFAULT");

    length += rtems_monitor_dump_assoc_bitfield(rtems_monitor_attribute_assoc,
                                                ":",
                                                attributes);
    return length;
}

static const rtems_assoc_t rtems_monitor_modes_assoc[] = {
    { "nP",     RTEMS_NO_PREEMPT, 0 },
    { "T",      RTEMS_TIMESLICE, 0 },
    { "nA",     RTEMS_NO_ASR, 0 },
    { 0, 0, 0 },
};

int
rtems_monitor_dump_modes(rtems_mode modes)
{
    uint32_t   length = 0;

    if (modes == RTEMS_DEFAULT_MODES)  /* value is 0 */
        length += fprintf(stdout,"P:T:nA");

    length += rtems_monitor_dump_assoc_bitfield(rtems_monitor_modes_assoc,
                                                ":",
                                                modes);
    return length;
}

int
rtems_monitor_dump_events(rtems_event_set events)
{
    if (events == 0)
        return fprintf(stdout,"  NONE  ");

    return fprintf(stdout,"%08" PRIx32, events);
}