1 | /* |
---|
2 | * Print misc stuff for the monitor dump routines |
---|
3 | * Each routine returns the number of characters it output. |
---|
4 | * |
---|
5 | * TODO: |
---|
6 | */ |
---|
7 | |
---|
8 | #ifdef HAVE_CONFIG_H |
---|
9 | #include "config.h" |
---|
10 | #endif |
---|
11 | |
---|
12 | #include <rtems.h> |
---|
13 | #include <rtems/monitor.h> |
---|
14 | #include <rtems/assoc.h> |
---|
15 | |
---|
16 | #include <stdio.h> |
---|
17 | #include <ctype.h> |
---|
18 | #include <inttypes.h> |
---|
19 | |
---|
20 | void |
---|
21 | rtems_monitor_separator(void) |
---|
22 | { |
---|
23 | fprintf(stdout,"------------------------------------------------------------------------------\n"); |
---|
24 | } |
---|
25 | |
---|
26 | uint32_t |
---|
27 | rtems_monitor_pad( |
---|
28 | uint32_t destination_column, |
---|
29 | uint32_t current_column |
---|
30 | ) |
---|
31 | { |
---|
32 | int pad_length; |
---|
33 | |
---|
34 | if (destination_column <= current_column) |
---|
35 | pad_length = 1; |
---|
36 | else |
---|
37 | pad_length = destination_column - current_column; |
---|
38 | |
---|
39 | return fprintf(stdout,"%*s", pad_length, ""); |
---|
40 | } |
---|
41 | |
---|
42 | int |
---|
43 | rtems_monitor_dump_decimal(uint32_t num) |
---|
44 | { |
---|
45 | return fprintf(stdout,"%4" PRId32, num); |
---|
46 | } |
---|
47 | |
---|
48 | int |
---|
49 | rtems_monitor_dump_addr(const void *addr) |
---|
50 | { |
---|
51 | return fprintf(stdout,"%08" PRIxPTR, (intptr_t) addr); |
---|
52 | } |
---|
53 | |
---|
54 | int |
---|
55 | rtems_monitor_dump_hex(uint32_t num) |
---|
56 | { |
---|
57 | return fprintf(stdout,"0x%" PRIx32, num); |
---|
58 | } |
---|
59 | |
---|
60 | static int |
---|
61 | rtems_monitor_dump_assoc_bitfield( |
---|
62 | const rtems_assoc_t *ap, |
---|
63 | const char *separator, |
---|
64 | uint32_t value |
---|
65 | ) |
---|
66 | { |
---|
67 | uint32_t b; |
---|
68 | uint32_t length = 0; |
---|
69 | const char *name; |
---|
70 | |
---|
71 | for (b = 1; b; b <<= 1) |
---|
72 | if (b & value) |
---|
73 | { |
---|
74 | if (length) |
---|
75 | length += fprintf(stdout,"%s", separator); |
---|
76 | |
---|
77 | name = rtems_assoc_name_by_local(ap, b); |
---|
78 | |
---|
79 | if (name) |
---|
80 | length += fprintf(stdout,"%s", name); |
---|
81 | else |
---|
82 | length += fprintf(stdout,"0x%" PRIx32, b); |
---|
83 | } |
---|
84 | |
---|
85 | return length; |
---|
86 | } |
---|
87 | |
---|
88 | int |
---|
89 | rtems_monitor_dump_id(rtems_id id) |
---|
90 | { |
---|
91 | #if defined(RTEMS_USE_16_BIT_OBJECT) |
---|
92 | return fprintf(stdout,"%08" PRIx16, id); |
---|
93 | #else |
---|
94 | return fprintf(stdout,"%08" PRIx32, id); |
---|
95 | #endif |
---|
96 | } |
---|
97 | |
---|
98 | int |
---|
99 | rtems_monitor_dump_name(rtems_id id) |
---|
100 | { |
---|
101 | char name_buffer[18] = "????"; |
---|
102 | |
---|
103 | rtems_object_get_name( id, sizeof(name_buffer), name_buffer ); |
---|
104 | |
---|
105 | return fprintf(stdout, "%s", name_buffer); |
---|
106 | } |
---|
107 | |
---|
108 | int |
---|
109 | rtems_monitor_dump_priority(rtems_task_priority priority) |
---|
110 | { |
---|
111 | return fprintf(stdout,"%3" PRId32, priority); |
---|
112 | } |
---|
113 | |
---|
114 | int |
---|
115 | rtems_monitor_dump_state(States_Control state) |
---|
116 | { |
---|
117 | char buf[16]; |
---|
118 | |
---|
119 | rtems_assoc_thread_states_to_string(state, buf, sizeof(buf)); |
---|
120 | return fprintf(stdout, "%s", buf); |
---|
121 | } |
---|
122 | |
---|
123 | static const rtems_assoc_t rtems_monitor_attribute_assoc[] = { |
---|
124 | { "GL", RTEMS_GLOBAL, 0 }, |
---|
125 | { "PR", RTEMS_PRIORITY, 0 }, |
---|
126 | { "FL", RTEMS_FLOATING_POINT, 0 }, |
---|
127 | { "BI", RTEMS_BINARY_SEMAPHORE, 0 }, |
---|
128 | { "SB", RTEMS_SIMPLE_BINARY_SEMAPHORE, 0 }, |
---|
129 | { "IN", RTEMS_INHERIT_PRIORITY, 0 }, |
---|
130 | { "CE", RTEMS_PRIORITY_CEILING, 0 }, |
---|
131 | { "AR", RTEMS_BARRIER_AUTOMATIC_RELEASE, 0 }, |
---|
132 | { "ST", RTEMS_SYSTEM_TASK, 0 }, |
---|
133 | { 0, 0, 0 }, |
---|
134 | }; |
---|
135 | |
---|
136 | int |
---|
137 | rtems_monitor_dump_attributes(rtems_attribute attributes) |
---|
138 | { |
---|
139 | int length = 0; |
---|
140 | |
---|
141 | if (attributes == RTEMS_DEFAULT_ATTRIBUTES) /* value is 0 */ |
---|
142 | length += fprintf(stdout,"DEFAULT"); |
---|
143 | |
---|
144 | length += rtems_monitor_dump_assoc_bitfield(rtems_monitor_attribute_assoc, |
---|
145 | ":", |
---|
146 | attributes); |
---|
147 | return length; |
---|
148 | } |
---|
149 | |
---|
150 | static const rtems_assoc_t rtems_monitor_modes_assoc[] = { |
---|
151 | { "nP", RTEMS_NO_PREEMPT, 0 }, |
---|
152 | { "T", RTEMS_TIMESLICE, 0 }, |
---|
153 | { "nA", RTEMS_NO_ASR, 0 }, |
---|
154 | { 0, 0, 0 }, |
---|
155 | }; |
---|
156 | |
---|
157 | int |
---|
158 | rtems_monitor_dump_modes(rtems_mode modes) |
---|
159 | { |
---|
160 | uint32_t length = 0; |
---|
161 | |
---|
162 | if (modes == RTEMS_DEFAULT_MODES) /* value is 0 */ |
---|
163 | length += fprintf(stdout,"P:T:nA"); |
---|
164 | |
---|
165 | length += rtems_monitor_dump_assoc_bitfield(rtems_monitor_modes_assoc, |
---|
166 | ":", |
---|
167 | modes); |
---|
168 | return length; |
---|
169 | } |
---|
170 | |
---|
171 | int |
---|
172 | rtems_monitor_dump_events(rtems_event_set events) |
---|
173 | { |
---|
174 | if (events == 0) |
---|
175 | return fprintf(stdout," NONE "); |
---|
176 | |
---|
177 | return fprintf(stdout,"%08" PRIx32, events); |
---|
178 | } |
---|