Hey everyone,
I have a question out of complete curiosity
I have seen alot of code use an infinity loop to "halt" execution. My question is "why"?
i.e., why not use HLT or a combination of CLI and HLT?
Is it just personal preference?
Using CLI in combination with HLT will completely halt the system, and is more efficient then a jmp $ instruction.
Using HLT alone halts the processor, but still allows execution of interrupts (Which can restart the processor, when needed)
Is there any specific reason?
Just curious,
Thanks
Why use jmp $ to halt the system?
Why use jmp $ to halt the system?
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
For some reason I just feel that a hlt is not as final as jmp $. But I usually use
in my code.
Code: Select all
loop:
hlt
jmp loop:
lol--I just might do that!Combuster wrote:even CLI + HLT can still be restarted (with an NMI, that is) An infinite loop can't be passed over in such a fashion. The reason to use a halt-loop construct is to conserve energy.
If you really want to lock up the computer, try to trigger the F00F bug
You are correct about the NMIs though--I did not think of that.