From 1c0fe61eb340d0b5f59fb81517f468fbd4fe1208 Mon Sep 17 00:00:00 2001 From: Niklas Halle Date: Tue, 5 May 2020 18:25:29 +0200 Subject: better reboot --- 01_exercise/bootloader.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/01_exercise/bootloader.c b/01_exercise/bootloader.c index afd4d96..50a6b0e 100644 --- a/01_exercise/bootloader.c +++ b/01_exercise/bootloader.c @@ -29,20 +29,22 @@ char getc() { char ret; asm volatile( ".no_key:" - "xor %%ax, %%ax;" + "xor %%eax, %%eax;" "mov $0x0100, %%ax;" // check for keystroke: "int $0x16;" // http://www.ctyme.com/intr/rb-1755.htm "jz .no_key;" // wait for a key ".done:" - "xor %%ax, %%ax;" + + "xor %%eax, %%eax;" "mov $0x1000, %%ax;" // get keystroke: http://www.ctyme.com/intr/rb-1754.htm "int $0x16;" + "mov %%al, %%bl;" // temp store char in bl "mov $0400, %%ax;" // clear keyboard buffer: "int $0x16;" // http://www.ctyme.com/intr/rb-1759.htm : "=b"(ret) : - : "ax"); + : "eax"); return ret; } @@ -67,20 +69,16 @@ void main(void) { char c = getc(); if (c == '\r') { if (i == 0) { // empty entry - print("Reboot!"); - /*asm volatile( - "mov $0x5307, %%ax;" // TURN OFF SYSTEM: - // http://www.ctyme.com/intr/rb-1356.htm - "mov $0x0001, %%bx;" - "mov $0x0003, %%cx;" - "int $0x15" :: - : "ax", "bx", "cx");*/ - asm volatile("xor %%eax, %%eax\n" - "push %%eax\n" - "push %%ax\n" - "lidt (%%esp)\n" - "mov %%ss, %%eax" :: - : "eax"); + print("Reboot!\n\r"); + sleep(250); // too see the reboot print out, even if short + asm volatile( + "cli;" // disable interrupts + "mov $0x0FE, %%al;" // tell the keyboard controller to... + "out %%al, $0x64;" // ...activate the CPU reset line + ".halt:" + "hlt;" // some motherboards require this + "jmp .halt;" :: // and again, just to be sure + : "al"); return; } else { break; -- cgit v1.2.3-54-g00ecf