Voxia OS v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
irq_lock.h
Go to the documentation of this file.
1#ifndef __HAL__CPU__IRQ_H__
2#define __HAL__CPU__IRQ_H__
3
4#include <type.h>
5
6static inline uintptr_t irq_save(void) {
8 __asm__ volatile(
9 "pushfq \n\t" /* push RFLAGS ke stack */
10 "pop %0 \n\t" /* baca ke 'flags' */
11 "cli \n\t" /* clear IF — disable interrupt */
12 : "=r"(flags)
13 :
14 : "memory" /* barrier: compiler tidak boleh
15 reorder load/store melewati CLI */
16 );
17 return flags;
18}
19
20static inline void irq_restore(uintptr_t flags) {
21 __asm__ volatile(
22 "push %0 \n\t" /* push nilai flags lama ke stack */
23 "popfq \n\t" /* restore ke RFLAGS secara atomik */
24 :
25 : "r"(flags)
26 : "memory", "cc" /* cc: condition codes bisa berubah */
27 );
28}
29
30static inline void irq_enable(void) {
31 __asm__ volatile("sti" ::: "memory");
32}
33
34static inline void irq_disable(void) {
35 __asm__ volatile("cli" ::: "memory");
36}
37
38/* Cek apakah interrupt sedang aktif (IF set di RFLAGS) */
39static inline bool irq_is_enabled(void) {
41 __asm__ volatile("pushfq \n\t"
42 "pop %0 \n\t"
43 : "=r"(flags));
44 return (flags & (1UL << 9)) != 0; /* bit 9 = IF */
45}
46
47#endif // irq
uint16_t flags
Definition thread.h:5
static void irq_enable(void)
Definition irq_lock.h:30
static void irq_restore(uintptr_t flags)
Definition irq_lock.h:20
static bool irq_is_enabled(void)
Definition irq_lock.h:39
static void irq_disable(void)
Definition irq_lock.h:34
static uintptr_t irq_save(void)
Definition irq_lock.h:6
unsigned long uintptr_t
Definition type.h:73