reboot is done
This commit is contained in:
@ -85,7 +85,8 @@ void shell_init(void)
|
||||
"poweroff, echo, color, merdella\n");
|
||||
break;
|
||||
case REBOOT:
|
||||
kprintf(0, "rebooting\n");
|
||||
kprintf(0, "rebooting...\n");
|
||||
reboot();
|
||||
break;
|
||||
case POWEROFF:
|
||||
kprintf(0, "powering off\n");
|
||||
|
@ -0,0 +1,32 @@
|
||||
#include "sys/io.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define KBD_INTERFACE 0x64
|
||||
|
||||
/* keyboard interface bits */
|
||||
#define KBD_BIT_KDATA 0 /* keyboard data */
|
||||
#define KBD_BIT_UDATA 1 /* user data */
|
||||
|
||||
#define KBD_IO 0x60 /* keyboard IO port */
|
||||
#define KBD_RESET 0xFE /* reset CPU command */
|
||||
|
||||
#define bit(n) (1 << (n)) /* Set bit n to 1 */
|
||||
|
||||
/* Check if bit n in flags is set */
|
||||
#define check_flag(flags, n) ((flags) & bit(n))
|
||||
|
||||
void reboot(void)
|
||||
{
|
||||
uint8_t tmp;
|
||||
|
||||
asm volatile("cli"); /* disable all interrupts */
|
||||
do {
|
||||
tmp = inb(KBD_INTERFACE); /* empty user data */
|
||||
if (check_flag(tmp, KBD_BIT_KDATA))
|
||||
inb(KBD_IO); /* empty keyboard data */
|
||||
} while (check_flag(tmp, KBD_BIT_UDATA));
|
||||
outb(KBD_INTERFACE, KBD_RESET); /* pulse CPU reset line */
|
||||
loop:
|
||||
asm volatile("hlt"); /* if that didn't work, halt the CPU */
|
||||
goto loop; /* if a NMI is received, halt again */
|
||||
}
|
||||
|
Reference in New Issue
Block a user