Page 1 of 1

reset CPU not working

Posted: Fri Aug 14, 2009 6:37 pm
by alethiophile
I have written some code to reset the CPU, based on the instructions in PS2 Keyboard. This is called by some code in my command-prompt handler, which is very primitive. Code:

Code: Select all

void reset(void) {
  while ((inportb(0x64) & 0x02) != 0);
  outportb(0x64, 0xd1);
  while ((inportb(0x64) & 0x02) != 0);
  outportb(0x60, 0xfe);
}
And the caller:

Code: Select all

    else if (!strcmp(buf, "reboot")) {
      printf("Rebooting...\n");
      reset();
    }
The reset call works fine in both Qemu and Bochs; both reboot, so quickly that you can't see the printf output. However, on hardware it fails; there the printf is called and it goes back to the command line as if the reset() had done nothing. Does anyone know why this is?

Also, how do you halt the machine and power down? I've searched the wiki and the web in general, and nothing is obvious.

Re: reset CPU not working

Posted: Fri Aug 14, 2009 6:45 pm
by manonthemoon
Don't write 0xD1 to the keyboard controller. Instead send 0xFE directly to port 0x64. (Although I've never tried that on real hardware so I can't guarantee it.)
alethiophile wrote:Also, how do you halt the machine and power down? I've searched the wiki and the web in general, and nothing is obvious.
wiki: Shutdown

Re: reset CPU not working

Posted: Fri Aug 14, 2009 6:58 pm
by alethiophile
Yeah, I found that. Sigh... I hate things you have to do in real mode.
Thanks for the tip, I'll try that.

Re: reset CPU not working

Posted: Fri Aug 14, 2009 9:01 pm
by alethiophile
OK, reset now works.