DiskTool - Compiling again, now with modules
[tpg/acess2.git] / Tools / DiskTool / src / include / acess.h
1 /*
2  * Acess2 DiskTool utility
3  * - By John Hodge (thePowersGang)
4  *
5  * include/acess.h
6  * - Mock kernel core header
7  */
8 #ifndef _DISKTOOL__ACESS_H_
9 #define _DISKTOOL__ACESS_H_
10
11 #define CONCAT(x,y) x ## y
12 #define EXPAND_CONCAT(x,y) CONCAT(x,y)
13 #define STR(x) #x
14 #define EXPAND_STR(x) STR(x)
15
16 extern char     __buildnum[];
17 #define BUILD_NUM       ((int)(Uint)&__buildnum)
18 extern const char gsGitHash[];
19
20 #define BITS    32
21 #define NULL    ((void*)0)
22 #include <stdint.h>
23
24 typedef uintptr_t       Uint;
25 typedef unsigned int    size_t;
26 typedef uint64_t        off_t;
27 typedef char    BOOL;
28
29
30 typedef uint8_t         Uint8;
31 typedef uint16_t        Uint16;
32 typedef uint32_t        Uint32;
33 typedef uint64_t        Uint64;
34
35 typedef int8_t  Sint8;
36 typedef int16_t Sint16;
37 typedef int32_t Sint32;
38 typedef int64_t Sint64;
39
40 typedef uintptr_t       tVAddr;
41 typedef uint32_t        tPAddr;
42
43 typedef uint32_t        tUID;
44 typedef uint32_t        tGID;
45 typedef uint32_t        tTID;
46
47 // NOTE: Since this is single-threaded (for now) mutexes can be implimented as simple locks
48 typedef char    tMutex;
49 typedef char    tShortSpinlock;
50
51 typedef int64_t tTime;
52
53 #define PACKED  __attribute__((packed))
54 #define DEPRECATED
55 #define EXPORT(s)
56 #define EXPORTV(s)
57
58 #include <vfs_ext.h>
59
60 // These are actually library functions, but they can't be included, so they're defined manually
61 extern void     *malloc(size_t bytes);
62 extern void     *calloc(size_t nmemb, size_t size);
63 extern void     *realloc(void *oldptr, size_t bytes);
64 extern void     free(void *buffer);
65
66 #include <errno.h>
67
68 #include <acess_logging.h>
69
70 // Threads
71 extern int      *Threads_GetErrno(void);
72 //extern tPGID  Threads_GetPGID(void);
73 //extern tPID   Threads_GetPID(void);
74 extern tTID     Threads_GetTID(void);
75 extern tUID     Threads_GetUID(void);
76 extern tGID     Threads_GetGID(void);
77
78 // Kinda hacky way of not colliding with native errno
79 #define errno   (*(Threads_GetErrno()))
80
81 #include <string.h>
82 extern int      strpos(const char *Str, char Ch);
83 extern void     itoa(char *buf, uint64_t num, int base, int minLength, char pad);
84
85 // TODO: Move out?
86 extern int64_t  DivUp(int64_t value, int64_t divisor);
87
88 #if DEBUG
89 # define ENTER(str, v...)       Log("%s:%i: ENTER "str, __func__, __LINE__)
90 # define LOG(fmt, v...)         Log("%s:%i: "fmt, __func__, __LINE__, ##v)
91 # define LEAVE(...)     do{}while(0)
92 # define LEAVE_RET(t,v) return v;
93 #else
94 # define ENTER(...)     do{}while(0)
95 # define LOG(...)       do{}while(0)
96 # define LEAVE(...)     do{}while(0)
97 # define LEAVE_RET(t,v) return v;
98 #endif
99
100 static inline int Mutex_Acquire(tMutex *m) {
101         if(*m)  Log_KernelPanic("---", "Double mutex lock");
102         *m = 1;
103         return 0;
104 }
105 static inline void Mutex_Release(tMutex *m) { *m = 0; }
106
107 static inline void SHORTLOCK(tShortSpinlock *Lock) {
108         if(*Lock)       Log_KernelPanic("---", "Double short lock");
109         *Lock = 1;
110 }
111 static inline void SHORTREL(tShortSpinlock *m) { *m = 0; }
112
113 #endif
114

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