From: Amelia Coutard Date: Thu, 12 May 2022 12:23:23 +0000 (+0200) Subject: Restructured code a bit, to move all snippets of asm to utils.{c,h}pp X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=f9452e6a380c33f22cd89e8a349449743a3be4a6;p=voyage-au-centre-des-fichiers.git Restructured code a bit, to move all snippets of asm to utils.{c,h}pp --- diff --git a/src/serial.cpp b/src/serial.cpp index 384ba9d..d353fc8 100644 --- a/src/serial.cpp +++ b/src/serial.cpp @@ -2,14 +2,6 @@ #include "serial.hpp" namespace { - void outb(std::uint16_t port, std::uint8_t data) { - asm volatile ("outb %1,%0" : : "dN"(port), "a"(data)); - } - std::uint8_t inb(std::uint16_t port) { - std::uint8_t data; - asm volatile ("inb %1,%0" : "=a"(data) : "dN"(port)); - return data; - } } bool os::init_serial_port() { diff --git a/src/utils.cpp b/src/utils.cpp index 2c53ef6..5806cb6 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,9 +1,27 @@ #include "utils.hpp" +void os::cli() { + asm volatile("cli"); +} +void os::sti() { + asm volatile("sti"); +} +void os::hlt() { + asm volatile("hlt"); +} + void os::halt() { - asm volatile ( - "cli\n" - "\t1:\thlt\n" - "\tjmp 1b" - ); + cli(); + while (true) { + hlt(); + } +} + +void os::outb(std::uint16_t port, std::uint8_t data) { + asm volatile ("outb %1,%0" : : "dN"(port), "a"(data)); +} +std::uint8_t os::inb(std::uint16_t port) { + std::uint8_t data; + asm volatile ("inb %1,%0" : "=a"(data) : "dN"(port)); + return data; } diff --git a/src/utils.hpp b/src/utils.hpp index e2e242f..baa4b05 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -1,7 +1,14 @@ #pragma once +#include + namespace os { +void cli(); +void sti(); +void hlt(); void halt(); +void outb(std::uint16_t port, std::uint8_t data); +std::uint8_t inb(std::uint16_t port); } // namespace os