All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] nios2: fix out of reach case for do_reset
@ 2010-08-13  2:40 Thomas Chou
  2010-08-13  2:52 ` Mike Frysinger
  2010-08-13 23:51 ` [U-Boot] UNS: [Nios2-dev] " Brad Parker
  0 siblings, 2 replies; 7+ messages in thread
From: Thomas Chou @ 2010-08-13  2:40 UTC (permalink / raw)
  To: u-boot

The "Nios II Processor Reference Handbook" said,
"call can transfer execution anywhere within the 256 MByte range
determined by PC31..28. The Nios II GNU linker does not automatically
handle cases in which the address is out of this range."

So we have to use registered "callr" instruction to do the job.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
---
 arch/nios2/cpu/cpu.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/arch/nios2/cpu/cpu.c b/arch/nios2/cpu/cpu.c
index 6379534..d9c3003 100644
--- a/arch/nios2/cpu/cpu.c
+++ b/arch/nios2/cpu/cpu.c
@@ -40,11 +40,13 @@ int checkcpu (void)
 	return (0);
 }
 
-
-int do_reset (void)
+int do_reset(void)
 {
-	void (*rst)(void) = (void(*)(void))CONFIG_SYS_RESET_ADDR;
-	disable_interrupts ();
-	rst();
-	return(0);
+	disable_interrupts();
+	__asm__ __volatile__ (
+	"callr	%0"
+	:
+	: "r" (CONFIG_SYS_RESET_ADDR)
+	);
+	return 0;
 }
-- 
1.7.2.1

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

* [U-Boot] [PATCH] nios2: fix out of reach case for do_reset
  2010-08-13  2:40 [U-Boot] [PATCH] nios2: fix out of reach case for do_reset Thomas Chou
@ 2010-08-13  2:52 ` Mike Frysinger
  2010-08-13  3:26   ` Thomas Chou
  2010-08-13 23:51 ` [U-Boot] UNS: [Nios2-dev] " Brad Parker
  1 sibling, 1 reply; 7+ messages in thread
From: Mike Frysinger @ 2010-08-13  2:52 UTC (permalink / raw)
  To: u-boot

On Thu, Aug 12, 2010 at 10:40 PM, Thomas Chou wrote:
> The "Nios II Processor Reference Handbook" said,
> "call can transfer execution anywhere within the 256 MByte range
> determined by PC31..28. The Nios II GNU linker does not automatically
> handle cases in which the address is out of this range."
>
> So we have to use registered "callr" instruction to do the job.

doesnt NIOS have an insn to call indirectly via a register ?
typically that's how function pointers should be handled when gcc
generates code.
-mike

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

* [U-Boot] [PATCH] nios2: fix out of reach case for do_reset
  2010-08-13  2:52 ` Mike Frysinger
@ 2010-08-13  3:26   ` Thomas Chou
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Chou @ 2010-08-13  3:26 UTC (permalink / raw)
  To: u-boot

On 08/13/2010 10:52 AM, Mike Frysinger wrote:
> On Thu, Aug 12, 2010 at 10:40 PM, Thomas Chou wrote:
>> The "Nios II Processor Reference Handbook" said,
>> "call can transfer execution anywhere within the 256 MByte range
>> determined by PC31..28. The Nios II GNU linker does not automatically
>> handle cases in which the address is out of this range."
>>
>> So we have to use registered "callr" instruction to do the job.
>
> doesnt NIOS have an insn to call indirectly via a register ?
> typically that's how function pointers should be handled when gcc
> generates code.
> -mike
>
>
Hi Mike,

The nios2 does have "callr" instruction to do registered call. But the 
nios2 gcc didn't generate correct code when the reset vector is passed 
as a constant. It just generated a direct "call", which was wrong when 
the reset vector was not located in the same 256MB span as u-boot. The 
gcc does generate correct "callr" if the reset vector is passed as an 
argument. As Altera said, this is a limitation (or bug?) of nios2 toolchain.

So I'd take a similar inline asm approach as we do in linux kernel.

Best regards,
Thomas

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

* [U-Boot] UNS: [Nios2-dev] [PATCH] nios2: fix out of reach case for do_reset
  2010-08-13  2:40 [U-Boot] [PATCH] nios2: fix out of reach case for do_reset Thomas Chou
  2010-08-13  2:52 ` Mike Frysinger
@ 2010-08-13 23:51 ` Brad Parker
  2010-08-16  2:48   ` Thomas Chou
  2010-08-16  2:49   ` [U-Boot] [PATCH v2] " Thomas Chou
  1 sibling, 2 replies; 7+ messages in thread
From: Brad Parker @ 2010-08-13 23:51 UTC (permalink / raw)
  To: u-boot

As a comment, that patch looks pretty ugly.  I might suggest an inline 
function (called "callr" or "nios2_callr") which
encapsulates the __asm__.   That would make the code much easier to read.

You could put the inline function in one of the asm headers.

-brad

Thomas Chou wrote:
> The "Nios II Processor Reference Handbook" said,
> "call can transfer execution anywhere within the 256 MByte range
> determined by PC31..28. The Nios II GNU linker does not automatically
> handle cases in which the address is out of this range."
>
> So we have to use registered "callr" instruction to do the job.
>
> Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
> ---
>  arch/nios2/cpu/cpu.c |   14 ++++++++------
>  1 files changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/arch/nios2/cpu/cpu.c b/arch/nios2/cpu/cpu.c
> index 6379534..d9c3003 100644
> --- a/arch/nios2/cpu/cpu.c
> +++ b/arch/nios2/cpu/cpu.c
> @@ -40,11 +40,13 @@ int checkcpu (void)
>  	return (0);
>  }
>  
> -
> -int do_reset (void)
> +int do_reset(void)
>  {
> -	void (*rst)(void) = (void(*)(void))CONFIG_SYS_RESET_ADDR;
> -	disable_interrupts ();
> -	rst();
> -	return(0);
> +	disable_interrupts();
> +	__asm__ __volatile__ (
> +	"callr	%0"
> +	:
> +	: "r" (CONFIG_SYS_RESET_ADDR)
> +	);
> +	return 0;
>  }
>   

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

* [U-Boot] UNS: [Nios2-dev] [PATCH] nios2: fix out of reach case for do_reset
  2010-08-13 23:51 ` [U-Boot] UNS: [Nios2-dev] " Brad Parker
@ 2010-08-16  2:48   ` Thomas Chou
  2010-08-16  2:49   ` [U-Boot] [PATCH v2] " Thomas Chou
  1 sibling, 0 replies; 7+ messages in thread
From: Thomas Chou @ 2010-08-16  2:48 UTC (permalink / raw)
  To: u-boot

On 08/14/2010 07:51 AM, Brad Parker wrote:
> As a comment, that patch looks pretty ugly.  I might suggest an inline
> function (called "callr" or "nios2_callr") which
> encapsulates the __asm__.   That would make the code much easier to read.
>
> You could put the inline function in one of the asm headers.
>
> -brad

Hi Brad,

Thanks. I will add a macro for the inline asm.

- Thomas

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

* [U-Boot] [PATCH v2] nios2: fix out of reach case for do_reset
  2010-08-13 23:51 ` [U-Boot] UNS: [Nios2-dev] " Brad Parker
  2010-08-16  2:48   ` Thomas Chou
@ 2010-08-16  2:49   ` Thomas Chou
  2010-08-20  2:25     ` Scott McNutt
  1 sibling, 1 reply; 7+ messages in thread
From: Thomas Chou @ 2010-08-16  2:49 UTC (permalink / raw)
  To: u-boot

There is a limitation (or bug?) of nios2 toolchain. The nios2 gcc
didn't generate correct code when the reset vector is passed as a
constant. It just generated a direct "call", which was wrong when
the reset vector was not located in the same 256MB span as u-boot.

The "Nios II Processor Reference Handbook" said,
"call can transfer execution anywhere within the 256 MByte range
determined by PC31..28. The Nios II GNU linker does not automatically
handle cases in which the address is out of this range."

So we have to use registered "callr" instruction to do the job.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
---
v2, add a macro for the inlince asm nios2_callr.

 arch/nios2/cpu/cpu.c            |   11 +++++------
 arch/nios2/include/asm/system.h |    5 +++++
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/arch/nios2/cpu/cpu.c b/arch/nios2/cpu/cpu.c
index 6379534..d9c6544 100644
--- a/arch/nios2/cpu/cpu.c
+++ b/arch/nios2/cpu/cpu.c
@@ -40,11 +40,10 @@ int checkcpu (void)
 	return (0);
 }
 
-
-int do_reset (void)
+int do_reset(void)
 {
-	void (*rst)(void) = (void(*)(void))CONFIG_SYS_RESET_ADDR;
-	disable_interrupts ();
-	rst();
-	return(0);
+	disable_interrupts();
+	/* indirect call to go beyond 256MB limitation of toolchain */
+	nios2_callr(CONFIG_SYS_RESET_ADDR);
+	return 0;
 }
diff --git a/arch/nios2/include/asm/system.h b/arch/nios2/include/asm/system.h
index bb03ca5..086d92b 100644
--- a/arch/nios2/include/asm/system.h
+++ b/arch/nios2/include/asm/system.h
@@ -56,4 +56,9 @@
 	((flags & NIOS2_STATUS_PIE_MSK) == 0x0);	\
 })
 
+/* indirect call to go beyond 256MB limitation of toolchain */
+#define nios2_callr(addr) __asm__ __volatile__ (	\
+	"callr	%0"					\
+	: : "r" (addr))
+
 #endif /* __ASM_NIOS2_SYSTEM_H */
-- 
1.7.2.1

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

* [U-Boot] [PATCH v2] nios2: fix out of reach case for do_reset
  2010-08-16  2:49   ` [U-Boot] [PATCH v2] " Thomas Chou
@ 2010-08-20  2:25     ` Scott McNutt
  0 siblings, 0 replies; 7+ messages in thread
From: Scott McNutt @ 2010-08-20  2:25 UTC (permalink / raw)
  To: u-boot

Thomas,

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

Thanks,
--Scott

Thomas Chou wrote:
> There is a limitation (or bug?) of nios2 toolchain. The nios2 gcc
> didn't generate correct code when the reset vector is passed as a
> constant. It just generated a direct "call", which was wrong when
> the reset vector was not located in the same 256MB span as u-boot.
> 
> The "Nios II Processor Reference Handbook" said,
> "call can transfer execution anywhere within the 256 MByte range
> determined by PC31..28. The Nios II GNU linker does not automatically
> handle cases in which the address is out of this range."
> 
> So we have to use registered "callr" instruction to do the job.
> 
> Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
> ---
> v2, add a macro for the inlince asm nios2_callr.
> 
>  arch/nios2/cpu/cpu.c            |   11 +++++------
>  arch/nios2/include/asm/system.h |    5 +++++
>  2 files changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/nios2/cpu/cpu.c b/arch/nios2/cpu/cpu.c
> index 6379534..d9c6544 100644
> --- a/arch/nios2/cpu/cpu.c
> +++ b/arch/nios2/cpu/cpu.c
> @@ -40,11 +40,10 @@ int checkcpu (void)
>  	return (0);
>  }
>  
> -
> -int do_reset (void)
> +int do_reset(void)
>  {
> -	void (*rst)(void) = (void(*)(void))CONFIG_SYS_RESET_ADDR;
> -	disable_interrupts ();
> -	rst();
> -	return(0);
> +	disable_interrupts();
> +	/* indirect call to go beyond 256MB limitation of toolchain */
> +	nios2_callr(CONFIG_SYS_RESET_ADDR);
> +	return 0;
>  }
> diff --git a/arch/nios2/include/asm/system.h b/arch/nios2/include/asm/system.h
> index bb03ca5..086d92b 100644
> --- a/arch/nios2/include/asm/system.h
> +++ b/arch/nios2/include/asm/system.h
> @@ -56,4 +56,9 @@
>  	((flags & NIOS2_STATUS_PIE_MSK) == 0x0);	\
>  })
>  
> +/* indirect call to go beyond 256MB limitation of toolchain */
> +#define nios2_callr(addr) __asm__ __volatile__ (	\
> +	"callr	%0"					\
> +	: : "r" (addr))
> +
>  #endif /* __ASM_NIOS2_SYSTEM_H */

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

end of thread, other threads:[~2010-08-20  2:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-13  2:40 [U-Boot] [PATCH] nios2: fix out of reach case for do_reset Thomas Chou
2010-08-13  2:52 ` Mike Frysinger
2010-08-13  3:26   ` Thomas Chou
2010-08-13 23:51 ` [U-Boot] UNS: [Nios2-dev] " Brad Parker
2010-08-16  2:48   ` Thomas Chou
2010-08-16  2:49   ` [U-Boot] [PATCH v2] " Thomas Chou
2010-08-20  2:25     ` Scott McNutt

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.