mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-08-04 09:46:10 -04:00
Doc and cleanup
This commit is contained in:
parent
13da670496
commit
510cda7f86
@ -8,16 +8,20 @@
|
|||||||
#ifndef PHYSICAL_POINTER_H
|
#ifndef PHYSICAL_POINTER_H
|
||||||
#define PHYSICAL_POINTER_H
|
#define PHYSICAL_POINTER_H
|
||||||
|
|
||||||
|
#include <type_traits.hpp>
|
||||||
|
|
||||||
#include "virtual_allocator.hpp"
|
#include "virtual_allocator.hpp"
|
||||||
#include "paging.hpp"
|
#include "paging.hpp"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief A special pointer to physical memory
|
||||||
|
*/
|
||||||
struct physical_pointer {
|
struct physical_pointer {
|
||||||
private:
|
/*!
|
||||||
size_t phys;
|
* \brief Creates a new physical pointer
|
||||||
size_t pages;
|
* \param phys_p Physical address
|
||||||
size_t virt;
|
* \param pages_p The nubmer of pages
|
||||||
|
*/
|
||||||
public:
|
|
||||||
physical_pointer(size_t phys_p, size_t pages_p) : phys(phys_p), pages(pages_p) {
|
physical_pointer(size_t phys_p, size_t pages_p) : phys(phys_p), pages(pages_p) {
|
||||||
if(pages > 0){
|
if(pages > 0){
|
||||||
virt = virtual_allocator::allocate(pages);
|
virt = virtual_allocator::allocate(pages);
|
||||||
@ -38,6 +42,9 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Destroys the physical pointer and releases its memory
|
||||||
|
*/
|
||||||
~physical_pointer(){
|
~physical_pointer(){
|
||||||
if(virt){
|
if(virt){
|
||||||
if(pages == 1){
|
if(pages == 1){
|
||||||
@ -50,27 +57,52 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Reinterprets the virtual memory as the given type.
|
||||||
|
*
|
||||||
|
* This should
|
||||||
|
*
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T as(){
|
T as(){
|
||||||
|
static_assert(std::is_pointer<T>::value, "as<T>() should only be used with pointer types");
|
||||||
return reinterpret_cast<T>(virt);
|
return reinterpret_cast<T>(virt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Returns a pointer of a given type to the memory
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T* as_ptr(){
|
T* as_ptr(){
|
||||||
return reinterpret_cast<T*>(virt);
|
return reinterpret_cast<T*>(virt);
|
||||||
}
|
}
|
||||||
|
|
||||||
uintptr_t get(){
|
/*!
|
||||||
|
* \brief Returns the virtual address
|
||||||
|
*/
|
||||||
|
uintptr_t get() const {
|
||||||
return virt;
|
return virt;
|
||||||
}
|
}
|
||||||
|
|
||||||
uintptr_t get_phys(){
|
/*!
|
||||||
|
* \brief Returns the physical address
|
||||||
|
*/
|
||||||
|
uintptr_t get_phys() const {
|
||||||
return virt;
|
return virt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Convert the pointer to a boolean
|
||||||
|
*/
|
||||||
operator bool() const {
|
operator bool() const {
|
||||||
return virt != 0;
|
return virt != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const size_t phys; ///< The physical memory address
|
||||||
|
const size_t pages; ///< The number of pages
|
||||||
|
size_t virt; ///< The virtual memory
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user