x86 now has a driver for rebooting.

This commit is contained in:
Jonas 'Sortie' Termansen 2011-08-12 15:13:18 +02:00
parent fe65e12992
commit 64d191a882
2 changed files with 37 additions and 0 deletions

View File

@ -64,5 +64,40 @@ namespace Sortix
asm volatile("inl %1, %0" : "=a" (Result) : "dN" (Port));
return Result;
}
void Reboot()
{
// Keyboard interface IO port: data and control.
const uint16_t KEYBOARD_INTERFACE = 0x64;
// Keyboard IO port.
const uint16_t KEYBOARD_IO = 0x60;
// Keyboard data is in buffer (output buffer is empty) (bit 0).
const uint8_t KEYBOARD_DATA = (1<<0);
// User data is in buffer (command buffer is empty) (bit 1).
const uint8_t USER_DATA = (1<<1);
// Disable interrupts.
asm volatile("cli");
// Clear all keyboard buffers (output and command buffers).
uint8_t byte;
do
{
byte = InPortB(KEYBOARD_INTERFACE);
if ( ( byte & KEYBOARD_DATA ) != 0 ) { InPortB(KEYBOARD_IO); }
} while ( ( byte & USER_DATA ) != 0 );
// CPU reset command.
uint8_t KEYBOARD_RESET_CPU = 0xFE;
// Now pulse the CPU reset line and reset.
OutPortB(KEYBOARD_INTERFACE, KEYBOARD_RESET_CPU);
// If that didn't work, just halt.
asm volatile("hlt");
}
}
}

View File

@ -44,6 +44,8 @@ namespace Sortix
uint32_t int_no, err_code; // Interrupt number and error code (if applicable)
uint32_t eip, cs, eflags, useresp, ss; // Pushed by the processor automatically.
};
void Reboot();
}
}