How to completely suspend the processor?

前端 未结 3 1766
鱼传尺愫
鱼传尺愫 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:16

    This question can be reformulated into more correct question: how to completly suspend the control flow? In fact this task can be split into two subtasks:

    1. Suspending of the current (synchronous) control flow.

      • Simple busy loop (100% CPU usage, big power consumption, high thermal effect).

      • Halt based loop (power saving mode C1, most of CPU logic unpowered).

    2. Prevention of the asynchronous switching of control flows.

      • Stub interrupt handlers in IDT.

      • Masking of the interrupts on global interrupt controller (PIC or IO APIC).

      • Masking of the interrupts on local interrupt controller (Local APIC).

      • Masking of the interrupt on CPU core logic.

    In any case, you must be aware and be prepared to NMI handling, because there is no mechanisms which give you power to disable them.

    Ideal solution:

        mov  EDX, NMI_INT_HANDLER_STUB; // address of installed handler
        mov  ECX, 0x02                ; // id of the NMI handler in IDT 
        call InstallHandlerInIDT      ; 
        cli                           ; // mask all maskable interrupts on CPU core
    SUSPEND:
        hlt                           ; // turn CPU into HALT state (power saving mode C1)
        jmp SUSPEND                   ; // try again if NMI had happened
    
    NMI_INT_HANDLER_STUB:
        iretd                         ; // Complete handling immediatelly and return back.
    

提交回复
热议问题