From: John Hodge Date: Tue, 7 Feb 2012 08:34:10 +0000 (+0800) Subject: AcessNative - Fixing for recent kernel changes X-Git-Tag: rel0.15~789^2~9 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=6bcb63ea0505129d32b249772b554b0848bb5612;p=tpg%2Facess2.git AcessNative - Fixing for recent kernel changes --- diff --git a/AcessNative/acesskernel_src/Makefile b/AcessNative/acesskernel_src/Makefile index ec64b5fe..a9b7278e 100644 --- a/AcessNative/acesskernel_src/Makefile +++ b/AcessNative/acesskernel_src/Makefile @@ -17,7 +17,8 @@ KERNEL_OBJ := logging.o adt.o lib.o drvutil.o debug.o KERNEL_OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/io.o vfs/dir.o 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 +KERNEL_OBJ += drv/fifo.o drv/proc.o +KERNEL_OBJ += drv/vterm.o drv/vterm_font.o drv/vterm_vt100.o drv/vterm_output.o drv/vterm_input.o drv/vterm_termbuf.o N_OBJ := main.o diff --git a/AcessNative/acesskernel_src/keyboard.c b/AcessNative/acesskernel_src/keyboard.c index 329e003d..f008fd81 100644 --- a/AcessNative/acesskernel_src/keyboard.c +++ b/AcessNative/acesskernel_src/keyboard.c @@ -15,13 +15,12 @@ // === GLOBALS === MODULE_DEFINE(0, 0x0100, NativeKeyboard, NativeKeyboard_Install, NULL, NULL); +tVFS_NodeType gKB_NodeType = { + .IOCtl = NativeKeyboard_IOCtl +}; tDevFS_Driver gKB_DevInfo = { NULL, "NativeKeyboard", - { - .NumACLs = 0, - .Size = 0, - .IOCtl = NativeKeyboard_IOCtl - } + { .Type = &gKB_NodeType } }; // === CODE === diff --git a/AcessNative/acesskernel_src/nativefs.c b/AcessNative/acesskernel_src/nativefs.c index ca2f7dfe..8490dd13 100644 --- a/AcessNative/acesskernel_src/nativefs.c +++ b/AcessNative/acesskernel_src/nativefs.c @@ -33,6 +33,13 @@ char *NativeFS_ReadDir(tVFS_Node *Node, int Position); Uint64 NativeFS_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); // === GLOBALS === +tVFS_NodeType gNativeFS_FileNodeType = { + .Read = NativeFS_Read +}; +tVFS_NodeType gNativeFS_DirNodeType = { + .FindDir = NativeFS_FindDir, + .ReadDir = NativeFS_ReadDir, +}; tVFS_Driver gNativeFS_Driver = { "nativefs", 0, NativeFS_Mount, NativeFS_Unmount, @@ -70,9 +77,8 @@ tVFS_Node *NativeFS_Mount(const char *Device, const char **Arguments) ret->ImplInt = strlen(ret->Data); ret->ImplPtr = info; ret->Inode = (Uint64)dp; - - ret->FindDir = NativeFS_FindDir; - ret->ReadDir = NativeFS_ReadDir; + + ret->Type = &gNativeFS_DirNodeType; return ret; } @@ -124,8 +130,7 @@ tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name) { LOG("Directory"); baseRet.Inode = (Uint64) opendir(path); - baseRet.FindDir = NativeFS_FindDir; - baseRet.ReadDir = NativeFS_ReadDir; + baseRet.Type = &gNativeFS_DirNodeType; baseRet.Flags |= VFS_FFLAG_DIRECTORY; baseRet.Size = -1; } @@ -133,7 +138,7 @@ tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name) { LOG("File"); baseRet.Inode = (Uint64) fopen(path, "r+"); - baseRet.Read = NativeFS_Read; + baseRet.Type = &gNativeFS_FileNodeType; fseek( (FILE*)(tVAddr)baseRet.Inode, 0, SEEK_END ); baseRet.Size = ftell( (FILE*)(tVAddr)baseRet.Inode ); diff --git a/AcessNative/acesskernel_src/syscalls.c b/AcessNative/acesskernel_src/syscalls.c index 84eb416f..4d85e8c6 100644 --- a/AcessNative/acesskernel_src/syscalls.c +++ b/AcessNative/acesskernel_src/syscalls.c @@ -16,6 +16,18 @@ extern int Threads_Fork(void); // AcessNative only function typedef int (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int *Sizes); // === MACROS === +#define SYSCALL6(_name, _fmtstr, _t0, _t1, _t2, _t3, _t4, _t5, _call) int _name(Uint*Errno,const char*Fmt,void*Args,int*Sizes){\ + _t0 a0;_t1 a1;_t2 a2;_t3 a3;_t4 a4;_t5 a5;\ + 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);\ + a5 = *(_t5*)Args;Args+=sizeof(_t5);\ + LOG("SYSCALL5 '%s' %p %p %p %p %p %p", Fmt, (intptr_t)a0,(intptr_t)a1,(intptr_t)a2,(intptr_t)a3,(intptr_t)a4,(intptr_t)a5);\ + _call\ +} #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;\ @@ -124,8 +136,8 @@ 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); +SYSCALL6(Syscall_select, "iddddi", int, fd_set *, fd_set *, fd_set *, time_t *, unsigned int, + return VFS_Select(a0, a1, a2, a3, a4, a5, 0); ); SYSCALL3(Syscall_OpenChild, "isi", int, const char *, int, return VFS_OpenChild(a0, a1, a2|VFS_OPENFLAG_USER); @@ -155,14 +167,14 @@ SYSCALL1(Syscall_SetUID, "i", int, *Errno = -EINVAL; // TODO: Better message return -1; } - return Threads_SetUID(Errno, a0); + return Threads_SetUID(a0); ); SYSCALL1(Syscall_SetGID, "i", int, if(Sizes[0] < sizeof(int)) { *Errno = -EINVAL; // TODO: Better message return -1; } - return Threads_SetGID(Errno, a0); + return Threads_SetGID(a0); ); SYSCALL1(Syscall_Fork, "d", int *, diff --git a/AcessNative/acesskernel_src/threads.c b/AcessNative/acesskernel_src/threads.c index dc4d643a..1e7d0c3f 100644 --- a/AcessNative/acesskernel_src/threads.c +++ b/AcessNative/acesskernel_src/threads.c @@ -32,6 +32,15 @@ typedef struct sState } tState; #endif +typedef struct sProcess +{ + int nThreads; + int NativePID; + char *CWD; + char *Chroot; + int MaxFD; +} tProcess; + typedef struct sThread { struct sThread *GlobalNext; @@ -48,9 +57,7 @@ typedef struct sThread int State; // 0: Dead, 1: Active, 2: Paused, 3: Asleep int ExitStatus; - #if 0 - tState CurState; - #endif + int _errno; // Threads waiting for this thread to exit. // Quit logic: @@ -61,23 +68,35 @@ typedef struct sThread struct sThread *WaitingThreads; struct sThread *WaitingThreadsEnd; - // Config? - Uint Config[NUM_CFG_ENTRIES]; + tProcess *Process; + } tThread; // === PROTOTYPES === int Threads_Wake(tThread *Thread); // === GLOBALS === +tProcess gProcessZero = { + .NativePID = 0, + .CWD = "/", + .Chroot = "/", + .MaxFD = 100 +}; tThread gThreadZero = { .State=1, - .ThreadName="ThreadZero" + .ThreadName="ThreadZero", + .Process = &gProcessZero }; tThread *gpThreads = &gThreadZero; __thread tThread *gpCurrentThread = &gThreadZero; int giThreads_NextThreadID = 1; // === CODE === +tThread *Proc_GetCurThread(void) +{ + return gpCurrentThread; +} + void Threads_Dump(void) { tThread *thread; @@ -167,16 +186,10 @@ int Threads_SetGID(int *Errno, tGID NewGID) return 0; } -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 ) - return NULL; - return &gpCurrentThread->Config[Index]; -} +int *Threads_GetErrno(void) { return &gpCurrentThread->_errno; } +char **Threads_GetCWD(void) { return &gpCurrentThread->Process->CWD; } +char **Threads_GetChroot(void) { return &gpCurrentThread->Process->Chroot; } +int *Threads_GetMaxFD(void) { return &gpCurrentThread->Process->MaxFD; }; int Threads_WaitTID(int TID, int *Status) { @@ -346,35 +359,3 @@ int Semaphore_Signal(tSemaphore *Sem, int AmmountToAdd) return AmmountToAdd; } -#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 - diff --git a/AcessNative/acesskernel_src/ui.h b/AcessNative/acesskernel_src/ui.h index 24298b91..80241daf 100644 --- a/AcessNative/acesskernel_src/ui.h +++ b/AcessNative/acesskernel_src/ui.h @@ -13,7 +13,7 @@ extern const int giUI_Pitch; extern const Uint32 * const gUI_Framebuffer; extern void UI_SetWindowDims(int Width, int Height); -extern void UI_BlitBitmap(int DstX, int DstY, int SrcW, int SrcH, Uint32 *Bitmap); +extern void UI_BlitBitmap(int DstX, int DstY, int SrcW, int SrcH, const Uint32 *Bitmap); extern void UI_BlitFramebuffer(int DstX, int DstY, int SrcX, int SrcY, int W, int H); extern void UI_FillBitmap(int DstX, int DstY, int SrcW, int SrcH, Uint32 Value); extern void UI_Redraw(void); diff --git a/AcessNative/acesskernel_src/vfs_handle.c b/AcessNative/acesskernel_src/vfs_handle.c index 4d1e00d2..cfe04898 100644 --- a/AcessNative/acesskernel_src/vfs_handle.c +++ b/AcessNative/acesskernel_src/vfs_handle.c @@ -7,6 +7,7 @@ #include #include #include +#include // === CONSTANTS === #define MAX_KERNEL_FILES 128 @@ -68,21 +69,22 @@ void VFS_CloneHandleList(int PID) { tUserHandles *ent; tUserHandles *cur; - int i; + int i, maxhandles; cur = VFS_int_GetUserHandles(Threads_GetPID(), 0); if(!cur) return ; // Don't need to do anything if the current list is empty ent = VFS_int_GetUserHandles(PID, 1); - memcpy(ent->Handles, cur->Handles, CFGINT(CFG_VFS_MAXFILES)*sizeof(tVFS_Handle)); + maxhandles = *Threads_GetMaxFD(); + memcpy(ent->Handles, cur->Handles, maxhandles*sizeof(tVFS_Handle)); - for( i = 0; i < CFGINT(CFG_VFS_MAXFILES); i ++ ) + for( i = 0; i < maxhandles; i ++ ) { if(!cur->Handles[i].Node) continue; - if(ent->Handles[i].Node->Reference) - ent->Handles[i].Node->Reference(ent->Handles[i].Node); + if(ent->Handles[i].Node->Type->Reference) + ent->Handles[i].Node->Type->Reference(ent->Handles[i].Node); } } @@ -113,6 +115,7 @@ tVFS_Handle *VFS_GetHandle(int FD) { tUserHandles *ent; int pid = Threads_GetPID(); + int maxhandles = *Threads_GetMaxFD(); ent = VFS_int_GetUserHandles(pid, 0); if(!ent) { @@ -120,8 +123,8 @@ tVFS_Handle *VFS_GetHandle(int FD) return NULL; } - if(FD >= CFGINT(CFG_VFS_MAXFILES)) { - LOG("FD (%i) > Limit (%i), RETURN NULL", FD, CFGINT(CFG_VFS_MAXFILES)); + if(FD >= maxhandles) { + LOG("FD (%i) > Limit (%i), RETURN NULL", FD, maxhandles); return NULL; } h = &ent->Handles[ FD ]; @@ -144,10 +147,11 @@ int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode) if(bIsUser) { tUserHandles *ent; + int maxhandles = *Threads_GetMaxFD(); // Find the PID's handle list ent = VFS_int_GetUserHandles(Threads_GetPID(), 1); // Get a handle - for(i=0;iHandles[i].Node) continue; ent->Handles[i].Node = Node; diff --git a/AcessNative/acesskernel_src/video.c b/AcessNative/acesskernel_src/video.c index 304a9cf4..5408b56e 100644 --- a/AcessNative/acesskernel_src/video.c +++ b/AcessNative/acesskernel_src/video.c @@ -15,7 +15,7 @@ // === PROTOTYPES === int Video_Install(char **Arguments); Uint64 Video_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); -Uint64 Video_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); +Uint64 Video_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer); int Video_IOCtl(tVFS_Node *Node, int ID, void *Data); // --- 2D Acceleration Functions -- void Video_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour); @@ -23,13 +23,14 @@ void Video_2D_Blit(void *Ent, Uint16 DstX, Uint16 DstY, Uint16 SrcX, Uint16 SrcY // === GLOBALS === //MODULE_DEFINE(0, VERSION, NativeVideo, Video_Install, NULL, NULL); -tDevFS_Driver gVideo_DriverStruct = { - NULL, "NativeVideo", - { +tVFS_NodeType gVideo_NodeType = { .Read = Video_Read, .Write = Video_Write, .IOCtl = Video_IOCtl - } +}; +tDevFS_Driver gVideo_DriverStruct = { + NULL, "NativeVideo", + {.Type = &gVideo_NodeType} }; int giVideo_DriverID; int giVideo_CurrentFormat; @@ -62,7 +63,7 @@ Uint64 Video_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) /** * \brief Write to the framebuffer */ -Uint64 Video_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +Uint64 Video_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) { int i; ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer); @@ -76,7 +77,7 @@ Uint64 Video_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) { case VIDEO_BUFFMT_TEXT: { - tVT_Char *chars = Buffer; + const tVT_Char *chars = Buffer; // int pitch = giUI_Pitch; int widthInChars = giUI_Width/giVT_CharWidth; int heightInChars = giUI_Height/giVT_CharHeight;