summaryrefslogtreecommitdiff
path: root/lib/sbi/riscv_asm.c
diff options
context:
space:
mode:
authorAnup Patel <anup.patel@wdc.com>2020-02-18 06:56:33 +0300
committerAnup Patel <anup@brainfault.org>2020-02-18 06:58:33 +0300
commit0b414532c41303ce42fa2b9cc4861c5b01e76b40 (patch)
treee9f60f4b75db70f04857bc24481db583153bc5c4 /lib/sbi/riscv_asm.c
parent27a5c7f3c8f3d9ce3c032b73a5b2372560b41b90 (diff)
downloadopensbi-0b414532c41303ce42fa2b9cc4861c5b01e76b40.tar.xz
Revert "lib: Use __builtin_ctzl() in pmp_get()"
This reverts commit 897b8fbdd92fcfad194417d348b8dad16ab0e17a. We are seeing compile errors using newlib based GCC cross-toolchain so we restore back old ctz() implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com>
Diffstat (limited to 'lib/sbi/riscv_asm.c')
-rw-r--r--lib/sbi/riscv_asm.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c
index 68f5f17..7b612d4 100644
--- a/lib/sbi/riscv_asm.c
+++ b/lib/sbi/riscv_asm.c
@@ -184,6 +184,18 @@ void csr_write_num(int csr_num, unsigned long val)
};
}
+static unsigned long ctz(unsigned long x)
+{
+ unsigned long ret = 0;
+
+ while (!(x & 1UL)) {
+ ret++;
+ x = x >> 1;
+ }
+
+ return ret;
+}
+
int pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
unsigned long log2len)
{
@@ -275,7 +287,7 @@ int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,
addr = 0;
log2len = __riscv_xlen;
} else {
- t1 = __builtin_ctzl(~addr);
+ t1 = ctz(~addr);
addr = (addr & ~((1UL << t1) - 1)) << PMP_SHIFT;
log2len = (t1 + PMP_SHIFT + 1);
}