WIP: paging and better malloc.
This commit is contained in:
17
targets/_any/include/drivers/usb.hpp
Normal file
17
targets/_any/include/drivers/usb.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(BAD_APPLE_OS_DRIVERS_USB_HPP_INCLUDED)
|
||||
#define BAD_APPLE_OS_DRIVERS_USB_HPP_INCLUDED
|
||||
|
||||
namespace baos::pci
|
||||
{
|
||||
struct Header;
|
||||
}
|
||||
|
||||
namespace baos::usb
|
||||
{
|
||||
[[nodiscard]] bool initController(const pci::Header& pciHeader) noexcept;
|
||||
}
|
||||
|
||||
#endif // !defined(BAD_APPLE_OS_DRIVERS_USB_HPP_INCLUDED)
|
||||
72
targets/_any/include/os/memory.hpp
Normal file
72
targets/_any/include/os/memory.hpp
Normal file
@@ -0,0 +1,72 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(BAD_APPLE_OS_OS_MEMORY_HPP_INCLUDED)
|
||||
#define BAD_APPLE_OS_OS_MEMORY_HPP_INCLUDED
|
||||
|
||||
#include <bit>
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
|
||||
extern "C" int gKernelStart;
|
||||
extern "C" int gKernelEnd;
|
||||
|
||||
namespace baos
|
||||
{
|
||||
struct PageTableEntry
|
||||
{
|
||||
bool present : 1;
|
||||
bool writable : 1;
|
||||
bool user : 1;
|
||||
bool writeThrough : 1;
|
||||
bool cacheDisabled : 1;
|
||||
bool accessed : 1;
|
||||
bool dirty : 1;
|
||||
bool pageSize : 1;
|
||||
bool global : 1;
|
||||
std::uint8_t avl : 3;
|
||||
std::uint64_t address : 40;
|
||||
std::uint16_t avl2 : 11;
|
||||
bool executeDisable : 1;
|
||||
};
|
||||
|
||||
enum class MemoryType
|
||||
{
|
||||
USABLE,
|
||||
UNUSABLE,
|
||||
MMIO,
|
||||
RESERVED
|
||||
};
|
||||
|
||||
struct MemoryRange
|
||||
{
|
||||
std::uint64_t pageBase;
|
||||
std::uint64_t numPages;
|
||||
MemoryType type = MemoryType::USABLE;
|
||||
|
||||
MemoryRange& operator=(const MemoryRange&) noexcept = default;
|
||||
bool operator<(const MemoryRange& other) const noexcept
|
||||
{
|
||||
return pageBase < other.pageBase;
|
||||
}
|
||||
};
|
||||
|
||||
void setupPaging(std::span<const MemoryRange> memoryRanges) noexcept;
|
||||
[[nodiscard]] const char* memoryTypeName(MemoryType type) noexcept;
|
||||
|
||||
[[nodiscard]] void* allocatePages(unsigned numConsecutive) noexcept;
|
||||
[[nodiscard]] inline void* allocatePage() noexcept { return allocatePages(1); }
|
||||
|
||||
void setupIdentityPaging(std::uint64_t page) noexcept;
|
||||
void setupIdentityPaging2M(std::uint64_t page) noexcept;
|
||||
void setupIdentityPaging(std::uint64_t firstPage, std::uint64_t lastPage) noexcept;
|
||||
|
||||
inline void identityMapRegion(void* start, std::size_t bytes) noexcept
|
||||
{
|
||||
std::uint64_t firstPage = std::bit_cast<std::uint64_t>(start) / 4096;
|
||||
std::uint64_t lastPage = std::bit_cast<std::uint64_t>(static_cast<std::uint8_t*>(start) + bytes) / 4096 + 1;
|
||||
setupIdentityPaging(firstPage, lastPage);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !defined(BAD_APPLE_OS_OS_MEMORY_HPP_INCLUDED)
|
||||
Reference in New Issue
Block a user