Commit a2fa38da200cbd454bcb8dc7659bde00044302f7
Committed by
Simon Glass
1 parent
7ef8e9b09a
Exists in
smarc_8mq_lf_v2020.04
and in
9 other branches
trace: conserve gd register
An UEFI application may change the value of the register that gd lives in. But some of our functions like get_ticks() access this register. So we have to set the gd register to the U-Boot value when entering a trace point and set it back to the application value when exiting the trace point. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
Showing 1 changed file with 49 additions and 0 deletions Side-by-side Diff
lib/trace.c
... | ... | @@ -56,6 +56,49 @@ |
56 | 56 | return offset / FUNC_SITE_SIZE; |
57 | 57 | } |
58 | 58 | |
59 | +#ifdef CONFIG_EFI_LOADER | |
60 | + | |
61 | +/** | |
62 | + * trace_gd - the value of the gd register | |
63 | + */ | |
64 | +static volatile void *trace_gd; | |
65 | + | |
66 | +/** | |
67 | + * trace_save_gd() - save the value of the gd register | |
68 | + */ | |
69 | +static void __attribute__((no_instrument_function)) trace_save_gd(void) | |
70 | +{ | |
71 | + trace_gd = gd; | |
72 | +} | |
73 | + | |
74 | +/** | |
75 | + * trace_swap_gd() - swap between U-Boot and application gd register value | |
76 | + * | |
77 | + * An UEFI application may change the value of the register that gd lives in. | |
78 | + * But some of our functions like get_ticks() access this register. So we | |
79 | + * have to set the gd register to the U-Boot value when entering a trace | |
80 | + * point and set it back to the application value when exiting the trace point. | |
81 | + */ | |
82 | +static void __attribute__((no_instrument_function)) trace_swap_gd(void) | |
83 | +{ | |
84 | + volatile void *temp_gd = trace_gd; | |
85 | + | |
86 | + trace_gd = gd; | |
87 | + gd = temp_gd; | |
88 | +} | |
89 | + | |
90 | +#else | |
91 | + | |
92 | +static void __attribute__((no_instrument_function)) trace_save_gd(void) | |
93 | +{ | |
94 | +} | |
95 | + | |
96 | +static void __attribute__((no_instrument_function)) trace_swap_gd(void) | |
97 | +{ | |
98 | +} | |
99 | + | |
100 | +#endif | |
101 | + | |
59 | 102 | static void __attribute__((no_instrument_function)) add_ftrace(void *func_ptr, |
60 | 103 | void *caller, ulong flags) |
61 | 104 | { |
... | ... | @@ -100,6 +143,7 @@ |
100 | 143 | if (trace_enabled) { |
101 | 144 | int func; |
102 | 145 | |
146 | + trace_swap_gd(); | |
103 | 147 | add_ftrace(func_ptr, caller, FUNCF_ENTRY); |
104 | 148 | func = func_ptr_to_num(func_ptr); |
105 | 149 | if (func < hdr->func_count) { |
... | ... | @@ -111,6 +155,7 @@ |
111 | 155 | hdr->depth++; |
112 | 156 | if (hdr->depth > hdr->depth_limit) |
113 | 157 | hdr->max_depth = hdr->depth; |
158 | + trace_swap_gd(); | |
114 | 159 | } |
115 | 160 | } |
116 | 161 | |
117 | 162 | |
... | ... | @@ -126,8 +171,10 @@ |
126 | 171 | void *func_ptr, void *caller) |
127 | 172 | { |
128 | 173 | if (trace_enabled) { |
174 | + trace_swap_gd(); | |
129 | 175 | add_ftrace(func_ptr, caller, FUNCF_EXIT); |
130 | 176 | hdr->depth--; |
177 | + trace_swap_gd(); | |
131 | 178 | } |
132 | 179 | } |
133 | 180 | |
... | ... | @@ -283,6 +330,8 @@ |
283 | 330 | ulong func_count = gd->mon_len / FUNC_SITE_SIZE; |
284 | 331 | size_t needed; |
285 | 332 | int was_disabled = !trace_enabled; |
333 | + | |
334 | + trace_save_gd(); | |
286 | 335 | |
287 | 336 | if (!was_disabled) { |
288 | 337 | #ifdef CONFIG_TRACE_EARLY |