update main #1

Merged
Sinipelto merged 240 commits from Bananymous/banan-os:main into main 2023-11-20 13:20:51 +02:00
1 changed files with 25 additions and 0 deletions
Showing only changes of commit e5ffadb109 - Show all commits

View File

@ -1,12 +1,20 @@
#pragma once #pragma once
#include <BAN/Errors.h> #include <BAN/Errors.h>
#include <BAN/Traits.h>
#include <kernel/CriticalScope.h>
#include <kernel/Memory/Types.h> #include <kernel/Memory/Types.h>
#include <kernel/SpinLock.h> #include <kernel/SpinLock.h>
namespace Kernel namespace Kernel
{ {
template<typename F>
concept with_fast_page_callback = requires(F func)
{
requires BAN::is_same_v<decltype(func()), void>;
};
class PageTable class PageTable
{ {
public: public:
@ -33,6 +41,15 @@ namespace Kernel
static void unmap_fast_page(); static void unmap_fast_page();
static constexpr vaddr_t fast_page() { return KERNEL_OFFSET; } static constexpr vaddr_t fast_page() { return KERNEL_OFFSET; }
template<with_fast_page_callback F>
static void with_fast_page(paddr_t paddr, F callback)
{
CriticalScope _;
map_fast_page(paddr);
callback();
unmap_fast_page();
}
// FIXME: implement sized checks, return span, etc // FIXME: implement sized checks, return span, etc
static void* fast_page_as_ptr(size_t offset = 0) static void* fast_page_as_ptr(size_t offset = 0)
{ {
@ -47,6 +64,14 @@ namespace Kernel
return *reinterpret_cast<T*>(fast_page() + offset); return *reinterpret_cast<T*>(fast_page() + offset);
} }
// Retrieves index'th element from fast_page
template<typename T>
static T& fast_page_as_sized(size_t index)
{
ASSERT((index + 1) * sizeof(T) <= PAGE_SIZE);
return *reinterpret_cast<T*>(fast_page() + index * sizeof(T));
}
static bool is_valid_pointer(uintptr_t); static bool is_valid_pointer(uintptr_t);
static BAN::ErrorOr<PageTable*> create_userspace(); static BAN::ErrorOr<PageTable*> create_userspace();