- NOTE: Windows does not support fork(), time to fix my process creation code.
BUILDINFO_OBJ := obj-$(PLATFORM)/buildinfo.o\r
BUILDINFO_SRC := $(BUILDINFO_OBJ:%.o=%.c)\r
\r
-OBJ := helpers.o threads.o server.o syscalls.o time.o\r
+OBJ := helpers.o threads.o threads_glue.o server.o syscalls.o time.o\r
OBJ += video.o keyboard.o mouse.o nativefs.o vfs_handle.o ui_sdl.o\r
OBJ := $(addprefix obj-$(PLATFORM)/,$(OBJ))\r
N_OBJ := $(addprefix obj-$(PLATFORM)/,$(N_OBJ))\r
\r
ifeq ($(PLATFORM),win)\r
BIN := ../AcessKernel.exe\r
+ LDFLAGS += -lws2_32 -lpthread\r
endif\r
ifeq ($(PLATFORM),lin)\r
BIN := ../AcessKernel\r
#include <stdint.h>
//#include <stdlib.h>
-#include <pthread.h>
#undef CLONE_VM
#define _MODULE_NAME_ "NativeKernel"
typedef int BOOL;
+#include <stddef.h>
+#undef NULL
+#undef offsetof
+
struct sShortSpinlock
{
- int IsValid;
- pthread_mutex_t Mutex;
+ void *Mutex;
};
#define SHORTLOCK(...)
--- /dev/null
+/*
+ */
+#ifndef _ACESSNATIVE__THREADS_GLUE_H_
+#define _ACESSNATIVE__THREADS_GLUE_H_
+
+
+extern void Threads_Glue_Yield(void);
+extern void Threads_Glue_AcquireMutex(void **Lock);
+extern void Threads_Glue_ReleaseMutex(void **Lock);
+extern void Threads_Glue_SemInit(void **Ptr, int Val);
+extern int Threads_Glue_SemWait(void *Ptr, int Max);
+extern int Threads_Glue_SemSignal( void *Ptr, int AmmountToAdd );
+
+#endif
+
#endif
#include <unistd.h>
#include <string.h>
+#include "../../KernelLand/Kernel/include/logdebug.h"
#define VALGRIND_CLIENT 0
UI_Initialise(800, 480);
// - Ignore SIGUSR1 (used to wake threads)
+ #ifdef SIGUSR1
signal(SIGUSR1, SIG_IGN);
+ #endif
// Initialise VFS
VFS_Init();
{
int pid;
int argcount = 0;
- char *args[7+rootapp_argc+1+1];
+ const char *args[7+rootapp_argc+1+1];
#if VALGRIND_CLIENT
args[argcount++] = "valgrind";
for( i = 0; i < rootapp_argc; i ++ )
args[argcount+i] = rootapp[i];
args[argcount+rootapp_argc] = NULL;
-
- pid = fork();
+ pid = spawnv(P_NOWAIT, "./ld-acess", args);
if(pid < 0) {
perror("Starting root application [fork(2)]");
return 1;
}
- if(pid == 0)
- {
- #ifdef __LINUX__
- prctl(PR_SET_PDEATHSIG, SIGHUP); // LINUX ONLY!
- #endif
- #if VALGRIND_CLIENT
- execv("valgrind", args);
- #else
- execv("./ld-acess", args);
- #endif
- }
printf("Root application running as PID %i\n", pid);
}
#include <string.h>
#include <SDL/SDL.h>
#ifdef __WIN32__
+# define _WIN32_WINNT 0x0501
# include <windows.h>
-# include <winsock.h>
+# include <winsock2.h>
+# include <ws2tcpip.h>
+# define close(fd) closesocket(fd)
+typedef int socklen_t;
#else
# include <unistd.h>
# include <sys/socket.h>
# include <netinet/in.h>
# include <arpa/inet.h> // inet_ntop
+# include "include/windows_helpers.h"
#endif
+#define DONT_INCLUDE_SYSCALL_NAMES
#include "../syscalls.h"
-//#include <debug.h>
+#include <logdebug.h> // acess but std
#include <errno.h>
#define USE_TCP 1
extern tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength);
extern int Threads_CreateRootProcess(void);
extern void Threads_SetThread(int TID);
-// HACK: Should have these in a header
-extern void Log_Debug(const char *Subsys, const char *Message, ...);
-extern void Log_Notice(const char *Subsys, const char *Message, ...);
-extern void Log_Warning(const char *Subsys, const char *Message, ...);
+extern void *Threads_GetThread(int TID);
+extern void Threads_PostEvent(void *Thread, uint32_t Event);
// === PROTOTYPES ===
tClient *Server_GetClient(int ClientID);
const int ciMaxParamCount = 6;
char lbuf[sizeof(tRequestHeader) + ciMaxParamCount*sizeof(tRequestValue)];
tRequestHeader *hdr = (void*)lbuf;
- size_t len = recv(Client->Socket, hdr, sizeof(*hdr), 0);
+ size_t len = recv(Client->Socket, (void*)hdr, sizeof(*hdr), 0);
Log_Debug("Server", "%i bytes of header", len);
if( len == 0 ) break;
if( len == -1 ) {
if( hdr->NParams > 0 )
{
- len = recv(Client->Socket, hdr->Params, hdr->NParams*sizeof(tRequestValue), 0);
+ len = recv(Client->Socket, (void*)hdr->Params, hdr->NParams*sizeof(tRequestValue), 0);
Log_Debug("Server", "%i bytes of params", len);
if( len != hdr->NParams*sizeof(tRequestValue) ) {
// Oops.
continue ;
}
- send(Client->Socket, retHeader, retlen, 0);
+ send(Client->Socket, (void*)retHeader, retlen, 0);
// Clean up
free(hdr);
}
char addrstr[4*8+8+1];
- inet_ntop(clientaddr.sin_family, &clientaddr.sin_addr, addrstr, sizeof(addrstr));
+ getnameinfo((struct sockaddr*)&clientaddr, sizeof(clientaddr),
+ addrstr, sizeof(addrstr), NULL, 0, NI_NUMERICHOST);
Log_Debug("Server", "Client connection %s:%i", addrstr, ntohs(clientaddr.sin_port));
// Perform auth
size_t len;
tRequestAuthHdr authhdr;
- len = recv(clientSock, &authhdr, sizeof(authhdr), 0);
+ len = recv(clientSock, (void*)&authhdr, sizeof(authhdr), 0);
if( len != sizeof(authhdr) ) {
// Some form of error?
Log_Warning("Server", "Client auth block bad size (%i != exp %i)",
}
Log_Debug("Server", "Client given PID %i - info %p", authhdr.pid, client);
- len = send(clientSock, &authhdr, sizeof(authhdr), 0);
+ len = send(clientSock, (void*)&authhdr, sizeof(authhdr), 0);
if( len != sizeof(authhdr) ) {
// Ok, this is an error
perror("Sending auth reply");
return -1;
return VFS_ReadDir(a0, a1);
);
-SYSCALL6(Syscall_select, "iddddi", int, fd_set *, fd_set *, fd_set *, time_t *, unsigned int,
+SYSCALL6(Syscall_select, "iddddi", int, fd_set *, fd_set *, fd_set *, tTime *, unsigned int,
return VFS_Select(a0, a1, a2, a3, a4, a5, 0);
);
SYSCALL3(Syscall_OpenChild, "isi", int, const char *, int,
* threads.c
* - Thread and process handling
*/
-#define _SIGNAL_H_ // Stop the acess signal.h being used
-#define _HEAP_H_ // Stop heap.h being imported (collides with stdlib heap)
-#define _VFS_EXT_H // Stop vfs_ext.h being imported (collides with fd_set)
-#define off_t _acess_off_t
#include <arch.h>
-#undef NULL // Remove acess definition
#include <acess.h>
#include <mutex.h>
-#include <semaphore.h>
+#include "../../KernelLand/Kernel/include/semaphore.h"
#include <rwlock.h>
#include <events.h>
#include <threads_int.h>
-
-#undef CLONE_VM // Such a hack
-#undef off_t
-
-// - Native headers
-#include <unistd.h>
-#include <sys/types.h>
-#include <stdint.h>
-#include "/usr/include/signal.h"
-#include <SDL/SDL.h>
+#include <limits.h>
+#include "include/threads_glue.h"
#define THREAD_EVENT_WAKEUP 0x80000000
void VFS_CloneHandleList(int PID);
// === STRUCTURES ===
-#if 0
-typedef struct sState
-{
- void *CurState;
- Uint SP, BP, IP;
-} tState;
-#endif
-
// === PROTOTYPES ===
int Threads_Wake(tThread *Thread);
ret->TID = giThreads_NextThreadID ++;
ret->ThreadName = strdup(TemplateThread->ThreadName);
- ret->EventSem = SDL_CreateSemaphore(0);
- if( !ret->EventSem ) {
- Log_Warning("Threads", "Semaphore creation failed - %s", SDL_GetError());
- }
+ Threads_Glue_SemInit( &ret->EventSem, 0 );
ret->WaitingThreads = NULL;
ret->WaitingThreadsEnd = NULL;
void Threads_Sleep(void)
{
// TODO: Add to a sleeping queue
- pause();
+ //pause();
}
void Threads_Yield(void)
{
// Wait for the thread to be waited upon
while( gpCurrentThread->WaitingThreads == NULL )
- SDL_Delay(10);
+ Threads_Glue_Yield();
}
#endif
Threads_Wake(toWake);
while(gpCurrentThread->WaitingThreads == toWake)
- SDL_Delay(10);
+ Threads_Glue_Yield();
}
}
// --------------------------------------------------------------------
int Mutex_Acquire(tMutex *Mutex)
{
- if(!Mutex->Protector.IsValid) {
- pthread_mutex_init( &Mutex->Protector.Mutex, NULL );
- Mutex->Protector.IsValid = 1;
- }
- pthread_mutex_lock( &Mutex->Protector.Mutex );
+ Threads_Glue_AcquireMutex(&Mutex->Protector.Mutex);
return 0;
}
void Mutex_Release(tMutex *Mutex)
{
- pthread_mutex_unlock( &Mutex->Protector.Mutex );
+ Threads_Glue_ReleaseMutex(&Mutex->Protector.Mutex);
}
// --------------------------------------------------------------------
{
memset(Sem, 0, sizeof(tSemaphore));
// HACK: Use `Sem->Protector` as space for the semaphore pointer
- *(void**)(&Sem->Protector) = SDL_CreateSemaphore(InitValue);
+ Threads_Glue_SemInit( &Sem->Protector.Mutex, InitValue );
}
int Semaphore_Wait(tSemaphore *Sem, int MaxToTake)
{
- SDL_SemWait( *(void**)(&Sem->Protector) );
- return 1;
+ return Threads_Glue_SemWait( Sem->Protector.Mutex, MaxToTake );
}
int Semaphore_Signal(tSemaphore *Sem, int AmmountToAdd)
{
- int i;
- for( i = 0; i < AmmountToAdd; i ++ )
- SDL_SemPost( *(void**)(&Sem->Protector) );
- return AmmountToAdd;
-}
-
-// --------------------------------------------------------------------
-// Event handling
-// --------------------------------------------------------------------
-int RWLock_AcquireRead(tRWLock *Lock)
-{
- if( !Lock->ReaderWaiting ) {
- Lock->ReaderWaiting = malloc(sizeof(pthread_rwlock_t));
- pthread_rwlock_init( (void*)Lock->ReaderWaiting, 0 );
- }
- pthread_rwlock_rdlock( (void*)Lock->ReaderWaiting );
- return 0;
-}
-int RWLock_AcquireWrite(tRWLock *Lock)
-{
- if( !Lock->ReaderWaiting ) {
- Lock->ReaderWaiting = malloc(sizeof(pthread_rwlock_t));
- pthread_rwlock_init( (void*)Lock->ReaderWaiting, 0 );
- }
- pthread_rwlock_wrlock( (void*)Lock->ReaderWaiting );
- return 0;
-}
-void RWLock_Release(tRWLock *Lock)
-{
- pthread_rwlock_unlock( (void*)Lock->ReaderWaiting );
+ return Threads_Glue_SemSignal( Sem->Protector.Mutex, AmmountToAdd );
}
-
// --------------------------------------------------------------------
// Event handling
// --------------------------------------------------------------------
gpCurrentThread->WaitMask = Mask;
if( !(gpCurrentThread->Events & Mask) )
{
- do {
- if( SDL_SemWait( gpCurrentThread->EventSem ) == -1 ) {
- Log_Warning("Threads", "Wait on eventsem of %p, %p failed",
- gpCurrentThread, gpCurrentThread->EventSem);
- break;
- }
- } while(SDL_SemValue(gpCurrentThread->EventSem));
- // NOTE: While loop catches multiple event occurances
+ if( Threads_Glue_SemWait(gpCurrentThread->EventSem, INT_MAX) == -1 ) {
+ Log_Warning("Threads", "Wait on eventsem of %p, %p failed",
+ gpCurrentThread, gpCurrentThread->EventSem);
+ }
Log_Debug("Threads", "Woken from nap (%i here)", SDL_SemValue(gpCurrentThread->EventSem));
}
rv = gpCurrentThread->Events & Mask;
Log_Debug("Threads", "Trigger event %x (->Events = %p)", Events, Thread->Events);
if( Events == 0 || Thread->WaitMask & Events ) {
- SDL_SemPost( Thread->EventSem );
+ Threads_Glue_SemSignal( Thread->EventSem, 1 );
// Log_Debug("Threads", "Waking %p(%i %s)", Thread, Thread->TID, Thread->ThreadName);
}
}
--- /dev/null
+/*
+ * Acess2 Native Kernel
+ * - Acess kernel emulation on another OS using SDL and UDP
+ *
+ * threads.c
+ * - Thread and process handling
+ */
+#include "include/threads_glue.h"
+
+#define _ACESS_H
+typedef void **tShortSpinlock;
+#include <rwlock.h>
+
+// - Native headers
+#include <unistd.h>
+#include <sys/types.h>
+#include <stdint.h>
+//#include "/usr/include/signal.h"
+#include <SDL/SDL.h>
+#include <pthread.h>
+#include <assert.h>
+
+#include <logdebug.h> // Kernel land, but uses standards
+
+// === CODE ===
+void Threads_Glue_Yield(void)
+{
+ SDL_Delay(10);
+}
+
+void Threads_Glue_AcquireMutex(void **Lock)
+{
+ if(!*Lock) {
+ *Lock = malloc( sizeof(pthread_mutex_t) );
+ pthread_mutex_init( *Lock, NULL );
+ }
+ pthread_mutex_lock( *Lock );
+}
+
+void Threads_Glue_ReleaseMutex(void **Lock)
+{
+ pthread_mutex_unlock( *Lock );
+}
+
+void Threads_Glue_SemInit(void **Ptr, int Val)
+{
+ *Ptr = SDL_CreateSemaphore(Val);
+ if( !*Ptr ) {
+ Log_Warning("Threads", "Semaphore creation failed - %s", SDL_GetError());
+ }
+}
+
+int Threads_Glue_SemWait(void *Ptr, int Max)
+{
+ int have = 0;
+ assert(Ptr);
+ do {
+ if( SDL_SemWait( Ptr ) == -1 ) {
+ return -1;
+ }
+ have ++;
+ } while( SDL_SemValue(Ptr) && have < Max );
+ return have;
+}
+
+int Threads_Glue_SemSignal( void *Ptr, int AmmountToAdd )
+{
+ int i;
+ for( i = 0; i < AmmountToAdd; i ++ )
+ SDL_SemPost( Ptr );
+ return AmmountToAdd;
+}
+
+// --------------------------------------------------------------------
+// Event handling
+// --------------------------------------------------------------------
+int RWLock_AcquireRead(tRWLock *Lock)
+{
+ if( !Lock->ReaderWaiting ) {
+ Lock->ReaderWaiting = malloc(sizeof(pthread_rwlock_t));
+ pthread_rwlock_init( (void*)Lock->ReaderWaiting, 0 );
+ }
+ pthread_rwlock_rdlock( (void*)Lock->ReaderWaiting );
+ return 0;
+}
+int RWLock_AcquireWrite(tRWLock *Lock)
+{
+ if( !Lock->ReaderWaiting ) {
+ Lock->ReaderWaiting = malloc(sizeof(pthread_rwlock_t));
+ pthread_rwlock_init( (void*)Lock->ReaderWaiting, 0 );
+ }
+ pthread_rwlock_wrlock( (void*)Lock->ReaderWaiting );
+ return 0;
+}
+void RWLock_Release(tRWLock *Lock)
+{
+ pthread_rwlock_unlock( (void*)Lock->ReaderWaiting );
+}
+
ifeq ($(PLATFORM),win)
BIN := ../ld-acess.exe
+ LDFLAGS += -lws2_32
endif
ifeq ($(PLATFORM),lin)
BIN := ../ld-acess
$(RM) $(BIN) $(OBJ) $(DEPFILES) obj-$(PLATFORM)/link.ld
$(BIN): obj-$(PLATFORM)/link.ld $(OBJ)
- $(CC) $(LDFLAGS) -o $@ $(OBJ)
+ $(CC) -o $@ $(OBJ) $(LDFLAGS)
obj-$(PLATFORM)/%.o: %.c
@echo "Making Linker Script ($@)"
$(LD) -g --verbose | awk '{ if( substr($$1,0,5) == "====="){ bPrint = !bPrint; } else { if(bPrint){ print $$0;} } }' | sed 's/\b0x[048][0-9]*\b/$(LINKADDR)/g' | sed 's/CONSTANT (MAXPAGESIZE)/0x1000/g' > $@
+# Modify the default makefile to put the executable at 1MB instead
+obj-win/link.ld: Makefile
+ @mkdir -p $(dir $@)
+ @echo "Making Linker Script ($@)"
+ $(LD) -g --verbose | awk '{ if( substr($$1,0,5) == "====="){ bPrint = !bPrint; } else { if(bPrint){ print $$0;} } }' | sed 's/\b0x[048][0-9]*\b/$(LINKADDR)/g' | sed 's/CONSTANT (MAXPAGESIZE)/0x1000/g' > $@
+
-include $(DEPFILES)
-../../Usermode/Libraries/ld-acess.so_src/elf.c
\ No newline at end of file
+#include "common.h"
+#define _COMMON_H // stops real ld-acess.so common.h being included
+#include "../../Usermode/Libraries/ld-acess.so_src/elf.c"
-../../Usermode/Libraries/ld-acess.so_src/elf32.h
\ No newline at end of file
+#include "../../Usermode/Libraries/ld-acess.so_src/elf32.h"
-../../Usermode/Libraries/ld-acess.so_src/elf64.h
\ No newline at end of file
+#include "../../Usermode/Libraries/ld-acess.so_src/elf64.h"
#include <stdio.h>\r
#include <string.h>\r
#include <unistd.h>\r
+#include <inttypes.h> // PRIx64\r
#include "common.h"\r
#include "elf32.h"\r
#include "elf64.h"\r
addr = phtab[i].p_vaddr + baseDiff;\r
\r
if( AllocateMemory( addr, phtab[i].p_memsz ) ) {\r
- fprintf(stderr, "Elf_Load: Unable to map memory at %llx (0x%llx bytes)\n",\r
- (long long)addr, (long long)phtab[i].p_memsz);\r
+ fprintf(stderr, "Elf_Load: Unable to map memory at %"PRIx64" (0x%"PRIx64" bytes)\n",\r
+ (uint64_t)addr, (uint64_t)phtab[i].p_memsz);\r
free( phtab );\r
return NULL;\r
}\r
typedef struct sFILE FILE;
-extern FILE *stderr;
extern void exit(int) __attribute__ ((noreturn));
extern int printf(const char *, ...);
extern int fprintf(FILE *,const char *, ...);
extern void _InitSyscalls(void);
extern void _CloseSyscalls(void);
+extern void Warning(const char *Format, ...);
extern void Debug(const char *Format, ...);
extern int AllocateMemory(uintptr_t VirtAddr, size_t ByteCount);
// --- Process Management ---
int acess_clone(int flags, void *stack)
{
+ #ifdef __WIN32__
+ Warning("Win32 does not support anything like fork(2), cannot emulate");
+ exit(-1);
+ #else
extern int fork(void);
if(flags & CLONE_VM) {
int ret, newID, kernel_tid=0;
}
else
{
- fprintf(stderr, "ERROR: Threads currently unsupported\n");
+ Warning("ERROR: Threads currently unsupported\n");
exit(-1);
}
+ #endif
}
-int acess_execve(char *path, char **argv, char **envp)
+int acess_execve(char *path, char **argv, const char **envp)
{
int i, argc;
for( argc = 0; argv[argc]; argc ++ ) ;
DEBUG(" acess_execve: argc = %i", argc);
- char *new_argv[7+argc+1];
+ const char *new_argv[7+argc+1];
char client_id_str[11];
char socket_fd_str[11];
sprintf(client_id_str, "%i", giSyscall_ClientID);
extern int native_seek(int FD, int64_t Offset, int Dir);
extern uint64_t native_tell(int FD);
-extern int native_execve(const char *filename, char *const argv[], char *const envp[]);
+extern int native_execve(const char *filename, const char *const argv[], const char *const envp[]);
// Syscalls used by the linker
extern int acess_open(const char *Path, int Flags);
size_t size = (VirtAddr & 0xFFF) + ByteCount;
void *tmp;
#if __WIN32__
- tmp = VirtualAlloc(base, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+ tmp = VirtualAlloc((void*)base, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if( tmp == NULL ) {
- printf("ERROR: Unable to allocate memory (%i)\n", GetLastError());
+ printf("ERROR: Unable to allocate memory (0x%x)\n", (int)GetLastError());
return -1;
}
#else
uintptr_t FindFreeRange(size_t ByteCount, int MaxBits)
{
- #if __WIN32__
- # error "Windows FindFreeRange() unimplemented"
- #else
uintptr_t base, ofs, size;
uintptr_t end = -1;
static const int PAGE_SIZE = 0x1000;
for( base = end - size + 1; base > 0; base -= PAGE_SIZE )
{
for( ofs = 0; ofs < size; ofs += PAGE_SIZE ) {
+ #if __WIN32__
+ MEMORY_BASIC_INFORMATION info;
+ VirtualQuery( (void*)(base + ofs), &info, sizeof(info) );
+ if( info.State != MEM_FREE )
+ break;
+ #else
if( msync( (void*)(base+ofs), 1, 0) == 0 )
break;
if( errno != ENOMEM )
perror("FindFreeRange, msync");
+ #endif
}
if( ofs >= size ) {
return base;
}
}
return 0;
- #endif
}
return ftell( gaSyscall_LocalFPs[FD] );
}
-int native_execve(const char *filename, char *const argv[], char *const envp[])
+int native_execve(const char *filename, const char *const argv[], const char *const envp[])
{
int ret;
ret = execve(filename, argv, envp);
#endif
}
-void Debug_HexDump(const char *Header, const void *Data, Uint Length)
+void Debug_HexDump(const char *Header, const void *Data, size_t Length)
{
const Uint8 *cdat = Data;
Uint pos = 0;
* \brief Acess2 Kernel API Core
*/
+#include <arch.h>
+
//! NULL Pointer
#define NULL ((void*)0)
//! Pack a structure
* \}
*/
-#include <arch.h>
#include <stdarg.h>
#include "errno.h"
* \}
*/
-// --- Logging ---
-/**
- * \name Logging to kernel ring buffer
- * \{
- */
-extern void Log_KernelPanic(const char *Ident, const char *Message, ...);
-extern void Log_Panic(const char *Ident, const char *Message, ...);
-extern void Log_Error(const char *Ident, const char *Message, ...);
-extern void Log_Warning(const char *Ident, const char *Message, ...);
-extern void Log_Notice(const char *Ident, const char *Message, ...);
-extern void Log_Log(const char *Ident, const char *Message, ...);
-extern void Log_Debug(const char *Ident, const char *Message, ...);
-/**
- * \}
- */
-
-// --- Debug ---
-/**
- * \name Debugging and Errors
- * \{
- */
-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)
-# define LEAVE(_t...) Debug_Leave((char*)__func__, _t)
-# define LEAVE_RET(_t,_v...) do{LEAVE(_t,_v);return _v;}while(0)
-# define LEAVE_RET0() do{LEAVE('-');return;}while(0)
-#else
-# define ENTER(...)
-# define LOG(...)
-# define LEAVE(...)
-# define LEAVE_RET(_t,_v...) return (_v)
-# define LEAVE_RET0() return
-#endif
-#if SANITY
-# define ASSERT(expr) do{if(!(expr))Panic("%s:%i - %s: Assertion '"#expr"' failed",__FILE__,__LINE__,(char*)__func__);}while(0)
-#else
-# define ASSERT(expr)
-#endif
-/**
- * \}
- */
+#include "logdebug.h"
// --- IO ---
#if NO_IO_BUS
--- /dev/null
+/*
+ * Acess2 Kernel
+ * - By John Hodge (thePowersGang)
+ *
+ * logdebug.h
+ * - Logging / Debug printing functions
+ */
+#ifndef _KERNEL__LOGDEBUG_H_
+#define _KERNEL__LOGDEBUG_H_
+
+#include <stdarg.h>
+
+// --- Logging ---
+/**
+ * \name Logging to kernel ring buffer
+ * \{
+ */
+extern void Log_KernelPanic(const char *Ident, const char *Message, ...);
+extern void Log_Panic(const char *Ident, const char *Message, ...);
+extern void Log_Error(const char *Ident, const char *Message, ...);
+extern void Log_Warning(const char *Ident, const char *Message, ...);
+extern void Log_Notice(const char *Ident, const char *Message, ...);
+extern void Log_Log(const char *Ident, const char *Message, ...);
+extern void Log_Debug(const char *Ident, const char *Message, ...);
+/**
+ * \}
+ */
+
+// --- Debug ---
+/**
+ * \name Debugging and Errors
+ * \{
+ */
+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, size_t 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)
+# define LEAVE(_t...) Debug_Leave((char*)__func__, _t)
+# define LEAVE_RET(_t,_v...) do{LEAVE(_t,_v);return _v;}while(0)
+# define LEAVE_RET0() do{LEAVE('-');return;}while(0)
+#else
+# define ENTER(...)
+# define LOG(...)
+# define LEAVE(...)
+# define LEAVE_RET(_t,_v...) return (_v)
+# define LEAVE_RET0() return
+#endif
+#if SANITY
+# define ASSERT(expr) do{if(!(expr))Panic("%s:%i - %s: Assertion '"#expr"' failed",__FILE__,__LINE__,(char*)__func__);}while(0)
+#else
+# define ASSERT(expr)
+#endif
+/**
+ * \}
+ */
+
+#endif
+
DEBUGS("Elf64Relocate: e_phnum = %i", hdr->e_phnum);
// Scan for the dynamic table (and find the compiled base)
- phtab = (void*)((uintptr_t)Base + hdr->e_phoff);
+ phtab = (void*)((uintptr_t)Base + (uintptr_t)hdr->e_phoff);
for( i = 0; i < hdr->e_phnum; i ++ )
{
if(phtab[i].p_type == PT_DYNAMIC)
int j;
// Locate the tables
- phtab = (void*)( (intptr_t)Base + hdr->e_phoff );
+ phtab = (void*)( (intptr_t)Base + (uintptr_t)hdr->e_phoff );
for( i = 0; i < hdr->e_phnum; i ++ )
{
if(phtab[i].p_type == PT_LOAD && iBaseDiff > phtab[i].p_vaddr)