From 053aa8ff8006427abe89afc0df944a201d424af2 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Tue, 3 Jun 2014 11:06:38 -0700 Subject: Turn off interrupts when talking to host --- pk/atomic.h | 14 ++++++++++++++ pk/frontend.c | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'pk') diff --git a/pk/atomic.h b/pk/atomic.h index 8e80c78..fea1330 100644 --- a/pk/atomic.h +++ b/pk/atomic.h @@ -4,6 +4,7 @@ #define _RISCV_ATOMIC_H #include "config.h" +#include "encoding.h" typedef struct { volatile long val; } atomic_t; typedef struct { atomic_t lock; } spinlock_t; @@ -71,4 +72,17 @@ static inline void spinlock_unlock(spinlock_t* lock) atomic_set(&lock->lock,0); } +static inline long spinlock_lock_irqsave(spinlock_t* lock) +{ + long flags = clear_csr(status, SR_EI); + spinlock_lock(lock); + return flags; +} + +static inline void spinlock_unlock_irqrestore(spinlock_t* lock, long flags) +{ + spinlock_unlock(lock); + set_csr(status, flags & SR_EI); +} + #endif diff --git a/pk/frontend.c b/pk/frontend.c index 4c6051e..7bf4710 100644 --- a/pk/frontend.c +++ b/pk/frontend.c @@ -10,7 +10,7 @@ long frontend_syscall(long n, long a0, long a1, long a2, long a3, long a4) static volatile uint64_t magic_mem[8]; static spinlock_t lock = SPINLOCK_INIT; - spinlock_lock(&lock); + long irq = spinlock_lock_irqsave(&lock); magic_mem[0] = n; magic_mem[1] = a0; @@ -28,6 +28,6 @@ long frontend_syscall(long n, long a0, long a1, long a2, long a3, long a4) long ret = magic_mem[0]; - spinlock_unlock(&lock); + spinlock_unlock_irqrestore(&lock, irq); return ret; } -- cgit v1.1