From 716974a9169cd4513e7faa67181e7ef96eef05b6 Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 6 Sep 2022 12:13:43 +0200 Subject: [PATCH] Add a minimal shutdown method, that only works on emulators (at least for now) --- kernel/include/power/shutdown.h | 3 +++ kernel/src/main.cpp | 4 ++-- kernel/src/power/shutdown.cpp | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 kernel/include/power/shutdown.h create mode 100644 kernel/src/power/shutdown.cpp diff --git a/kernel/include/power/shutdown.h b/kernel/include/power/shutdown.h new file mode 100644 index 00000000..4c620652 --- /dev/null +++ b/kernel/include/power/shutdown.h @@ -0,0 +1,3 @@ +#pragma once + +[[noreturn]] void shutdown(); \ No newline at end of file diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index b79c8d62..f1fcbbdc 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -15,7 +15,7 @@ #include "memory/KernelHeap.h" #include "memory/Memory.h" #include "panic/hang.h" -#include "power/reboot.h" +#include "power/shutdown.h" #include "render/BBRenderer.h" #include "render/Draw.h" #include "render/TextRenderer.h" @@ -131,7 +131,7 @@ extern "C" void _start() } sleep(2500); - reboot(); + shutdown(); while (1) halt(); loop: diff --git a/kernel/src/power/shutdown.cpp b/kernel/src/power/shutdown.cpp new file mode 100644 index 00000000..52e225b5 --- /dev/null +++ b/kernel/src/power/shutdown.cpp @@ -0,0 +1,16 @@ +#include "power/shutdown.h" +#include "io/IO.h" +#include "log/Log.h" +#include "panic/hang.h" + +[[noreturn]] void shutdown() +{ + kinfoln("Attempting shutdown using the Bochs method"); + IO::outw(0xB004, 0x2000); + kinfoln("Attempting shutdown using the QEMU method"); + IO::outw(0x604, 0x2000); + kinfoln("Attempting shutdown using the VirtualBox method"); + IO::outw(0x4004, 0x3400); + kerrorln("Failed to shutdown, halting. It is now safe to turn off your computer manually, though."); + hang(); +} \ No newline at end of file