diff options
author | Will Deacon <will.deacon@arm.com> | 2017-10-17 13:14:28 +0100 |
---|---|---|
committer | Will Deacon <will.deacon@arm.com> | 2017-10-17 13:14:28 +0100 |
commit | 9a73e86a5f072d5cbba35d92b1695fa512842c1c (patch) | |
tree | 74dc2a8be6722f9c9f26e1ef828eb9ab99208f3f | |
parent | 8d304c4027e74e2f81373b206181df72e5b5f19e (diff) | |
download | qrwlock-rmem-9a73e86a5f072d5cbba35d92b1695fa512842c1c.tar.gz |
Hack in basic assertions
Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | compiler.h | 2 | ||||
-rw-r--r-- | kernel.h | 11 | ||||
-rw-r--r-- | main.c | 10 | ||||
-rw-r--r-- | rmem.h | 6 |
5 files changed, 26 insertions, 7 deletions
@@ -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) @@ -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 */ @@ -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 */ \ } \ } @@ -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) @@ -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"); } |