*/
#ifndef _ACESS_H
#define _ACESS_H
+/**
+ * \file acess.h
+ * \brief Acess2 Kernel API Core
+ */
+//! NULL Pointer
#define NULL ((void*)0)
+//! Pack a structure
#define PACKED __attribute__((packed))
+//! Mark a function as not returning
+#define NORETURN __attribute__((noreturn))
+//! Mark a parameter as unused
#define UNUSED(x) UNUSED_##x __attribute__((unused))
+//! Get the offset of a member in a structure
#define offsetof(st, m) ((Uint)((char *)&((st *)(0))->m - (char *)0 ))
+/**
+ * \name Boolean constants
+ * \{
+ */
+#define TRUE 1
+#define FALSE 0
+/**
+ * \}
+ */
+
#include <arch.h>
#include <stdarg.h>
#include "errno.h"
// --- Types ---
-typedef int tPID;
-typedef int tTID;
-typedef Uint tUID;
-typedef Uint tGID;
-typedef Sint64 tTimestamp;
-typedef Sint64 tTime;
-typedef struct sShortSpinlock tShortSpinlock;
+typedef int tPID; //!< Process ID type
+typedef int tTID; //!< Thread ID Type
+typedef Uint tUID; //!< User ID Type
+typedef Uint 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
// --- Helper Macros ---
/**
#define STR(x) #x
#define EXPAND_STR(x) STR(x)
+extern char __buildnum[];
+#define BUILD_NUM ((int)(Uint)&__buildnum)
+extern const char gsGitHash[];
+
#define VER2(major,minor) ((((major)&0xFF)<<8)|((minor)&0xFF))
/**
* \}
* \}
*/
// --- Interface Flags & Macros
+/**
+ * \name Flags for Proc_Clone
+ * \{
+ */
+//! Clone the entire process
#define CLONE_VM 0x10
+/**
+ * \}
+ */
// === Types ===
+/**
+ * \brief Thread root function
+ *
+ * Function pointer prototype of a thread entrypoint. When it
+ * returns, Threads_Exit is called
+ */
typedef void (*tThreadFunction)(void*);
// === Kernel Export Macros ===
/**
- * \name Kernel Function
+ * \name Kernel exports
* \{
*/
+//! Kernel symbol definition
typedef struct sKernelSymbol {
- const char *Name;
- tVAddr Value;
+ const char *Name; //!< Symbolic name
+ tVAddr Value; //!< Value of the symbol
} tKernelSymbol;
+//! Export a pointer symbol (function/array)
#define EXPORT(_name) tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (tVAddr)_name}
+//! Export a variable
#define EXPORTV(_name) tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (tVAddr)&_name}
+//! Export a symbol under another name
#define EXPORTAS(_sym,_name) tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (tVAddr)_sym}
/**
* \}
// === FUNCTIONS ===
// --- IRQs ---
-extern int IRQ_AddHandler(int Num, void (*Callback)(int));
+/**
+ * \name IRQ hander registration
+ * \{
+ */
+extern int IRQ_AddHandler(int Num, void (*Callback)(int, void*), void *Ptr);
extern void IRQ_RemHandler(int Handle);
+/**
+ * \}
+ */
// --- Logging ---
+/**
+ * \name Logging to kernel ring buffer
+ * \{
+ */
extern void Log_KernelPanic(const char *Ident, const char *Message, ...);
extern void Log_Panic(const char *Ident, const char *Message, ...);
extern void Log_Error(const char *Ident, const char *Message, ...);
extern void Log_Notice(const char *Ident, const char *Message, ...);
extern void Log_Log(const char *Ident, const char *Message, ...);
extern void Log_Debug(const char *Ident, const char *Message, ...);
+/**
+ * \}
+ */
// --- Debug ---
/**
*/
// --- IO ---
+#if NO_IO_BUS
+#define inb(a) (Log_Panic("Arch", "ARMv7 does not support in*/out* (%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)
+#else
/**
* \name I/O Memory Access
* \{
/**
* \}
*/
-
+#endif
// --- Memory Management ---
/**
* \name Memory Management
extern tVAddr MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr);
/**
* \brief Unmaps an allocated hardware range
- * \param VAddr Virtual address allocate by ::MM_MapHWPage or ::MM_AllocDMA
+ * \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 int MM_GetRefCount(tPAddr PAddr);
/**
- * \brief Set the node/offset associated with a page
+ * \brief Set the node associated with a page
* \param PAddr Physical address of page
* \param Node Node pointer (tVFS_Node)
- * \param Offset File offset
* \return Boolean failure
* \retval 0 Success
* \retval 1 Page not allocated
*/
-extern int MM_SetPageInfo(tPAddr PAddr, void *Node, Uint64 Offset);
+extern int MM_SetPageNode(tPAddr PAddr, void *Node);
/**
- * \brief Get the node/offset associated with a page
+ * \brief Get the node associated with a page
* \param PAddr Physical address of page
* \param Node Node pointer (tVFS_Node) destination
- * \param Offset File offset destination (pointer)
* \return Boolean failure
* \retval 0 Success
* \retval 1 Page not allocated
*/
-extern int MM_GetPageInfo(tPAddr PAddr, void **Node, Uint64 *Offset);
+extern int MM_GetPageNode(tPAddr PAddr, void **Node);
/**
* \}
*/
* \{
*/
extern int memcmp(const void *m1, const void *m2, size_t count);
-extern void *memcpy(void *dest, const void *src, size_t count);
-extern void *memcpyd(void *dest, const void *src, size_t count);
-extern void *memset(void *dest, int val, size_t count);
-extern void *memsetd(void *dest, Uint32 val, size_t count);
+extern void *memcpy(void *dest, const void *src, size_t count);
+extern void *memcpyd(void *dest, const void *src, size_t count);
+extern void *memmove(void *dest, const void *src, size_t len);
+extern void *memset(void *dest, int val, size_t count);
+extern void *memsetd(void *dest, Uint32 val, size_t count);
/**
* \}
*/
* \}
*/
+/**
+ * \brief Get a random number
+ * \return Random number
+ * \note Current implementation is a linear congruency
+ */
extern int rand(void);
+/**
+ * \brief Call a function with a variable number of arguments
+ * \param Function Function address
+ * \param NArgs Number of entries in \a Args
+ * \param Args Array of arguments
+ * \return Integer from called Function
+ */
extern int CallWithArgArray(void *Function, int NArgs, Uint *Args);
// --- Heap ---
* \name Threads and Processes
* \{
*/
-extern int Proc_SpawnWorker(void);
+extern int Proc_SpawnWorker(void (*Fcn)(void*), void *Data);
extern int Proc_Spawn(const char *Path);
extern void Threads_Exit(int TID, int Status);
extern void Threads_Yield(void);
*/
// --- Simple Math ---
+//! Divide and round up
extern int DivUp(int num, int dem);
+//! Divide and Modulo 64-bit unsigned integer
+extern Uint64 DivMod64U(Uint64 Num, Uint64 Den, Uint64 *Rem);
#include <binary_ext.h>
#include <vfs_ext.h>