Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions kernel/riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,32 @@ w_sstatus(uint64 x)
asm volatile("csrw sstatus, %0" : : "r" (x));
}

static inline void
s_sstatus(uint64 x)
{
__asm__ __volatile__("csrs sstatus, %0" ::
"rK" (x) :
"memory");
}

static inline void
c_sstatus(uint64 x)
{
__asm__ __volatile__("csrc sstatus, %0" ::
"rK" (x) :
"memory");
}

static inline uint64
rc_sstatus(uint64 x)
{
__asm__ __volatile__("csrrc %0, sstatus, %1" :
"=r" (x) :
"rK" (x) :
"memory");
return x;
}

// Supervisor Interrupt Pending
static inline uint64
r_sip()
Expand Down Expand Up @@ -286,14 +312,14 @@ r_time()
static inline void
intr_on()
{
w_sstatus(r_sstatus() | SSTATUS_SIE);
s_sstatus(SSTATUS_SIE);
}

// disable device interrupts
static inline void
intr_off()
{
w_sstatus(r_sstatus() & ~SSTATUS_SIE);
c_sstatus(SSTATUS_SIE);
}

// are device interrupts enabled?
Expand Down
5 changes: 2 additions & 3 deletions kernel/spinlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ holding(struct spinlock *lk)
void
push_off(void)
{
int old = intr_get();

// disable interrupts to prevent an involuntary context
// switch while using mycpu().
intr_off();
uint64 flags = rc_sstatus(SSTATUS_SIE);
int old = !!(flags & SSTATUS_SIE);

if(mycpu()->noff == 0)
mycpu()->intena = old;
Expand Down