Re: [ARM] atomics for rtems, aka bare metal

2012-03-12 Thread Sebastian Huber

Hello Richard,

thank you very much for your implementation.

On 03/09/2012 02:56 AM, Richard Henderson wrote:

On 03/08/12 10:02, Joel Sherrill wrote:

If so, it is just a matter of ifdef's to get the right code.


Ok.


Does arm-eabi have this support? We probably could
just use the same code.


There's scant bare metal support atm.  For sufficiently new ARM core revisions,
gcc will inline operations.  In order to get all of it, you have to target 
ARMv7.

I threw this together today.  It likely needs quite a bit of spit and polish:

[...]

   * This has received only compile testing with the arm-rtemseabi multilibs.
 There may well be bugs.

[...]

I run the test suite with this patch and now the link errors vanish.  I have 
currently no time to test the C++ atomics, but it would be nice if we can use 
this work in GCC 4.7.


=== g++ tests ===

Schedule of variations:
rtems-arm-edb7312

Running target rtems-arm-edb7312
Using /home/sh/rtems-testing/dejagnu/boards/rtems-arm-edb7312.exp as board
description file for target.
Using /usr/share/dejagnu/config/sim.exp as generic interface file for target.
Using /usr/share/dejagnu/baseboards/basic-sim.exp as board description file for
target.
Using /home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/config/default.exp
as tool-and-target-specific interface file.
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/bprob/bprob.exp ...
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/charset/charset.exp 
...
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/compat/compat.exp 
...
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/compat/struct-layout-1.exp
...
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/debug/debug.exp ...
FAIL: g++.dg/debug/const1.C -gdwarf-2 -g3 (test for excess errors)
FAIL: g++.dg/debug/const1.C -gdwarf-2 -g3 -O2 (test for excess errors)
FAIL: g++.dg/debug/const1.C -gdwarf-2 -g3 -O3 (test for excess errors)
FAIL: g++.dg/debug/debug4.C -gdwarf-2 -g3 (test for excess errors)
FAIL: g++.dg/debug/debug4.C -gdwarf-2 -g3 -O2 (test for excess errors)
FAIL: g++.dg/debug/debug4.C -gdwarf-2 -g3 -O3 (test for excess errors)
FAIL: g++.dg/debug/pr27657.C -gdwarf-2 -g3 (test for excess errors)
FAIL: g++.dg/debug/pr27657.C -gdwarf-2 -g3 -O2 (test for excess errors)
FAIL: g++.dg/debug/pr27657.C -gdwarf-2 -g3 -O3 (test for excess errors)
FAIL: g++.dg/debug/trivial.C -gdwarf-2 -g3 (test for excess errors)
WARNING: g++.dg/debug/trivial.C -gdwarf-2 -g3 compilation failed to produce
executable
FAIL: g++.dg/debug/trivial.C -gdwarf-2 -g3 -O2 (test for excess errors)
WARNING: g++.dg/debug/trivial.C -gdwarf-2 -g3 -O2 compilation failed to produce
executable
FAIL: g++.dg/debug/trivial.C -gdwarf-2 -g3 -O3 (test for excess errors)
WARNING: g++.dg/debug/trivial.C -gdwarf-2 -g3 -O3 compilation failed to produce
executable
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/debug/dwarf2/dwarf2.exp
...
Running /home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/dfp/dfp.exp 
...
Running /home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/dg.exp ...
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/gcov/gcov.exp ...
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/gomp/gomp.exp ...
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/graphite/graphite.exp
...
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/guality/guality.exp 
...
Running /home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/lto/lto.exp 
...
Running /home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/pch/pch.exp 
...
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/plugin/plugin.exp 
...
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/simulate-thread/simulate-thread.exp
...
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/special/ecos.exp ...
Running /home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/tls/tls.exp 
...
Running /home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/tm/tm.exp 
...
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/torture/dg-torture.exp
...
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/torture/stackalign/stackalign.exp
...
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/tree-prof/tree-prof.exp
...
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.dg/vect/vect.exp ...
Running
/home/sh/archive/gcc-4.7.0-RC-20120302/gcc/testsuite/g++.old-deja/old-deja.exp 
...

=== g++ Summary ===

# of expected passes 43093
# of unexpected failures 12
# of expected failures 277
# of unsupported tests 738
/home/sh/rtems-testing/gcc/b-arm-gcc/gcc/testsuite/g++/../../g++ version 4.7.0
20120307 (prerelease) (GCC)

--
Sebastian Huber, embedded brains GmbH

Address : Obere Lagerstr. 30, D-82178 Puchheim, Germany
Phone   : +49 89 18 90 80 79-6
Fax 

[ARM] atomics for rtems, aka bare metal

2012-03-08 Thread Richard Henderson
On 03/08/12 10:02, Joel Sherrill wrote:
> If so, it is just a matter of ifdef's to get the right code.

Ok.

> Does arm-eabi have this support? We probably could
> just use the same code.

There's scant bare metal support atm.  For sufficiently new ARM core revisions,
gcc will inline operations.  In order to get all of it, you have to target 
ARMv7.

I threw this together today.  It likely needs quite a bit of spit and polish:

  * There's quite a bit of boiler plate that could be shared with lib1funcs.S.

  * I know Richard E has cautioned me time and again about SWP, but
I have to assume that it's useful for at least some CPU revisions.
Knowing exactly when and where is the trick.  E.g. it might be correct
to use them on arm-rtems, but not generically for arm-eabi.

  * It might be cleaner to split this into multiple files, which can
be re-used in interesting ways.  For instance, when targeting ARMv6
it might be a win to use some of these routines instead of linux-atomic.c,
particularly when lacking LDREX[BH].

  * The __atomic_fetch_op and __atomic_op_fetch routines are missing.

  * Given that this is bare metal, and pre-ARMv6 is certainly non-SMP, you
might well want to provide fallback versions of these routines that
disable interrupts.

  * This has received only compile testing with the arm-rtemseabi multilibs.
There may well be bugs.

  * It's quite likely that this actually belongs in the not-yet-extant libatomic
and not in libgcc at all.


r~
diff --git a/libgcc/config.host b/libgcc/config.host
index 257622a..251ecb6 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -359,7 +359,7 @@ arm*-*-eabi* | arm*-*-symbianelf* | arm*-*-rtemseabi*)
tm_file="$tm_file arm/bpabi-lib.h"
case ${host} in
arm*-*-eabi* | arm*-*-rtemseabi*)
- tmake_file="${tmake_file} arm/t-bpabi"
+ tmake_file="${tmake_file} arm/t-bpabi arm/t-atomic"
  extra_parts="crtbegin.o crtend.o crti.o crtn.o"
  ;;
arm*-*-symbianelf*)
diff --git a/libgcc/config/arm/native-atomic.S 
b/libgcc/config/arm/native-atomic.S
new file mode 100644
index 000..d646706
--- /dev/null
+++ b/libgcc/config/arm/native-atomic.S
@@ -0,0 +1,509 @@
+/* Atomic operations for ARM, assuming only native cpu support.
+   Copyright (C) 2012 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+.  */
+
+
+#if defined(__ARM_ARCH_2__)
+# define __ARM_ARCH__ 2
+#endif
+
+#if defined(__ARM_ARCH_3__) || defined(__ARM_ARCH_3M__)
+# define __ARM_ARCH__ 3
+#endif
+
+#if defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__)
+# define __ARM_ARCH__ 4
+#endif
+
+#if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \
+   || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \
+   || defined(__ARM_ARCH_5TEJ__)
+# define __ARM_ARCH__ 5
+#endif
+
+#if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
+   || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \
+   || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \
+   || defined(__ARM_ARCH_6M__)
+# define __ARM_ARCH__ 6
+#endif
+
+#if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
+   || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \
+   || defined(__ARM_ARCH_7EM__)
+# define __ARM_ARCH__ 7
+#endif
+
+#ifndef __ARM_ARCH__
+#error Unable to determine architecture.
+#endif
+
+#if __ARM_ARCH__ >= 7 || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__)
+# define HAVE_STREX
+# define HAVE_STREXB
+# define HAVE_STREXH
+# define HAVE_STREXD
+#elif __ARM_ARCH__ == 6
+# define HAVE_STREX
+#elif __ARM_ARCH__ == 4 || __ARM_ARCH__ == 5
+/* This assumes that we are *not* running on ARM6+ SMP.  */
+# define HAVE_SWP
+#endif
+
+#ifdef __ARM_EABI__
+/* Some attributes that are common to all routines in this file.  */
+   /* Tag_ABI_align_needed: This code does not require 8-byte
+  alignment from the caller.  */
+   /* .eabi_attribute 24, 0  -- default setting.  */
+   /* Tag_ABI_align_preserved: This code preserves 8-byte
+  alignment in any callee.  */
+   .eabi_attribu