1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (c) 2015 Chris Johns <chrisj@rtems.org> |
---|
5 | * |
---|
6 | * Redistribution and use in source and binary forms, with or without |
---|
7 | * modification, are permitted provided that the following conditions |
---|
8 | * are met: |
---|
9 | * 1. Redistributions of source code must retain the above copyright |
---|
10 | * notice, this list of conditions and the following disclaimer. |
---|
11 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
12 | * notice, this list of conditions and the following disclaimer in the |
---|
13 | * documentation and/or other materials provided with the distribution. |
---|
14 | * |
---|
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
25 | * POSSIBILITY OF SUCH DAMAGE. |
---|
26 | */ |
---|
27 | |
---|
28 | #include <rtems/trace/rtems-trace-buffer-vars.h> |
---|
29 | |
---|
30 | #include <rtems.h> |
---|
31 | |
---|
32 | ISR_LOCK_DEFINE (static, __rtld_tbg_lock, "RTLD TBG") |
---|
33 | |
---|
34 | uint32_t |
---|
35 | rtems_trace_names_size (void) |
---|
36 | { |
---|
37 | return __rtld_trace_names_size; |
---|
38 | } |
---|
39 | |
---|
40 | const char* |
---|
41 | rtems_trace_names (const uint32_t index) |
---|
42 | { |
---|
43 | return __rtld_trace_names[index]; |
---|
44 | } |
---|
45 | |
---|
46 | uint32_t |
---|
47 | rtems_trace_enables_size (void) |
---|
48 | { |
---|
49 | return __rtld_trace_enables_size; |
---|
50 | } |
---|
51 | |
---|
52 | uint32_t |
---|
53 | rtems_trace_enables (const uint32_t index) |
---|
54 | { |
---|
55 | return __rtld_trace_enables[index]; |
---|
56 | } |
---|
57 | |
---|
58 | uint32_t |
---|
59 | rtems_trace_triggers_size (void) |
---|
60 | { |
---|
61 | return __rtld_trace_triggers_size; |
---|
62 | } |
---|
63 | |
---|
64 | uint32_t |
---|
65 | rtems_trace_triggers (const uint32_t index) |
---|
66 | { |
---|
67 | return __rtld_trace_triggers[index]; |
---|
68 | } |
---|
69 | |
---|
70 | const rtems_trace_sig* |
---|
71 | rtems_trace_signatures (const uint32_t index) |
---|
72 | { |
---|
73 | return &__rtld_trace_signatures[index]; |
---|
74 | } |
---|
75 | |
---|
76 | bool |
---|
77 | rtems_trace_enable_set(const uint32_t index) |
---|
78 | { |
---|
79 | return (__rtld_trace_enables[index / 32] & (1 << (index & (32 - 1)))) != 0 ? true : false; |
---|
80 | } |
---|
81 | |
---|
82 | bool |
---|
83 | rtems_trace_trigger_set(const uint32_t index) |
---|
84 | { |
---|
85 | return (__rtld_trace_triggers[index / 32] & (1 << (index & (32 - 1)))) != 0 ? true : false; |
---|
86 | } |
---|
87 | |
---|
88 | bool |
---|
89 | rtems_trace_buffering_present (void) |
---|
90 | { |
---|
91 | return __rtld_tbg_present; |
---|
92 | } |
---|
93 | |
---|
94 | uint32_t |
---|
95 | rtems_trace_buffering_mode (void) |
---|
96 | { |
---|
97 | return __rtld_tbg_mode; |
---|
98 | } |
---|
99 | |
---|
100 | uint32_t |
---|
101 | rtems_trace_buffering_buffer_size (void) |
---|
102 | { |
---|
103 | return __rtld_tbg_buffer_size; |
---|
104 | } |
---|
105 | |
---|
106 | uint32_t* |
---|
107 | rtems_trace_buffering_buffer (void) |
---|
108 | { |
---|
109 | return &__rtld_tbg_buffer[0]; |
---|
110 | } |
---|
111 | |
---|
112 | uint32_t |
---|
113 | rtems_trace_buffering_buffer_in (void) |
---|
114 | { |
---|
115 | rtems_interrupt_lock_context lcontext; |
---|
116 | uint32_t in; |
---|
117 | rtems_interrupt_lock_acquire(&__rtld_tbg_lock, &lcontext); |
---|
118 | in = __rtld_tbg_buffer_in; |
---|
119 | rtems_interrupt_lock_release(&__rtld_tbg_lock, &lcontext); |
---|
120 | return in; |
---|
121 | } |
---|
122 | |
---|
123 | bool |
---|
124 | rtems_trace_buffering_finished (void) |
---|
125 | { |
---|
126 | rtems_interrupt_lock_context lcontext; |
---|
127 | bool finished; |
---|
128 | rtems_interrupt_lock_acquire(&__rtld_tbg_lock, &lcontext); |
---|
129 | finished = __rtld_tbg_finished; |
---|
130 | rtems_interrupt_lock_release(&__rtld_tbg_lock, &lcontext); |
---|
131 | return finished; |
---|
132 | } |
---|
133 | |
---|
134 | bool |
---|
135 | rtems_trace_buffering_triggered (void) |
---|
136 | { |
---|
137 | rtems_interrupt_lock_context lcontext; |
---|
138 | bool triggered; |
---|
139 | rtems_interrupt_lock_acquire(&__rtld_tbg_lock, &lcontext); |
---|
140 | triggered = __rtld_tbg_triggered; |
---|
141 | rtems_interrupt_lock_release(&__rtld_tbg_lock, &lcontext); |
---|
142 | return triggered; |
---|
143 | } |
---|
144 | |
---|
145 | void |
---|
146 | rtems_trace_buffering_start (void) |
---|
147 | { |
---|
148 | rtems_interrupt_lock_context lcontext; |
---|
149 | rtems_interrupt_lock_acquire(&__rtld_tbg_lock, &lcontext); |
---|
150 | __rtld_tbg_triggered = false; |
---|
151 | __rtld_tbg_buffer_in = 0; |
---|
152 | __rtld_tbg_finished = false; |
---|
153 | rtems_interrupt_lock_release(&__rtld_tbg_lock, &lcontext); |
---|
154 | } |
---|
155 | |
---|
156 | void |
---|
157 | rtems_trace_buffering_stop (void) |
---|
158 | { |
---|
159 | rtems_interrupt_lock_context lcontext; |
---|
160 | rtems_interrupt_lock_acquire(&__rtld_tbg_lock, &lcontext); |
---|
161 | __rtld_tbg_finished = true; |
---|
162 | rtems_interrupt_lock_release(&__rtld_tbg_lock, &lcontext); |
---|
163 | } |
---|
164 | |
---|
165 | void |
---|
166 | rtems_trace_buffering_resume (void) |
---|
167 | { |
---|
168 | rtems_interrupt_lock_context lcontext; |
---|
169 | rtems_interrupt_lock_acquire(&__rtld_tbg_lock, &lcontext); |
---|
170 | __rtld_tbg_finished = false; |
---|
171 | rtems_interrupt_lock_release(&__rtld_tbg_lock, &lcontext); |
---|
172 | } |
---|