reset CPU not working

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
alethiophile
Member
Member
Posts: 90
Joined: Sat May 30, 2009 10:28 am

reset CPU not working

Post 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.
If I had an OS, there would be a link here.
manonthemoon
Member
Member
Posts: 65
Joined: Sat Jul 04, 2009 9:39 pm

Re: reset CPU not working

Post 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
User avatar
alethiophile
Member
Member
Posts: 90
Joined: Sat May 30, 2009 10:28 am

Re: reset CPU not working

Post 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.
If I had an OS, there would be a link here.
User avatar
alethiophile
Member
Member
Posts: 90
Joined: Sat May 30, 2009 10:28 am

Re: reset CPU not working

Post by alethiophile »

OK, reset now works.
If I had an OS, there would be a link here.
Post Reply