From: John Hodge Date: Sat, 11 Jun 2011 13:37:10 +0000 (+0800) Subject: Kernel - x86 Fixed a couple of bugs X-Git-Tag: rel0.10~70 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=49a69690b65eb0e13530110bce5724967b55e140;p=tpg%2Facess2.git Kernel - x86 Fixed a couple of bugs - Page fault handler used a spinlock, needed interupts enabled - Added a check for HLT() IF=0 - Added a backtrace to kernel panic code - Random bugcatching in mm_phys --- diff --git a/Kernel/arch/x86/errors.c b/Kernel/arch/x86/errors.c index 22ad1a39..dcedcd5c 100644 --- a/Kernel/arch/x86/errors.c +++ b/Kernel/arch/x86/errors.c @@ -75,6 +75,7 @@ void ErrorHandler(tRegs *Regs) // Page Fault if(Regs->int_num == 14) { + __asm__ __volatile__ ("sti"); // Should be OK, TODO: Test __asm__ __volatile__ ("mov %%cr2, %0":"=r"(cr)); MM_PageFault( cr, Regs->err_code, Regs ); return ; diff --git a/Kernel/arch/x86/include/arch.h b/Kernel/arch/x86/include/arch.h index 66d7a792..ade74916 100644 --- a/Kernel/arch/x86/include/arch.h +++ b/Kernel/arch/x86/include/arch.h @@ -58,7 +58,16 @@ struct sShortSpinlock { /** * \brief Halt the CPU (shorter version of yield) */ +#if 1 +#define HALT() do { \ + Uint32 flags; \ + __asm__ __volatile__ ("pushf;pop %0" : "=a"(flags)); \ + if( !(flags & 0x200) ) Panic("HALT called with interrupts disabled"); \ + __asm__ __volatile__ ("hlt"); \ +} while(0) +#else #define HALT() __asm__ __volatile__ ("hlt") +#endif /** * \brief Fire a magic breakpoint (bochs) */ diff --git a/Kernel/arch/x86/kpanic.c b/Kernel/arch/x86/kpanic.c index 0950be82..ccb10737 100644 --- a/Kernel/arch/x86/kpanic.c +++ b/Kernel/arch/x86/kpanic.c @@ -6,11 +6,16 @@ #include + + #define FB ((Uint16 *)(KERNEL_BASE|0xB8000)) #define BGC 0x4F00 // White on Red //#define BGC 0xC000 // Black on Bright Red //#define BGC 0x1F00 // White on Blue (BSOD!) +extern Uint32 GetEIP(void); +extern void Error_Backtrace(Uint32 eip, Uint32 ebp); + int giKP_Pos = 0; const struct { @@ -70,7 +75,7 @@ void KernelPanic_SetMode(void) if( giKP_Pos ) return ; // Restore VGA 0xB8000 text mode - #if 0 + #if 1 for( i = 0; i < NUM_REGVALUES; i++ ) { // Reset Flip-Flop @@ -90,6 +95,13 @@ void KernelPanic_SetMode(void) { FB[i] = BGC; } + + { + Uint32 eip = GetEIP(); + Uint32 ebp; + __asm__ __volatile__ ("mov %%ebp, %0" : "=r" (ebp)); + Error_Backtrace(eip, ebp); + } } void KernelPanic_PutChar(char Ch) diff --git a/Kernel/arch/x86/lib.c b/Kernel/arch/x86/lib.c index dbdb98d3..a3f98be5 100644 --- a/Kernel/arch/x86/lib.c +++ b/Kernel/arch/x86/lib.c @@ -178,7 +178,7 @@ int putDebugChar(char ch) outb(GDB_SERIAL_PORT + 3, 0x03); // 8 bits, no parity, one stop bit (8N1) outb(GDB_SERIAL_PORT + 2, 0xC7); // Enable FIFO with 14-byte threshold and clear it outb(GDB_SERIAL_PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set - gbDebug_SerialSetup = 1; + gbGDB_SerialSetup = 1; } while( (inb(GDB_SERIAL_PORT + 5) & 0x20) == 0 ); outb(GDB_SERIAL_PORT, ch); @@ -194,7 +194,7 @@ int getDebugChar(void) outb(GDB_SERIAL_PORT + 3, 0x03); // 8 bits, no parity, one stop bit outb(GDB_SERIAL_PORT + 2, 0xC7); // Enable FIFO with 14-byte threshold and clear it outb(GDB_SERIAL_PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set - gbDebug_SerialSetup = 1; + gbGDB_SerialSetup = 1; } while( (inb(GDB_SERIAL_PORT + 5) & 1) == 0) ; return inb(GDB_SERIAL_PORT); diff --git a/Kernel/arch/x86/mm_phys.c b/Kernel/arch/x86/mm_phys.c index a1feb464..29c280db 100644 --- a/Kernel/arch/x86/mm_phys.c +++ b/Kernel/arch/x86/mm_phys.c @@ -1,4 +1,4 @@ -/* +"/* * Acess2 * - Physical memory manager */ @@ -248,6 +248,13 @@ tPAddr MM_AllocPhys(void) Panic("The fuck? Too many pages! (indx = 0x%x)", indx); } + if( indx >= giPageCount ) { + Mutex_Release( &glPhysAlloc ); + Log_Error("PMem", "MM_AllocPhys - indx(%i) > giPageCount(%i)", indx, giPageCount); + LEAVE('i', 0); + return 0; + } + // Mark page used if(gaPageReferences) gaPageReferences[ indx ] = 1;