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[];
21 #define NULL ((void*)0)
24 typedef uintptr_t Uint;
25 typedef unsigned int size_t;
26 typedef uint64_t off_t;
30 typedef uint8_t Uint8;
31 typedef uint16_t Uint16;
32 typedef uint32_t Uint32;
33 typedef uint64_t Uint64;
36 typedef int16_t Sint16;
37 typedef int32_t Sint32;
38 typedef int64_t Sint64;
40 typedef uintptr_t tVAddr;
41 typedef uint32_t tPAddr;
43 typedef uint32_t tUID;
44 typedef uint32_t tGID;
45 typedef uint32_t tTID;
47 // NOTE: Since this is single-threaded (for now) mutexes can be implimented as simple locks
49 typedef char tShortSpinlock;
51 typedef int64_t tTime;
53 #define PACKED __attribute__((packed))
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);
68 #include <acess_logging.h>
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);
78 // Kinda hacky way of not colliding with native errno
79 #define errno (*(Threads_GetErrno()))
82 extern int strpos(const char *Str, char Ch);
83 extern void itoa(char *buf, uint64_t num, int base, int minLength, char pad);
86 extern int64_t DivUp(int64_t value, int64_t divisor);
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;
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;
100 static inline int Mutex_Acquire(tMutex *m) {
101 if(*m) Log_KernelPanic("---", "Double mutex lock");
105 static inline void Mutex_Release(tMutex *m) { *m = 0; }
107 static inline void SHORTLOCK(tShortSpinlock *Lock) {
108 if(*Lock) Log_KernelPanic("---", "Double short lock");
111 static inline void SHORTREL(tShortSpinlock *m) { *m = 0; }