Post by Marek VasutHello,
I am trying to add support for nios2 CPU into libatomic-ops and gc .
The Linux kernel exports kuser helper for cmpxchg [1], so I believe
this might be the way to go? Or shall I somehow use the gcc atomic
builtin ops [2] ? Note that nios2 does not have dedicated atomic
instructions which could be used in userland, that's why the kuser
helper.
Thank you for any input!
[1] http://lxr.free-electrons.com/source/arch/nios2/kernel/entry.S#L535
[2]
https://github.com/gcc-mirror/gcc/blob/master/libgcc/config/nios2/linux-
atomic.c
Best regards,
Marek Vasut
The libgcc builtins still end up using the kuser interface as well, so
in a certain sense they're equivalent.
Yeah, I would've expected that, but at least they have a well defined
unified interface.
You may want to go the direct kuser route. A little bit of inline asm
should get you more performance compared to calling into libgcc, and
nios2 softcores can really use that bit of optimization. That's also
what I did in glibc.
Aren't those gcc builtins expanded in place anyway ? Or do you see some
real performance drop if you don't use the kuser helper directly ?
btw. I tried making two patches, one for libatomic-ops and one for bdwgc,
find them below, but I have no clue if they are correct:
libatomic-ops:
-------------------->8--------------------
From dd3b4b22feb87fc18c188cf594b0e16afdc0caa8 Mon Sep 17 00:00:00 2001
From: Marek Vasut <***@denx.de>
Date: Tue, 26 Jan 2016 13:52:26 +0100
Subject: [PATCH] Add nios2 support
Signed-off-by: Marek Vasut <***@denx.de>
---
src/Makefile.am | 1 +
src/atomic_ops.h | 3 +++
src/atomic_ops/sysdeps/gcc/nios2.h | 10 ++++++++++
3 files changed, 14 insertions(+)
create mode 100644 src/atomic_ops/sysdeps/gcc/nios2.h
diff --git a/src/Makefile.am b/src/Makefile.am
index fc09b27..d463427 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -79,6 +79,7 @@ nobase_private_HEADERS = atomic_ops/ao_version.h \
atomic_ops/sysdeps/gcc/ia64.h \
atomic_ops/sysdeps/gcc/m68k.h \
atomic_ops/sysdeps/gcc/mips.h \
+ atomic_ops/sysdeps/gcc/nios2.h \
atomic_ops/sysdeps/gcc/powerpc.h \
atomic_ops/sysdeps/gcc/s390.h \
atomic_ops/sysdeps/gcc/sh.h \
diff --git a/src/atomic_ops.h b/src/atomic_ops.h
index 33fe00e..ec02ba4 100644
--- a/src/atomic_ops.h
+++ b/src/atomic_ops.h
@@ -262,6 +262,9 @@
# if defined(__m68k__)
# include "atomic_ops/sysdeps/gcc/m68k.h"
# endif /* __m68k__ */
+# if defined(__nios2__)
+# include "atomic_ops/sysdeps/gcc/nios2.h"
+# endif /* __nios2__ */
# if defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) \
|| defined(__powerpc64__) || defined(__ppc64__)
# include "atomic_ops/sysdeps/gcc/powerpc.h"
diff --git a/src/atomic_ops/sysdeps/gcc/nios2.h
b/src/atomic_ops/sysdeps/gcc/nios2.h
new file mode 100644
index 0000000..41c86f7
--- /dev/null
+++ b/src/atomic_ops/sysdeps/gcc/nios2.h
@@ -0,0 +1,10 @@
+/*
+ * Copyright (C) 2016 Marek Vasut <***@denx.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "../test_and_set_t_is_ao_t.h"
+#include "generic.h"
+
+#define AO_T_IS_INT
--
2.7.0.rc3
--------------------8<--------------------
bdwgc:
-------------------->8--------------------
Enter passphrase for key '/home/marex/.ssh/id_rsa':
From cecaaf68e60bb07dffa8effb945bc43e2f4c87cb Mon Sep 17 00:00:00 2001
From: Marek Vasut <***@denx.de>
Date: Thu, 28 Jan 2016 04:13:13 +0100
Subject: [PATCH] Add nios2 support
Add simple nios2 configuration support.
Signed-off-by: Marek Vasut <***@denx.de>
---
include/private/gcconfig.h | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h
index 1aa4923..b2c2d78 100644
--- a/include/private/gcconfig.h
+++ b/include/private/gcconfig.h
@@ -188,6 +188,10 @@
# endif
# define mach_type_known
# endif
+# if defined(__NIOS2__) || defined(__NIOS2) || defined(__nios2__)
+# define NIOS2 /* Altera NIOS2 */
+# define mach_type_known
+# endif
# if defined(__or1k__)
# define OR1K /* OpenRISC/or1k */
# define mach_type_known
@@ -1729,6 +1733,24 @@
# endif
# endif
+# ifdef NIOS2
+# define CPP_WORDSZ 32
+# define MACH_TYPE "NIOS2"
+# ifdef LINUX
+# define OS_TYPE "LINUX"
+# define DYNAMIC_LOADING
+ extern int _end[];
+ extern int __data_start[];
+# define DATASTART ((ptr_t)(__data_start))
+# define DATAEND ((ptr_t)(_end))
+# define ALIGNMENT 4
+# ifndef HBLKSIZE
+# define HBLKSIZE 4096
+# endif
+# define LINUX_STACKBOTTOM
+# endif /* Linux */
+# endif
+
# ifdef OR1K
# define CPP_WORDSZ 32
# define MACH_TYPE "OR1K"
@@ -2800,7 +2822,7 @@
#if ((defined(UNIX_LIKE) && (defined(DARWIN) || defined(HURD) \
|| defined(OPENBSD) || defined(ARM32) \
|| defined(MIPS) || defined(AVR32) \
- || defined(OR1K))) \
+ || defined(OR1K) || defined(NIOS2))) \
|| (defined(LINUX) && !defined(__gnu_linux__)) \
|| (defined(RTEMS) && defined(I386)) || defined(PLATFORM_ANDROID)) \
&& !defined(NO_GETCONTEXT)
--
2.7.0.rc3
--------------------8<--------------------
Best regards,
Marek Vasut