problem with freezing computer

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
beyondsociety

problem with freezing computer

Post by beyondsociety »

When I issue my "freeze the computer function" which uses a for loop, my computer delays for a while and then reboots instead of freezing. The for loop is as follows:

Code: Select all

for(;;);
If I comment it out, I still get the delay followed by the reboot. Before it used to just freeze, what could be the problem?
Tim

Re:problem with freezing computer

Post by Tim »

This will only freeze the computer if interrupts are disabled. To do a full freeze, either:

Code: Select all

__asm__("cli");
for (;;) ;
or:

Code: Select all

__asm__("cli ; hlt");
CLI followed by HLT effectively turns the CPU off.
tuxaroo

Re:problem with freezing computer

Post by tuxaroo »

This may be off topic, but how come some OSes I have to shutdown by hand? Like Linux just stops there.
Tim

Re:problem with freezing computer

Post by Tim »

Shutdown by hand as opposed to what? Pulling the power cable out of the wall? You need to inform the OS that you're about to turn the computer off, to make sure any applications get a chance to save and exit, that any cached data is written to disk, and that the file system is left in a consistent state. Recent versions of Windows look for the power button being pressed (through ACPI) and will treat that as a shutdown request. Without ACPI, you have to ask the OS to shutdown before you can remove the power.
Curufir

Re:problem with freezing computer

Post by Curufir »

Think he means that some OS don't turn the computer off after shutdown (Eg Win98).

The answer is it depends which OS your running, which hardware you're running on and most especially if one of either ACPI or APM is supported by both OS and hardware. These functions are what is used to power down the computer, shutdown the monitor etc. If they aren't there, then the best the OS can do is put up a little message saying 'Turn me off now please' or similar.
beyondsociety

Re:problem with freezing computer

Post by beyondsociety »

Trying what tim suggested didn't help. I wonder if there is something wrong with my cli and hlt functions?

Code: Select all

void cli()
{
       __asm__ __volatile__("cli");
}

void hlt()
{
      __asm__ __volatile__("hlt");
}
Tim

Re:problem with freezing computer

Post by Tim »

Maybe the way you're calling them. CLI *always* turns off interrupts. HLT *always* halts the processor until the next interrupt is received. So CLI followed by HLT halts the processor forever.
beyondsociety

Re:problem with freezing computer

Post by beyondsociety »

After some testing, my problem is not with my cli or hlt functions but with my c function that adds interrupt handlers as it is tripple faulting my computer. I tested it in bochs and I get the same exception. I now have to figure out why this is happening.
Post Reply