2 * Acess2 DiskTool utility
3 * - By John Hodge (thePowersGang)
6 * - Mock kernel core header
8 #ifndef _DISKTOOL__ACESS_H_
9 #define _DISKTOOL__ACESS_H_
11 #define CONCAT(x,y) x ## y
12 #define EXPAND_CONCAT(x,y) CONCAT(x,y)
14 #define EXPAND_STR(x) STR(x)
16 extern char __buildnum[];
17 #define BUILD_NUM ((int)(Uint)&__buildnum)
18 extern const char gsGitHash[];
19 extern const char gsBuildInfo[];
20 #define VER2(major,minor) ((((major)&0xFF)<<8)|((minor)&0xFF))
24 #define NULL ((void*)0)
28 typedef uintptr_t Uint;
29 //typedef unsigned int size_t;
31 typedef uint64_t off_t;
35 typedef uint8_t Uint8;
36 typedef uint16_t Uint16;
37 typedef uint32_t Uint32;
38 typedef uint64_t Uint64;
41 typedef int16_t Sint16;
42 typedef int32_t Sint32;
43 typedef int64_t Sint64;
45 typedef uintptr_t tVAddr;
46 typedef uint32_t tPAddr;
48 typedef uint32_t tUID;
49 typedef uint32_t tGID;
50 typedef uint32_t tTID;
51 typedef uint32_t tPGID;
53 typedef int64_t tTime;
54 extern tTime now(void);
55 extern int64_t timestamp(int sec, int min, int hr, int day, int month, int year);
56 extern void format_date(tTime TS, int *year, int *month, int *day, int *hrs, int *mins, int *sec, int *ms);
58 #define PACKED __attribute__((packed))
59 #define NORETURN __attribute__((noreturn))
66 // These are actually library functions, but they can't be included, so they're defined manually
67 extern void *malloc(size_t bytes);
68 extern void *calloc(size_t nmemb, size_t size);
69 extern void *realloc(void *oldptr, size_t bytes);
70 extern void free(void *buffer);
71 extern char *strdup(const char *str);
74 //#include <acess_logging.h>
77 extern void Debug_TraceEnter(const char *Function, const char *Format, ...);
78 extern void Debug_TraceLog(const char *Function, const char *Format, ...);
79 extern void Debug_TraceLeave(const char *Function, char Type, ...);
85 # define ENTER(str, v...) Debug_TraceEnter(__func__, str, ##v)
86 # define LOG(fmt, v...) Debug_TraceLog(__func__, fmt, ##v)
87 # define LEAVE(t, v...) Debug_TraceLeave(__func__, t, ##v)
88 # define LEAVE_RET(t,v) do{LEAVE('-');return v;}while(0)
90 # define ENTER(...) do{}while(0)
91 # define LOG(...) do{}while(0)
92 # define LEAVE(...) do{}while(0)
93 # define LEAVE_RET(t,v) do{return v;}while(0)
97 extern void **Threads_GetHandlesPtr(void);
98 extern int *Threads_GetErrno(void);
99 //extern tPGID Threads_GetPGID(void);
100 //extern tPID Threads_GetPID(void);
101 extern tTID Threads_GetTID(void);
102 extern tUID Threads_GetUID(void);
103 extern tGID Threads_GetGID(void);
105 extern struct sThread *Proc_SpawnWorker(void (*Fcn)(void*), void *Data);
106 extern void Threads_Sleep(void);
107 extern void Threads_Yield(void);
108 extern int Threads_SetName(const char *NewName);
110 // Kinda hacky way of not colliding with native errno
111 #define errno (*(Threads_GetErrno()))
114 * \name Endianness Swapping
117 #ifdef __BIG_ENDIAN__
118 #define LittleEndian16(_val) SwapEndian16(_val)
119 #define LittleEndian32(_val) SwapEndian32(_val)
120 #define LittleEndian64(_val) SwapEndian32(_val)
121 #define BigEndian16(_val) (_val)
122 #define BigEndian32(_val) (_val)
123 #define BigEndian64(_val) (_val)
125 #define LittleEndian16(_val) (_val)
126 #define LittleEndian32(_val) (_val)
127 #define LittleEndian64(_val) (_val)
128 #define BigEndian16(_val) SwapEndian16(_val)
129 #define BigEndian32(_val) SwapEndian32(_val)
130 #define BigEndian64(_val) SwapEndian64(_val)
132 extern Uint16 SwapEndian16(Uint16 Val);
133 extern Uint32 SwapEndian32(Uint32 Val);
134 extern Uint64 SwapEndian64(Uint64 Val);
141 #include <acess_string.h>
143 extern int strucmp(const char *s1, const char *s2);
144 extern int strpos(const char *Str, char Ch);
145 extern void itoa(char *buf, uint64_t num, int base, int minLength, char pad);
146 extern int snprintf(char *buf, size_t len, const char *fmt, ...);
147 extern int sprintf(char *buf, const char *fmt, ...);
148 extern int ReadUTF8(const Uint8 *str, Uint32 *Val);
149 extern int WriteUTF8(Uint8 *str, Uint32 Val);
150 extern int ParseInt(const char *string, int *Val);
152 extern int ModUtil_SetIdent(char *Dest, const char *Value);
153 extern int ModUtil_LookupString(const char **Array, const char *Needle);
154 extern Uint8 ByteSum(const void *Ptr, int Size);
155 extern int Hex(char *Dest, size_t Size, const Uint8 *SourceData);
156 extern int UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString);
158 #define CheckString(str) (1)
159 #define CheckMem(mem,sz) (1)
160 extern int rand(void);
163 extern int DivUp(int value, int divisor);
164 extern uint64_t DivMod64U(uint64_t Num, uint64_t Den, uint64_t *Rem);
165 static inline int MIN(int a, int b) { return a < b ? a : b; }
166 static inline int MAX(int a, int b) { return a > b ? a : b; }
168 #include <shortlock.h>
170 static inline intptr_t MM_GetPhysAddr(void *Ptr) { return 1; }
171 static inline int MM_IsUser(const void *Ptr) { return 1; }