Merge branch 'master' of serenade.mutabah.net:acess2
authorJohn Hodge <[email protected]>
Fri, 10 Dec 2010 05:02:21 +0000 (13:02 +0800)
committerJohn Hodge <[email protected]>
Fri, 10 Dec 2010 05:02:21 +0000 (13:02 +0800)
21 files changed:
AcessNative/acesskernel_src/Details.txt [new file with mode: 0644]
AcessNative/acesskernel_src/Makefile [new file with mode: 0644]
AcessNative/acesskernel_src/include/arch.h [new file with mode: 0644]
AcessNative/acesskernel_src/include/heap.h [new file with mode: 0644]
AcessNative/acesskernel_src/keyboard.c [new file with mode: 0644]
AcessNative/acesskernel_src/main.c [new file with mode: 0644]
AcessNative/acesskernel_src/mouse.c [new file with mode: 0644]
AcessNative/acesskernel_src/nativefs.c [new file with mode: 0644]
AcessNative/acesskernel_src/vfs_handle.c [new file with mode: 0644]
AcessNative/acesskernel_src/video.c [new file with mode: 0644]
AcessNative/ld-acess.so_src/Makefile [new file with mode: 0644]
AcessNative/ld-acess.so_src/request.c [new file with mode: 0644]
AcessNative/ld-acess.so_src/syscalls.c [new file with mode: 0644]
Kernel/Makefile
Kernel/include/acess.h
Kernel/syscalls.c
Kernel/threads.c
Kernel/vfs/handle.c [new file with mode: 0644]
Kernel/vfs/main.c
Kernel/vfs/open.c
Modules/IPStack/link.c

diff --git a/AcessNative/acesskernel_src/Details.txt b/AcessNative/acesskernel_src/Details.txt
new file mode 100644 (file)
index 0000000..bd20953
--- /dev/null
@@ -0,0 +1,7 @@
+Provides Acess Kernel services\r
+- UDP Server listening on 127.0.0.1:2766 (0XACE)\r
+ > See ld-acess.so_src/syscalls for the spec\r
+- Starts acess applications\r
+ > Provides kernel loader services and loads libacess\r
+- Provides "vterms" / control panel\r
+- Cross platform (GTK?/SDL)
\ No newline at end of file
diff --git a/AcessNative/acesskernel_src/Makefile b/AcessNative/acesskernel_src/Makefile
new file mode 100644 (file)
index 0000000..d7bfcb8
--- /dev/null
@@ -0,0 +1,43 @@
+# AcessNative Server\r
+# Makefile\r
+\r
+ifeq ($(PLATFORM),)\r
+       PLATFORM := lin\r
+endif\r
+\r
+KERNEL_SRC = ../../Kernel/\r
+\r
+KERNEL_OBJ := logging.o adt.o\r
+KERNEL_OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/io.o vfs/dir.o vfs/nodecache.o vfs/mount.o\r
+KERNEL_OBJ += vfs/fs/root.o vfs/fs/devfs.o\r
+KERNEL_OBJ += drv/vterm.o drv/fifo.o\r
+\r
+OBJ := main.o video.o keyboard.o mouse.o nativefs.o vfs_handle.o\r
+OBJ += $(addprefix $(KERNEL_SRC),$(KERNEL_OBJ))\r
+\r
+OBJ := $(addsuffix .$(PLATFORM),$(OBJ))\r
+\r
+CPPFLAGS += -I include/ -I $(KERNEL_SRC)include/\r
+CFLAGS += -Wall\r
+LDFLAGS += -lSDL -lSDLmain\r
+\r
+ifeq ($(PLATFORM),win)\r
+       BIN := ../AcessKernel.exe\r
+endif\r
+ifeq ($(PLATFORM),lin)\r
+       BIN := ../AcessKernel\r
+       CFLAGS +=\r
+endif\r
+\r
+.PHONY: all clean\r
+\r
+all: $(BIN)\r
+\r
+clean:\r
+       $(RM) $(BIN) $(OBJ)\r
+\r
+$(BIN): $(OBJ)\r
+       $(CC) $(LDFLAGS) -o $@ $(OBJ)\r
+\r
+%.o.$(PLATFORM): %.c\r
+       $(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS)\r
diff --git a/AcessNative/acesskernel_src/include/arch.h b/AcessNative/acesskernel_src/include/arch.h
new file mode 100644 (file)
index 0000000..e985789
--- /dev/null
@@ -0,0 +1,37 @@
+/**
+ */
+#ifndef _ARCH_H_
+#define _ARCH_H_
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#define        _MODULE_NAME_   "NativeKernel"
+
+#define BITS   (sizeof(intptr_t)*8)
+
+typedef uint8_t        Uint8;
+typedef uint16_t       Uint16;
+typedef uint32_t       Uint32;
+typedef uint64_t       Uint64;
+
+typedef int8_t Sint8;
+typedef int16_t        Sint16;
+typedef int32_t        Sint32;
+typedef int64_t        Sint64;
+
+typedef intptr_t       Uint;
+
+typedef intptr_t       tVAddr;
+typedef intptr_t       tPAddr;
+
+struct sShortSpinlock
+{
+        int    Lock;
+};
+
+#define SHORTLOCK(...)
+#define SHORTREL(...)
+
+#endif
+
diff --git a/AcessNative/acesskernel_src/include/heap.h b/AcessNative/acesskernel_src/include/heap.h
new file mode 100644 (file)
index 0000000..2052559
--- /dev/null
@@ -0,0 +1,8 @@
+/**
+ */
+#ifndef _HEAP_H_
+#define _HEAP_H_
+
+// NOP (stdlib.h defines the heap functions)
+
+#endif
diff --git a/AcessNative/acesskernel_src/keyboard.c b/AcessNative/acesskernel_src/keyboard.c
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/AcessNative/acesskernel_src/main.c b/AcessNative/acesskernel_src/main.c
new file mode 100644 (file)
index 0000000..45e6aa0
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Acess2 Native Kernel
+ * - Acess kernel emulation on another OS using SDL and UDP
+ *
+ * Kernel Main
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <SDL/SDL.h>
+
+int main(int argc, char *argv[])
+{
+       return 0;
+}
+
+void LogF(const char *Fmt, ...)
+{
+       va_list args;
+       va_start(args, Fmt);
+       vprintf(Fmt, args);
+       va_end(args);
+}
+
+void Log(const char *Fmt, ...)
+{
+       va_list args;
+       printf("Log: ");
+       va_start(args, Fmt);
+       vprintf(Fmt, args);
+       va_end(args);
+       printf("\n");
+}
+
+void Warning(const char *Fmt, ...)
+{
+       va_list args;
+       printf("Warning: ");
+       va_start(args, Fmt);
+       vprintf(Fmt, args);
+       va_end(args);
+       printf("\n");
+}
+
+int CheckMem(void *Mem, int Count)
+{
+       return 1;
+}
+
+int CheckString(const char *String)
+{
+       return 1;
+}
diff --git a/AcessNative/acesskernel_src/mouse.c b/AcessNative/acesskernel_src/mouse.c
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/AcessNative/acesskernel_src/nativefs.c b/AcessNative/acesskernel_src/nativefs.c
new file mode 100644 (file)
index 0000000..71774e2
--- /dev/null
@@ -0,0 +1,17 @@
+/*\r
+ * Acess2 Native Kernel\r
+ * - Acess kernel emulation on another OS using SDL and UDP\r
+ *\r
+ * nativefs.c\r
+ * - Host filesystem access\r
+ */\r
+#include <acess.h>\r
+#include <vfs.h>\r
+\r
+// === GLOBALS ===\r
+\r
+// === CODE ===\r
+tVFS_Node *Native_Mount(const char *Device, const char **Arguments)\r
+{\r
+       return NULL;\r
+}\r
diff --git a/AcessNative/acesskernel_src/vfs_handle.c b/AcessNative/acesskernel_src/vfs_handle.c
new file mode 100644 (file)
index 0000000..aab30fc
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * Acess2 VFS
+ * - AllocHandle, GetHandle
+ */
+#define DEBUG  0
+#include <acess.h>
+#include "vfs.h"
+#include "vfs_int.h"
+#include "vfs_ext.h"
+
+// === CONSTANTS ===
+#define MAX_KERNEL_FILES       128
+#define MAX_USER_FILES 64
+
+// === PROTOTYPES ===
+tVFS_Handle    *VFS_GetHandle(int FD);
+ int   VFS_AllocHandle(int FD, tVFS_Node *Node, int Mode);
+
+typedef struct sUserHandles
+{
+       struct sUserHandles     *Next;
+        int    PID;
+       tVFS_Handle     Handles[MAX_USER_FILES];
+}      tUserHandles;
+
+// === GLOBALS ===
+tUserHandles   *gpUserHandles = NULL;
+tVFS_Handle    gaKernelHandles[MAX_KERNEL_FILES];
+
+// === CODE ===
+/**
+ * \fn tVFS_Handle *VFS_GetHandle(int FD)
+ * \brief Gets a pointer to the handle information structure
+ */
+tVFS_Handle *VFS_GetHandle(int FD)
+{
+       tVFS_Handle     *h;
+       
+       //Log_Debug("VFS", "VFS_GetHandle: (FD=0x%x)", FD);
+       
+       if(FD < 0)      return NULL;
+       
+       if(FD & VFS_KERNEL_FLAG) {
+               FD &= (VFS_KERNEL_FLAG - 1);
+               if(FD >= MAX_KERNEL_FILES)      return NULL;
+               h = &gaKernelHandles[ FD ];
+       }
+       else {
+               tUserHandles    *ent;
+                int    pid = Threads_GetPID();
+               for( ent = gpUserHandles; ent; ent = ent->Next ) {
+                       if( ent->PID == pid )   break;
+                       if( ent->PID > pid ) {
+                               Log_Error("VFS", "PID %i does not have a handle list", pid);
+                               return NULL;
+                       }
+               }
+               if(FD >= CFGINT(CFG_VFS_MAXFILES))      return NULL;
+               h = &ent->Handles[ FD ];
+       }
+       
+       if(h->Node == NULL)     return NULL;
+       //Log_Debug("VFS", "VFS_GetHandle: RETURN %p", h);
+       return h;
+}
+
+int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode)
+{
+        int    i;
+       
+       // Check for a user open
+       if(bIsUser)
+       {
+               tUserHandles    *ent, *prev;
+                int    pid = Threads_GetPID();
+               for( ent = gpUserHandles; ent; prev = ent, ent = ent->Next ) {
+                       if( ent->PID == pid )   break;
+                       if( ent->PID > pid )    break;
+               }
+               if( ent->PID > pid ) {
+                       ent = calloc( 1, sizeof(tUserHandles) );
+                       if( prev ) {
+                               ent->Next = prev->Next;
+                               prev->Next = ent;
+                       }
+                       else {
+                               ent->Next = gpUserHandles;
+                               gpUserHandles = ent;
+                       }
+               }
+               // Get a handle
+               for(i=0;i<CFGINT(CFG_VFS_MAXFILES);i++)
+               {
+                       if(ent->Handles[i].Node)        continue;
+                       ent->Handles[i].Node = Node;
+                       ent->Handles[i].Position = 0;
+                       ent->Handles[i].Mode = Mode;
+                       return i;
+               }
+       }
+       else
+       {
+               // Get a handle
+               for(i=0;i<MAX_KERNEL_FILES;i++)
+               {
+                       if(gaKernelHandles[i].Node)     continue;
+                       gaKernelHandles[i].Node = Node;
+                       gaKernelHandles[i].Position = 0;
+                       gaKernelHandles[i].Mode = Mode;
+                       return i|VFS_KERNEL_FLAG;
+               }
+       }
+       
+       return -1;
+}
diff --git a/AcessNative/acesskernel_src/video.c b/AcessNative/acesskernel_src/video.c
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/AcessNative/ld-acess.so_src/Makefile b/AcessNative/ld-acess.so_src/Makefile
new file mode 100644 (file)
index 0000000..3531f71
--- /dev/null
@@ -0,0 +1,31 @@
+#
+#
+
+ifeq ($(PLATFORM),)
+       PLATFORM := lin
+endif
+
+OBJ := syscalls.$(PLATFORM).o request.$(PLATFORM).o
+
+ifeq ($(PLATFORM),win)
+       BIN := ../libacess.dll
+endif
+ifeq ($(PLATFORM),lin)
+       BIN := ../libacess.so
+       CFLAGS += -fPIC
+endif
+
+
+.PHONY: all clean
+
+all: $(BIN)
+
+clean:
+       $(RM) $(BIN) $(OBJ)
+
+$(BIN): $(OBJ)
+       $(CC) -shared -o $@ $<
+
+%.$(PLATFORM).o: %.c
+       $(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
+
diff --git a/AcessNative/ld-acess.so_src/request.c b/AcessNative/ld-acess.so_src/request.c
new file mode 100644 (file)
index 0000000..5a64119
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ */
+#include <windows.h>
+#include <stdio.h>
+#include <winsock.h>
+
+#define        SERVER_PORT     0xACE
+
+// === GLOBALS ===
+#ifdef __WIN32__
+WSADATA        gWinsock;
+SOCKET gSocket;
+#endif
+
+// === CODE ===
+int _InitSyscalls()
+{
+       struct sockaddr_in      server;
+       struct sockaddr_in      client;
+       
+       #ifdef __WIN32__
+       /* Open windows connection */
+       if (WSAStartup(0x0101, &gWinsock) != 0)
+       {
+               fprintf(stderr, "Could not open Windows connection.\n");
+               exit(0);
+       }
+       #endif
+       
+       // Open UDP Connection
+       gSocket = socket(AF_INET, SOCK_DGRAM, 0);
+       if (gSocket == INVALID_SOCKET)
+       {
+               fprintf(stderr, "Could not create socket.\n");
+               WSACleanup();
+               exit(0);
+       }
+       
+       // Set server address
+       memset((void *)&server, '\0', sizeof(struct sockaddr_in));
+       server.sin_family = AF_INET;
+       server.sin_port = htons(SERVER_PORT);
+       server.sin_addr.S_un.S_un_b.s_b1 = (unsigned char)127;
+       server.sin_addr.S_un.S_un_b.s_b2 = (unsigned char)0;
+       server.sin_addr.S_un.S_un_b.s_b3 = (unsigned char)0;
+       server.sin_addr.S_un.S_un_b.s_b4 = (unsigned char)1;
+       
+       // Set client address
+       memset((void *)&client, '\0', sizeof(struct sockaddr_in));
+       client.sin_family = AF_INET;
+       client.sin_port = htons(0);
+       client.sin_addr.S_un.S_un_b.s_b1 = (unsigned char)127;
+       client.sin_addr.S_un.S_un_b.s_b2 = (unsigned char)0;
+       client.sin_addr.S_un.S_un_b.s_b3 = (unsigned char)0;
+       client.sin_addr.S_un.S_un_b.s_b4 = (unsigned char)1;
+       
+       // Bind
+       if( bind(gSocket, (struct sockaddr *)&client, sizeof(struct sockaddr_in)) == -1 )
+       {
+               fprintf(stderr, "Cannot bind address to socket.\n");
+               closesocket(gSocket);
+               WSACleanup();
+               exit(0);
+       }
+}
+
+int _Syscall(const char *ArgTypes, ...)
+{
+       return 0;
+}
diff --git a/AcessNative/ld-acess.so_src/syscalls.c b/AcessNative/ld-acess.so_src/syscalls.c
new file mode 100644 (file)
index 0000000..35fa6ae
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ */
+//#include <acess/sys.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+// === IMPORTS ===
+/**
+ * \param ArgTypes
+ *
+ * Whitespace is ignored
+ * >i: Input Integer
+ * >I: Input Long Integer (64-bits)
+ * >s: Input String
+ * >d: Input Buffer (Preceded by valid size)
+ * <I: Output long integer
+ * <d: Output Buffer (Preceded by valid size)
+ */
+int _Syscall(const char *ArgTypes, ...)
+{
+        int    outBufSize = 0;
+       va_list args;
+       
+       va_start(args, ArgTypes);
+       va_end(args);
+       
+}
+
+int open(const char *Path, int Flags) {
+       return _Syscall(">s >i", Path, Flags);
+}
+
+void close(int FD) {
+       _Syscall(">i", FD);
+}
+
+size_t read(int FD, size_t Bytes, void *Dest) {
+       return _Syscall(">i >i <d", FD, Bytes, Bytes, Dest);
+}
+
+size_t write(int FD, size_t Bytes, void *Src) {
+       return _Syscall(">i >i >d", FD, Bytes, Bytes, Src);
+}
+
+uint64_t tell(int FD) {
+       uint64_t        ret;
+       _Syscall("<I >i", &ret, FD);
+       return ret;
+}
+
+int seek(int FD, uint64_t Ofs, int Dir) {
+       return _Syscall(">i >I >i", FD, Ofs, Dir);
+}
+
index 7c23b10..83c1240 100644 (file)
@@ -31,7 +31,7 @@ OBJ += messages.o modules.o syscalls.o system.o threads.o
 OBJ += $(addprefix vfs/fs/, $(addsuffix .o,$(FILESYSTEMS)))
 OBJ += drv/kb.o drv/vterm.o drv/proc.o drv/fifo.o drv/iocache.o drv/dma.o drv/pci.o drv/vga.o
 OBJ += binary.o bin/elf.o bin/pe.o
-OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/dir.o vfs/io.o vfs/mount.o vfs/memfile.o vfs/nodecache.o
+OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/dir.o vfs/io.o vfs/mount.o vfs/memfile.o vfs/nodecache.o vfs/handle.o
 OBJ += vfs/fs/root.o vfs/fs/devfs.o
 OBJ += $(addprefix drv/, $(addsuffix .o,$(DRIVERS)))
 OBJ := $(addsuffix .$(ARCH), $(OBJ))
index 779cf88..861fd30 100644 (file)
@@ -95,11 +95,11 @@ typedef void (*tThreadFunction)(void*);
  */
 typedef struct sKernelSymbol {
        char    *Name;
-       Uint    Value;
+       tVAddr  Value;
 } tKernelSymbol;
-#define        EXPORT(_name)   tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (Uint)_name}
-#define        EXPORTV(_name)  tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (Uint)&_name}
-#define        EXPORTAS(_sym,_name)    tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (Uint)_sym}
+#define        EXPORT(_name)   tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (tVAddr)_name}
+#define        EXPORTV(_name)  tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (tVAddr)&_name}
+#define        EXPORTAS(_sym,_name)    tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (tVAddr)_sym}
 /**
  * \}
  */
@@ -323,7 +323,7 @@ extern Uint32       BigEndian32(Uint32 Val);
  */
 extern int     vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args);
 extern int     sprintf(char *__s, const char *__format, ...);
-extern Uint    strlen(const char *Str);
+extern size_t  strlen(const char *Str);
 extern char    *strcpy(char *__dest, const char *__src);
 extern char    *strncpy(char *__dest, const char *__src, size_t max);
 extern int     strcmp(const char *__str1, const char *__str2);
@@ -349,7 +349,7 @@ extern int  UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString);
  * \}
  */
 
-extern Uint    rand(void);
+extern int     rand(void);
 extern int     CallWithArgArray(void *Function, int NArgs, Uint *Args);
 
 // --- Heap ---
@@ -416,7 +416,7 @@ extern tUID Threads_GetUID(void);
 extern tGID    Threads_GetGID(void);
 extern int     SpawnTask(tThreadFunction Function, void *Arg);
 extern Uint    *Threads_GetCfgPtr(int Id);
-extern int     Threads_SetName(char *NewName);
+extern int     Threads_SetName(const char *NewName);
 extern void    Mutex_Acquire(tMutex *Mutex);
 extern void    Mutex_Release(tMutex *Mutex);
 extern int     Mutex_IsLocked(tMutex *Mutex);
index 14950dd..6e8d60e 100644 (file)
@@ -25,7 +25,6 @@ extern Uint   Proc_SendMessage(Uint *Err, Uint Dest, Uint Length, void *Data);
 extern int     Proc_GetMessage(Uint *Err, Uint *Source, void *Buffer);
 extern int     Proc_Execve(char *File, char **ArgV, char **EnvP);
 extern Uint    Binary_Load(char *file, Uint *entryPoint);
-extern int     Threads_SetName(char *NewName);
 extern int     Threads_SetUID(Uint *errno, tUID ID);
 extern int     Threads_SetGID(Uint *errno, tGID ID);
 extern int     Threads_SetFaultHandler(Uint Handler);
index b76fe59..c9a123d 100644 (file)
@@ -35,10 +35,11 @@ extern void Proc_Start(void);
 extern tThread *Proc_GetCurThread(void);
 extern int     Proc_Clone(Uint *Err, Uint Flags);
 extern void    Proc_CallFaultHandler(tThread *Thread);
+extern int     GetCPUNum(void);
 
 // === PROTOTYPES ===
 void   Threads_Init(void);
- int   Threads_SetName(char *NewName);
+ int   Threads_SetName(const char *NewName);
 char   *Threads_GetName(int ID);
 void   Threads_SetPriority(tThread *Thread, int Pri);
 tThread        *Threads_CloneTCB(Uint *Err, Uint Flags);
@@ -123,12 +124,12 @@ void Threads_Init(void)
 }
 
 /**
- * \fn void Threads_SetName(char *NewName)
+ * \fn void Threads_SetName(const char *NewName)
  * \brief Sets the current thread's name
  * \param NewName      New name for the thread
  * \return Boolean Failure
  */
-int Threads_SetName(char *NewName)
+int Threads_SetName(const char *NewName)
 {
        tThread *cur = Proc_GetCurThread();
        char    *oldname = cur->ThreadName;
@@ -662,6 +663,12 @@ void Threads_AddActive(tThread *Thread)
 {
        SHORTLOCK( &glThreadListLock );
        
+       if( Thread->Status == THREAD_STAT_ACTIVE ) {
+               tThread *cur = Proc_GetCurThread();
+               Warning("WTF, CPU%i %p (%i %s) is adding %p (%i %s) when it is active",
+                       GetCPUNum(), cur, cur->TID, cur->ThreadName, Thread, Thread->TID, Thread->ThreadName);
+       }
+       
        // Set state
        Thread->Status = THREAD_STAT_ACTIVE;
        Thread->CurCPU = -1;
@@ -680,8 +687,8 @@ void Threads_AddActive(tThread *Thread)
        #if SCHEDULER_TYPE == SCHED_LOTTERY
        giFreeTickets += caiTICKET_COUNTS[ Thread->Priority ];
        # if DEBUG_TRACE_TICKETS
-       Log("Threads_AddActive: %p %i (%s) added, new giFreeTickets = %i",
-               Thread, Thread->TID, Thread->ThreadName, giFreeTickets);
+       Log("Threads_AddActive: CPU%i %p %i (%s) added, new giFreeTickets = %i",
+               GetCPUNum(), Thread, Thread->TID, Thread->ThreadName, giFreeTickets);
        # endif
        #endif
        
@@ -718,8 +725,8 @@ tThread *Threads_RemActive(void)
        // no need to decrement tickets, scheduler did it for us
        
        #if SCHEDULER_TYPE == SCHED_LOTTERY && DEBUG_TRACE_TICKETS
-       Log("Threads_RemActive: %p %i (%s) removed, giFreeTickets = %i",
-               ret, ret->TID, ret->ThreadName, giFreeTickets);
+       Log("Threads_RemActive: CPU%i %p %i (%s) removed, giFreeTickets = %i",
+               GetCPUNum(), ret, ret->TID, ret->ThreadName, giFreeTickets);
        #endif
        
        SHORTREL( &glThreadListLock );
@@ -836,8 +843,8 @@ void Threads_DumpActive(void)
                for(thread=gActiveThreads;thread;thread=thread->Next)
        #endif
                {
-                       Log(" %i (%i) - %s (CPU %i)",
-                               thread->TID, thread->TGID, thread->ThreadName, thread->CurCPU);
+                       Log(" %p %i (%i) - %s (CPU %i)",
+                               thread, thread->TID, thread->TGID, thread->ThreadName, thread->CurCPU);
                        if(thread->Status != THREAD_STAT_ACTIVE)
                                Log("  ERROR State (%i) != THREAD_STAT_ACTIVE (%i)", thread->Status, THREAD_STAT_ACTIVE);
                        Log("  Priority %i, Quantum %i", thread->Priority, thread->Quantum);
@@ -863,8 +870,8 @@ void Threads_Dump(void)
        Log("All Threads:");
        for(thread=gAllThreads;thread;thread=thread->GlobalNext)
        {
-               Log(" %i (%i) - %s (CPU %i)",
-                       thread->TID, thread->TGID, thread->ThreadName, thread->CurCPU);
+               Log(" %p %i (%i) - %s (CPU %i)",
+                       thread, thread->TID, thread->TGID, thread->ThreadName, thread->CurCPU);
                Log("  State %i (%s)", thread->Status, casTHREAD_STAT[thread->Status]);
                switch(thread->Status)
                {
diff --git a/Kernel/vfs/handle.c b/Kernel/vfs/handle.c
new file mode 100644 (file)
index 0000000..7d679be
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Acess2 VFS
+ * - AllocHandle, GetHandle
+ */
+#define DEBUG  0
+#include <acess.h>
+#include <mm_virt.h>
+#include "vfs.h"
+#include "vfs_int.h"
+#include "vfs_ext.h"
+
+// === CONSTANTS ===
+#define MAX_KERNEL_FILES       128
+
+// === PROTOTYPES ===
+tVFS_Handle    *VFS_GetHandle(int FD);
+ int   VFS_AllocHandle(int FD, tVFS_Node *Node, int Mode);
+
+// === GLOBALS ===
+tVFS_Handle    *gaUserHandles = (void*)MM_PPD_VFS;
+tVFS_Handle    *gaKernelHandles = (void*)MM_KERNEL_VFS;
+
+// === CODE ===
+/**
+ * \fn tVFS_Handle *VFS_GetHandle(int FD)
+ * \brief Gets a pointer to the handle information structure
+ */
+tVFS_Handle *VFS_GetHandle(int FD)
+{
+       tVFS_Handle     *h;
+       
+       //Log_Debug("VFS", "VFS_GetHandle: (FD=0x%x)", FD);
+       
+       if(FD < 0)      return NULL;
+       
+       if(FD & VFS_KERNEL_FLAG) {
+               FD &= (VFS_KERNEL_FLAG - 1);
+               if(FD >= MAX_KERNEL_FILES)      return NULL;
+               h = &gaKernelHandles[ FD ];
+       } else {
+               if(FD >= CFGINT(CFG_VFS_MAXFILES))      return NULL;
+               h = &gaUserHandles[ FD ];
+       }
+       
+       if(h->Node == NULL)     return NULL;
+       //Log_Debug("VFS", "VFS_GetHandle: RETURN %p", h);
+       return h;
+}
+
+int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode)
+{
+        int    i;
+       
+       // Check for a user open
+       if(bIsUser)
+       {
+               // Allocate Buffer
+               if( MM_GetPhysAddr( (Uint)gaUserHandles ) == 0 )
+               {
+                       Uint    addr, size;
+                       size = CFGINT(CFG_VFS_MAXFILES) * sizeof(tVFS_Handle);
+                       for(addr = 0; addr < size; addr += 0x1000)
+                               MM_Allocate( (Uint)gaUserHandles + addr );
+                       memset( gaUserHandles, 0, size );
+               }
+               // Get a handle
+               for(i=0;i<CFGINT(CFG_VFS_MAXFILES);i++)
+               {
+                       if(gaUserHandles[i].Node)       continue;
+                       gaUserHandles[i].Node = node;
+                       gaUserHandles[i].Position = 0;
+                       gaUserHandles[i].Mode = Mode;
+                       return i;
+               }
+       }
+       else
+       {
+               // Allocate space if not already
+               if( MM_GetPhysAddr( (Uint)gaKernelHandles ) == 0 )
+               {
+                       Uint    addr, size;
+                       size = MAX_KERNEL_FILES * sizeof(tVFS_Handle);
+                       for(addr = 0; addr < size; addr += 0x1000)
+                               MM_Allocate( (Uint)gaKernelHandles + addr );
+                       memset( gaKernelHandles, 0, size );
+               }
+               // Get a handle
+               for(i=0;i<MAX_KERNEL_FILES;i++)
+               {
+                       if(gaKernelHandles[i].Node)     continue;
+                       gaKernelHandles[i].Node = node;
+                       gaKernelHandles[i].Position = 0;
+                       gaKernelHandles[i].Mode = Mode;
+                       return i|VFS_KERNEL_FLAG;
+               }
+       }
+       
+       return -1;
+}
index 4fe8cf9..ef1cd56 100644 (file)
@@ -90,7 +90,7 @@ char *VFS_GetTruePath(char *Path)
 void VFS_GetMemPath(char *Dest, void *Base, Uint Length)
 {
        Dest[0] = '$';
-       itoa( &Dest[1], (Uint)Base, 16, BITS/4, '0' );
+       itoa( &Dest[1], (tVAddr)Base, 16, BITS/4, '0' );
        Dest[BITS/4+1] = ':';
        itoa( &Dest[BITS/4+2], Length, 16, BITS/4, '0' );
        Dest[BITS/2+2] = '\0';
index 5420b33..b0de784 100644 (file)
@@ -4,23 +4,20 @@
  */
 #define DEBUG  0
 #include <acess.h>
-#include <mm_virt.h>
 #include "vfs.h"
 #include "vfs_int.h"
 #include "vfs_ext.h"
 
 // === CONSTANTS ===
 #define        OPEN_MOUNT_ROOT 1
-#define MAX_KERNEL_FILES       128
 #define MAX_PATH_SLASHES       256
 
 // === IMPORTS ===
 extern tVFS_Node       gVFS_MemRoot;
 extern tVFS_Mount      *gVFS_RootMount;
 
-// === GLOBALS ===
-tVFS_Handle    *gaUserHandles = (void*)MM_PPD_VFS;
-tVFS_Handle    *gaKernelHandles = (void*)MM_KERNEL_VFS;
+extern tVFS_Handle     *VFS_GetHandle(int FD);
+extern int     VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode);
 
 // === CODE ===
 /**
@@ -512,50 +509,10 @@ int VFS_Open(char *Path, Uint Mode)
                return -1;
        }
        
-       // Check for a user open
-       if(Mode & VFS_OPENFLAG_USER)
-       {
-               // Allocate Buffer
-               if( MM_GetPhysAddr( (Uint)gaUserHandles ) == 0 )
-               {
-                       Uint    addr, size;
-                       size = CFGINT(CFG_VFS_MAXFILES) * sizeof(tVFS_Handle);
-                       for(addr = 0; addr < size; addr += 0x1000)
-                               MM_Allocate( (Uint)gaUserHandles + addr );
-                       memset( gaUserHandles, 0, size );
-               }
-               // Get a handle
-               for(i=0;i<CFGINT(CFG_VFS_MAXFILES);i++)
-               {
-                       if(gaUserHandles[i].Node)       continue;
-                       gaUserHandles[i].Node = node;
-                       gaUserHandles[i].Position = 0;
-                       gaUserHandles[i].Mode = Mode;
-                       LEAVE('i', i);
-                       return i;
-               }
-       }
-       else
-       {
-               // Allocate space if not already
-               if( MM_GetPhysAddr( (Uint)gaKernelHandles ) == 0 )
-               {
-                       Uint    addr, size;
-                       size = MAX_KERNEL_FILES * sizeof(tVFS_Handle);
-                       for(addr = 0; addr < size; addr += 0x1000)
-                               MM_Allocate( (Uint)gaKernelHandles + addr );
-                       memset( gaKernelHandles, 0, size );
-               }
-               // Get a handle
-               for(i=0;i<MAX_KERNEL_FILES;i++)
-               {
-                       if(gaKernelHandles[i].Node)     continue;
-                       gaKernelHandles[i].Node = node;
-                       gaKernelHandles[i].Position = 0;
-                       gaKernelHandles[i].Mode = Mode;
-                       LEAVE('x', i|VFS_KERNEL_FLAG);
-                       return i|VFS_KERNEL_FLAG;
-               }
+       i = VFS_AllocHandle( !!(Mode & VFS_OPENFLAG_USER), node, Mode );
+       if( i > 0 ) {
+               LEAVE('x', i);
+               return i;
        }
        
        Log("VFS_Open: Out of handles");
@@ -612,50 +569,10 @@ int VFS_OpenChild(Uint *Errno, int FD, char *Name, Uint Mode)
                return -1;
        }
        
-       // Check for a user open
-       if(Mode & VFS_OPENFLAG_USER)
-       {
-               // Allocate Buffer
-               if( MM_GetPhysAddr( (Uint)gaUserHandles ) == 0 )
-               {
-                       Uint    addr, size;
-                       size = CFGINT(CFG_VFS_MAXFILES) * sizeof(tVFS_Handle);
-                       for(addr = 0; addr < size; addr += 0x1000)
-                               MM_Allocate( (Uint)gaUserHandles + addr );
-                       memset( gaUserHandles, 0, size );
-               }
-               // Get a handle
-               for(i=0;i<CFGINT(CFG_VFS_MAXFILES);i++)
-               {
-                       if(gaUserHandles[i].Node)       continue;
-                       gaUserHandles[i].Node = node;
-                       gaUserHandles[i].Position = 0;
-                       gaUserHandles[i].Mode = Mode;
-                       LEAVE('i', i);
-                       return i;
-               }
-       }
-       else
-       {
-               // Allocate space if not already
-               if( MM_GetPhysAddr( (Uint)gaKernelHandles ) == 0 )
-               {
-                       Uint    addr, size;
-                       size = MAX_KERNEL_FILES * sizeof(tVFS_Handle);
-                       for(addr = 0; addr < size; addr += 0x1000)
-                               MM_Allocate( (Uint)gaKernelHandles + addr );
-                       memset( gaKernelHandles, 0, size );
-               }
-               // Get a handle
-               for(i=0;i<MAX_KERNEL_FILES;i++)
-               {
-                       if(gaKernelHandles[i].Node)     continue;
-                       gaKernelHandles[i].Node = node;
-                       gaKernelHandles[i].Position = 0;
-                       gaKernelHandles[i].Mode = Mode;
-                       LEAVE('x', i|VFS_KERNEL_FLAG);
-                       return i|VFS_KERNEL_FLAG;
-               }
+       i = VFS_AllocHandle( !!(Mode & VFS_OPENFLAG_USER), node, Mode );
+       if( i > 0 ) {
+               LEAVE('x', i);
+               return i;
        }
        
        Log_Error("VFS", "VFS_OpenChild - Out of handles");
@@ -787,32 +704,6 @@ int VFS_ChRoot(char *New)
        return 1;
 }
 
-/**
- * \fn tVFS_Handle *VFS_GetHandle(int FD)
- * \brief Gets a pointer to the handle information structure
- */
-tVFS_Handle *VFS_GetHandle(int FD)
-{
-       tVFS_Handle     *h;
-       
-       //Log_Debug("VFS", "VFS_GetHandle: (FD=0x%x)", FD);
-       
-       if(FD < 0)      return NULL;
-       
-       if(FD & VFS_KERNEL_FLAG) {
-               FD &= (VFS_KERNEL_FLAG - 1);
-               if(FD >= MAX_KERNEL_FILES)      return NULL;
-               h = &gaKernelHandles[ FD ];
-       } else {
-               if(FD >= CFGINT(CFG_VFS_MAXFILES))      return NULL;
-               h = &gaUserHandles[ FD ];
-       }
-       
-       if(h->Node == NULL)     return NULL;
-       //Log_Debug("VFS", "VFS_GetHandle: RETURN %p", h);
-       return h;
-}
-
 // === EXPORTS ===
 EXPORT(VFS_Open);
 EXPORT(VFS_Close);
index 07234df..88d92db 100644 (file)
@@ -115,6 +115,9 @@ void Link_WatchDevice(tAdapter *Adapter)
        if( !gbLink_CRCTableGenerated )
                Link_InitCRC();
        
+       Threads_SetName(Adapter->Device);
+       Log_Log("NET", "Thread %i watching '%s'", Threads_GetTID(), Adapter->Device);
+       
        // Child Thread
        while(Adapter->DeviceFD != -1)
        {

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