From 9fd358e9395aae73622bdcf58ebe43f12671c990 Mon Sep 17 00:00:00 2001 From: Ada Christine Date: Tue, 14 Feb 2023 15:14:35 +0000 Subject: refactors --- kc/core/cpu/irq.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'kc/core/cpu/irq.c') diff --git a/kc/core/cpu/irq.c b/kc/core/cpu/irq.c index e4dd29f..f42db4c 100644 --- a/kc/core/cpu/irq.c +++ b/kc/core/cpu/irq.c @@ -4,13 +4,25 @@ static volatile atomic_uint_fast64_t irq_lock_count = 0; -void irq_lock(void) +uint64_t irq_lock(void) { + uint64_t flags; + + __asm__ volatile + ( + "pushf\n" + "pop %0\n" + "cli\n" + : + "=r"(flags) + ); + irq_lock_count++; - __asm__ volatile ("cli;"); + + return flags; } -void irq_unlock(void) +void irq_unlock(uint64_t flags) { if (atomic_load(&irq_lock_count) >= 1) { @@ -19,7 +31,14 @@ void irq_unlock(void) if (atomic_load(&irq_lock_count) == 0) { - __asm__ volatile ("sti;"); + __asm__ volatile + ( + "push %q0\n" + "popf" + : + : + "r"(flags) + ); } } -- cgit v1.3.1-1-g115d