summaryrefslogtreecommitdiff
path: root/payloads/libpayload
diff options
context:
space:
mode:
Diffstat (limited to 'payloads/libpayload')
-rw-r--r--payloads/libpayload/arch/x86/exception.c32
-rw-r--r--payloads/libpayload/include/x86/arch/exception.h4
2 files changed, 36 insertions, 0 deletions
diff --git a/payloads/libpayload/arch/x86/exception.c b/payloads/libpayload/arch/x86/exception.c
index b562660910..fe50d09c51 100644
--- a/payloads/libpayload/arch/x86/exception.c
+++ b/payloads/libpayload/arch/x86/exception.c
@@ -32,6 +32,8 @@
#include <libpayload.h>
#include <stdint.h>
+#define IF_FLAG (1 << 9)
+
u32 exception_stack[0x400] __attribute__((aligned(8)));
static exception_hook hook;
@@ -182,3 +184,33 @@ void exception_install_hook(exception_hook h)
die_if(hook, "Implement support for a list of hooks if you need it.");
hook = h;
}
+
+static uint32_t eflags(void)
+{
+ uint32_t eflags;
+ asm volatile(
+ "pushf\n\t"
+ "pop %0\n\t"
+ : "=rm" (eflags));
+ return eflags;
+}
+
+void enable_interrupts(void)
+{
+ asm volatile (
+ "sti\n"
+ : : : "cc"
+ );
+}
+void disable_interrupts(void)
+{
+ asm volatile (
+ "cli\n"
+ : : : "cc"
+ );
+}
+
+int interrupts_enabled(void)
+{
+ return !!(eflags() & IF_FLAG);
+}
diff --git a/payloads/libpayload/include/x86/arch/exception.h b/payloads/libpayload/include/x86/arch/exception.h
index 8acdb09552..a6c2afcf0d 100644
--- a/payloads/libpayload/include/x86/arch/exception.h
+++ b/payloads/libpayload/include/x86/arch/exception.h
@@ -34,6 +34,10 @@
void exception_init_asm(void);
void exception_dispatch(void);
+void enable_interrupts(void);
+void disable_interrupts(void);
+/** Returns 1 if interrupts are enabled. */
+int interrupts_enabled(void);
struct exception_state
{