blob: f42db4c4dd6e79bb63b320ef65727943eb6b9db2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include "irq.h"
#include <stdatomic.h>
static volatile atomic_uint_fast64_t irq_lock_count = 0;
uint64_t irq_lock(void)
{
uint64_t flags;
__asm__ volatile
(
"pushf\n"
"pop %0\n"
"cli\n"
:
"=r"(flags)
);
irq_lock_count++;
return flags;
}
void irq_unlock(uint64_t flags)
{
if (atomic_load(&irq_lock_count) >= 1)
{
irq_lock_count--;
}
if (atomic_load(&irq_lock_count) == 0)
{
__asm__ volatile
(
"push %q0\n"
"popf"
:
:
"r"(flags)
);
}
}
|