#define OS_CRITICAL_METHOD 2
#if OS_CRITICAL_METHOD == 1 #define OS_ENTER_CRITICAL() asm CLI /* Disable interrupts */ #define OS_EXIT_CRITICAL() asm STI /* Enable interrupts */ #endif
#if OS_CRITICAL_METHOD == 2 #define OS_ENTER_CRITICAL() asm {PUSHF; CLI} /* Disable interrupts */ #define OS_EXIT_CRITICAL() asm POPF /* Enable interrupts */ #endif
#if OS_CRITICAL_METHOD == 3 #define OS_ENTER_CRITICAL() (cpu_sr = OSCPUSaveSR()) /* Disable interrupts */ #define OS_EXIT_CRITICAL() (OSCPURestoreSR(cpu_sr)) /* Enable interrupts */ #endif
很显然,编译程序只会处理8-12行的代码,
为什么开中断只用popf,而不加上sti呢,它是如何工作的?
谢谢!