feat(io): IoPort

This commit is contained in:
Daniel Hammer
2025-04-16 18:54:48 +02:00
parent fcd81be1c5
commit 0b77abfc23
3 changed files with 52 additions and 6 deletions
+10
View File
@@ -12,11 +12,21 @@ void* operator new(std::size_t size)
return Memory::g_heap->Request(size);
}
void* operator new[](std::size_t size)
{
return Memory::g_heap->Request(size);
}
void operator delete(void* block)
{
Memory::g_heap->Free(block);
}
void operator delete[](void* block)
{
delete block;
}
void operator delete(void* block, long unsigned int)
{
Memory::g_heap->Free(block);
+41
View File
@@ -0,0 +1,41 @@
/*
* PortIo.hpp
* Inline Intel port IO functions
* Copyright (c) 2025 Daniel Hammer
*/
#pragma once
#include <cstdint>
namespace Io {
// OSDev website has the parameters for out(b/w/l) in the opposite order in their example,
// (port, then value), but the manpage on GNU ('man outb') has it in this order.
inline void Out8(uint8_t value, uint16_t port) {
asm ("outb %0, %1" : : "a"(value), "Nd"(port) : "memory");
}
inline void Out16(uint16_t value, uint16_t port) {
asm ("outw %0, %1" : : "a"(value), "Nd"(port) : "memory");
}
inline void Out32(uint32_t value, uint16_t port) {
asm ("outl %0, %1" : : "a"(value), "Nd"(port) : "memory");
}
inline uint8_t In8(uint16_t port) {
asm ("inb %0" : : "Nd"(port) : "memory");
}
inline uint16_t In16(uint16_t port) {
asm ("inw %0" : : "Nd"(port) : "memory");
}
inline uint32_t In32(uint16_t port) {
asm ("inl %0" : : "Nd"(port) : "memory");
}
inline void IoPortWait() {
Out8(0x80, 0);
}
};
+1 -6
View File
@@ -7,7 +7,6 @@
#include <cstdint>
#include <cstddef>
#include <limine.h>
#include <Hal/GDT.hpp>
#include <Terminal/Terminal.hpp>
#include <Libraries/String.hpp>
@@ -16,20 +15,16 @@
#include <Memory/Memmap.hpp>
#include <Memory/Heap.hpp>
#include <Memory/HHDM.hpp>
#include <CppLib/Stream.hpp>
#include <CppLib/Vector.hpp>
#include <CppLib/CString.hpp>
#include <Platform/Limine.hpp>
#include <Platform/Util.hpp>
#include <Libraries/Memory.hpp>
#include <Hal/IDT.hpp>
#include <Memory/PageFrameAllocator.hpp>
#include <Memory/HHDM.hpp>
#include <Io/IoPort.hpp>
using namespace Kt;