From 345c7f4e6915237f27fe0e82b4d57d6a17b91269 Mon Sep 17 00:00:00 2001
From: Armin Luntzer <armin.luntzer@univie.ac.at>
Date: Thu, 24 May 2018 11:26:03 +0200
Subject: [PATCH] add __clzsi2()

---
 arch/sparc/kernel/ttable.S |  5 +--
 lib/Makefile               |  1 +
 lib/libc_bitops.c          | 66 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 4 deletions(-)
 create mode 100644 lib/libc_bitops.c

diff --git a/arch/sparc/kernel/ttable.S b/arch/sparc/kernel/ttable.S
index 8e9dcd4..c77453f 100644
--- a/arch/sparc/kernel/ttable.S
+++ b/arch/sparc/kernel/ttable.S
@@ -149,10 +149,9 @@ fpe_trap_handler:
 hw_div0_trap_handler:
 	.global __interrupt_entry
 __interrupt_entry:
-	.global __clzsi2
-__clzsi2:
 	.global memset
 memset:
+	ta 1
 	.global nmi_entry
 nmi_entry:
 	.global reg_access_trap_handler
@@ -165,8 +164,6 @@ strtol:
 syscall_tbl:
 	.global syscall_trap
 syscall_trap:
-	.global tag_overflow_trap_handler
-tag_overflow_trap_handler:
 	.global .udiv
 .udiv:
 	.global .umul
diff --git a/lib/Makefile b/lib/Makefile
index 317fd22..ecd6def 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -9,3 +9,4 @@ lib-y			+= elf.o
 lib-y			+= data_proc_tracker.o
 lib-y			+= data_proc_task.o
 lib-y			+= data_proc_net.o
+lib-y			+= libc_bitops.o
diff --git a/lib/libc_bitops.c b/lib/libc_bitops.c
new file mode 100644
index 0000000..b84b9fa
--- /dev/null
+++ b/lib/libc_bitops.c
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0
+/**
+ * @file lib/libc_bitops.c
+ *
+ * @ingroup libc
+ * @defgroup functions expected by the compiler
+ *
+ * @note these can be overridden by linking architecture-specific implementation
+ *
+ * @note add as needed
+ *
+ * @see https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html
+ *
+ */
+
+
+#include <kernel/export.h>
+
+
+/**
+ * @brief locates the most significant bit set in a word
+ * @note taken from linux: include/asm-generic/bitops/fls.h
+ */
+
+static int fls(int x)
+{
+	int r = 32;
+
+	if (!x)
+		return 0;
+	if (!(x & 0xffff0000u)) {
+		x <<= 16;
+		r -= 16;
+	}
+	if (!(x & 0xff000000u)) {
+		x <<= 8;
+		r -= 8;
+	}
+	if (!(x & 0xf0000000u)) {
+		x <<= 4;
+		r -= 4;
+	}
+	if (!(x & 0xc0000000u)) {
+		x <<= 2;
+		r -= 2;
+	}
+	if (!(x & 0x80000000u)) {
+		x <<= 1;
+		r -= 1;
+	}
+	return r;
+}
+
+
+/**
+ * @brief returns the number of leading 0-bits in a,
+ *	  starting at the most significant bit position.
+ *	  If a is zero, the result is undefined.
+ */
+
+int __attribute__((weak)) __clzsi2(unsigned int a);
+int __attribute__((weak)) __clzsi2(unsigned int a)
+{
+	return 32 - fls(a);
+}
+EXPORT_SYMBOL(__clzsi2);
-- 
GitLab