X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Finclude%2Facess.h;h=e6afcf5e1f15441f9c796fe967aba3a676b5144e;hb=05e8b329edc7c55eec967c3caba1982c173025e3;hp=db2dd96490987b1301d99cb743b5b04afdcfaeb6;hpb=077a1c5d962b20dee54c6b31c8f37d2fe79105ad;p=tpg%2Facess2.git diff --git a/Kernel/include/acess.h b/Kernel/include/acess.h index db2dd964..e6afcf5e 100644 --- a/Kernel/include/acess.h +++ b/Kernel/include/acess.h @@ -1,14 +1,15 @@ /* * AcessOS Microkernel Version - * common.h + * acess.h */ -#ifndef _COMMON_H -#define _COMMON_H +#ifndef _ACESS_H +#define _ACESS_H #define NULL ((void*)0) -#define PACKED __attribute__ ((packed)) +#define PACKED __attribute__((packed)) +#define UNUSED(x) UNUSED_##x __attribute__((unused)) +#define offsetof(st, m) ((Uint)((char *)&((st *)(0))->m - (char *)0 )) -#include #include #include #include "errno.h" @@ -19,6 +20,15 @@ typedef int tTID; typedef Uint tUID; typedef Uint tGID; typedef Sint64 tTimestamp; +typedef struct sShortSpinlock tShortSpinlock; +typedef struct sMutex tMutex; + +struct sMutex { + tShortSpinlock Protector; //!< Protector for the lock strucure + struct sThread *volatile Owner; //!< Owner of the lock (set upon getting the lock) + struct sThread *Waiting; //!< Waiting threads + struct sThread *LastWaiting; //!< Waiting threads +}; // --- Helper Macros --- /** @@ -95,9 +105,6 @@ typedef struct sKernelSymbol { */ // === FUNCTIONS === -// --- Core --- -extern void System_Init(char *ArgString); - // --- IRQs --- extern int IRQ_AddHandler(int Num, void (*Callback)(int)); @@ -115,11 +122,13 @@ extern void Log_Debug(char *Ident, char *Message, ...); * \name Debugging and Errors * \{ */ -extern void Panic(char *Msg, ...); -extern void Warning(char *Msg, ...); -extern void Log(char *Fmt, ...); -extern void LogV(char *Fmt, va_list Args); -extern void LogF(char *Fmt, ...); +extern void Debug_KernelPanic(void); //!< Initiate a kernel panic +extern void Panic(char *Msg, ...); //!< Print a panic message (initiates a kernel panic) +extern void Warning(char *Msg, ...); //!< Print a warning message +extern void LogF(char *Fmt, ...); //!< Print a log message without a trailing newline +extern void Log(char *Fmt, ...); //!< Print a log message +extern void Debug(char *Fmt, ...); //!< Print a debug message (doesn't go to KTerm) +extern void LogV(char *Fmt, va_list Args); //!< va_list Log message extern void Debug_Enter(char *FuncName, char *ArgTypes, ...); extern void Debug_Log(char *FuncName, char *Fmt, ...); extern void Debug_Leave(char *FuncName, char RetType, ...); @@ -194,12 +203,6 @@ extern int MM_Map(tVAddr VAddr, tPAddr PAddr); * \return Physical page mapped at \a Addr */ extern tPAddr MM_GetPhysAddr(tVAddr Addr); -/** - * \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 - */ -extern int MM_IsUser(tVAddr VAddr); /** * \brief Set the access flags on a page * \param VAddr Virtual address of the page @@ -207,6 +210,18 @@ extern int MM_IsUser(tVAddr VAddr); * \param Mask Flags to set */ extern void MM_SetFlags(tVAddr 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); +/** + * \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)) /** * \brief Temporarily map a page into the address space * \param PAddr Physical addres to map @@ -243,10 +258,11 @@ extern void MM_UnmapHWPages(tVAddr VAddr, Uint Number); * \brief Allocate a single physical page * \return Physical address allocated */ -extern tPAddr MM_AllocPhys(); +extern tPAddr MM_AllocPhys(void); /** * \brief Allocate a contiguous range of physical pages * \param Pages Number of pages to allocate + * \param MaxBits Maximum number of address bits allowed * \return First physical address allocated */ extern tPAddr MM_AllocPhysRange(int Pages, int MaxBits); @@ -314,6 +330,7 @@ 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); extern char *strdup(const char *Str); +extern char **str_split(const char *__str, char __ch); extern int strpos(const char *Str, char Ch); extern int strpos8(const char *str, Uint32 search); extern void itoa(char *buf, Uint num, int base, int minLength, char pad); @@ -327,22 +344,11 @@ extern Uint8 ByteSum(void *Ptr, int Size); * \} */ -extern Uint rand(); +extern Uint rand(void); extern int CallWithArgArray(void *Function, int NArgs, Uint *Args); // --- Heap --- -/** - * \name Heap - * \{ - */ -extern void *malloc(size_t size); -extern void *calloc(size_t num, size_t size); -extern void *realloc(void *ptr, size_t size); -extern void free(void *Ptr); -extern int IsHeap(void *Ptr); -/** - * \} - */ +#include // --- Modules --- /** @@ -364,8 +370,24 @@ extern int Module_LoadFile(char *Path, char *ArgStr); * \brief Create a timestamp from a time */ extern Sint64 timestamp(int sec, int mins, int hrs, int day, int month, int year); -extern Sint64 now(); -extern int Time_CreateTimer(int Delta, void *Callback, void *Argument); +/** + * \brief Gets the current timestamp (miliseconds since Midnight 1st January 1970) + */ +extern Sint64 now(void); +/** + * \brief Timer callback function + */ +typedef void (tTimerCallback)(void *); +/** + * \brief Creates a one-shot timer + * \param Delta Period of the timer + * \param Callback Function to call each time + * \param Argument Argument to pass to the callback + */ +extern int Time_CreateTimer(int Delta, tTimerCallback *Callback, void *Argument); +/** + * \brief Removed an active timer + */ extern void Time_RemoveTimer(int ID); extern void Time_Delay(int Delay); /** @@ -377,19 +399,22 @@ extern void Time_Delay(int Delay); * \name Threads and Processes * \{ */ -extern int Proc_SpawnWorker(); +extern int Proc_SpawnWorker(void); extern int Proc_Spawn(char *Path); -extern void Threads_Exit(); -extern void Threads_Yield(); -extern void Threads_Sleep(); -extern void Threads_WakeTID(tTID Thread); -extern tPID Threads_GetPID(); -extern tTID Threads_GetTID(); -extern tUID Threads_GetUID(); -extern tGID Threads_GetGID(); +extern void Threads_Exit(int TID, int Status); +extern void Threads_Yield(void); +extern void Threads_Sleep(void); +extern int Threads_WakeTID(tTID Thread); +extern tPID Threads_GetPID(void); +extern tTID Threads_GetTID(void); +extern tUID Threads_GetUID(void); +extern tGID Threads_GetGID(void); extern int SpawnTask(tThreadFunction Function, void *Arg); extern Uint *Threads_GetCfgPtr(int Id); extern int Threads_SetName(char *NewName); +extern void Mutex_Acquire(tMutex *Mutex); +extern void Mutex_Release(tMutex *Mutex); +extern int Mutex_IsLocked(tMutex *Mutex); /** * \} */