From: John Hodge Date: Wed, 22 Jun 2011 09:36:42 +0000 (+0800) Subject: AcessNative - Fixing Fixing Fixing X-Git-Tag: rel0.10~61 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=717454930aa0e255517c68c837927deac49bd78e;p=tpg%2Facess2.git AcessNative - Fixing Fixing Fixing - Now can do stuff at the CLIShell prompt - Fixed some loading issues - Fixed debug in Kernel/VFS/io.c --- diff --git a/AcessNative/acesskernel_src/syscalls.c b/AcessNative/acesskernel_src/syscalls.c index f48b1a98..ec874161 100644 --- a/AcessNative/acesskernel_src/syscalls.c +++ b/AcessNative/acesskernel_src/syscalls.c @@ -73,8 +73,10 @@ SYSCALL1(Syscall_Close, "i", int, return 0; ); SYSCALL3(Syscall_Read, "iid", int, int, void *, - if( Sizes[2] < a1 ) + if( Sizes[2] < a1 ) { + Log_Warning("Syscalls", "Read - %i < %i", Sizes[2], a1); return -1; + } return VFS_Read(a0, a1, a2); ); SYSCALL3(Syscall_Write, "iid", int, int, const void *, @@ -112,6 +114,9 @@ SYSCALL2(Syscall_GetACL, "id", int, void *, SYSCALL4(Syscall_Mount, "ssss", const char *, const char *, const char *, const char *, return VFS_Mount(a0, a1, a2, a3); ); +SYSCALL1(Syscall_Chdir, "s", const char *, + return VFS_ChDir(a0); +); SYSCALL0(Syscall_Sleep, Threads_Sleep(); return 0; @@ -156,6 +161,7 @@ const tSyscallHandler caSyscalls[] = { Syscall_GetACL, Syscall_Mount, NULL, // SYS_REOPEN + Syscall_Chdir, Syscall_WaitTID, Syscall_SetUID, @@ -306,7 +312,7 @@ tRequestHeader *SyscallRecieve(tRequestHeader *Request, int *ReturnLength) *(Uint64*)inData = retVal; inData += sizeof(Uint64); - LOG("Syscalls", "Return 0x%llx", retVal); + Log_Debug("Syscalls", "Return 0x%llx", retVal); retValueCount = 1; for( i = 0; i < Request->NParams; i ++ ) diff --git a/AcessNative/acesskernel_src/threads.c b/AcessNative/acesskernel_src/threads.c index 9d125178..34659926 100644 --- a/AcessNative/acesskernel_src/threads.c +++ b/AcessNative/acesskernel_src/threads.c @@ -92,6 +92,19 @@ void Threads_Dump(void) } } +void Threads_SetThread(int TID) +{ + tThread *thread; + for( thread = gpThreads; thread; thread = thread->GlobalNext ) + { + if( thread->TID == TID ) { + gpCurrentThread = thread; + return ; + } + } + Log_Error("Threads", "_SetThread - Thread %i is not on global list", TID); +} + tThread *Threads_GetThread(int TID) { tThread *thread; @@ -156,6 +169,8 @@ int Threads_SetGID(int *Errno, tGID NewGID) Uint *Threads_GetCfgPtr(int Index) { +// Log_Debug("Threads", "Index=%i, gpCurrentThread=%p", +// Index, gpCurrentThread); if( Index < 0 || Index >= NUM_CFG_ENTRIES ) return NULL; if( !gpCurrentThread ) diff --git a/AcessNative/acesskernel_src/vfs_handle.c b/AcessNative/acesskernel_src/vfs_handle.c index 91caeffe..4d1e00d2 100644 --- a/AcessNative/acesskernel_src/vfs_handle.c +++ b/AcessNative/acesskernel_src/vfs_handle.c @@ -2,7 +2,7 @@ * Acess2 VFS * - AllocHandle, GetHandle */ -#define DEBUG 1 +#define DEBUG 0 #include #include #include @@ -37,7 +37,8 @@ tUserHandles *VFS_int_GetUserHandles(int PID, int bCreate) tUserHandles *ent, *prev = NULL; for( ent = gpUserHandles; ent; prev = ent, ent = ent->Next ) { if( ent->PID == PID ) { - Log_Warning("VFS", "Process %i already has a handle list", PID); + if( bCreate ) + Log_Warning("VFS", "Process %i already has a handle list", PID); return ent; } if( ent->PID > PID ) break; diff --git a/AcessNative/ld-acess_src/binary.c b/AcessNative/ld-acess_src/binary.c index 6439fb96..3ae8d7f1 100644 --- a/AcessNative/ld-acess_src/binary.c +++ b/AcessNative/ld-acess_src/binary.c @@ -96,7 +96,7 @@ void *Binary_LoadLibrary(const char *Name) { char *path; void *ret; - int (*entry)(int,char*[],char**) = NULL; + int (*entry)(void *,int,char*[],char**) = NULL; // Find File path = Binary_LocateLibrary(Name); @@ -108,6 +108,7 @@ void *Binary_LoadLibrary(const char *Name) } ret = Binary_Load(path, (uintptr_t*)&entry); + printf("LOADED '%s' to %p (Entry=%p)\n", path, ret, entry); free(path); #if DEBUG @@ -118,7 +119,7 @@ void *Binary_LoadLibrary(const char *Name) #if DEBUG printf("Calling '%s' entry point %p\n", Name, entry); #endif - entry(0, argv, NULL); + entry(ret, 0, argv, NULL); } return ret; diff --git a/AcessNative/ld-acess_src/main.c b/AcessNative/ld-acess_src/main.c index 852b3981..8363ce69 100644 --- a/AcessNative/ld-acess_src/main.c +++ b/AcessNative/ld-acess_src/main.c @@ -6,6 +6,9 @@ #include #include +// === PROTOTYPES === +void CallUser(void *Entry, int argc, char *argv[], char **envp) __attribute__((noreturn)); + // === CODE === int main(int argc, char *argv[], char **envp) { @@ -42,7 +45,13 @@ int main(int argc, char *argv[], char **envp) } if( i >= argc ) { - fprintf(stderr, "Usage: ld-acess [arguments ...]\n"); + fprintf(stderr, + "Usage: ld-acess [arguments ...]\n" + "\n" + "--key\t(internal) used to pass the system call handle when run with execve\n" + "--binary\tLoad a local binary directly\n" + "--open\tOpen a file before executing\n" + ); return 1; } @@ -60,9 +69,12 @@ int main(int argc, char *argv[], char **envp) if( !base ) return 127; printf("==============================\n"); + printf("%i %p ", appArgc, appArgv); for(i = 0; i < appArgc; i ++) printf("\"%s\" ", appArgv[i]); printf("\n"); + printf("appMain = %p\n", appMain); + #if 0 __asm__ __volatile__ ( "push %0;\n\t" "push %1;\n\t" @@ -70,6 +82,21 @@ int main(int argc, char *argv[], char **envp) "jmp *%3;\n\t" : : "r" (envp), "r" (appArgv), "r" (appArgc), "r" (appMain) ); return -1; + #elif 1 + CallUser(appMain, appArgc, appArgv, envp); + #else + return appMain(appArgc, appArgv, NULL); + #endif +} + +void CallUser(void *Entry, int argc, char *argv[], char **envp) +{ + __asm__ __volatile__ ( + "mov %1, %%esp;\n\t" + "jmp *%0" + : : "r" (Entry), "r" (&argc) + ); + for(;;); } void Warning(const char *Format, ...) diff --git a/AcessNative/ld-acess_src/syscalls.c b/AcessNative/ld-acess_src/syscalls.c index 5fbecbd2..e3c78df8 100644 --- a/AcessNative/ld-acess_src/syscalls.c +++ b/AcessNative/ld-acess_src/syscalls.c @@ -277,6 +277,11 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) } // --- VFS Calls +int acess_chdir(const char *Path) +{ + return _Syscall(SYS_CHDIR, ">s", Path); +} + int acess_open(const char *Path, int Flags) { if( strncmp(Path, "$$$$", 4) == 0 ) @@ -491,6 +496,7 @@ void acess__exit(int Status) const tSym caBuiltinSymbols[] = { DEFSYM(_exit), + DEFSYM(chdir), DEFSYM(open), DEFSYM(close), DEFSYM(reopen), diff --git a/AcessNative/syscalls.h b/AcessNative/syscalls.h index 158a6ccb..b75a93d9 100644 --- a/AcessNative/syscalls.h +++ b/AcessNative/syscalls.h @@ -47,6 +47,7 @@ enum eSyscalls { SYS_GETACL, SYS_MOUNT, SYS_REOPEN, + SYS_CHDIR, SYS_WAITTID, SYS_SETUID, diff --git a/Kernel/vfs/io.c b/Kernel/vfs/io.c index 67d384c1..7260df70 100644 --- a/Kernel/vfs/io.c +++ b/Kernel/vfs/io.c @@ -2,22 +2,11 @@ * AcessMicro VFS * - File IO Passthru's */ +#define DEBUG 0 #include #include "vfs.h" #include "vfs_int.h" -#define DEBUG 0 - -#if DEBUG -#else -# undef ENTER -# undef LOG -# undef LEAVE -# define ENTER(...) -# define LOG(...) -# define LEAVE(...) -#endif - // === CODE === /** * \fn Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer) @@ -31,23 +20,15 @@ Uint64 VFS_Read(int FD, Uint64 Length, void *Buffer) ENTER("iFD XLength pBuffer", FD, Length, Buffer); h = VFS_GetHandle(FD); - if(!h) return -1; + if(!h) LEAVE_RET('i', -1); - if( !(h->Mode & VFS_OPENFLAG_READ) || h->Node->Flags & VFS_FFLAG_DIRECTORY ) { - LEAVE('i', -1); - return -1; - } + if( !(h->Mode & VFS_OPENFLAG_READ) || h->Node->Flags & VFS_FFLAG_DIRECTORY ) + LEAVE_RET('i', -1); - if(!h->Node->Read) { - LEAVE('i', 0); - return 0; - } + if(!h->Node->Read) LEAVE_RET('i', 0); ret = h->Node->Read(h->Node, h->Position, Length, Buffer); - if(ret == -1) { - LEAVE('i', -1); - return -1; - } + if(ret == -1) LEAVE_RET('i', -1); h->Position += ret; LEAVE('X', ret); diff --git a/Modules/Input/PS2KbMouse/kb.c b/Modules/Input/PS2KbMouse/kb.c index 07170a26..d8ef32ee 100644 --- a/Modules/Input/PS2KbMouse/kb.c +++ b/Modules/Input/PS2KbMouse/kb.c @@ -55,16 +55,19 @@ Uint8 gbaKB_States[3][256]; */ int KB_Install(char **Arguments) { - Uint8 temp; - - // Attempt to get around a strange bug in Bochs/Qemu by toggling - // the controller on and off - temp = inb(0x61); - outb(0x61, temp | 0x80); - outb(0x61, temp & 0x7F); - inb(0x60); // Clear keyboard buffer IRQ_AddHandler(1, KB_IRQHandler); + + { + Uint8 temp; + // Attempt to get around a strange bug in Bochs/Qemu by toggling + // the controller on and off + temp = inb(0x61); + outb(0x61, temp | 0x80); + outb(0x61, temp & 0x7F); + inb(0x60); // Clear keyboard buffer + } + DevFS_AddDevice( &gKB_DevInfo ); //Log("KB_Install: Installed"); return MODULE_ERR_OK; diff --git a/Usermode/Libraries/libreadline.so_src/main.c b/Usermode/Libraries/libreadline.so_src/main.c index a07b052c..58bcb43d 100644 --- a/Usermode/Libraries/libreadline.so_src/main.c +++ b/Usermode/Libraries/libreadline.so_src/main.c @@ -81,6 +81,7 @@ char *Readline_NonBlock(tReadline *Info) // Read as much as possible (appending to remaining data) len = read(STDIN_FD, READ_BUFFER_SIZE - 1 - Info->ReadBufferLen, Info->ReadBuffer); + if( len <= 0 ) return NULL; Info->ReadBuffer[Info->ReadBufferLen + len] = '\0'; // Parse the data we have diff --git a/Usermode/include/sys/sys.h b/Usermode/include/sys/sys.h index d932eb33..a934f75a 100644 --- a/Usermode/include/sys/sys.h +++ b/Usermode/include/sys/sys.h @@ -27,7 +27,7 @@ extern int close(int fp); extern int read(int fp, int len, void *buf); extern int write(int fp, int len, void *buf); extern int tell(int fp); -extern void seek(int fp, int64_t dist, int flag); +extern void seek(int fp, int64_t dist, int flag); extern int fstat(int fp, t_fstat *st); extern int ioctl(int fp, int call, void *arg); extern int readdir(int fp, char *file);