Why use jmp $ to halt the system?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Why use jmp $ to halt the system?

Post by neon »

Hey everyone,

I have a question out of complete curiosity :D

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 :D
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

For some reason I just feel that a hlt is not as final as jmp $. But I usually use

Code: Select all

loop:
hlt
jmp loop:
in my code.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

I uses the same as frank, if not it will run at near 100% in single-tasking OS.
You can find lots of case of why do coders do this and that, eg: in Pmode why do coders do pusha and popa, instead of pushad or popad ?.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

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 :twisted:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

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 :twisted:
lol--I just might do that! :evil: :D

You are correct about the NMIs though--I did not think of that. :)
Post Reply