*/
#include <stddef.h>
+#include <stdbool.h>
#include <arch.h>
#ifndef HALT_CPU
#define DEPRECATED __attribute__((deprecated))
//! Mark a parameter as unused
#define UNUSED(x) UNUSED_##x __attribute__((unused))
-//!
+//! Apply alignment to a variable
#define ALIGN(x) __attribute__((aligned(x)))
/**
typedef Sint64 tTimestamp; //!< Timestamp (miliseconds since 00:00 1 Jan 1970)
typedef Sint64 tTime; //!< Same again
typedef struct sShortSpinlock tShortSpinlock; //!< Opaque (kinda) spinlock
-typedef int bool; //!< Boolean type
typedef Uint64 off_t; //!< VFS Offset
+typedef struct { char _[PAGE_SIZE];} tPage; // Representation of a page for pointer arithmatic
// --- Helper Macros ---
/**
* \{
* \todo Move to mm_virt.h
*/
-#define MM_PFLAG_RO 0x01 // Writes disallowed
-#define MM_PFLAG_EXEC 0x02 // Allow execution
-#define MM_PFLAG_NOPAGE 0x04 // Prevent from being paged out
-#define MM_PFLAG_COW 0x08 // Copy-On-Write
-#define MM_PFLAG_KERNEL 0x10 // Kernel-Only (Ring0)
+#define MM_PFLAG_RO 0x01 //!< Writes disallowed
+#define MM_PFLAG_EXEC 0x02 //!< Allow execution
+#define MM_PFLAG_NOPAGE 0x04 //!< Prevent from being paged out
+#define MM_PFLAG_COW 0x08 //!< Copy-On-Write
+#define MM_PFLAG_KERNEL 0x10 //!< Kernel-Only (Ring0)
/**
* \}
*/
* \name IRQ hander registration
* \{
*/
+//! Register a callback for when an IRQ is raised
extern int IRQ_AddHandler(int Num, void (*Callback)(int, void*), void *Ptr);
+//! Remove a previously registered IRQ handler
extern void IRQ_RemHandler(int Handle);
/**
* \}
* \param VAddr Virtual Address to allocate at
* \return Physical address allocated
*/
-extern tPAddr MM_Allocate(tVAddr VAddr) __attribute__ ((warn_unused_result));
+extern tPAddr MM_Allocate(volatile void *VAddr) __attribute__ ((warn_unused_result));
+/**
+ * \breif Allocate a zeroed COW page to \a VAddr
+ * \param VAddr Virtual address to allocate at
+ * \return Physical address allocated (don't cache)
+ */
+extern void MM_AllocateZero(volatile void *VAddr);
/**
* \brief Deallocate a page
* \param VAddr Virtual address to unmap
*/
-extern void MM_Deallocate(tVAddr VAddr);
+extern void MM_Deallocate(volatile void *VAddr);
/**
* \brief Map a physical page at \a PAddr to \a VAddr
* \param VAddr Target virtual address
* \param PAddr Physical address to map
* \return Boolean Success
*/
-extern int MM_Map(tVAddr VAddr, tPAddr PAddr);
+extern int MM_Map(volatile void * VAddr, tPAddr PAddr);
/**
* \brief Get the physical address of \a Addr
* \param Addr Address of the page to get the physical address of
* \param Flags New flags value
* \param Mask Flags to set
*/
-extern void MM_SetFlags(tVAddr VAddr, Uint Flags, Uint Mask);
+extern void MM_SetFlags(volatile void *VAddr, Uint Flags, Uint Mask);
/**
* \brief Get the flags on a flag
* \param VAddr Virtual address of page
* \return Flags value of the page
*/
-extern Uint MM_GetFlags(tVAddr VAddr);
+extern Uint MM_GetFlags(volatile const void *VAddr);
/**
* \brief Checks is a memory range is user accessable
* \param VAddr Base address to check
* \return 1 if the memory is all user-accessable, 0 otherwise
*/
-#define MM_IsUser(VAddr) (!(MM_GetFlags((tVAddr)(VAddr))&MM_PFLAG_KERNEL))
+#define MM_IsUser(VAddr) (!(MM_GetFlags((const void*)(VAddr))&MM_PFLAG_KERNEL))
/**
* \brief Temporarily map a page into the address space
* \param PAddr Physical addres to map
* \note There is only a limited ammount of slots avaliable
*/
extern void *MM_MapTemp(tPAddr PAddr);
+/**
+ * \brief Peform a temporary map of a page from another process
+ * \param Process Source process
+ * \param Address Source virtual address
+ * \return Virtual address of page in memory
+ * \note Limited slots
+ */
+struct sProcess;
+extern void *MM_MapTempFromProc(struct sProcess *Process, const void *Address);
/**
* \brief Free a temporarily mapped page
* \param Ptr Pointer to page base
* \param VAddr Virtual address allocate by ::MM_MapHWPages or ::MM_AllocDMA
* \param Number Number of pages to free
*/
-extern void MM_UnmapHWPages(tVAddr VAddr, Uint Number);
+extern void MM_UnmapHWPages(volatile void *VAddr, Uint Number);
/**
* \brief Allocate a single physical page
* \return Physical address allocated