diff mbox

[U-Boot] RFC: Aligning arch initialisation sequences

Message ID 20101114195506.B5B7A14EA7E@gemini.denx.de
State RFC
Headers show

Commit Message

Wolfgang Denk Nov. 14, 2010, 7:55 p.m. UTC
Dear Albert ARIBAUD,

In message <4CE0388E.2070601@free.fr> you wrote:
>
> > Register use is documented in the top level README.
>
> My bad: I'd missed that one because I always go straight to the doc/
> directory for documentation of this kind -- the root README I never read
> apart from the first few pages, and I would not have thought it to give
> this level of detail.

;-)

> BTW, a fix to this ./README is in order as GOT is not used any more with
> ELF ARM relocation, so r9 is not needed for this anymore...

Agreed.

> ... and even though I don't like the idea of reserving a register for
> gd, since we must for the moment, then using the (now available) r9
> register would be *more* 'EABI/AAPCS-compliant' than using r8 (as I
> said, one could think of this use of r9 as 'our AAPCS variant').

Actually situation might be differenton ARM. I just did  quick and
ditry test for the TX25 board:




Compare sizes for "tx25":

   text    data     bss     dec     hex filename
 158730    8668   37120  204518   31ee6 ./u-boot	with register
 158574    8672   37120  204366   31e4e ./u-boot	with global pointer

The global pointer method saves a total of 152 bytes here
(156 in .text saved, but 4 in .data needed).

OK, this is not even 0.1% of the size, but anyway...

Best regards,

Wolfgang Denk

Comments

Albert ARIBAUD Nov. 14, 2010, 8:10 p.m. UTC | #1
Le 14/11/2010 20:55, Wolfgang Denk a écrit :

 > Actually situation might be differenton ARM. I just did  quick and
 > ditry test for the TX25 board:
 >
 > [...]
 >
 > The global pointer method saves a total of 152 bytes here
 > (156 in .text saved, but 4 in .data needed).
 >
 > OK, this is not even 0.1% of the size, but anyway...

If the difference in size is marginal, then I prefer the implementation 
that has the least 'quirks' and most closely complies with EABI/AAPCS.

BTW your quick'n'dirty test puts GD at a fixed location identical for 
code running before and after relocation, right? But do we not change 
the stack location?

 > Best regards,
 >
 > Wolfgang Denk

Amicalement,
Wolfgang Denk Nov. 14, 2010, 8:42 p.m. UTC | #2
Dear Albert ARIBAUD,

In message <4CE04241.7070407@free.fr> you wrote:
> 
>  > OK, this is not even 0.1% of the size, but anyway...
> 
> If the difference in size is marginal, then I prefer the implementation 
> that has the least 'quirks' and most closely complies with EABI/AAPCS.

Yes, I agree. On ARM the global pointermethod has both the advantage
of being cleaner and giving slightly smaller code.

> BTW your quick'n'dirty test puts GD at a fixed location identical for 
> code running before and after relocation, right? But do we not change 
> the stack location?

Yes, we do. I just wanted to compile it for the code size difference;
I did not attempt to make a perfect patch yet :-)

Best regards,

Wolfgang Denk
diff mbox

Patch

diff --git a/arch/arm/cpu/arm926ejs/config.mk b/arch/arm/cpu/arm926ejs/config.mk
index f8ef90f..f8bbeba 100644
--- a/arch/arm/cpu/arm926ejs/config.mk
+++ b/arch/arm/cpu/arm926ejs/config.mk
@@ -21,7 +21,7 @@ 
 # MA 02111-1307 USA
 #
 
-PLATFORM_RELFLAGS += -fno-common -ffixed-r8 -msoft-float
+PLATFORM_RELFLAGS += -fno-common -msoft-float
 
 PLATFORM_CPPFLAGS += -march=armv5te
 # =========================================================================
diff --git a/arch/arm/include/asm/global_data.h b/arch/arm/include/asm/global_data.h
index ada3fbb..7561523 100644
--- a/arch/arm/include/asm/global_data.h
+++ b/arch/arm/include/asm/global_data.h
@@ -86,6 +86,13 @@  typedef	struct	global_data {
 #define GD_FLG_DISABLE_CONSOLE	0x00040	/* Disable console (in & out)		*/
 #define GD_FLG_ENV_READY	0x00080	/* Environment imported into hash table	*/
 
+
+#if 0
 #define DECLARE_GLOBAL_DATA_PTR     register volatile gd_t *gd asm ("r8")
+#else /* We could use plain global data, but the resulting code is bigger */
+#define XTRN_DECLARE_GLOBAL_DATA_PTR	extern
+#define DECLARE_GLOBAL_DATA_PTR     XTRN_DECLARE_GLOBAL_DATA_PTR \
+				    gd_t *gd
+#endif
 
 #endif /* __ASM_GBL_DATA_H */
diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
index 1fd5f83..b0de6c7 100644
--- a/arch/arm/lib/board.c
+++ b/arch/arm/lib/board.c
@@ -647,3 +647,14 @@  void hang (void)
 	puts ("### ERROR ### Please RESET the board ###\n");
 	for (;;);
 }
+
+#if 1 /* We could use plain global data, but the resulting code is bigger */
+/*
+ * Pointer to initial global data area
+ *
+ * Here we initialize it.
+ */
+#undef	XTRN_DECLARE_GLOBAL_DATA_PTR
+#define XTRN_DECLARE_GLOBAL_DATA_PTR	/* empty = allocate here */
+DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_SP_ADDR);
+#endif  /* 0 */