Skip to content
Snippets Groups Projects
Commit c0758a3d authored by John Hodge's avatar John Hodge
Browse files

Through many hacks, AcessNative now compiles

- Still doesn't do anything
parent 4e949acb
No related merge requests found
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h>
#define _MODULE_NAME_ "NativeKernel" #define _MODULE_NAME_ "NativeKernel"
...@@ -27,7 +28,8 @@ typedef intptr_t tPAddr; ...@@ -27,7 +28,8 @@ typedef intptr_t tPAddr;
struct sShortSpinlock struct sShortSpinlock
{ {
int Lock; int IsValid;
pthread_mutex_t Mutex;
}; };
#define SHORTLOCK(...) #define SHORTLOCK(...)
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <acess.h> #include <acess.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/time.h>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -41,6 +42,22 @@ void Warning(const char *Fmt, ...) ...@@ -41,6 +42,22 @@ void Warning(const char *Fmt, ...)
printf("\n"); printf("\n");
} }
void Panic(const char *Format, ...)
{
va_list args;
printf("Panic: ");
va_start(args, Format);
vprintf(Format, args);
va_end(args);
printf("\n");
exit(-1);
}
void Debug_SetKTerminal(const char *Path)
{
// Ignored, kernel debug goes to stdout
}
void *Heap_Allocate(int Count, const char *File, int Line) void *Heap_Allocate(int Count, const char *File, int Line)
{ {
return malloc(Count); return malloc(Count);
...@@ -55,3 +72,17 @@ Uint MM_GetFlags(tVAddr VAddr) ...@@ -55,3 +72,17 @@ Uint MM_GetFlags(tVAddr VAddr)
{ {
return 0; return 0;
} }
int Modules_InitialiseBuiltin(const char *Name)
{
return 0; // Ignored
}
Sint64 now(void)
{
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);
return tv.tv_sec * 1000 + tv.tv_usec/1000;
}
...@@ -5,12 +5,28 @@ ...@@ -5,12 +5,28 @@
* threads.c * threads.c
* - Thread and process handling * - Thread and process handling
*/ */
#define _SIGNAL_H_
#undef CLONE_VM // Such a hack
#include <acess.h> #include <acess.h>
#include <unistd.h>
#include <stdint.h>
#include "/usr/include/signal.h"
// === STRUCTURES === // === STRUCTURES ===
#if 0
typedef struct sState
{
void *CurState;
Uint SP, BP, IP;
} tState;
#endif
typedef struct sThread typedef struct sThread
{ {
struct sThread *Next; struct sThread *Next;
int KernelTID;
tTID TID, PID; tTID TID, PID;
tUID UID, GID; tUID UID, GID;
...@@ -18,6 +34,11 @@ typedef struct sThread ...@@ -18,6 +34,11 @@ typedef struct sThread
char *ThreadName; char *ThreadName;
int State; // 0: Dead, 1: Active, 2: Paused, 3: Asleep
#if 0
tState CurState;
#endif
// Config? // Config?
Uint Config[NUM_CFG_ENTRIES]; Uint Config[NUM_CFG_ENTRIES];
} tThread; } tThread;
...@@ -27,6 +48,17 @@ tThread *gpThreads; ...@@ -27,6 +48,17 @@ tThread *gpThreads;
__thread tThread *gpCurrentThread; __thread tThread *gpCurrentThread;
// === CODE === // === CODE ===
tThread *Threads_GetThread(int TID)
{
tThread *thread;
for( thread = gpThreads; thread; thread = thread->Next )
{
if( thread->TID == TID )
return thread;
}
return NULL;
}
tUID Threads_GetUID() { return gpCurrentThread->UID; } tUID Threads_GetUID() { return gpCurrentThread->UID; }
tGID Threads_GetGID() { return gpCurrentThread->GID; } tGID Threads_GetGID() { return gpCurrentThread->GID; }
tTID Threads_GetTID() { return gpCurrentThread->TID; } tTID Threads_GetTID() { return gpCurrentThread->TID; }
...@@ -36,3 +68,69 @@ Uint *Threads_GetCfgPtr(int Index) ...@@ -36,3 +68,69 @@ Uint *Threads_GetCfgPtr(int Index)
{ {
return &gpCurrentThread->Config[Index]; return &gpCurrentThread->Config[Index];
} }
void Threads_Sleep(void)
{
pause();
}
void Threads_Yield(void)
{
// yield();
}
int Threads_WakeTID(tTID TID)
{
tThread *thread;
thread = Threads_GetThread(TID);
if( !thread ) return -1;
kill( thread->KernelTID, SIGUSR1 );
return 0;
}
void 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 );
}
void Mutex_Release(tMutex *Mutex)
{
pthread_mutex_unlock( &Mutex->Protector.Mutex );
}
#if 0
void Threads_Sleep()
{
gpCurrentThread->State = 3;
if( setjmp(&gpCurrentThread->CurState) == 0 ) {
// Return to user wait
// Hmm... maybe I should have a "kernel" thread for every "user" thread
}
else {
// Just woken up, return
return ;
}
}
int SaveState(tState *To)
{
Uint ip;
__asm__ __volatile__(
"call 1f;\n\t"
"1f:\n\t"
"pop %%eax"
: "=a" (ip)
: );
// If we just returned
if(!ip) return 1;
To->IP = ip;
__asm__ __volatile__ ("mov %%esp, %1" : "=r"(To->SP));
__asm__ __volatile__ ("mov %%ebp, %1" : "=r"(To->BP));
}
#endif
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment