1 | /* |
---|
2 | * Copyright (c) 2015 Chris Johns <chrisj@rtems.org> |
---|
3 | * |
---|
4 | * The license and distribution terms for this file may be |
---|
5 | * found in the file LICENSE in this distribution or at |
---|
6 | * http://www.rtems.org/license/LICENSE. |
---|
7 | */ |
---|
8 | |
---|
9 | #include <rtems.h> |
---|
10 | |
---|
11 | #include <rtems/trace/rtems-trace-buffer-vars.h> |
---|
12 | |
---|
13 | /** |
---|
14 | * External Trace Linker and TBG data. We provide weak versions to allow us to |
---|
15 | * link and be present in an application that has not been trace linked. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * Trace linker data. |
---|
20 | */ |
---|
21 | uint32_t __rtld_trace_names_size __attribute__ ((weak)); |
---|
22 | const char const* __rtld_trace_names[1] __attribute__ ((weak)); |
---|
23 | uint32_t __rtld_trace_enables_size __attribute__ ((weak)); |
---|
24 | const uint32_t __rtld_trace_enables[1] __attribute__ ((weak)); |
---|
25 | uint32_t __rtld_trace_triggers_size __attribute__ ((weak)); |
---|
26 | const uint32_t __rtld_trace_triggers[1] __attribute__ ((weak)); |
---|
27 | const __rtld_trace_sig __rtld_trace_signatures[1] __attribute__ ((weak)); |
---|
28 | |
---|
29 | /* |
---|
30 | * Trace buffer generator data. |
---|
31 | */ |
---|
32 | const bool __rtld_tbg_present __attribute__ ((weak)); |
---|
33 | const uint32_t __rtld_tbg_mode __attribute__ ((weak)); |
---|
34 | const uint32_t __rtld_tbg_buffer_size __attribute__ ((weak)); |
---|
35 | uint32_t __rtld_tbg_buffer[1] __attribute__ ((weak)); |
---|
36 | volatile uint32_t __rtld_tbg_buffer_in __attribute__ ((weak)); |
---|
37 | volatile bool __rtld_tbg_finished __attribute__ ((weak)); |
---|
38 | volatile bool __rtld_tbg_triggered __attribute__ ((weak)); |
---|
39 | |
---|
40 | ISR_LOCK_DEFINE (static, __rtld_tbg_lock, "RTLD TBG") |
---|
41 | |
---|
42 | uint32_t |
---|
43 | rtems_trace_names_size (void) |
---|
44 | { |
---|
45 | return __rtld_trace_names_size; |
---|
46 | } |
---|
47 | |
---|
48 | const char* |
---|
49 | rtems_trace_names (const uint32_t index) |
---|
50 | { |
---|
51 | return __rtld_trace_names[index]; |
---|
52 | } |
---|
53 | |
---|
54 | uint32_t |
---|
55 | rtems_trace_enables_size (void) |
---|
56 | { |
---|
57 | return __rtld_trace_enables_size; |
---|
58 | } |
---|
59 | |
---|
60 | uint32_t |
---|
61 | rtems_trace_enables (const uint32_t index) |
---|
62 | { |
---|
63 | return __rtld_trace_enables[index]; |
---|
64 | } |
---|
65 | |
---|
66 | uint32_t |
---|
67 | rtems_trace_triggers_size (void) |
---|
68 | { |
---|
69 | return __rtld_trace_triggers_size; |
---|
70 | } |
---|
71 | |
---|
72 | uint32_t |
---|
73 | rtems_trace_triggers (const uint32_t index) |
---|
74 | { |
---|
75 | return __rtld_trace_triggers[index]; |
---|
76 | } |
---|
77 | |
---|
78 | const rtems_trace_sig* |
---|
79 | rtems_trace_signatures (const uint32_t index) |
---|
80 | { |
---|
81 | return &__rtld_trace_signatures[index]; |
---|
82 | } |
---|
83 | |
---|
84 | bool |
---|
85 | rtems_trace_enable_set(const uint32_t index) |
---|
86 | { |
---|
87 | return (__rtld_trace_enables[index / 32] & (1 << (index & (32 - 1)))) != 0 ? true : false; |
---|
88 | } |
---|
89 | |
---|
90 | bool |
---|
91 | rtems_trace_trigger_set(const uint32_t index) |
---|
92 | { |
---|
93 | return (__rtld_trace_triggers[index / 32] & (1 << (index & (32 - 1)))) != 0 ? true : false; |
---|
94 | } |
---|
95 | |
---|
96 | bool |
---|
97 | rtems_trace_buffering_present (void) |
---|
98 | { |
---|
99 | return __rtld_tbg_present; |
---|
100 | } |
---|
101 | |
---|
102 | uint32_t |
---|
103 | rtems_trace_buffering_mode (void) |
---|
104 | { |
---|
105 | return __rtld_tbg_mode; |
---|
106 | } |
---|
107 | |
---|
108 | uint32_t |
---|
109 | rtems_trace_buffering_buffer_size (void) |
---|
110 | { |
---|
111 | return __rtld_tbg_buffer_size; |
---|
112 | } |
---|
113 | |
---|
114 | uint32_t* |
---|
115 | rtems_trace_buffering_buffer (void) |
---|
116 | { |
---|
117 | return &__rtld_tbg_buffer[0]; |
---|
118 | } |
---|
119 | |
---|
120 | uint32_t |
---|
121 | rtems_trace_buffering_buffer_in (void) |
---|
122 | { |
---|
123 | rtems_interrupt_lock_context lcontext; |
---|
124 | uint32_t in; |
---|
125 | rtems_interrupt_lock_acquire(&__rtld_tbg_lock, &lcontext); |
---|
126 | in = __rtld_tbg_buffer_in; |
---|
127 | rtems_interrupt_lock_release(&__rtld_tbg_lock, &lcontext); |
---|
128 | return in; |
---|
129 | } |
---|
130 | |
---|
131 | bool |
---|
132 | rtems_trace_buffering_finished (void) |
---|
133 | { |
---|
134 | rtems_interrupt_lock_context lcontext; |
---|
135 | bool finished; |
---|
136 | rtems_interrupt_lock_acquire(&__rtld_tbg_lock, &lcontext); |
---|
137 | finished = __rtld_tbg_finished; |
---|
138 | rtems_interrupt_lock_release(&__rtld_tbg_lock, &lcontext); |
---|
139 | return finished; |
---|
140 | } |
---|
141 | |
---|
142 | bool |
---|
143 | rtems_trace_buffering_triggered (void) |
---|
144 | { |
---|
145 | rtems_interrupt_lock_context lcontext; |
---|
146 | bool triggered; |
---|
147 | rtems_interrupt_lock_acquire(&__rtld_tbg_lock, &lcontext); |
---|
148 | triggered = __rtld_tbg_triggered; |
---|
149 | rtems_interrupt_lock_release(&__rtld_tbg_lock, &lcontext); |
---|
150 | return triggered; |
---|
151 | } |
---|
152 | |
---|
153 | void |
---|
154 | rtems_trace_buffering_start (void) |
---|
155 | { |
---|
156 | rtems_interrupt_lock_context lcontext; |
---|
157 | rtems_interrupt_lock_acquire(&__rtld_tbg_lock, &lcontext); |
---|
158 | __rtld_tbg_triggered = false; |
---|
159 | __rtld_tbg_buffer_in = 0; |
---|
160 | __rtld_tbg_finished = false; |
---|
161 | rtems_interrupt_lock_release(&__rtld_tbg_lock, &lcontext); |
---|
162 | } |
---|
163 | |
---|
164 | void |
---|
165 | rtems_trace_buffering_stop (void) |
---|
166 | { |
---|
167 | rtems_interrupt_lock_context lcontext; |
---|
168 | rtems_interrupt_lock_acquire(&__rtld_tbg_lock, &lcontext); |
---|
169 | __rtld_tbg_finished = true; |
---|
170 | rtems_interrupt_lock_release(&__rtld_tbg_lock, &lcontext); |
---|
171 | } |
---|
172 | |
---|
173 | void |
---|
174 | rtems_trace_buffering_resume (void) |
---|
175 | { |
---|
176 | rtems_interrupt_lock_context lcontext; |
---|
177 | rtems_interrupt_lock_acquire(&__rtld_tbg_lock, &lcontext); |
---|
178 | __rtld_tbg_finished = false; |
---|
179 | rtems_interrupt_lock_release(&__rtld_tbg_lock, &lcontext); |
---|
180 | } |
---|