- Misc changes
authorJohn Hodge <[email protected]>
Tue, 18 Jan 2011 23:44:34 +0000 (07:44 +0800)
committerJohn Hodge <[email protected]>
Tue, 18 Jan 2011 23:44:34 +0000 (07:44 +0800)
- Tracing case where interrupts are disabled
 > In the x86 build, somewhere (in some cases) IF is cleared when it should
   not be, causing a system lock up.
- Sped up Heap_Allocate with __Bytes == 0 (returns an non-null invalid pointer)

Kernel/Makefile.BuildNum.x86_64
Kernel/arch/x86/include/arch.h
Kernel/arch/x86/irq.c
Kernel/arch/x86/lib.c
Kernel/arch/x86_64/include/arch.h
Kernel/heap.c

index c4b3a2e..109f650 100644 (file)
@@ -10,6 +10,8 @@
 #define        KERNEL_BASE     0xC0000000
 #define BITS   32
 
+#define INVLPTR        ((void*)-1)
+
 // Allow nested spinlocks?
 #define STACKED_LOCKS  2       // 0: No, 1: Per-CPU, 2: Per-Thread
 #define LOCK_DISABLE_INTS      1
index 7ff1fe9..e08f1ba 100644 (file)
@@ -6,6 +6,7 @@
 
 // === CONSTANTS ===
 #define        MAX_CALLBACKS_PER_IRQ   4
+#define TRACE_IRQS     0
 
 // === TYPES ===
 typedef void (*tIRQ_Callback)(int);
@@ -28,9 +29,13 @@ void IRQ_Handler(tRegs *Regs)
 
        for( i = 0; i < MAX_CALLBACKS_PER_IRQ; i++ )
        {
-               //Log(" IRQ_Handler: Call %p", gIRQ_Handlers[Regs->int_num][i]);
-               if( gIRQ_Handlers[Regs->int_num][i] )
+               if( gIRQ_Handlers[Regs->int_num][i] ) {
                        gIRQ_Handlers[Regs->int_num][i](Regs->int_num);
+                       #if TRACE_IRQS
+                       if( Regs->int_num != 8 )
+                               Log("IRQ %i: Call %p", Regs->int_num, gIRQ_Handlers[Regs->int_num][i]);
+                       #endif
+               }
        }
 
        //Log(" IRQ_Handler: Resetting");
index 1f56394..86117cc 100644 (file)
@@ -58,8 +58,8 @@ void SHORTLOCK(struct sShortSpinlock *Lock)
        #endif
        
        #if LOCK_DISABLE_INTS
-       // Save interrupt state and clear interrupts
-       __ASM__ ("pushf;\n\tpop %%eax\n\tcli" : "=a"(IF));
+       // Save interrupt state
+       __ASM__ ("pushf;\n\tpop %0" : "=r"(IF));
        IF &= 0x200;    // AND out all but the interrupt flag
        #endif
        
@@ -93,9 +93,14 @@ void SHORTLOCK(struct sShortSpinlock *Lock)
                #else
                __ASM__("xchgl %%eax, (%%edi)":"=a"(v):"a"(1),"D"(&Lock->Lock));
                #endif
+               
+               #if LOCK_DISABLE_INTS
+               if( v ) __ASM__("sti"); // Re-enable interrupts
+               #endif
        }
        
        #if LOCK_DISABLE_INTS
+       __ASM__("cli");
        Lock->IF = IF;
        #endif
 }
index 78b2acc..038b638 100644 (file)
@@ -13,6 +13,8 @@
 #define STACKED_LOCKS  0
 #define LOCK_DISABLE_INTS      1
 
+#define INVLPTR        ((void*)0x0FFFFFFFFFFFFFFFULL)
+
 //#define INT_MAX      0x7FFFFFFF
 //#define UINT_MAX     0xFFFFFFFF
 
index abf5f27..34dd5f2 100644 (file)
@@ -143,6 +143,11 @@ void *Heap_Allocate(const char *File, int Line, size_t __Bytes)
        tHeapHead       *best = NULL;
        Uint    bestSize = 0;   // Speed hack
        size_t  Bytes;
+
+       if( __Bytes == 0 ) {
+               //return NULL;  // TODO: Return a known un-mapped range.
+               return INVLPTR;
+       }
        
        // Get required size
        #if POW2_SIZES
@@ -277,6 +282,10 @@ void Heap_Deallocate(void *Ptr)
        Log_Log("Heap", "free: Returns to %p", __builtin_return_address(0));
        #endif
        
+       // INVLPTR is returned from Heap_Allocate when the allocation
+       // size is zero.
+       if( Ptr == INVLPTR )    return;
+       
        // Alignment Check
        if( (Uint)Ptr & (sizeof(Uint)-1) ) {
                Log_Warning("Heap", "free - Passed a non-aligned address (%p)", Ptr);
@@ -644,8 +653,8 @@ void Heap_Stats(void)
                
                // Print the block info?
                #if 1
-               Log_Debug("Heap", "%p - 0x%x Owned by %s:%i",
-                       head, head->Size, head->File, head->Line);
+               Log_Debug("Heap", "%p - 0x%x (%i) Owned by %s:%i",
+                       head, head->Size, head->ValidSize, head->File, head->Line);
                #endif
        }
 

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