From: John Hodge Date: Sat, 2 Jul 2011 04:36:09 +0000 (+0800) Subject: AcessNative - Debugging and implementing, getting there now X-Git-Tag: rel0.10~58 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=a6f11cb266052c58ae7e2d6d6e8abd34a9e93214;p=tpg%2Facess2.git AcessNative - Debugging and implementing, getting there now --- diff --git a/AcessNative/acesskernel_src/Makefile b/AcessNative/acesskernel_src/Makefile index ed79684b..74f8920a 100644 --- a/AcessNative/acesskernel_src/Makefile +++ b/AcessNative/acesskernel_src/Makefile @@ -13,12 +13,15 @@ KERNEL_OBJ += vfs/nodecache.o vfs/mount.o vfs/memfile.o vfs/select.o KERNEL_OBJ += vfs/fs/root.o vfs/fs/devfs.o KERNEL_OBJ += drv/vterm.o drv/fifo.o drv/proc.o -OBJ := main.o helpers.o threads.o server.o syscalls.o +N_OBJ := main.o + +OBJ := helpers.o threads.o server.o syscalls.o OBJ += video.o keyboard.o mouse.o nativefs.o vfs_handle.o ui_sdl.o OBJ += $(addprefix $(KERNEL_SRC),$(KERNEL_OBJ)) OBJ := $(addsuffix .$(PLATFORM),$(OBJ)) -DEPFILES = $(filter %.o.$(PLATFORM),$(OBJ)) +N_OBJ := $(addsuffix .$(PLATFORM),$(N_OBJ)) +DEPFILES = $(filter %.o.$(PLATFORM),$(OBJ) $(N_OBJ)) DEPFILES := $(DEPFILES:%.o.$(PLATFORM)=%.d.$(PLATFORM)) CPPFLAGS += -I include/ -I $(KERNEL_SRC)include/ @@ -38,15 +41,20 @@ endif all: $(BIN) clean: - $(RM) $(BIN) $(OBJ) $(DEPFILES) + $(RM) $(BIN) $(OBJ) $(N_OBJ) $(DEPFILES) -$(BIN): $(OBJ) +$(BIN): $(OBJ) $(N_OBJ) @echo [LINK] -o $@ - @$(CC) $(LDFLAGS) -o $@ $(OBJ) + @$(CC) $(LDFLAGS) -o $@ $(N_OBJ) $(OBJ) -%.o.$(PLATFORM): %.c +$(OBJ): %.o.$(PLATFORM): %.c @echo [CC] -o $@ @$(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS) @$(CC) -M $(CPPFLAGS) -MT $@ -o $*.d.$(PLATFORM) $< +$(N_OBJ): %.o.$(PLATFORM): %.c + @echo [CC] -o $@ + @$(CC) -c $< -o $@ $(CFLAGS) + @$(CC) -M -MT $@ -o $*.d.$(PLATFORM) $< + -include $(DEPFILES) diff --git a/AcessNative/acesskernel_src/main.c b/AcessNative/acesskernel_src/main.c index 363fea1f..3f724130 100644 --- a/AcessNative/acesskernel_src/main.c +++ b/AcessNative/acesskernel_src/main.c @@ -6,6 +6,7 @@ */ #include #include +#include // === IMPORTS === extern int UI_Initialise(int Width, int Height); @@ -23,7 +24,10 @@ const char *gsAcessDir = "../Usermode/Output/i386"; int main(int argc, char *argv[]) { // Parse command line settings - + + // - Ignore SIGUSR1 (used to wake threads) + signal(SIGUSR1, SIG_IGN); + // Start UI subsystem UI_Initialise(800, 480); diff --git a/AcessNative/acesskernel_src/server.c b/AcessNative/acesskernel_src/server.c index 0cede83c..264f4122 100644 --- a/AcessNative/acesskernel_src/server.c +++ b/AcessNative/acesskernel_src/server.c @@ -267,7 +267,8 @@ int SyscallServer(void) ntohl(addr.sin_addr.s_addr), ntohs(addr.sin_port)); client = Server_GetClient(req->ClientID); - if( req->ClientID == 0 ) + // NOTE: Hack - Should check if all zero + if( req->ClientID == 0 || client->ClientAddr.sin_port == 0 ) { memcpy(&client->ClientAddr, &addr, sizeof(addr)); } diff --git a/AcessNative/acesskernel_src/syscalls.c b/AcessNative/acesskernel_src/syscalls.c index ec874161..b41e3544 100644 --- a/AcessNative/acesskernel_src/syscalls.c +++ b/AcessNative/acesskernel_src/syscalls.c @@ -15,6 +15,16 @@ extern int Threads_Fork(void); // AcessNative only function typedef int (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int *Sizes); // === MACROS === +#define SYSCALL5(_name, _fmtstr, _t0, _t1, _t2, _t3, _t4, _call) int _name(Uint*Errno,const char*Fmt,void*Args,int*Sizes){\ + _t0 a0;_t1 a1;_t2 a2;_t3 a3;_t4 a4;\ + if(strcmp(Fmt,_fmtstr)!=0)return 0;\ + a0 = *(_t0*)Args;Args+=sizeof(_t0);\ + a1 = *(_t1*)Args;Args+=sizeof(_t1);\ + a2 = *(_t2*)Args;Args+=sizeof(_t2);\ + a3 = *(_t3*)Args;Args+=sizeof(_t3);\ + a4 = *(_t4*)Args;Args+=sizeof(_t4);\ + _call\ +} #define SYSCALL4(_name, _fmtstr, _t0, _t1, _t2, _t3, _call) int _name(Uint*Errno,const char*Fmt,void*Args,int*Sizes){\ _t0 a0;_t1 a1;_t2 a2;_t3 a3;\ if(strcmp(Fmt,_fmtstr)!=0)return 0;\ @@ -103,6 +113,9 @@ SYSCALL2(Syscall_ReadDir, "id", int, char *, return -1; return VFS_ReadDir(a0, a1); ); +SYSCALL5(Syscall_select, "idddd", int, fd_set *, fd_set *, fd_set *, time_t *, + return VFS_Select(a0, a1, a2, a3, a4, 0); +); SYSCALL3(Syscall_OpenChild, "isi", int, const char *, int, return VFS_OpenChild(NULL, a0, a1, a2|VFS_OPENFLAG_USER); ); @@ -141,8 +154,11 @@ SYSCALL1(Syscall_SetGID, "i", int, return Threads_SetGID(Errno, a0); ); -SYSCALL0(Syscall_Fork, - return Threads_Fork(); +SYSCALL1(Syscall_Fork, "d", int *, + if(Sizes[0] < sizeof(int)) + return -1; + *a0 = Threads_Fork(); + return *a0; ); const tSyscallHandler caSyscalls[] = { @@ -168,7 +184,11 @@ const tSyscallHandler caSyscalls[] = { Syscall_SetGID, Syscall_Sleep, - Syscall_Fork + Syscall_Fork, + + NULL, + NULL, + Syscall_select }; const int ciNumSyscalls = sizeof(caSyscalls)/sizeof(caSyscalls[0]); /** diff --git a/AcessNative/acesskernel_src/ui_sdl.c b/AcessNative/acesskernel_src/ui_sdl.c index 3f3cb139..2e56a647 100644 --- a/AcessNative/acesskernel_src/ui_sdl.c +++ b/AcessNative/acesskernel_src/ui_sdl.c @@ -57,6 +57,10 @@ Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym, Uint16 Unicode) // Fast return if( gUI_Keymap[shiftState][Sym] ) return gUI_Keymap[shiftState][Sym]; + + // Enter key on acess returns \n, but SDL returns \r + if( Sym == SDLK_RETURN ) + Unicode = '\n'; // How nice of you, a unicode value if( Unicode ) @@ -85,6 +89,7 @@ Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym, Uint16 Unicode) case SDLK_F10: ret = KEY_F10; break; case SDLK_F11: ret = KEY_F11; break; case SDLK_F12: ret = KEY_F12; break; + case SDLK_RETURN: ret = '\n'; break; default: printf("Unhandled key code %i\n", Sym); break; diff --git a/AcessNative/acesskernel_src/video.c b/AcessNative/acesskernel_src/video.c index f3903fb2..2c38533d 100644 --- a/AcessNative/acesskernel_src/video.c +++ b/AcessNative/acesskernel_src/video.c @@ -264,16 +264,14 @@ int Video_IOCtl(tVFS_Node *Node, int ID, void *Data) #if 0 case VIDEO_IOCTL_SETCURSOR: // Set cursor position #if !BLINKING_CURSOR - if(giVesaCursorX > 0) - Vesa_FlipCursor(Node); + if(giVideo_CursorX > 0) + Video_FlipCursor(Node); #endif - giVesaCursorX = ((tVideo_IOCtl_Pos*)Data)->x; - giVesaCursorY = ((tVideo_IOCtl_Pos*)Data)->y; - //Log_Debug("VESA", "Cursor position (%i,%i)", giVesaCursorX, giVesaCursorY); - if( - giVesaCursorX < 0 || giVesaCursorY < 0 - || giVesaCursorX >= gpVesaCurMode->width/giVT_CharWidth - || giVesaCursorY >= gpVesaCurMode->height/giVT_CharHeight) + giVideo_CursorX = ((tVideo_IOCtl_Pos*)Data)->x; + giVideo_CursorY = ((tVideo_IOCtl_Pos*)Data)->y; + if( giVideo_CursorX < 0 || giVesaCursorY < 0 + || giVideo_CursorX >= gpVesaCurMode->width/giVT_CharWidth + || giVideo_CursorY >= gpVesaCurMode->height/giVT_CharHeight) { #if BLINKING_CURSOR if(giVesaCursorTimer != -1) { diff --git a/AcessNative/ld-acess_src/common.h b/AcessNative/ld-acess_src/common.h index b544a459..05c288b2 100644 --- a/AcessNative/ld-acess_src/common.h +++ b/AcessNative/ld-acess_src/common.h @@ -17,6 +17,7 @@ extern uintptr_t FindFreeRange(size_t ByteCount, int MaxBits); extern void Warning(const char *Format, ...); extern void Notice(const char *Format, ...); +extern void Debug(const char *Format, ...); #define ACESS_SEEK_CUR 0 #define ACESS_SEEK_SET 1 diff --git a/AcessNative/ld-acess_src/main.c b/AcessNative/ld-acess_src/main.c index 8363ce69..598055f4 100644 --- a/AcessNative/ld-acess_src/main.c +++ b/AcessNative/ld-acess_src/main.c @@ -6,6 +6,9 @@ #include #include +// === IMPORTS === +extern int giSyscall_ClientID; + // === PROTOTYPES === void CallUser(void *Entry, int argc, char *argv[], char **envp) __attribute__((noreturn)); @@ -19,12 +22,12 @@ int main(int argc, char *argv[], char **envp) int (*appMain)(int, char *[], char **); void *base; - int syscall_handle = -1; +// int syscall_handle = -1; for( i = 1; i < argc; i ++ ) { if(strcmp(argv[i], "--key") == 0) { - syscall_handle = atoi(argv[++i]); + giSyscall_ClientID = atoi(argv[++i]); continue ; } @@ -61,19 +64,19 @@ int main(int argc, char *argv[], char **envp) appArgc = argc - i; appArgv = &argv[i]; - printf("Exectutable Path: '%s'\n", appPath); - printf("Executable argc = %i\n", appArgc); +// printf("Exectutable Path: '%s'\n", appPath); +// printf("Executable argc = %i\n", appArgc); base = Binary_Load(appPath, (uintptr_t*)&appMain); - printf("base = %p\n", base); + printf("[DEBUG %i] base = %p\n", giSyscall_ClientID, base); if( !base ) return 127; printf("==============================\n"); - printf("%i %p ", appArgc, appArgv); + printf("[DEBUG %i] %i %p ", giSyscall_ClientID, appArgc, appArgv); for(i = 0; i < appArgc; i ++) printf("\"%s\" ", appArgv[i]); printf("\n"); - printf("appMain = %p\n", appMain); + printf("[DEBUG %i] appMain = %p\n", giSyscall_ClientID, appMain); #if 0 __asm__ __volatile__ ( "push %0;\n\t" @@ -102,7 +105,7 @@ void CallUser(void *Entry, int argc, char *argv[], char **envp) void Warning(const char *Format, ...) { va_list args; - printf("Warning: "); + printf("[WARN %i] ", giSyscall_ClientID); va_start(args, Format); vprintf(Format, args); va_end(args); @@ -112,7 +115,17 @@ void Warning(const char *Format, ...) void Notice(const char *Format, ...) { va_list args; - printf("Notice: "); + printf("[NOTICE %i] ", giSyscall_ClientID); + va_start(args, Format); + vprintf(Format, args); + va_end(args); + printf("\n"); +} + +void Debug(const char *Format, ...) +{ + va_list args; + printf("[DEBUG %i] ", giSyscall_ClientID); va_start(args, Format); vprintf(Format, args); va_end(args); diff --git a/AcessNative/ld-acess_src/request.c b/AcessNative/ld-acess_src/request.c index 8655377e..b8a3239b 100644 --- a/AcessNative/ld-acess_src/request.c +++ b/AcessNative/ld-acess_src/request.c @@ -89,7 +89,8 @@ int _InitSyscalls() #if USE_TCP if( connect(gSocket, (struct sockaddr *)&gSyscall_ServerAddr, sizeof(struct sockaddr_in)) < 0 ) { - fprintf(stderr, "Cannot connect to server (localhost:%i)\n", SERVER_PORT); + fprintf(stderr, "[ERROR -] Cannot connect to server (localhost:%i)\n", SERVER_PORT); + fprintf(stderr, "[ERROR -] ", giSyscall_ClientID); perror("_InitSyscalls"); #if __WIN32__ closesocket(gSocket); @@ -119,6 +120,7 @@ int _InitSyscalls() #if !USE_TCP // Ask server for a client ID + if( !giSyscall_ClientID ) { tRequestHeader req; int len; @@ -210,6 +212,7 @@ void SendData(void *Data, int Length) #endif if( len != Length ) { + fprintf(stderr, "[ERROR %i] ", giSyscall_ClientID); perror("SendData"); exit(-1); } @@ -236,12 +239,13 @@ int ReadData(void *Dest, int MaxLength, int Timeout) ret = select(gSocket+1, &fds, NULL, NULL, timeoutPtr); if( ret == -1 ) { + fprintf(stderr, "[ERROR %i] ", giSyscall_ClientID); perror("ReadData - select"); exit(-1); } if( !ret ) { - printf("Timeout reading from socket\n"); + printf("[ERROR %i] Timeout reading from socket\n", giSyscall_ClientID); return 0; // Timeout } @@ -252,6 +256,7 @@ int ReadData(void *Dest, int MaxLength, int Timeout) #endif if( ret < 0 ) { + fprintf(stderr, "[ERROR %i] ", giSyscall_ClientID); perror("ReadData"); exit(-1); } diff --git a/AcessNative/ld-acess_src/syscalls.c b/AcessNative/ld-acess_src/syscalls.c index e3c78df8..54609561 100644 --- a/AcessNative/ld-acess_src/syscalls.c +++ b/AcessNative/ld-acess_src/syscalls.c @@ -12,7 +12,7 @@ #include "request.h" #include "../syscalls.h" -#define DEBUG(x...) printf(x) +#define DEBUG(str, x...) Debug(str, x) #define NATIVE_FILE_MASK 0x40000000 #define MAX_FPS 16 @@ -59,7 +59,7 @@ const char *ReadEntry(tRequestValue *Dest, void *DataDest, void **PtrDest, const case 'i': if( direction != 1 ) { - fprintf(stderr, "ReadEntry: Recieving an integer is not defined\n"); + Warning("ReadEntry: Recieving an integer is not defined"); return NULL; } @@ -271,7 +271,7 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) free( req ); free( retPtrs ); - DEBUG(": %llx\n", retValue); + DEBUG(": %llx", retValue); return retValue; } @@ -349,6 +349,7 @@ uint64_t acess_tell(int FD) { int acess_ioctl(int fd, int id, void *data) { // NOTE: 1024 byte size is a hack + DEBUG("ioctl(%i, %i, %p)", fd, id, data); return _Syscall(SYS_IOCTL, ">i >i ?d", fd, id, 1024, data); } int acess_finfo(int fd, t_sysFInfo *info, int maxacls) { @@ -359,9 +360,21 @@ int acess_finfo(int fd, t_sysFInfo *info, int maxacls) { } int acess_readdir(int fd, char *dest) { + DEBUG("readdir(%i, %p)", fd, dest); return _Syscall(SYS_READDIR, ">i i ?d ?d ?d >d", nfds, + read ? (nfds+7)/8 : 0, read, + write ? (nfds+7)/8 : 0, write, + error ? (nfds+7)/8 : 0, error, + sizeof(*timeout), timeout + ); +} + int acess__SysOpenChild(int fd, char *name, int flags) { return _Syscall(SYS_OPENCHILD, ">i >s >i", fd, name, flags); } @@ -408,7 +421,7 @@ int acess_clone(int flags, void *stack) return 0; } - // TODO: Return the acess TID instead + // Return the acess TID instead return kernel_tid; } else @@ -422,11 +435,11 @@ int acess_execve(char *path, char **argv, char **envp) { int i, argc; - printf("acess_execve: (path='%s', argv=%p, envp=%p)\n", path, argv, envp); + DEBUG("acess_execve: (path='%s', argv=%p, envp=%p)", path, argv, envp); // Get argument count for( argc = 0; argv[argc]; argc ++ ) ; - printf(" acess_execve: argc = %i\n", argc); + DEBUG(" acess_execve: argc = %i", argc); char *new_argv[5+argc+1]; char key[11]; @@ -470,6 +483,19 @@ int acess_setgid(int ID) return _Syscall(SYS_SETGID, ">i", ID); } +int acess_SysSendMessage(int DestTID, int Length, void *Data) +{ + return _Syscall(SYS_SENDMSG, ">i >d", DestTID, Length, Data); +} + +int acess_SysGetMessage(int *SourceTID, void *Data) +{ + return _Syscall(SYS_GETMSG, "i", Status); exit(Status); } @@ -507,6 +534,7 @@ const tSym caBuiltinSymbols[] = { DEFSYM(ioctl), DEFSYM(finfo), DEFSYM(readdir), + DEFSYM(select), DEFSYM(_SysOpenChild), DEFSYM(_SysGetACL), DEFSYM(_SysMount), @@ -518,6 +546,9 @@ const tSym caBuiltinSymbols[] = { DEFSYM(waittid), DEFSYM(setuid), DEFSYM(setgid), + + DEFSYM(SysSendMessage), + DEFSYM(SysGetMessage), DEFSYM(_SysAllocate), DEFSYM(_SysDebug), diff --git a/AcessNative/syscalls.h b/AcessNative/syscalls.h index b75a93d9..078944d1 100644 --- a/AcessNative/syscalls.h +++ b/AcessNative/syscalls.h @@ -56,6 +56,9 @@ enum eSyscalls { // IPC SYS_SLEEP, SYS_FORK, + SYS_SENDMSG, + SYS_GETMSG, + SYS_SELECT, N_SYSCALLS };