Kernel - So... should remember to initialise structures
authorJohn Hodge <[email protected]>
Sun, 23 Jan 2011 13:34:53 +0000 (21:34 +0800)
committerJohn Hodge <[email protected]>
Sun, 23 Jan 2011 13:34:53 +0000 (21:34 +0800)
- 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
AcessNative/syscalls.h
Kernel/arch/x86/lib.c
Kernel/arch/x86/start.asm
Kernel/drv/iocache.c
Kernel/logging.c
Kernel/threads.c

index ff29997..02a59b9 100644 (file)
@@ -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 >i <d", FD, Bytes, Bytes, Dest);
 }
@@ -314,6 +318,14 @@ int        _SysSetFaultHandler(int (*Handler)(int)) {
        return 0;
 }
 
+// --- Memory Management ---
+uint64_t _SysAllocate(uint vaddr)
+{
+       if( AllocateMemory(vaddr, 0x1000) == -1 )       // Allocate a page
+               return 0;
+       return vaddr;   // Just ignore the need for paddrs :)
+}
+
 
 // === Symbol List ===
 #define DEFSYM(name)   {#name, name}
@@ -322,6 +334,7 @@ const tSym  caBuiltinSymbols[] = {
        
        DEFSYM(open),
        DEFSYM(close),
+       DEFSYM(reopen),
        DEFSYM(read),
        DEFSYM(write),
        DEFSYM(seek),
@@ -333,6 +346,8 @@ const tSym  caBuiltinSymbols[] = {
        DEFSYM(_SysGetACL),
        DEFSYM(_SysMount),
        
+       DEFSYM(_SysAllocate),
+       
        {"_SysSetFaultHandler", _SysSetFaultHandler}
 };
 
index 4a64474..b4d211c 100644 (file)
@@ -43,6 +43,7 @@ enum eSyscalls {
        SYS_OPENCHILD,
        SYS_GETACL,
        SYS_MOUNT,
+       SYS_REOPEN,
        N_SYSCALLS
 };
 
index 2160805..796baa4 100644 (file)
@@ -5,7 +5,11 @@
 #include <acess.h>
 #include <threads.h>
 
-#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) {
index d161e69..0a4f920 100644 (file)
@@ -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
index 743dabc..271fc84 100644 (file)
@@ -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 );
index 1650342..cb3c61c 100644 (file)
@@ -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 );
index c9a123d..73c3f3c 100644 (file)
@@ -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
 }
 
 /**

UCC git Repository :: git.ucc.asn.au