aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWill Deacon <will.deacon@arm.com>2017-10-17 13:14:28 +0100
committerWill Deacon <will.deacon@arm.com>2017-10-17 13:14:28 +0100
commit9a73e86a5f072d5cbba35d92b1695fa512842c1c (patch)
tree74dc2a8be6722f9c9f26e1ef828eb9ab99208f3f
parent8d304c4027e74e2f81373b206181df72e5b5f19e (diff)
downloadqrwlock-rmem-9a73e86a5f072d5cbba35d92b1695fa512842c1c.tar.gz
Hack in basic assertions
Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r--Makefile4
-rw-r--r--compiler.h2
-rw-r--r--kernel.h11
-rw-r--r--main.c10
-rw-r--r--rmem.h6
5 files changed, 26 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index efee9a1..aeaab39 100644
--- a/Makefile
+++ b/Makefile
@@ -2,8 +2,8 @@ CC=aarch64-linux-gnu-gcc
CFLAGS=-Wall -O2 -fno-strict-aliasing -g -ffreestanding
LDFLAGS=-static -nostdlib
TARGET=qrwlock
-HDRS= kernel.h compiler.h rmem.h
-OBJS= main.o qrwlock.o
+HDRS=kernel.h compiler.h rmem.h
+OBJS=main.o qrwlock.o
$(TARGET) : $(OBJS) $(HDRS)
all: $(TARGET)
diff --git a/compiler.h b/compiler.h
index b188726..8677fa8 100644
--- a/compiler.h
+++ b/compiler.h
@@ -1,6 +1,7 @@
#ifndef __COMPILER_H
#define __COMPILER_H
+#define barrier() asm volatile("" ::: "memory")
#define __branch_check__(x, expect, is_constant) ({ \
int ______r; \
______r = __builtin_expect(!!(x), expect); \
@@ -14,5 +15,6 @@
#define __always_inline inline __attribute__((always_inline))
#define noinline __attribute__((noinline))
#define __noreturn __attribute__((noreturn))
+#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })
#endif /* __COMPILER_H */
diff --git a/kernel.h b/kernel.h
index afecbaf..1455a91 100644
--- a/kernel.h
+++ b/kernel.h
@@ -8,7 +8,10 @@
#include "compiler.h"
#include "rmem.h"
-#define _abort __rmem_stop
+/* Different ways to exit the model */
+#define assert(cond) ({ if (!(cond)) __rmem_stop(_THIS_IP_); })
+#define abort() __rmem_stop(-1)
+#define exit() __rmem_stop(0)
/* Type definitions */
typedef unsigned char u8;
@@ -60,7 +63,7 @@ typedef struct qrwlock {
case 4: *(u32 *)res = *(volatile u32 *)p; break; \
case 8: *(u64 *)res = *(volatile u64 *)p; break; \
default: \
- _abort(); /* hack for userspace */ \
+ abort(); /* hack for userspace */ \
} \
})
@@ -130,7 +133,7 @@ static inline unsigned long __cmpxchg##sfx(volatile void *ptr, \
case 8: \
return __cmpxchg_case##sfx##_8(ptr, old, new); \
default: \
- _abort(); /* hack for userspace */ \
+ abort(); /* hack for userspace */ \
} \
}
@@ -249,7 +252,7 @@ static inline void __cmpwait##sfx(volatile void *ptr, \
case 8: \
return __cmpwait_case##sfx##_8(ptr, val); \
default: \
- _abort(); /* hack for userspace */ \
+ abort(); /* hack for userspace */ \
} \
}
diff --git a/main.c b/main.c
index 589ce79..5f143c5 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,8 @@
#include "qrwlock.h"
+unsigned long __rmem_stop_addr = 0x0;
struct qrwlock lock = __ARCH_RW_LOCK_UNLOCKED;
+static int count = 0;
/*
* Test driver for qrwlock.
@@ -8,14 +10,22 @@ struct qrwlock lock = __ARCH_RW_LOCK_UNLOCKED;
*/
static void writer(void)
{
+#if 0
arch_write_lock(&lock);
+ count = 1;
+ barrier();
+ count = 2;
arch_write_unlock(&lock);
+#endif
+ exit();
}
static void reader(void)
{
arch_read_lock(&lock);
+ assert(count != 1);
arch_read_unlock(&lock);
+ exit();
}
void _start(void)
diff --git a/rmem.h b/rmem.h
index 77f0986..ab66735 100644
--- a/rmem.h
+++ b/rmem.h
@@ -3,8 +3,12 @@
#include "compiler.h"
-static inline void __noreturn __rmem_stop(void)
+extern unsigned long __rmem_stop_addr;
+
+static inline void __noreturn __rmem_stop(unsigned long pc)
{
+ __rmem_stop_addr = pc;
+
while (1)
asm volatile(".inst 0xd50bb001");
}