Page 1 of 1

quick question about my interrupt off/on stuff

Posted: Wed Jul 06, 2005 2:01 pm
by proxy
i was just doing one of my code reviews and i realized something. My Interrupt managment functions look like this:

Code: Select all

#define local_save_flags(x)         __asm__ __volatile__("pushfl ; popl %0" :"=g" (x): )
#define local_restore_flags(x)       __asm__ __volatile__("pushl %0 ; popfl" : :"g" (x):"memory", "cc")
#define local_irq_disable()         __asm__ __volatile__("cli": : :"memory")
#define local_irq_enable()         __asm__ __volatile__("sti": : :"memory")

//------------------------------------------------------------------------------
// Name: disable()
//------------------------------------------------------------------------------
Interrupt::State Interrupt::disable() {
   State ret;
   local_save_flags(ret);
   local_irq_disable();
   return ret;
}


//------------------------------------------------------------------------------
// Name: enable()
//------------------------------------------------------------------------------
Interrupt::State Interrupt::enable() {
   State ret;
   local_save_flags(ret);
   local_irq_enable();
   return ret;
}


//------------------------------------------------------------------------------
// Name: set(State state)
//------------------------------------------------------------------------------
Interrupt::State Interrupt::set(Interrupt::State state) {
   State ret;
   local_save_flags(ret);
   local_restore_flags(state);
   return ret;
}

well it occured to me that there may be a flaw in my Interrupt::set function. If i shut off interrupts, then do some operations that affect the flags, then do a set to restore them. Well I would be restoring ALL the flags (not just interrupt line) to what they were possibly breaking code that assumes the flags are in a certain state.

#1) is this something I shoudl even care about?
#2) i figure i could just make my on/off return flags & 0x0200 and my set just OR in the state saved (which would only set the interrupt flag
#3) is there a way to tell gcc's inline assembler that the flags may get hosed by my operation?

thoughts and advice are welcome :)

proxy

Re:quick question about my interrupt off/on stuff

Posted: Wed Jul 06, 2005 2:24 pm
by AR
GCC Function calls always assume EFLAGS is clobbered (along with EAX, ECX and EDX). It should be safe as when the function returns GCC will assume the flags are inconsistant.