From d4e805e3e3aebb0bd96596985f45df5ebd66b06e Mon Sep 17 00:00:00 2001 From: Avi Kivity <avi@cloudius-systems.com> Date: Mon, 4 Feb 2013 20:27:57 +0200 Subject: [PATCH] x64: add facility for saving/restoring interrupt flag state It's somewhat complicated due to the red zone, but there's no way around it. --- arch/x64/arch.hh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/x64/arch.hh b/arch/x64/arch.hh index 5eab78f2f..7185ddabf 100644 --- a/arch/x64/arch.hh +++ b/arch/x64/arch.hh @@ -18,6 +18,20 @@ inline void irq_enable() processor::sti(); } +class irq_flag { +public: + // need to clear the red zone when playing with the stack. also, can't + // use "m" constraint as it might be addressed relative to %rsp + void save() { + asm volatile("sub $128, %%rsp; pushfq; popq %0; add $128, %%rsp" : "=r"(_rflags)); + } + void restore() { + asm volatile("sub $128, %%rsp; pushq %0; popfq; add $128, %%rsp" : : "r"(_rflags)); + } +private: + unsigned long _rflags; +}; + } -- GitLab