Adds pointer.hpp which provides a wrapper around a simple pointer.
This commit is contained in:
parent
167e578276
commit
02d6f683e8
2 changed files with 51 additions and 3 deletions
44
prototypes/base/include/pointer.hpp
Normal file
44
prototypes/base/include/pointer.hpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
#pragma once
|
||||
|
||||
template<typename TIdent>
|
||||
class pointer
|
||||
{
|
||||
private:
|
||||
void *ptr;
|
||||
public:
|
||||
explicit pointer(void *ptr) :
|
||||
ptr(ptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
explicit pointer(uint32_t value) :
|
||||
ptr(reinterpret_cast<void*>(value))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
pointer(const pointer &) = default;
|
||||
pointer(pointer &&) = default;
|
||||
~pointer() = default;
|
||||
|
||||
void * data() const {
|
||||
return this->ptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T * data () const {
|
||||
return reinterpret_cast<T*>(this->ptr);
|
||||
}
|
||||
|
||||
explicit operator void * () const {
|
||||
return this->ptr;
|
||||
}
|
||||
};
|
||||
|
||||
struct physical_t_ident;
|
||||
struct virtual_t_ident;
|
||||
|
||||
// Add different memory pointer types here....
|
||||
using physical_t = pointer<physical_t_ident>;
|
||||
using virtual_t = pointer<virtual_t_ident>;
|
|
@ -3,6 +3,7 @@
|
|||
#include "console.hpp"
|
||||
#include "pmm.hpp"
|
||||
#include "numeric.hpp"
|
||||
#include "pointer.hpp"
|
||||
#include "compat.h"
|
||||
|
||||
extern "C" void init(void)
|
||||
|
@ -12,10 +13,13 @@ extern "C" void init(void)
|
|||
<< FColor(Color::Yellow) << "Hello color!" << FColor() << "\n"
|
||||
<< BColor(Color::Blue) << "Hello blue!" << BColor() << "\n"
|
||||
<< "Hello default color.\n";
|
||||
for(int i = 0; i < 4097; i++) {
|
||||
|
||||
PMM::markOccupied((void*)0x1500);
|
||||
|
||||
for(int i = 0; i < 10; i++) {
|
||||
bool success;
|
||||
void *page = PMM::alloc(success);
|
||||
Console::main << "allocated page " << i << " [" << success << "]: 0x" << page << "\n";
|
||||
physical_t page(PMM::alloc(success));
|
||||
Console::main << "allocated page " << i << " [" << success << "]: 0x" << page.data() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue