summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Makefile.inc6
-rw-r--r--src/lib/clog2.c37
-rw-r--r--src/lib/libgcc.c56
3 files changed, 59 insertions, 40 deletions
diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc
index 557cd66846..76c8fd3dc5 100644
--- a/src/lib/Makefile.inc
+++ b/src/lib/Makefile.inc
@@ -25,7 +25,7 @@ bootblock-y += cbfs.c
bootblock-y += cbfs_boot_props.c
bootblock-$(CONFIG_COMMON_CBFS_SPI_WRAPPER) += cbfs_spi.c
bootblock-$(CONFIG_GENERIC_GPIO_LIB) += gpio.c
-
+bootblock-y += libgcc.c
bootblock-$(CONFIG_GENERIC_UDELAY) += timer.c
bootblock-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
@@ -45,6 +45,7 @@ verstage-y += cbfs.c
verstage-y += halt.c
verstage-y += fmap.c
verstage-y += cbfs_boot_props.c
+verstage-y += libgcc.c
verstage-y += memcmp.c
verstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
verstage-y += region.c
@@ -77,6 +78,7 @@ romstage-y += cbfs.c
romstage-y += cbfs_boot_props.c
romstage-$(CONFIG_COMMON_CBFS_SPI_WRAPPER) += cbfs_spi.c
romstage-$(CONFIG_COMPRESS_RAMSTAGE) += lzma.c lzmadecode.c
+romstage-y += libgcc.c
romstage-$(CONFIG_PRIMITIVE_MEMTEST) += primitive_memtest.c
ramstage-$(CONFIG_PRIMITIVE_MEMTEST) += primitive_memtest.c
romstage-$(CONFIG_CACHE_AS_RAM) += ramtest.c
@@ -115,8 +117,6 @@ ramstage-y += cbfs_boot_props.c
ramstage-$(CONFIG_COMMON_CBFS_SPI_WRAPPER) += cbfs_spi.c
ramstage-y += lzma.c lzmadecode.c
ramstage-y += stack.c
-ramstage-y += clog2.c
-romstage-y += clog2.c
ramstage-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
ramstage-$(CONFIG_BOOTSPLASH) += jpeg.c
ramstage-$(CONFIG_TRACE) += trace.c
diff --git a/src/lib/clog2.c b/src/lib/clog2.c
deleted file mode 100644
index 5e0d591de4..0000000000
--- a/src/lib/clog2.c
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <console/console.h>
-#include <lib.h>
-
-/* Assume 8 bits per byte */
-#define CHAR_BIT 8
-
-unsigned long log2(unsigned long x)
-{
- /* assume 8 bits per byte. */
- unsigned long pow = sizeof(x) * CHAR_BIT - 1ULL;
- unsigned long i = 1ULL << pow;
-
- if (!x) {
- printk(BIOS_WARNING, "%s called with invalid parameter of 0\n",
- __func__);
- return -1;
- }
-
- for (; i > x; i >>= 1, pow--);
-
- return pow;
-}
-
-unsigned long log2_ceil(unsigned long x)
-{
- unsigned long pow;
-
- if (!x)
- return -1;
-
- pow = log2(x);
-
- if (x > (1ULL << pow))
- pow++;
-
- return pow;
-}
diff --git a/src/lib/libgcc.c b/src/lib/libgcc.c
new file mode 100644
index 0000000000..14685becf0
--- /dev/null
+++ b/src/lib/libgcc.c
@@ -0,0 +1,56 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2015 Google Inc.
+ *
+ * This program 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; version 2 of the License.
+ *
+ * This program 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc.
+ */
+
+#include <types.h>
+
+/*
+ * Provide platform-independent backend implementation for __builtin_clz() in
+ * <lib.h> in case GCC does not have an assembly version for this arch.
+ */
+
+#if !IS_ENABLED(CONFIG_ARCH_X86) /* work around lack of --gc-sections on x86 */
+int __clzsi2(u32 a);
+int __clzsi2(u32 a)
+{
+ static const u8 four_bit_table[] = {
+ [0x0] = 4, [0x1] = 3, [0x2] = 2, [0x3] = 2,
+ [0x4] = 1, [0x5] = 1, [0x6] = 1, [0x7] = 1,
+ [0x8] = 0, [0x9] = 0, [0xa] = 0, [0xb] = 0,
+ [0xc] = 0, [0xd] = 0, [0xe] = 0, [0xf] = 0,
+ };
+ int r = 0;
+
+ if (!(a & (0xffff << 16))) {
+ r += 16;
+ a <<= 16;
+ }
+
+ if (!(a & (0xff << 24))) {
+ r += 8;
+ a <<= 8;
+ }
+
+ if (!(a & (0xf << 28))) {
+ r += 4;
+ a <<= 4;
+ }
+
+ return r + four_bit_table[a >> 28];
+}
+#endif