From 9143c184873d0b55444dc1c1084f3e9f3f2614bf Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 23 Jan 2011 21:34:53 +0800 Subject: [PATCH] Kernel - So... should remember to initialise structures - Forgot to clear the ret->Lock in IOCache_Create > Caused random locks if the lock protector was not 0 when malloc'd - Set up fractal mappings from boot > Exposed by trying to use Log_Debug before VMem was fully initialised --- AcessNative/ld-acess_src/syscalls.c | 15 +++++++++++++++ AcessNative/syscalls.h | 1 + Kernel/arch/x86/lib.c | 26 +++++++++++++++++++------- Kernel/arch/x86/start.asm | 10 ++++++---- Kernel/drv/iocache.c | 4 +--- Kernel/logging.c | 2 ++ Kernel/threads.c | 12 ++++++++++++ 7 files changed, 56 insertions(+), 14 deletions(-) diff --git a/AcessNative/ld-acess_src/syscalls.c b/AcessNative/ld-acess_src/syscalls.c index ff299973..02a59b90 100644 --- a/AcessNative/ld-acess_src/syscalls.c +++ b/AcessNative/ld-acess_src/syscalls.c @@ -265,6 +265,10 @@ void close(int FD) { _Syscall(SYS_CLOSE, ">i", FD); } +int reopen(int FD, const char *Path, int Flags) { + return _Syscall(SYS_REOPEN, ">i >s >i", FD, Path, Flags); +} + size_t read(int FD, size_t Bytes, void *Dest) { return _Syscall(SYS_READ, "i >i #include -#define TRACE_LOCKS 1 +#define TRACE_LOCKS 0 + +#if TRACE_LOCKS +struct sShortSpinlock glDebug_Lock; +#endif extern int GetCPUNum(void); @@ -107,7 +111,11 @@ void SHORTLOCK(struct sShortSpinlock *Lock) #endif #if TRACE_LOCKS - Log_Log("LOCK", "%p locked by %p\n", Lock, __builtin_return_address(0)); + if( Lock != &glDebug_Lock ) + { + //Log_Log("LOCK", "%p locked by %p", Lock, __builtin_return_address(0)); + LogF("Lock %p locked by %p\n", Lock, __builtin_return_address(0)); + } #endif } /** @@ -115,11 +123,7 @@ void SHORTLOCK(struct sShortSpinlock *Lock) * \param Lock Lock pointer */ void SHORTREL(struct sShortSpinlock *Lock) -{ - #if TRACE_LOCKS - Log_Log("LOCK", "%p released by %p\n", Lock, __builtin_return_address(0)); - #endif - +{ #if STACKED_LOCKS if( Lock->Depth ) { Lock->Depth --; @@ -127,6 +131,14 @@ void SHORTREL(struct sShortSpinlock *Lock) } #endif + #if TRACE_LOCKS + if( Lock != &glDebug_Lock ) + { + //Log_Log("LOCK", "%p released by %p", Lock, __builtin_return_address(0)); + LogF("Lock %p released by %p\n", Lock, __builtin_return_address(0)); + } + #endif + #if LOCK_DISABLE_INTS // Lock->IF can change anytime once Lock->Lock is zeroed if(Lock->IF) { diff --git a/Kernel/arch/x86/start.asm b/Kernel/arch/x86/start.asm index d161e699..0a4f920e 100644 --- a/Kernel/arch/x86/start.asm +++ b/Kernel/arch/x86/start.asm @@ -221,10 +221,12 @@ CallWithArgArray: [global gaInitPageTable] align 0x1000 gaInitPageDir: - dd gaInitPageTable-KERNEL_BASE+3 ; 0x00 - times 1024-256-1 dd 0 - dd gaInitPageTable-KERNEL_BASE+3 ; 0xC0 - times 256-1 dd 0 + dd gaInitPageTable-KERNEL_BASE+3 ; 0x000 - Low kernel + times 0x300-1 dd 0 + dd gaInitPageTable-KERNEL_BASE+3 ; 0xC00 - High kernel + times 0x3F0-0x300-1 dd 0 + dd gaInitPageDir-KERNEL_BASE+3 ; 0xFC0 - Fractal + times 0x400-0x3F0-1 dd 0 align 0x1000 gaInitPageTable: %assign i 0 diff --git a/Kernel/drv/iocache.c b/Kernel/drv/iocache.c index 743dabc4..271fc840 100644 --- a/Kernel/drv/iocache.c +++ b/Kernel/drv/iocache.c @@ -46,7 +46,7 @@ tIOCache *gIOCache_Caches = NULL; */ tIOCache *IOCache_Create( tIOCache_WriteCallback Write, Uint32 ID, int SectorSize, int CacheSize ) { - tIOCache *ret = malloc( sizeof(tIOCache) ); + tIOCache *ret = calloc( 1, sizeof(tIOCache) ); // Sanity Check if(!ret) return NULL; @@ -57,8 +57,6 @@ tIOCache *IOCache_Create( tIOCache_WriteCallback Write, Uint32 ID, int SectorSiz ret->ID = ID; ret->Write = Write; ret->CacheSize = CacheSize; - ret->CacheUsed = 0; - ret->Entries = 0; // Append to list SHORTLOCK( &glIOCache_Caches ); diff --git a/Kernel/logging.c b/Kernel/logging.c index 16503428..cb3c61cb 100644 --- a/Kernel/logging.c +++ b/Kernel/logging.c @@ -111,6 +111,8 @@ void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args) { #define LOG_HDR_LEN (14+1+2+8+2) char newData[ LOG_HDR_LEN + len + 2 + 1 ]; + char _ident[9]; + strncpy(_ident, Ident, 9); sprintf( newData, "%014lli%s [%+8s] ", ent->Time, csaLevelCodes[Level], Ident); strcpy( newData + LOG_HDR_LEN, ent->Data ); diff --git a/Kernel/threads.c b/Kernel/threads.c index c9a123d1..73c3f3c0 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -1174,6 +1174,12 @@ void Mutex_Acquire(tMutex *Mutex) Mutex->Owner = us; SHORTREL( &Mutex->Protector ); } + + #if 0 + extern tMutex glPhysAlloc; + if( Mutex != &glPhysAlloc ) + LogF("Mutex %p taken by %i %p\n", Mutex, us->TID, __builtin_return_address(0)); + #endif } /** @@ -1204,6 +1210,12 @@ void Mutex_Release(tMutex *Mutex) Mutex->Owner = NULL; } SHORTREL( &Mutex->Protector ); + + #if 0 + extern tMutex glPhysAlloc; + if( Mutex != &glPhysAlloc ) + LogF("Mutex %p released by %i %p\n", Mutex, Threads_GetTID(), __builtin_return_address(0)); + #endif } /** -- 2.20.1