X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Finclude%2Facess.h;h=1f969f8a2b128b3cce21285d2ce00a720b1d8373;hb=8c50e4a0672bdf9e9f6266fa5f485ad7f8b74f5b;hp=7bf2e4816921ac9077f8a63f0c5ee5d45683b2e0;hpb=c2adb8d03edd3bcf25eb2fd9a90ed74200ca78fe;p=tpg%2Facess2.git diff --git a/Kernel/include/acess.h b/Kernel/include/acess.h index 7bf2e481..1f969f8a 100644 --- a/Kernel/include/acess.h +++ b/Kernel/include/acess.h @@ -1,14 +1,44 @@ /* * 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 UNUSED(x) UNUSED_##x __attribute__((unused)) +#define offsetof(st, m) ((Uint)((char *)&((st *)(0))->m - (char *)0 )) #include #include +#include "errno.h" + +// --- Types --- +typedef int tPID; +typedef int tTID; +typedef Uint tUID; +typedef Uint tGID; +typedef Sint64 tTimestamp; +typedef struct sShortSpinlock tShortSpinlock; +typedef struct sMutex tMutex; +typedef struct sSemaphore tSemaphore; + +struct sMutex { + tShortSpinlock Protector; //!< Protector for the lock strucure + const char *Name; //!< Human-readable name + struct sThread *volatile Owner; //!< Owner of the lock (set upon getting the lock) + struct sThread *Waiting; //!< Waiting threads + struct sThread *LastWaiting; //!< Waiting threads +}; + +struct sSemaphore { + tShortSpinlock Protector; //!< Protector for the lock strucure + const char *Name; //!< Human-readable name + volatile int Value; //!< Current mutex value + struct sThread *Waiting; //!< Waiting threads + struct sThread *LastWaiting; //!< Waiting threads +}; // --- Helper Macros --- /** @@ -19,6 +49,8 @@ #define EXPAND_CONCAT(x,y) CONCAT(x,y) #define STR(x) #x #define EXPAND_STR(x) STR(x) + +#define VER2(major,minor) ((((major)&0xFF)<<8)|((minor)&0xFF)) /** * \} */ @@ -73,36 +105,45 @@ typedef void (*tThreadFunction)(void*); */ typedef struct sKernelSymbol { char *Name; - unsigned int Value; + tVAddr Value; } tKernelSymbol; -#define EXPORT(_name) tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (Uint)_name} -#define EXPORTV(_name) tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (Uint)&_name} -#define EXPORTAS(_sym,_name) tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (Uint)_sym} +#define EXPORT(_name) tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (tVAddr)_name} +#define EXPORTV(_name) tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (tVAddr)&_name} +#define EXPORTAS(_sym,_name) tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (tVAddr)_sym} /** * \} */ // === FUNCTIONS === -// --- Core --- -extern void System_Init(char *ArgString); - // --- IRQs --- extern int IRQ_AddHandler(int Num, void (*Callback)(int)); +// --- Logging --- +extern void Log_KernelPanic(char *Ident, char *Message, ...); +extern void Log_Panic(char *Ident, char *Message, ...); +extern void Log_Error(char *Ident, char *Message, ...); +extern void Log_Warning(char *Ident, char *Message, ...); +extern void Log_Notice(char *Ident, char *Message, ...); +extern void Log_Log(char *Ident, char *Message, ...); +extern void Log_Debug(char *Ident, char *Message, ...); + // --- Debug --- /** * \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_Enter(char *FuncName, char *ArgTypes, ...); -extern void Debug_Log(char *FuncName, char *Fmt, ...); -extern void Debug_Leave(char *FuncName, char RetType, ...); -extern void Debug_HexDump(char *Header, void *Data, Uint Length); +extern void Debug_KernelPanic(void); //!< Initiate a kernel panic +extern void Panic(const char *Msg, ...); //!< Print a panic message (initiates a kernel panic) +extern void Warning(const char *Msg, ...); //!< Print a warning message +extern void LogF(const char *Fmt, ...); //!< Print a log message without a trailing newline +extern void Log(const char *Fmt, ...); //!< Print a log message +extern void Debug(const char *Fmt, ...); //!< Print a debug message (doesn't go to KTerm) +extern void LogV(const char *Fmt, va_list Args); //!< va_list Log message +extern void Debug_Enter(const char *FuncName, const char *ArgTypes, ...); +extern void Debug_Log(const char *FuncName, const char *Fmt, ...); +extern void Debug_Leave(const char *FuncName, char RetType, ...); +extern void Debug_HexDump(const char *Header, const void *Data, Uint Length); +#define UNIMPLEMENTED() Warning("'%s' unimplemented", __func__) #if DEBUG # define ENTER(_types...) Debug_Enter((char*)__func__, _types) # define LOG(_fmt...) Debug_Log((char*)__func__, _fmt) @@ -167,17 +208,11 @@ extern void MM_Deallocate(tVAddr VAddr); */ extern int MM_Map(tVAddr VAddr, tPAddr PAddr); /** - * \brief Get the physical address of \a VAddr - * \param VAddr Address of the page to get the physical address of - * \return Physical page mapped at \a VAddr - */ -extern tPAddr MM_GetPhysAddr(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 + * \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 int MM_IsUser(tVAddr VAddr); +extern tPAddr MM_GetPhysAddr(tVAddr Addr); /** * \brief Set the access flags on a page * \param VAddr Virtual address of the page @@ -185,6 +220,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 @@ -202,7 +249,7 @@ extern void MM_FreeTemp(tVAddr VAddr); * \param PAddr Physical address to map in * \param Number Number of pages to map */ -extern tVAddr MM_MapHWPage(tPAddr PAddr, Uint Number); +extern tVAddr MM_MapHWPages(tPAddr PAddr, Uint Number); /** * \brief Allocates DMA physical memory * \param Pages Number of pages required @@ -216,15 +263,16 @@ extern tVAddr MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr); * \param VAddr Virtual address allocate by ::MM_MapHWPage or ::MM_AllocDMA * \param Number Number of pages to free */ -extern void MM_UnmapHWPage(tVAddr VAddr, Uint Number); +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); @@ -247,11 +295,11 @@ extern void MM_DerefPhys(tPAddr PAddr); * \name Memory Manipulation * \{ */ -extern int memcmp(const void *m1, const void *m2, Uint count); -extern void *memcpy(void *dest, const void *src, Uint count); -extern void *memcpyd(void *dest, const void *src, Uint count); -extern void *memset(void *dest, int val, Uint count); -extern void *memsetd(void *dest, Uint val, Uint count); +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); /** * \} */ @@ -283,38 +331,39 @@ extern Uint32 BigEndian32(Uint32 Val); * \name Strings * \{ */ -extern Uint strlen(const char *Str); +extern int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args); +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 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 *strdup(const char *Str); +#define strdup(Str) _strdup(_MODULE_NAME_"/"__FILE__, __LINE__, (Str)) +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 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); +extern int atoi(const char *string); extern int ReadUTF8(Uint8 *str, Uint32 *Val); extern int WriteUTF8(Uint8 *str, Uint32 Val); -extern int LookupString(char **Array, char *Needle); +extern int ModUtil_SetIdent(char *Dest, char *Value); +extern int ModUtil_LookupString(char **Array, char *Needle); + extern Uint8 ByteSum(void *Ptr, int Size); +extern int UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString); /** * \} */ -extern Uint rand(); +extern int 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 --- /** @@ -336,8 +385,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); /** @@ -349,15 +414,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 int Threads_GetUID(); -extern int 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(const char *NewName); +extern void Mutex_Acquire(tMutex *Mutex); +extern void Mutex_Release(tMutex *Mutex); +extern int Mutex_IsLocked(tMutex *Mutex); /** * \} */ @@ -367,5 +439,6 @@ extern int DivUp(int num, int dem); #include #include +#include #endif