How to completely suspend the processor?

前端 未结 3 1771
鱼传尺愫
鱼传尺愫 2020-12-18 01:37

I\'m writing a small bootloader for an x86 based PC. The problem is that the CPU is somehow still active after executing these instructions:

sti
hlt
<         


        
3条回答
  •  遥遥无期
    2020-12-18 02:38

    I would like to add a comment about 'cli' as I have been bitten by this a couple of times in the past. The 'cli' instruction does not block all interrupts--it only blocks the maskable ones. Conceivably, the system could still be woken up due to a non-maskable interrupt (NMI).

    As one of the comments indicates that the computer is ready to be turned off, I expect that there are no other threads/processes/tasks ready to run in the system (otherwise an NMI could conceivably lead to a reschedule). For the scenario you describe an NMI is unlikely; however depending upon your level of paranoia of things going wrong, you may wish to add a loop to guard against the possibility.

    sysSuspend:
        cli
        hlt
        jmp sysSuspend
    

提交回复
热议问题