From 45672f51180f1f0af73c2ba75723eca8f8bb8e89 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 10 Dec 2010 12:52:02 +0800 Subject: [PATCH] AcessNative - Wine equivalent for Acess - Allows native Acess applications to be run on Windows/Linux - Uses large parts of the main kernel, reducing code duplication - Still incomplete, will use SDL for video, and a UDP server for User->Kernel requests. --- AcessNative/acesskernel_src/Details.txt | 7 ++ AcessNative/acesskernel_src/Makefile | 43 ++++++++ AcessNative/acesskernel_src/include/arch.h | 37 +++++++ AcessNative/acesskernel_src/include/heap.h | 8 ++ AcessNative/acesskernel_src/keyboard.c | 0 AcessNative/acesskernel_src/main.c | 52 ++++++++++ AcessNative/acesskernel_src/mouse.c | 0 AcessNative/acesskernel_src/nativefs.c | 17 +++ AcessNative/acesskernel_src/vfs_handle.c | 115 +++++++++++++++++++++ AcessNative/acesskernel_src/video.c | 0 10 files changed, 279 insertions(+) create mode 100644 AcessNative/acesskernel_src/Details.txt create mode 100644 AcessNative/acesskernel_src/Makefile create mode 100644 AcessNative/acesskernel_src/include/arch.h create mode 100644 AcessNative/acesskernel_src/include/heap.h create mode 100644 AcessNative/acesskernel_src/keyboard.c create mode 100644 AcessNative/acesskernel_src/main.c create mode 100644 AcessNative/acesskernel_src/mouse.c create mode 100644 AcessNative/acesskernel_src/nativefs.c create mode 100644 AcessNative/acesskernel_src/vfs_handle.c create mode 100644 AcessNative/acesskernel_src/video.c diff --git a/AcessNative/acesskernel_src/Details.txt b/AcessNative/acesskernel_src/Details.txt new file mode 100644 index 00000000..bd209536 --- /dev/null +++ b/AcessNative/acesskernel_src/Details.txt @@ -0,0 +1,7 @@ +Provides Acess Kernel services +- UDP Server listening on 127.0.0.1:2766 (0XACE) + > See ld-acess.so_src/syscalls for the spec +- Starts acess applications + > Provides kernel loader services and loads libacess +- Provides "vterms" / control panel +- 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 index 00000000..d7bfcb8a --- /dev/null +++ b/AcessNative/acesskernel_src/Makefile @@ -0,0 +1,43 @@ +# AcessNative Server +# Makefile + +ifeq ($(PLATFORM),) + PLATFORM := lin +endif + +KERNEL_SRC = ../../Kernel/ + +KERNEL_OBJ := logging.o adt.o +KERNEL_OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/io.o vfs/dir.o vfs/nodecache.o vfs/mount.o +KERNEL_OBJ += vfs/fs/root.o vfs/fs/devfs.o +KERNEL_OBJ += drv/vterm.o drv/fifo.o + +OBJ := main.o video.o keyboard.o mouse.o nativefs.o vfs_handle.o +OBJ += $(addprefix $(KERNEL_SRC),$(KERNEL_OBJ)) + +OBJ := $(addsuffix .$(PLATFORM),$(OBJ)) + +CPPFLAGS += -I include/ -I $(KERNEL_SRC)include/ +CFLAGS += -Wall +LDFLAGS += -lSDL -lSDLmain + +ifeq ($(PLATFORM),win) + BIN := ../AcessKernel.exe +endif +ifeq ($(PLATFORM),lin) + BIN := ../AcessKernel + CFLAGS += +endif + +.PHONY: all clean + +all: $(BIN) + +clean: + $(RM) $(BIN) $(OBJ) + +$(BIN): $(OBJ) + $(CC) $(LDFLAGS) -o $@ $(OBJ) + +%.o.$(PLATFORM): %.c + $(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS) diff --git a/AcessNative/acesskernel_src/include/arch.h b/AcessNative/acesskernel_src/include/arch.h new file mode 100644 index 00000000..e9857890 --- /dev/null +++ b/AcessNative/acesskernel_src/include/arch.h @@ -0,0 +1,37 @@ +/** + */ +#ifndef _ARCH_H_ +#define _ARCH_H_ + +#include +#include + +#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 index 00000000..20525597 --- /dev/null +++ b/AcessNative/acesskernel_src/include/heap.h @@ -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 index 00000000..e69de29b diff --git a/AcessNative/acesskernel_src/main.c b/AcessNative/acesskernel_src/main.c new file mode 100644 index 00000000..45e6aa02 --- /dev/null +++ b/AcessNative/acesskernel_src/main.c @@ -0,0 +1,52 @@ +/* + * Acess2 Native Kernel + * - Acess kernel emulation on another OS using SDL and UDP + * + * Kernel Main + */ +#include +#include +#include + +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 index 00000000..e69de29b diff --git a/AcessNative/acesskernel_src/nativefs.c b/AcessNative/acesskernel_src/nativefs.c new file mode 100644 index 00000000..71774e23 --- /dev/null +++ b/AcessNative/acesskernel_src/nativefs.c @@ -0,0 +1,17 @@ +/* + * Acess2 Native Kernel + * - Acess kernel emulation on another OS using SDL and UDP + * + * nativefs.c + * - Host filesystem access + */ +#include +#include + +// === GLOBALS === + +// === CODE === +tVFS_Node *Native_Mount(const char *Device, const char **Arguments) +{ + return NULL; +} diff --git a/AcessNative/acesskernel_src/vfs_handle.c b/AcessNative/acesskernel_src/vfs_handle.c new file mode 100644 index 00000000..aab30fc0 --- /dev/null +++ b/AcessNative/acesskernel_src/vfs_handle.c @@ -0,0 +1,115 @@ +/* + * Acess2 VFS + * - AllocHandle, GetHandle + */ +#define DEBUG 0 +#include +#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;iHandles[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