Kernel - (minor) Documentation comment tweaks
[tpg/acess2.git] / KernelLand / Kernel / include / acess.h
index e8ca0d3..de16818 100644 (file)
  */
 
 #include <stddef.h>
+#include <stdbool.h>
 #include <arch.h>
 
+#ifndef HALT_CPU
+# define HALT_CPU()    for(;;);
+#endif
+
 //! Pack a structure
 #define PACKED __attribute__((packed))
 //! Mark a function as not returning
@@ -22,6 +27,8 @@
 #define DEPRECATED     __attribute__((deprecated))
 //! Mark a parameter as unused
 #define UNUSED(x)      UNUSED_##x __attribute__((unused))
+//! 
+#define ALIGN(x)       __attribute__((aligned(x)))
 
 /**
  * \name Boolean constants
@@ -45,8 +52,8 @@ typedef Uint32        tGID;   //!< Group ID Type
 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 ---
 /**
@@ -78,11 +85,11 @@ extern const char   gsBuildInfo[];
  * \{
  * \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)
 /**
  * \}
  */
@@ -136,7 +143,9 @@ typedef struct sKernelSymbol {
  * \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);
 /**
  * \}
@@ -146,14 +155,14 @@ extern void       IRQ_RemHandler(int Handle);
 
 // --- IO ---
 #if NO_IO_BUS
-#define inb(a) (Log_Panic("Arch", STR(ARCHDIR)" does not support in*/out* (%s:%i)", __FILE__, __LINE__),0)
+#define inb(a) (Log_Panic("Arch", STR(ARCHDIR)" does not support in* (%s:%i)", __FILE__, __LINE__),0)
 #define inw(a) inb(a)
 #define ind(a) inb(a)
 #define inq(a) inb(a)
-#define outb(a,b)      inb(a)
-#define outw(a,b)      inb(a)
-#define outd(a,b)      inb(a)
-#define outq(a,b)      inb(a)
+#define outb(a,b)      (Log_Panic("Arch", STR(ARCHDIR)" does not support out* (%s:%i)", __FILE__, __LINE__),(void)(b))
+#define outw(a,b)      outb(a,b)
+#define outd(a,b)      outb(a,b)
+#define outq(a,b)      outb(a,b)
 #else
 /**
  * \name I/O Memory Access
@@ -182,44 +191,50 @@ extern Uint64     inq(Uint16 Port);
  * \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
  * \return Physical page mapped at \a Addr
  */
-extern tPAddr  MM_GetPhysAddr(const void *Addr);
+extern tPAddr  MM_GetPhysAddr(volatile const void *Addr);
 /**
  * \brief Set the access flags on a page
  * \param VAddr        Virtual address of the page
  * \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((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
@@ -229,7 +244,7 @@ extern Uint MM_GetFlags(tVAddr VAddr);
 extern void    *MM_MapTemp(tPAddr PAddr);
 /**
  * \brief Free a temporarily mapped page
- * \param VAddr        Allocate virtual addres of page
+ * \param Ptr  Pointer to page base
  */
 extern void    MM_FreeTemp(void *Ptr);
 /**
@@ -237,7 +252,7 @@ extern void MM_FreeTemp(void *Ptr);
  * \param PAddr        Physical address to map in
  * \param Number       Number of pages to map
  */
-extern tVAddr  MM_MapHWPages(tPAddr PAddr, Uint Number);
+extern void    *MM_MapHWPages(tPAddr PAddr, Uint Number);
 /**
  * \brief Allocates DMA physical memory
  * \param Pages        Number of pages required
@@ -245,13 +260,13 @@ extern tVAddr     MM_MapHWPages(tPAddr PAddr, Uint Number);
  * \param PhysAddr     Pointer to the location to place the physical address allocated
  * \return Virtual address allocate
  */
-extern tVAddr  MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr);
+extern void    *MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr);
 /**
  * \brief Unmaps an allocated hardware range
  * \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
@@ -354,46 +369,7 @@ extern Uint64      SwapEndian64(Uint64 Val);
  */
 
 // --- Strings ---
-/**
- * \name Strings
- * \{
- */
-extern int     vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args);
-extern int     snprintf(char *__s, size_t __n, const char *__format, ...);
-extern int     sprintf(char *__s, const char *__format, ...);
-extern size_t  strlen(const char *Str);
-extern char    *strcpy(char *__dest, const char *__src);
-extern char    *strncpy(char *__dest, const char *__src, size_t max);
-extern char    *strcat(char *__dest, const char *__src);
-extern char    *strncat(char *__dest, const char *__src, size_t n);
-extern int     strcmp(const char *__str1, const char *__str2);
-extern int     strncmp(const char *Str1, const char *Str2, size_t num);
-extern int     strucmp(const char *Str1, const char *Str2);
-// strdup macro is defined in heap.h
-extern char    *_strdup(const char *File, int Line, const char *Str);
-extern char    **str_split(const char *__str, char __ch);
-extern char    *strchr(const char *__s, int __c);
-extern char    *strrchr(const char *__s, int __c);
-extern int     strpos(const char *Str, char Ch);
-extern int     strpos8(const char *str, Uint32 search);
-extern void    itoa(char *buf, Uint64 num, int base, int minLength, char pad);
-extern int     atoi(const char *string);
-extern unsigned long long      strtoull(const char *str, char **end, int base);
-extern unsigned long   strtoul(const char *str, char **end, int base);
-extern signed long long        strtoll(const char *str, char **end, int base);
-extern signed long     strtol(const char *str, char **end, int base);
-extern int     ParseInt(const char *string, int *Val);
-extern int     ReadUTF8(const Uint8 *str, Uint32 *Val);
-extern int     WriteUTF8(Uint8 *str, Uint32 Val);
-extern int     ModUtil_SetIdent(char *Dest, const char *Value);
-extern int     ModUtil_LookupString(const char **Array, const char *Needle);
-
-extern Uint8   ByteSum(const void *Ptr, int Size);
-extern int     Hex(char *Dest, size_t Size, const Uint8 *SourceData);
-extern int     UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString);
-/**
- * \}
- */
+#include <acess_string.h>
 
 #include <ctype.h>
 

UCC git Repository :: git.ucc.asn.au