public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] ARM: Use do_div() instead of division for "long long".
@ 2008-09-08 22:59 Wolfgang Denk
  0 siblings, 0 replies; 7+ messages in thread
From: Wolfgang Denk @ 2008-09-08 22:59 UTC (permalink / raw)
  To: u-boot

From: Sergei Poselenov <sposelenov@emcraft.com>

Signed-off-by: Sergei Poselenov <sposelenov@emcraft.com>
Signed-off-by: Wolfgang Denk <wd@denx.de>
---

With some (more recent) compiler versions there are problems because
of the use of "long long" divisions in the U-Boot code. For ARM, this
requires the __udivdi3 GCC library function, which currently is not
present in lib_arm. This function was present in older 2.6 kernels,
but at some point it was removed from here, with suggestion to use
do_div() instead. In U-boot, the do_div() function is available, too,
so this patch generally does the replacement of the "long long"
divisions to do_div() to avoid the aforementions issues.

 board/integratorcp/integratorcp.c |    7 ++++++-
 board/trab/tsc2000.c              |   10 ++++++----
 cpu/arm1176/s3c64xx/interrupts.c  |    5 ++++-
 cpu/arm946es/config.mk            |    7 +++++++
 cpu/arm_intcm/config.mk           |    7 +++++++
 5 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/board/integratorcp/integratorcp.c b/board/integratorcp/integratorcp.c
index d6d6e13..220513f 100644
--- a/board/integratorcp/integratorcp.c
+++ b/board/integratorcp/integratorcp.c
@@ -34,6 +34,7 @@
  */
 
 #include <common.h>
+#include <div64.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -244,7 +245,11 @@ ulong get_timer_masked (void)
 		total_count += lastdec - now;
 	}
 	lastdec	  = now;
-	timestamp = (ulong)(total_count/div_timer);
+
+	/* Reuse "now" */
+	now = total_count;
+	do_div(now, div_timer);
+	timestamp = now;
 
 	return timestamp;
 }
diff --git a/board/trab/tsc2000.c b/board/trab/tsc2000.c
index 382a85b..f13a5a9 100644
--- a/board/trab/tsc2000.c
+++ b/board/trab/tsc2000.c
@@ -27,6 +27,7 @@
 
 #include <common.h>
 #include <s3c2400.h>
+#include <div64.h>
 #include "tsc2000.h"
 
 #include "Pt1000_temp_data.h"
@@ -332,6 +333,7 @@ void tsc2000_reg_init (void)
 int tsc2000_interpolate(long value, long data[][2], long *result)
 {
 	int i;
+	unsigned long long val;
 
 	/* the data is sorted and the first element is upper
 	 * limit so we can easily check for out-of-band values
@@ -347,10 +349,10 @@ int tsc2000_interpolate(long value, long data[][2], long *result)
 	   result in 'long long'.
 	*/
 
-	*result = data[i-1][1] +
-		((unsigned long long)(data[i][1] - data[i-1][1])
-		 * (unsigned long long)(value - data[i-1][0]))
-		/ (data[i][0] - data[i-1][0]);
+	val = ((unsigned long long)(data[i][1] - data[i-1][1])
+		   * (unsigned long long)(value - data[i-1][0]));
+	do_div(val, (data[i][0] - data[i-1][0]));
+	*result = data[i-1][1] + val;
 
 	return 0;
 }
diff --git a/cpu/arm1176/s3c64xx/interrupts.c b/cpu/arm1176/s3c64xx/interrupts.c
index 8356ae4..e34369f 100644
--- a/cpu/arm1176/s3c64xx/interrupts.c
+++ b/cpu/arm1176/s3c64xx/interrupts.c
@@ -41,6 +41,7 @@
 #include <common.h>
 #include <asm/proc-armv/ptrace.h>
 #include <s3c6400.h>
+#include <div64.h>
 
 static ulong timer_load_val;
 
@@ -148,7 +149,9 @@ void reset_timer(void)
 
 ulong get_timer_masked(void)
 {
-	return get_ticks() / (timer_load_val / (100 * CFG_HZ));
+	unsigned long long res = get_ticks();
+	do_div (res, (timer_load_val / (100 * CFG_HZ)));
+	return res;
 }
 
 ulong get_timer(ulong base)
diff --git a/cpu/arm946es/config.mk b/cpu/arm946es/config.mk
index 81ca288..f774c7e 100644
--- a/cpu/arm946es/config.mk
+++ b/cpu/arm946es/config.mk
@@ -25,3 +25,10 @@ PLATFORM_RELFLAGS += -fno-strict-aliasing  -fno-common -ffixed-r8 \
 	 -msoft-float
 
 PLATFORM_CPPFLAGS +=  -march=armv4
+# =========================================================================
+#
+# Supply options according to compiler version
+#
+# =========================================================================
+PLATFORM_CPPFLAGS +=$(call cc-option,-mapcs-32,-mabi=apcs-gnu)
+PLATFORM_RELFLAGS +=$(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,))
diff --git a/cpu/arm_intcm/config.mk b/cpu/arm_intcm/config.mk
index 81ca288..f774c7e 100644
--- a/cpu/arm_intcm/config.mk
+++ b/cpu/arm_intcm/config.mk
@@ -25,3 +25,10 @@ PLATFORM_RELFLAGS += -fno-strict-aliasing  -fno-common -ffixed-r8 \
 	 -msoft-float
 
 PLATFORM_CPPFLAGS +=  -march=armv4
+# =========================================================================
+#
+# Supply options according to compiler version
+#
+# =========================================================================
+PLATFORM_CPPFLAGS +=$(call cc-option,-mapcs-32,-mabi=apcs-gnu)
+PLATFORM_RELFLAGS +=$(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,))
-- 
1.5.4.2

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

* [U-Boot] [PATCH] ARM: Use do_div() instead of division for "long long"
  2008-09-09  0:04 ` Gururaja Hebbar K R
@ 2008-09-08 23:33   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 7+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2008-09-08 23:33 UTC (permalink / raw)
  To: u-boot

On 05:34 Tue 09 Sep     , Gururaja Hebbar K R wrote:
>  Hmm,
> 
> Interestingly i had sent a patch for the same for both
> integrator[ap/cp].
> http://article.gmane.org/gmane.comp.boot-loaders.u-boot/46044. 
> 

mail tag as SPAM in my mail box as a lot of your mail.

I'll take a look why.

Best Regards,
J.

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

* [U-Boot] [PATCH] ARM: Use do_div() instead of division for "long long"
       [not found] <mailman.680.1220914851.2783.u-boot@lists.denx.de>
@ 2008-09-09  0:04 ` Gururaja Hebbar K R
  2008-09-08 23:33   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 7+ messages in thread
From: Gururaja Hebbar K R @ 2008-09-09  0:04 UTC (permalink / raw)
  To: u-boot

 Hmm,

Interestingly i had sent a patch for the same for both
integrator[ap/cp].
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/46044. 

i had sent it to Jean-Christophe PLAGNIOL-VILLARD & Peter Pearse & also
to U-Boot user list. 

Don't know y it didn't reach there.

Regards
Gururaja

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

* [U-Boot] [PATCH] ARM: Use do_div() instead of division for "long long".
@ 2008-10-22  7:00 Wolfgang Denk
  2008-10-24 11:30 ` Jean-Christophe PLAGNIOL-VILLARD
  2008-11-02  9:41 ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 2 replies; 7+ messages in thread
From: Wolfgang Denk @ 2008-10-22  7:00 UTC (permalink / raw)
  To: u-boot

From: Sergei Poselenov <sposelenov@emcraft.com>

Also make sure to feed the right compiler options.

Signed-off-by: Sergei Poselenov <sposelenov@emcraft.com>
Signed-off-by: Wolfgang Denk <wd@denx.de>
---
These changes are needed with some more recent tool chain versions
(including ELDK 4.2).

 board/integratorcp/integratorcp.c |    7 ++++++-
 board/trab/tsc2000.c              |   10 ++++++----
 cpu/arm1176/s3c64xx/interrupts.c  |    5 ++++-
 cpu/arm946es/config.mk            |    7 +++++++
 cpu/arm_intcm/config.mk           |    7 +++++++
 5 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/board/integratorcp/integratorcp.c b/board/integratorcp/integratorcp.c
index d6d6e13..220513f 100644
--- a/board/integratorcp/integratorcp.c
+++ b/board/integratorcp/integratorcp.c
@@ -34,6 +34,7 @@
  */
 
 #include <common.h>
+#include <div64.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -244,7 +245,11 @@ ulong get_timer_masked (void)
 		total_count += lastdec - now;
 	}
 	lastdec	  = now;
-	timestamp = (ulong)(total_count/div_timer);
+
+	/* Reuse "now" */
+	now = total_count;
+	do_div(now, div_timer);
+	timestamp = now;
 
 	return timestamp;
 }
diff --git a/board/trab/tsc2000.c b/board/trab/tsc2000.c
index 382a85b..f13a5a9 100644
--- a/board/trab/tsc2000.c
+++ b/board/trab/tsc2000.c
@@ -27,6 +27,7 @@
 
 #include <common.h>
 #include <s3c2400.h>
+#include <div64.h>
 #include "tsc2000.h"
 
 #include "Pt1000_temp_data.h"
@@ -332,6 +333,7 @@ void tsc2000_reg_init (void)
 int tsc2000_interpolate(long value, long data[][2], long *result)
 {
 	int i;
+	unsigned long long val;
 
 	/* the data is sorted and the first element is upper
 	 * limit so we can easily check for out-of-band values
@@ -347,10 +349,10 @@ int tsc2000_interpolate(long value, long data[][2], long *result)
 	   result in 'long long'.
 	*/
 
-	*result = data[i-1][1] +
-		((unsigned long long)(data[i][1] - data[i-1][1])
-		 * (unsigned long long)(value - data[i-1][0]))
-		/ (data[i][0] - data[i-1][0]);
+	val = ((unsigned long long)(data[i][1] - data[i-1][1])
+		   * (unsigned long long)(value - data[i-1][0]));
+	do_div(val, (data[i][0] - data[i-1][0]));
+	*result = data[i-1][1] + val;
 
 	return 0;
 }
diff --git a/cpu/arm1176/s3c64xx/interrupts.c b/cpu/arm1176/s3c64xx/interrupts.c
index 8356ae4..e34369f 100644
--- a/cpu/arm1176/s3c64xx/interrupts.c
+++ b/cpu/arm1176/s3c64xx/interrupts.c
@@ -41,6 +41,7 @@
 #include <common.h>
 #include <asm/proc-armv/ptrace.h>
 #include <s3c6400.h>
+#include <div64.h>
 
 static ulong timer_load_val;
 
@@ -148,7 +149,9 @@ void reset_timer(void)
 
 ulong get_timer_masked(void)
 {
-	return get_ticks() / (timer_load_val / (100 * CFG_HZ));
+	unsigned long long res = get_ticks();
+	do_div (res, (timer_load_val / (100 * CFG_HZ)));
+	return res;
 }
 
 ulong get_timer(ulong base)
diff --git a/cpu/arm946es/config.mk b/cpu/arm946es/config.mk
index 81ca288..f774c7e 100644
--- a/cpu/arm946es/config.mk
+++ b/cpu/arm946es/config.mk
@@ -25,3 +25,10 @@ PLATFORM_RELFLAGS += -fno-strict-aliasing  -fno-common -ffixed-r8 \
 	 -msoft-float
 
 PLATFORM_CPPFLAGS +=  -march=armv4
+# =========================================================================
+#
+# Supply options according to compiler version
+#
+# =========================================================================
+PLATFORM_CPPFLAGS +=$(call cc-option,-mapcs-32,-mabi=apcs-gnu)
+PLATFORM_RELFLAGS +=$(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,))
diff --git a/cpu/arm_intcm/config.mk b/cpu/arm_intcm/config.mk
index 81ca288..f774c7e 100644
--- a/cpu/arm_intcm/config.mk
+++ b/cpu/arm_intcm/config.mk
@@ -25,3 +25,10 @@ PLATFORM_RELFLAGS += -fno-strict-aliasing  -fno-common -ffixed-r8 \
 	 -msoft-float
 
 PLATFORM_CPPFLAGS +=  -march=armv4
+# =========================================================================
+#
+# Supply options according to compiler version
+#
+# =========================================================================
+PLATFORM_CPPFLAGS +=$(call cc-option,-mapcs-32,-mabi=apcs-gnu)
+PLATFORM_RELFLAGS +=$(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,))
-- 
1.5.5.1

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

* [U-Boot] [PATCH] ARM: Use do_div() instead of division for "long long".
  2008-10-22  7:00 [U-Boot] [PATCH] ARM: Use do_div() instead of division for "long long" Wolfgang Denk
@ 2008-10-24 11:30 ` Jean-Christophe PLAGNIOL-VILLARD
  2008-10-24 11:52   ` Wolfgang Denk
  2008-11-02  9:41 ` Jean-Christophe PLAGNIOL-VILLARD
  1 sibling, 1 reply; 7+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2008-10-24 11:30 UTC (permalink / raw)
  To: u-boot

>  #include <asm/proc-armv/ptrace.h>
>  #include <s3c6400.h>
> +#include <div64.h>
>  
>  static ulong timer_load_val;
>  
> @@ -148,7 +149,9 @@ void reset_timer(void)
>  
>  ulong get_timer_masked(void)
>  {
> -	return get_ticks() / (timer_load_val / (100 * CFG_HZ));
> +	unsigned long long res = get_ticks();
> +	do_div (res, (timer_load_val / (100 * CFG_HZ)));
> +	return res;
	CFG_HZ was renamed CONFIG_SYS_HZ
>  }

I've start to think to re-rename it CFG_HZ as done in Linux, normaly this
value is the same for all arch & board

Best Regards,
J.

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

* [U-Boot] [PATCH] ARM: Use do_div() instead of division for "long long".
  2008-10-24 11:30 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2008-10-24 11:52   ` Wolfgang Denk
  0 siblings, 0 replies; 7+ messages in thread
From: Wolfgang Denk @ 2008-10-24 11:52 UTC (permalink / raw)
  To: u-boot

Dear Jean-Christophe PLAGNIOL-VILLARD,

In message <20081024113041.GA32425@game.jcrosoft.org> you wrote:
>
...
> 	CFG_HZ was renamed CONFIG_SYS_HZ
...
> I've start to think to re-rename it CFG_HZ as done in Linux, normaly this
> value is the same for all arch & board

Mind that there is a slight difference in meaning and a bigger one in
implementation.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Anyone who doesn't believe in miracles is not a realist.
                                                   - David Ben Gurion

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

* [U-Boot] [PATCH] ARM: Use do_div() instead of division for "long long".
  2008-10-22  7:00 [U-Boot] [PATCH] ARM: Use do_div() instead of division for "long long" Wolfgang Denk
  2008-10-24 11:30 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2008-11-02  9:41 ` Jean-Christophe PLAGNIOL-VILLARD
  1 sibling, 0 replies; 7+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2008-11-02  9:41 UTC (permalink / raw)
  To: u-boot

On 09:00 Wed 22 Oct     , Wolfgang Denk wrote:
> From: Sergei Poselenov <sposelenov@emcraft.com>
> 
> Also make sure to feed the right compiler options.
> 
> Signed-off-by: Sergei Poselenov <sposelenov@emcraft.com>
> Signed-off-by: Wolfgang Denk <wd@denx.de>
> ---
> These changes are needed with some more recent tool chain versions
> (including ELDK 4.2).
> 
>  board/integratorcp/integratorcp.c |    7 ++++++-
>  board/trab/tsc2000.c              |   10 ++++++----
>  cpu/arm1176/s3c64xx/interrupts.c  |    5 ++++-
>  cpu/arm946es/config.mk            |    7 +++++++
>  cpu/arm_intcm/config.mk           |    7 +++++++
>  5 files changed, 30 insertions(+), 6 deletions(-)

do you have any plan to rebase it?

Best Regards,
J.

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

end of thread, other threads:[~2008-11-02  9:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-22  7:00 [U-Boot] [PATCH] ARM: Use do_div() instead of division for "long long" Wolfgang Denk
2008-10-24 11:30 ` Jean-Christophe PLAGNIOL-VILLARD
2008-10-24 11:52   ` Wolfgang Denk
2008-11-02  9:41 ` Jean-Christophe PLAGNIOL-VILLARD
     [not found] <mailman.680.1220914851.2783.u-boot@lists.denx.de>
2008-09-09  0:04 ` Gururaja Hebbar K R
2008-09-08 23:33   ` Jean-Christophe PLAGNIOL-VILLARD
  -- strict thread matches above, loose matches on Subject: below --
2008-09-08 22:59 Wolfgang Denk

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