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
<
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:
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).
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.