commit c08d939b47b910e5d09da04c5c490a3dc0ff15d1
parent 2feb45fcfff34bb9499d4d56cfeb0ebab12dc295
Author: Ambroise Vincent <ambroise.vincent@arm.com>
Date: Wed, 15 May 2019 17:11:50 +0100
[dev] Add dummy lock functions for test purposes
Change-Id: I9194c9153314f9a0faaded85209f48ed1b39af04
Signed-off-by: Ambroise Vincent <ambroise.vincent@arm.com>
Diffstat:
9 files changed, 65 insertions(+), 31 deletions(-)
diff --git a/drivers/dev.c b/drivers/dev.c
@@ -39,7 +39,7 @@ newchan(unsigned char type)
for (i = 0; i < NR_CHANS; i++) {
c = &fdset[i];
- if (trylock(&c->mutex) < 0)
+ if (!trylock(&c->mutex))
continue;
if (c->type == NODEV) {
c->type = type;
diff --git a/target/hosted/Makefile b/target/hosted/Makefile
@@ -5,6 +5,7 @@ include $(PROJECTDIR)/scripts/rules.mk
CRT = $(LIBDIR)/crt.o
ROMOBJS = arch.o \
+ lock.o \
rom.o \
romtab.o \
$(CRT) \
@@ -12,6 +13,7 @@ ROMOBJS = arch.o \
$(SRCDIR)/romfw/builtin.o \
RAMOBJS = arch.o \
+ lock.o \
ram.o \
ramtab.o \
$(CRT) \
diff --git a/target/hosted/arch.c b/target/hosted/arch.c
@@ -71,13 +71,3 @@ outm32(uint32_t val, void *addr)
{
return 0;
}
-
-void
-lock(mutex_t *m)
-{
-}
-
-void
-unlock(mutex_t *m)
-{
-}
diff --git a/target/hosted/lock.c b/target/hosted/lock.c
@@ -0,0 +1 @@
+#include "../lock.c"
diff --git a/target/lock.c b/target/lock.c
@@ -0,0 +1,32 @@
+#include <rcode/rcode.h>
+
+void
+lock(mutex_t *mutex)
+{
+ if (!mutex)
+ panic("lock segfault");
+ if (*mutex)
+ panic("deadlock");
+ *mutex = 1;
+}
+
+void
+unlock(mutex_t *mutex)
+{
+ if (!mutex)
+ panic("unlock segfault");
+ if (!*mutex)
+ panic("unlock");
+ *mutex = 0;
+}
+
+int
+trylock(mutex_t *mutex)
+{
+ if (!mutex)
+ panic("trylock segfault");
+ if (*mutex)
+ return 0;
+ *mutex = 1;
+ return 1;
+}
diff --git a/target/native/Makefile b/target/native/Makefile
@@ -5,6 +5,7 @@ include $(PROJECTDIR)/scripts/rules.mk
ROMOBJS = rom-crt.o \
rom.o \
arch.o \
+ debug_lock.o \
sysreg.o \
romtab.o \
$(DRVDIR)/builtin.o \
@@ -14,6 +15,7 @@ ROMOBJS = rom-crt.o \
RAMOBJS = ram-crt.o \
ram.o \
arch.o \
+ debug_lock.o \
sysreg.o \
ramtab.o \
$(SRCDIR)/ramfw/builtin.o \
diff --git a/target/native/arch.s b/target/native/arch.s
@@ -6,7 +6,6 @@
.globl outm8,outm16,outm32
.globl invdcachesetway,invicache,vectbl,doswtch
.globl inm8,inm16,inm32,outm8,outm16,outm32
- .globl lock,unlock,trylock
intr:
cmp x0,#0
@@ -70,25 +69,6 @@ outm32:
str w0,[x1]
ret
-lock:
- ret // TODO: fix casa external data abort
- mov w2,#1
- sevl
-1:
- wfe
- mov w1,wzr
- casa w1,w2,[x0]
- cbnz w1,1b
- ret
-
-unlock:
- stlr wzr,[x0]
- sev
- ret
-
-trylock:
- ret // TODO
-
dohalt:
msr daifset,#15
wfe
diff --git a/target/native/debug_lock.c b/target/native/debug_lock.c
@@ -0,0 +1 @@
+#include "../lock.c"
diff --git a/target/native/lock.s b/target/native/lock.s
@@ -0,0 +1,26 @@
+.globl lock,unlock,trylock
+
+/*
+ * Those functions are currently not used for two reasons:
+ * 1- We don't have caches and mmu enabled
+ * 2- We are executing only one execution thread.
+ */
+
+lock:
+ mov w2,#1
+ sevl
+1:
+ wfe
+ mov w1,wzr
+ casa w1,w2,[x0]
+ cbnz w1,1b
+ ret
+
+unlock:
+ stlr wzr,[x0]
+ sev
+ ret
+
+trylock: // TODO: implement trylock
+ mov w0,#1
+ ret