Skip to content
Snippets Groups Projects
Commit c4088eaf authored by John Hodge's avatar John Hodge
Browse files

- Misc changes

- 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)
parent 4726431c
No related merge requests found
BUILD_NUM = 223 BUILD_NUM = 224
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#define KERNEL_BASE 0xC0000000 #define KERNEL_BASE 0xC0000000
#define BITS 32 #define BITS 32
#define INVLPTR ((void*)-1)
// Allow nested spinlocks? // Allow nested spinlocks?
#define STACKED_LOCKS 2 // 0: No, 1: Per-CPU, 2: Per-Thread #define STACKED_LOCKS 2 // 0: No, 1: Per-CPU, 2: Per-Thread
#define LOCK_DISABLE_INTS 1 #define LOCK_DISABLE_INTS 1
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
// === CONSTANTS === // === CONSTANTS ===
#define MAX_CALLBACKS_PER_IRQ 4 #define MAX_CALLBACKS_PER_IRQ 4
#define TRACE_IRQS 0
// === TYPES === // === TYPES ===
typedef void (*tIRQ_Callback)(int); typedef void (*tIRQ_Callback)(int);
...@@ -28,9 +29,13 @@ void IRQ_Handler(tRegs *Regs) ...@@ -28,9 +29,13 @@ void IRQ_Handler(tRegs *Regs)
for( i = 0; i < MAX_CALLBACKS_PER_IRQ; i++ ) 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); 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"); //Log(" IRQ_Handler: Resetting");
......
...@@ -58,8 +58,8 @@ void SHORTLOCK(struct sShortSpinlock *Lock) ...@@ -58,8 +58,8 @@ void SHORTLOCK(struct sShortSpinlock *Lock)
#endif #endif
#if LOCK_DISABLE_INTS #if LOCK_DISABLE_INTS
// Save interrupt state and clear interrupts // Save interrupt state
__ASM__ ("pushf;\n\tpop %%eax\n\tcli" : "=a"(IF)); __ASM__ ("pushf;\n\tpop %0" : "=r"(IF));
IF &= 0x200; // AND out all but the interrupt flag IF &= 0x200; // AND out all but the interrupt flag
#endif #endif
...@@ -93,9 +93,14 @@ void SHORTLOCK(struct sShortSpinlock *Lock) ...@@ -93,9 +93,14 @@ void SHORTLOCK(struct sShortSpinlock *Lock)
#else #else
__ASM__("xchgl %%eax, (%%edi)":"=a"(v):"a"(1),"D"(&Lock->Lock)); __ASM__("xchgl %%eax, (%%edi)":"=a"(v):"a"(1),"D"(&Lock->Lock));
#endif #endif
#if LOCK_DISABLE_INTS
if( v ) __ASM__("sti"); // Re-enable interrupts
#endif
} }
#if LOCK_DISABLE_INTS #if LOCK_DISABLE_INTS
__ASM__("cli");
Lock->IF = IF; Lock->IF = IF;
#endif #endif
} }
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#define STACKED_LOCKS 0 #define STACKED_LOCKS 0
#define LOCK_DISABLE_INTS 1 #define LOCK_DISABLE_INTS 1
#define INVLPTR ((void*)0x0FFFFFFFFFFFFFFFULL)
//#define INT_MAX 0x7FFFFFFF //#define INT_MAX 0x7FFFFFFF
//#define UINT_MAX 0xFFFFFFFF //#define UINT_MAX 0xFFFFFFFF
......
...@@ -143,6 +143,11 @@ void *Heap_Allocate(const char *File, int Line, size_t __Bytes) ...@@ -143,6 +143,11 @@ void *Heap_Allocate(const char *File, int Line, size_t __Bytes)
tHeapHead *best = NULL; tHeapHead *best = NULL;
Uint bestSize = 0; // Speed hack Uint bestSize = 0; // Speed hack
size_t Bytes; size_t Bytes;
if( __Bytes == 0 ) {
//return NULL; // TODO: Return a known un-mapped range.
return INVLPTR;
}
// Get required size // Get required size
#if POW2_SIZES #if POW2_SIZES
...@@ -277,6 +282,10 @@ void Heap_Deallocate(void *Ptr) ...@@ -277,6 +282,10 @@ void Heap_Deallocate(void *Ptr)
Log_Log("Heap", "free: Returns to %p", __builtin_return_address(0)); Log_Log("Heap", "free: Returns to %p", __builtin_return_address(0));
#endif #endif
// INVLPTR is returned from Heap_Allocate when the allocation
// size is zero.
if( Ptr == INVLPTR ) return;
// Alignment Check // Alignment Check
if( (Uint)Ptr & (sizeof(Uint)-1) ) { if( (Uint)Ptr & (sizeof(Uint)-1) ) {
Log_Warning("Heap", "free - Passed a non-aligned address (%p)", Ptr); Log_Warning("Heap", "free - Passed a non-aligned address (%p)", Ptr);
...@@ -644,8 +653,8 @@ void Heap_Stats(void) ...@@ -644,8 +653,8 @@ void Heap_Stats(void)
// Print the block info? // Print the block info?
#if 1 #if 1
Log_Debug("Heap", "%p - 0x%x Owned by %s:%i", Log_Debug("Heap", "%p - 0x%x (%i) Owned by %s:%i",
head, head->Size, head->File, head->Line); head, head->Size, head->ValidSize, head->File, head->Line);
#endif #endif
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment