Is there a way to make my C code or my Assembly code loop forever without using while(1) or for(;;) in C or jmp $ in Assembly. My only issue is that it uses up a lot of my CPU. I would not have an issue with it if all kernels did this but the GRUB boot loader barely takes any CPU when it runs. Its is not until my kernel is loaded and booted that my CPU starts to run at 50% usage (I have a dual core).
Would some sort of time delay fix this, even thought that time delay would be on a for loop as well?
Thank you for your time.
while(1) && for(;;) && jmp $ statements
-
- Member
- Posts: 95
- Joined: Thu Jan 29, 2009 9:13 am
Re: while(1) && for(;;) && jmp $ statements
while(1)
{
__asm__ ("hlt");
}
for(;;)
{
__asm__ ("hlt");
}
haltloop:
hlt
jmp haltloop
try any of these, hlt will tell the cpu to wait for interupts.
{
__asm__ ("hlt");
}
for(;;)
{
__asm__ ("hlt");
}
haltloop:
hlt
jmp haltloop
try any of these, hlt will tell the cpu to wait for interupts.
-
- Member
- Posts: 95
- Joined: Thu Jan 29, 2009 9:13 am
Re: while(1) && for(;;) && jmp $ statements
__asm__ __volatile__("hlt"); //will work, but im not sure if the volatile keyword is needed.
Re: while(1) && for(;;) && jmp $ statements
PERFECTION!!!
Thank you very much.
I thought that the assembly instruction "hlt" literally halted the CPU completely, similar to rebooting or shutting down a computer.
Thank you very much.
I thought that the assembly instruction "hlt" literally halted the CPU completely, similar to rebooting or shutting down a computer.
- Kazinsal
- Member
- Posts: 559
- Joined: Wed Jul 13, 2011 7:38 pm
- Libera.chat IRC: Kazinsal
- Location: Vancouver
- Contact:
Re: while(1) && for(;;) && jmp $ statements
Only if you disable interrupts ("cli") first. "hlt" halts the processor until it externally woken up -- an interrupt does this, and the PIT sends out an interrupt on IRQ0 frequently (usually at a frequency of 18Hz unless otherwise specified).kammce wrote:I thought that the assembly instruction "hlt" literally halted the CPU completely, similar to rebooting or shutting down a computer.