mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] ARM lowlevel: Update function documentation
@ 2012-09-09  9:47 Sascha Hauer
  2012-09-09  9:47 ` [PATCH 2/3] ARM: Add assembler function to get runtime offset Sascha Hauer
  2012-09-09  9:47 ` [PATCH 3/3] ARM lowlevel: Use get_runtime_offset Sascha Hauer
  0 siblings, 2 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-09-09  9:47 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/cpu/start-pbl.c   |    3 +++
 arch/arm/cpu/start-reset.c |    3 +++
 arch/arm/cpu/start.c       |    5 ++++-
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/arm/cpu/start-pbl.c b/arch/arm/cpu/start-pbl.c
index 932a3da..09a1940 100644
--- a/arch/arm/cpu/start-pbl.c
+++ b/arch/arm/cpu/start-pbl.c
@@ -36,6 +36,9 @@
 unsigned long free_mem_ptr;
 unsigned long free_mem_end_ptr;
 
+/*
+ * First instructions in the pbl image
+ */
 void __naked __section(.text_head_entry) pbl_start(void)
 {
 	barebox_arm_head();
diff --git a/arch/arm/cpu/start-reset.c b/arch/arm/cpu/start-reset.c
index e0df676..fcfdce6 100644
--- a/arch/arm/cpu/start-reset.c
+++ b/arch/arm/cpu/start-reset.c
@@ -29,6 +29,9 @@
 /*
  * The actual reset vector. This code is position independent and usually
  * does not run at the address it's linked at.
+ *
+ * This is either executed in the pbl image (if enabled) or in the regular
+ * image.
  */
 void __naked __bare_init reset(void)
 {
diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 07e7dfe..e43ff9c 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -30,7 +30,7 @@
 
 #ifdef CONFIG_PBL_IMAGE
 /*
- * First function in the pbl image. We get here from
+ * First function in the uncompressed image. We get here from
  * the pbl.
  */
 void __naked __section(.text_entry) start(void)
@@ -47,6 +47,9 @@ void __naked __section(.text_entry) start(void)
 }
 #else
 
+/*
+ * First function in the image without pbl support
+ */
 void __naked __section(.text_entry) start(void)
 {
 	barebox_arm_head();
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 2/3] ARM: Add assembler function to get runtime offset
  2012-09-09  9:47 [PATCH 1/3] ARM lowlevel: Update function documentation Sascha Hauer
@ 2012-09-09  9:47 ` Sascha Hauer
  2012-09-09 11:12   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-09-09  9:47 ` [PATCH 3/3] ARM lowlevel: Use get_runtime_offset Sascha Hauer
  1 sibling, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2012-09-09  9:47 UTC (permalink / raw)
  To: barebox

This function returns the offset between the address barebox is linked at
and the address barebox is currently running at.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/include/asm/barebox-arm.h |    1 +
 arch/arm/lib/Makefile              |    2 ++
 arch/arm/lib/runtime-offset.S      |   16 ++++++++++++++++
 3 files changed, 19 insertions(+)
 create mode 100644 arch/arm/lib/runtime-offset.S

diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
index b880dd4..3639365 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -42,5 +42,6 @@ extern char __ll_return[];
 void board_init_lowlevel(void);
 void board_init_lowlevel_return(void);
 void arch_init_lowlevel(void);
+uint32_t get_runtime_offset(void);
 
 #endif	/* _BAREBOX_ARM_H_ */
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 9d0ff7a..2e624cd 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -16,6 +16,8 @@ obj-y	+= lib1funcs.o
 obj-y	+= ashrdi3.o
 obj-y	+= ashldi3.o
 obj-y	+= lshrdi3.o
+obj-y	+= runtime-offset.o
+pbl-y	+= runtime-offset.o
 obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS)	+= memcpy.o
 obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS)	+= memset.o
 obj-$(CONFIG_ARM_UNWIND) += unwind.o
diff --git a/arch/arm/lib/runtime-offset.S b/arch/arm/lib/runtime-offset.S
new file mode 100644
index 0000000..00d756d
--- /dev/null
+++ b/arch/arm/lib/runtime-offset.S
@@ -0,0 +1,16 @@
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+
+/*
+ * Get the offset between the link address and the address
+ * we are currently running at.
+ */
+ENTRY(get_runtime_offset)
+1:	adr r0, 1b
+	ldr r1, linkadr
+	subs r0, r1, r0
+	mov pc, lr
+
+linkadr:
+.word get_runtime_offset
+ENDPROC(get_runtime_offset)
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 3/3] ARM lowlevel: Use get_runtime_offset
  2012-09-09  9:47 [PATCH 1/3] ARM lowlevel: Update function documentation Sascha Hauer
  2012-09-09  9:47 ` [PATCH 2/3] ARM: Add assembler function to get runtime offset Sascha Hauer
@ 2012-09-09  9:47 ` Sascha Hauer
  1 sibling, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-09-09  9:47 UTC (permalink / raw)
  To: barebox

The current approach to get the offset between link and runtime address
is fragile. It requires a big fat comment to put no code above it and it
requires an extra linker section. Instead use a small assembler function.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/cpu/start-pbl.c           |   12 +++---------
 arch/arm/cpu/start.c               |   12 +++---------
 arch/arm/include/asm/barebox-arm.h |    1 -
 arch/arm/lib/barebox.lds.S         |    2 --
 arch/arm/pbl/zbarebox.lds.S        |    2 --
 5 files changed, 6 insertions(+), 23 deletions(-)

diff --git a/arch/arm/cpu/start-pbl.c b/arch/arm/cpu/start-pbl.c
index 09a1940..5a6b99b 100644
--- a/arch/arm/cpu/start-pbl.c
+++ b/arch/arm/cpu/start-pbl.c
@@ -152,23 +152,17 @@ static void barebox_uncompress(void *compressed_start, unsigned int len)
  * Board code can jump here by either returning from board_init_lowlevel
  * or by calling this function directly.
  */
-void __naked __section(.text_ll_return) board_init_lowlevel_return(void)
+void __naked board_init_lowlevel_return(void)
 {
-	uint32_t r, addr, offset;
+	uint32_t r, offset;
 	uint32_t pg_start, pg_end, pg_len;
 
-	/*
-	 * Get runtime address of this function. Do not
-	 * put any code above this.
-	 */
-	__asm__ __volatile__("1: adr %0, 1b":"=r"(addr));
-
 	/* Setup the stack */
 	r = STACK_BASE + STACK_SIZE - 16;
 	__asm__ __volatile__("mov sp, %0" : : "r"(r));
 
 	/* Get offset between linked address and runtime address */
-	offset = (uint32_t)__ll_return - addr;
+	offset = get_runtime_offset();
 
 	pg_start = (uint32_t)&input_data - offset;
 	pg_end = (uint32_t)&input_data_end - offset;
diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index e43ff9c..4fb0c07 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -59,22 +59,16 @@ void __naked __section(.text_entry) start(void)
  * Board code can jump here by either returning from board_init_lowlevel
  * or by calling this function directly.
  */
-void __naked __section(.text_ll_return) board_init_lowlevel_return(void)
+void __naked board_init_lowlevel_return(uint32_t params)
 {
-	uint32_t r, addr, offset;
-
-	/*
-	 * Get runtime address of this function. Do not
-	 * put any code above this.
-	 */
-	__asm__ __volatile__("1: adr %0, 1b":"=r"(addr));
+	uint32_t r, offset;
 
 	/* Setup the stack */
 	r = STACK_BASE + STACK_SIZE - 16;
 	__asm__ __volatile__("mov sp, %0" : : "r"(r));
 
 	/* Get offset between linked address and runtime address */
-	offset = (uint32_t)__ll_return - addr;
+	offset = get_runtime_offset();
 
 	/* relocate to link address if necessary */
 	if (offset)
diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
index 3639365..a71f420 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -37,7 +37,6 @@ int	board_init(void);
 int	dram_init (void);
 
 extern char __exceptions_start[], __exceptions_stop[];
-extern char __ll_return[];
 
 void board_init_lowlevel(void);
 void board_init_lowlevel_return(void);
diff --git a/arch/arm/lib/barebox.lds.S b/arch/arm/lib/barebox.lds.S
index a69013f..40af705 100644
--- a/arch/arm/lib/barebox.lds.S
+++ b/arch/arm/lib/barebox.lds.S
@@ -40,8 +40,6 @@ SECTIONS
 		_stext = .;
 		_text = .;
 		*(.text_entry*)
-		__ll_return = .;
-		*(.text_ll_return*)
 		__bare_init_start = .;
 		*(.text_bare_init*)
 		__bare_init_end = .;
diff --git a/arch/arm/pbl/zbarebox.lds.S b/arch/arm/pbl/zbarebox.lds.S
index 2dca278..37af4e9 100644
--- a/arch/arm/pbl/zbarebox.lds.S
+++ b/arch/arm/pbl/zbarebox.lds.S
@@ -39,8 +39,6 @@ SECTIONS
 		_stext = .;
 		_text = .;
 		*(.text_head_entry*)
-		__ll_return = .;
-		*(.text_ll_return*)
 		__bare_init_start = .;
 		*(.text_bare_init*)
 		__bare_init_end = .;
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 2/3] ARM: Add assembler function to get runtime offset
  2012-09-09  9:47 ` [PATCH 2/3] ARM: Add assembler function to get runtime offset Sascha Hauer
@ 2012-09-09 11:12   ` Jean-Christophe PLAGNIOL-VILLARD
  2012-09-09 16:27     ` Sascha Hauer
  0 siblings, 1 reply; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-09-09 11:12 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 11:47 Sun 09 Sep     , Sascha Hauer wrote:
> This function returns the offset between the address barebox is linked at
> and the address barebox is currently running at.
 this work on thumb2?

 IIRC you add the specific section as we have isseu on thumb2

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 2/3] ARM: Add assembler function to get runtime offset
  2012-09-09 11:12   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-09-09 16:27     ` Sascha Hauer
  0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-09-09 16:27 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Sun, Sep 09, 2012 at 01:12:40PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 11:47 Sun 09 Sep     , Sascha Hauer wrote:
> > This function returns the offset between the address barebox is linked at
> > and the address barebox is currently running at.
>  this work on thumb2?

No, it doesn't work on thumb2. Will fix.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 2/3] ARM: Add assembler function to get runtime offset
  2012-09-10  7:56 [PATCH v2] ARM lowlevel Sascha Hauer
@ 2012-09-10  7:56 ` Sascha Hauer
  0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-09-10  7:56 UTC (permalink / raw)
  To: barebox

This function returns the offset between the address barebox is linked at
and the address barebox is currently running at.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/include/asm/barebox-arm.h |    1 +
 arch/arm/lib/Makefile              |    2 ++
 arch/arm/lib/runtime-offset.S      |   17 +++++++++++++++++
 3 files changed, 20 insertions(+)
 create mode 100644 arch/arm/lib/runtime-offset.S

diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
index b880dd4..3639365 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -42,5 +42,6 @@ extern char __ll_return[];
 void board_init_lowlevel(void);
 void board_init_lowlevel_return(void);
 void arch_init_lowlevel(void);
+uint32_t get_runtime_offset(void);
 
 #endif	/* _BAREBOX_ARM_H_ */
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 9d0ff7a..2e624cd 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -16,6 +16,8 @@ obj-y	+= lib1funcs.o
 obj-y	+= ashrdi3.o
 obj-y	+= ashldi3.o
 obj-y	+= lshrdi3.o
+obj-y	+= runtime-offset.o
+pbl-y	+= runtime-offset.o
 obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS)	+= memcpy.o
 obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS)	+= memset.o
 obj-$(CONFIG_ARM_UNWIND) += unwind.o
diff --git a/arch/arm/lib/runtime-offset.S b/arch/arm/lib/runtime-offset.S
new file mode 100644
index 0000000..ffa668c
--- /dev/null
+++ b/arch/arm/lib/runtime-offset.S
@@ -0,0 +1,17 @@
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+
+/*
+ * Get the offset between the link address and the address
+ * we are currently running at.
+ */
+ENTRY(get_runtime_offset)
+1:	adr r0, 1b
+	ldr r1, linkadr
+	subs r0, r1, r0
+THUMB(	subs r0, r0, #1)
+	mov pc, lr
+
+linkadr:
+.word get_runtime_offset
+ENDPROC(get_runtime_offset)
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2012-09-10  7:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-09  9:47 [PATCH 1/3] ARM lowlevel: Update function documentation Sascha Hauer
2012-09-09  9:47 ` [PATCH 2/3] ARM: Add assembler function to get runtime offset Sascha Hauer
2012-09-09 11:12   ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-09 16:27     ` Sascha Hauer
2012-09-09  9:47 ` [PATCH 3/3] ARM lowlevel: Use get_runtime_offset Sascha Hauer
2012-09-10  7:56 [PATCH v2] ARM lowlevel Sascha Hauer
2012-09-10  7:56 ` [PATCH 2/3] ARM: Add assembler function to get runtime offset Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox