DiskTool - Cleanup, copy command
[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 #define ASSERT(x)       do{}while(0)
17
18 extern char     __buildnum[];
19 #define BUILD_NUM       ((int)(Uint)&__buildnum)
20 extern const char gsGitHash[];
21
22 #define BITS    32
23 #define NULL    ((void*)0)
24 #include <stdint.h>
25
26 typedef uintptr_t       Uint;
27 //typedef unsigned int  size_t;
28 #include <stddef.h>
29 typedef uint64_t        off_t;
30 typedef char    BOOL;
31
32
33 typedef uint8_t         Uint8;
34 typedef uint16_t        Uint16;
35 typedef uint32_t        Uint32;
36 typedef uint64_t        Uint64;
37
38 typedef int8_t  Sint8;
39 typedef int16_t Sint16;
40 typedef int32_t Sint32;
41 typedef int64_t Sint64;
42
43 typedef uintptr_t       tVAddr;
44 typedef uint32_t        tPAddr;
45
46 typedef uint32_t        tUID;
47 typedef uint32_t        tGID;
48 typedef uint32_t        tTID;
49
50 // NOTE: Since this is single-threaded (for now) mutexes can be implimented as simple locks
51 typedef char    tMutex;
52 typedef char    tShortSpinlock;
53
54 typedef int64_t tTime;
55 extern tTime    now(void);
56 extern int64_t  timestamp(int sec, int min, int hr, int day, int month, int year);
57
58 #define PACKED  __attribute__((packed))
59 #define DEPRECATED
60 #define EXPORT(s)
61 #define EXPORTV(s)
62
63 #include <vfs_ext.h>
64
65 // These are actually library functions, but they can't be included, so they're defined manually
66 extern void     *malloc(size_t bytes);
67 extern void     *calloc(size_t nmemb, size_t size);
68 extern void     *realloc(void *oldptr, size_t bytes);
69 extern void     free(void *buffer);
70
71 #include <errno.h>
72 #include <acess_logging.h>
73
74 // Threads
75 extern int      *Threads_GetErrno(void);
76 //extern tPGID  Threads_GetPGID(void);
77 //extern tPID   Threads_GetPID(void);
78 extern tTID     Threads_GetTID(void);
79 extern tUID     Threads_GetUID(void);
80 extern tGID     Threads_GetGID(void);
81
82 // Kinda hacky way of not colliding with native errno
83 #define errno   (*(Threads_GetErrno()))
84
85 #include <string.h>
86 extern int      strucmp(const char *s1, const char *s2);
87 extern int      strpos(const char *Str, char Ch);
88 extern void     itoa(char *buf, uint64_t num, int base, int minLength, char pad);
89 extern int      snprintf(char *buf, size_t len, const char *fmt, ...);
90 extern int      sprintf(char *buf, const char *fmt, ...);
91 extern int      ReadUTF8(const Uint8 *str, Uint32 *Val);
92 extern int      WriteUTF8(Uint8 *str, Uint32 Val);
93 #define CheckString(str)        (1)
94 #define CheckMem(mem,sz)        (1)
95
96 // TODO: Move out?
97 extern int      DivUp(int value, int divisor);
98 extern uint64_t DivMod64U(uint64_t Num, uint64_t Den, uint64_t *Rem);
99
100 #if DEBUG
101 # define ENTER(str, v...)       Log("%s:%i: ENTER "str, __func__, __LINE__)
102 # define LOG(fmt, v...)         Log("%s:%i: "fmt, __func__, __LINE__, ##v)
103 # define LEAVE(...)     do{}while(0)
104 # define LEAVE_RET(t,v) return v;
105 #else
106 # define ENTER(...)     do{}while(0)
107 # define LOG(...)       do{}while(0)
108 # define LEAVE(...)     do{}while(0)
109 # define LEAVE_RET(t,v) return v;
110 #endif
111
112 static inline int Mutex_Acquire(tMutex *m) {
113         if(*m)  Log_KernelPanic("---", "Double mutex lock");
114         *m = 1;
115         return 0;
116 }
117 static inline void Mutex_Release(tMutex *m) { *m = 0; }
118
119 static inline void SHORTLOCK(tShortSpinlock *Lock) {
120         if(*Lock)       Log_KernelPanic("---", "Double short lock");
121         *Lock = 1;
122 }
123 static inline void SHORTREL(tShortSpinlock *m) { *m = 0; }
124
125 #endif
126

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