All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/1] trace: conserve gd register
@ 2019-06-02 11:05 Heinrich Schuchardt
  2019-06-22 19:10 ` Simon Glass
  0 siblings, 1 reply; 3+ messages in thread
From: Heinrich Schuchardt @ 2019-06-02 11:05 UTC (permalink / raw)
  To: u-boot

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>
---
 lib/trace.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/lib/trace.c b/lib/trace.c
index 9956442fef..a13e5bf228 100644
--- a/lib/trace.c
+++ b/lib/trace.c
@@ -56,6 +56,49 @@ static inline uintptr_t __attribute__((no_instrument_function))
 	return offset / FUNC_SITE_SIZE;
 }

+#ifdef CONFIG_EFI_LOADER
+
+/**
+ * trace_gd - the value of the gd register
+ */
+static volatile void *trace_gd;
+
+/**
+ * trace_save_gd() - save the value of the gd register
+ */
+static void __attribute__((no_instrument_function)) trace_save_gd(void)
+{
+	trace_gd = gd;
+}
+
+/**
+ * trace_swap_gd() - swap between U-Boot and application gd register value
+ *
+ * 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.
+ */
+static void __attribute__((no_instrument_function)) trace_swap_gd(void)
+{
+	volatile void *temp_gd = trace_gd;
+
+	trace_gd = gd;
+	gd = temp_gd;
+}
+
+#else
+
+static void __attribute__((no_instrument_function)) trace_save_gd(void)
+{
+}
+
+static void __attribute__((no_instrument_function)) trace_swap_gd(void)
+{
+}
+
+#endif
+
 static void __attribute__((no_instrument_function)) add_ftrace(void *func_ptr,
 				void *caller, ulong flags)
 {
@@ -100,6 +143,7 @@ void __attribute__((no_instrument_function)) __cyg_profile_func_enter(
 	if (trace_enabled) {
 		int func;

+		trace_swap_gd();
 		add_ftrace(func_ptr, caller, FUNCF_ENTRY);
 		func = func_ptr_to_num(func_ptr);
 		if (func < hdr->func_count) {
@@ -111,6 +155,7 @@ void __attribute__((no_instrument_function)) __cyg_profile_func_enter(
 		hdr->depth++;
 		if (hdr->depth > hdr->depth_limit)
 			hdr->max_depth = hdr->depth;
+		trace_swap_gd();
 	}
 }

@@ -126,8 +171,10 @@ void __attribute__((no_instrument_function)) __cyg_profile_func_exit(
 		void *func_ptr, void *caller)
 {
 	if (trace_enabled) {
+		trace_swap_gd();
 		add_ftrace(func_ptr, caller, FUNCF_EXIT);
 		hdr->depth--;
+		trace_swap_gd();
 	}
 }

@@ -284,6 +331,8 @@ int __attribute__((no_instrument_function)) trace_init(void *buff,
 	size_t needed;
 	int was_disabled = !trace_enabled;

+	trace_save_gd();
+
 	if (!was_disabled) {
 #ifdef CONFIG_TRACE_EARLY
 		char *end;
--
2.20.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH 1/1] trace: conserve gd register
  2019-06-02 11:05 [U-Boot] [PATCH 1/1] trace: conserve gd register Heinrich Schuchardt
@ 2019-06-22 19:10 ` Simon Glass
  2019-06-28 13:55   ` Simon Glass
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Glass @ 2019-06-22 19:10 UTC (permalink / raw)
  To: u-boot

On Sun, 2 Jun 2019 at 12:05, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> 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>
> ---
>  lib/trace.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 49 insertions(+)

Ick. I can't think of a better idea.

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH 1/1] trace: conserve gd register
  2019-06-22 19:10 ` Simon Glass
@ 2019-06-28 13:55   ` Simon Glass
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Glass @ 2019-06-28 13:55 UTC (permalink / raw)
  To: u-boot

On Sat, 22 Jun 2019 at 13:10, Simon Glass <sjg@chromium.org> wrote:
>
> On Sun, 2 Jun 2019 at 12:05, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> >
> > 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>
> > ---
> >  lib/trace.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 49 insertions(+)
>
> Ick. I can't think of a better idea.
>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm/next, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-06-28 13:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-02 11:05 [U-Boot] [PATCH 1/1] trace: conserve gd register Heinrich Schuchardt
2019-06-22 19:10 ` Simon Glass
2019-06-28 13:55   ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.