public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Scott McNutt <smcnutt@psyent.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2] nios2: fix r15 issue for gcc4
Date: Tue, 25 May 2010 16:57:06 -0400	[thread overview]
Message-ID: <4BFC39A2.70804@psyent.com> (raw)
In-Reply-To: <1274411283-910-2-git-send-email-thomas@wytron.com.tw>

Applied to:
    git://git.denx.de/u-boot-nios.git next

Thanks,
--Scott

Thomas Chou wrote:
> The "-ffixed-r15" option doesn't work well for gcc4. Since we
> don't use gp for small data with option "-G0", we can use gp
> as global data pointer. This allows compiler to use r15. It
> is necessary for gcc4 to work properly.
> 
> Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
> ---
> v2: update standalone stubs and doc.
> 
>  README                               |    8 ++++++++
>  arch/nios2/config.mk                 |    2 +-
>  arch/nios2/cpu/start.S               |    7 -------
>  arch/nios2/include/asm/global_data.h |    2 +-
>  doc/README.standalone                |   13 +++++++------
>  examples/standalone/stubs.c          |    6 +++---
>  6 files changed, 20 insertions(+), 18 deletions(-)
> 
> diff --git a/README b/README
> index 81692c0..acb3308 100644
> --- a/README
> +++ b/README
> @@ -4023,6 +4023,14 @@ On ARM, the following registers are used:
>  
>      ==> U-Boot will use R8 to hold a pointer to the global data
>  
> +On Nios II, the ABI is documented here:
> +	http://www.altera.com/literature/hb/nios2/n2cpu_nii51016.pdf
> +
> +    ==> U-Boot will use gp to hold a pointer to the global data
> +
> +    Note: on Nios II, we give "-G0" option to gcc and don't use gp
> +    to access small data sections, so gp is free.
> +
>  NOTE: DECLARE_GLOBAL_DATA_PTR must be used with file-global scope,
>  or current versions of GCC may "optimize" the code too much.
>  
> diff --git a/arch/nios2/config.mk b/arch/nios2/config.mk
> index 8e5d6ef..6789038 100644
> --- a/arch/nios2/config.mk
> +++ b/arch/nios2/config.mk
> @@ -27,6 +27,6 @@ CROSS_COMPILE ?= nios2-elf-
>  STANDALONE_LOAD_ADDR = 0x02000000 -L $(gcclibdir)
>  
>  PLATFORM_CPPFLAGS += -DCONFIG_NIOS2 -D__NIOS2__
> -PLATFORM_CPPFLAGS += -ffixed-r15 -G0
> +PLATFORM_CPPFLAGS += -G0
>  
>  LDSCRIPT ?= $(SRCTREE)/$(CPUDIR)/u-boot.lds
> diff --git a/arch/nios2/cpu/start.S b/arch/nios2/cpu/start.S
> index d1016ea..76d3b52 100644
> --- a/arch/nios2/cpu/start.S
> +++ b/arch/nios2/cpu/start.S
> @@ -113,13 +113,6 @@ _cur:	movhi	r5, %hi(_cur - _start)
>  	 bne	r5, r6, 4b
>  5:
>  
> -	/* GLOBAL POINTER -- the global pointer is used to reference
> -	 * "small data" (see -G switch). The linker script must
> -	 * provide the gp address.
> -	 */
> -	 movhi	gp, %hi(_gp)
> -	 ori	gp, gp, %lo(_gp)
> -
>  	/* JUMP TO RELOC ADDR */
>  	movhi	r4, %hi(_reloc)
>  	ori	r4, r4, %lo(_reloc)
> diff --git a/arch/nios2/include/asm/global_data.h b/arch/nios2/include/asm/global_data.h
> index 34aa962..f1b3482 100644
> --- a/arch/nios2/include/asm/global_data.h
> +++ b/arch/nios2/include/asm/global_data.h
> @@ -48,6 +48,6 @@ typedef	struct	global_data {
>  #define	GD_FLG_LOGINIT	0x00020		/* Log Buffer has been initialized	*/
>  #define GD_FLG_DISABLE_CONSOLE	0x00040		/* Disable console (in & out)	 */
>  
> -#define DECLARE_GLOBAL_DATA_PTR     register gd_t *gd asm ("r15")
> +#define DECLARE_GLOBAL_DATA_PTR     register gd_t *gd asm ("gp")
>  
>  #endif /* __ASM_NIOS2_GLOBALDATA_H_ */
> diff --git a/doc/README.standalone b/doc/README.standalone
> index 885c92f..6381087 100644
> --- a/doc/README.standalone
> +++ b/doc/README.standalone
> @@ -19,12 +19,12 @@ Design Notes on Exporting U-Boot Functions to Standalone Applications:
>     thus the compiler cannot perform type checks on these assignments.
>  
>  2. The pointer to the jump table is passed to the application in a
> -   machine-dependent way. PowerPC, ARM, MIPS and Blackfin architectures
> -   use a dedicated register to hold the pointer to the 'global_data'
> -   structure: r2 on PowerPC, r8 on ARM, k0 on MIPS, and P3 on Blackfin.
> -   The x86 architecture does not use such a register; instead, the
> -   pointer to the 'global_data' structure is passed as 'argv[-1]'
> -   pointer.
> +   machine-dependent way. PowerPC, ARM, MIPS, Blackfin and Nios II
> +   architectures use a dedicated register to hold the pointer to the
> +   'global_data' structure: r2 on PowerPC, r8 on ARM, k0 on MIPS,
> +   P3 on Blackfin and gp on Nios II. The x86 architecture does not
> +   use such a register; instead, the pointer to the 'global_data'
> +   structure is passed as 'argv[-1]' pointer.
>  
>     The application can access the 'global_data' structure in the same
>     way as U-Boot does:
> @@ -56,6 +56,7 @@ Design Notes on Exporting U-Boot Functions to Standalone Applications:
>  	ARM		0x0c100000	0x0c100000
>  	MIPS		0x80200000	0x80200000
>  	Blackfin	0x00001000	0x00001000
> +	Nios II		0x02000000	0x02000000
>  
>     For example, the "hello world" application may be loaded and
>     executed on a PowerPC board with the following commands:
> diff --git a/examples/standalone/stubs.c b/examples/standalone/stubs.c
> index ce3371d..0187708 100644
> --- a/examples/standalone/stubs.c
> +++ b/examples/standalone/stubs.c
> @@ -84,7 +84,7 @@ gd_t *global_data;
>  	: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x) : "r0");
>  #elif defined(CONFIG_NIOS2)
>  /*
> - * r15 holds the pointer to the global_data, r8 is call-clobbered
> + * gp holds the pointer to the global_data, r8 is call-clobbered
>   */
>  #define EXPORT_FUNC(x) \
>  	asm volatile (			\
> @@ -92,11 +92,11 @@ gd_t *global_data;
>  #x ":\n"				\
>  "	movhi	r8, %%hi(%0)\n"		\
>  "	ori	r8, r0, %%lo(%0)\n"	\
> -"	add	r8, r8, r15\n"		\
> +"	add	r8, r8, gp\n"		\
>  "	ldw	r8, 0(r8)\n"		\
>  "	ldw	r8, %1(r8)\n"		\
>  "	jmp	r8\n"			\
> -	: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r15");
> +	: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "gp");
>  #elif defined(CONFIG_M68K)
>  /*
>   * d7 holds the pointer to the global_data, a0 is a call-clobbered

      reply	other threads:[~2010-05-25 20:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-14 22:00 [U-Boot] [PATCH] nios2: fix r15 issue for gcc4 Thomas Chou
2010-05-14 22:00 ` [U-Boot] [PATCH] nios2: fix div64 " Thomas Chou
2010-05-25 20:58   ` Scott McNutt
2010-05-19 23:11 ` [U-Boot] [PATCH] nios2: fix r15 " Mike Frysinger
2010-05-20  1:32   ` Thomas Chou
2010-05-21  3:08 ` [U-Boot] [PATCH] nios2: allow STANDALONE_LOAD_ADDR overriding Thomas Chou
2010-05-25 20:58   ` Scott McNutt
2010-05-21  3:08 ` [U-Boot] [PATCH v2] nios2: fix r15 issue for gcc4 Thomas Chou
2010-05-25 20:57   ` Scott McNutt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BFC39A2.70804@psyent.com \
    --to=smcnutt@psyent.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox