From 94ccf379b209c4729cb8790a633538f9e4df6a50 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 30 Oct 2010 21:22:18 +0800 Subject: [PATCH] x86_64 fixes - Changed register output to %llx instead of %x - Changed SPINLOCK technique - Fiddling with scheduling --- Kernel/Makefile.BuildNum.x86_64 | 2 +- Kernel/arch/x86_64/errors.c | 18 +++++++++--------- Kernel/arch/x86_64/include/arch.h | 3 +++ Kernel/arch/x86_64/lib.c | 2 +- Kernel/arch/x86_64/proc.c | 7 +++++-- Kernel/lib.c | 8 ++++++++ 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Kernel/Makefile.BuildNum.x86_64 b/Kernel/Makefile.BuildNum.x86_64 index cfc4f867..1775ddde 100644 --- a/Kernel/Makefile.BuildNum.x86_64 +++ b/Kernel/Makefile.BuildNum.x86_64 @@ -1 +1 @@ -BUILD_NUM = 215 +BUILD_NUM = 221 diff --git a/Kernel/arch/x86_64/errors.c b/Kernel/arch/x86_64/errors.c index 9f1d290a..6fe9298b 100644 --- a/Kernel/arch/x86_64/errors.c +++ b/Kernel/arch/x86_64/errors.c @@ -38,17 +38,17 @@ void Error_Handler(tRegs *Regs) Log("CPU Error %x, Code: 0x%x", Regs->IntNum, Regs->ErrorCode); Log(" - %s", csaERROR_NAMES[Regs->IntNum]); - Log(" CS:RIP = 0x%04x:%016x", Regs->CS, Regs->RIP); - Log(" SS:RSP = 0x%04x:%016x", Regs->SS, Regs->RSP); - Log(" RFLAGS = 0x%016x", Regs->RFlags); + Log(" CS:RIP = 0x%04x:%016llx", Regs->CS, Regs->RIP); + Log(" SS:RSP = 0x%04x:%016llx", Regs->SS, Regs->RSP); + Log(" RFLAGS = 0x%016llx", Regs->RFlags); - Log(" RAX %016x RCX %016x RDX %016x RBX %016x", + Log(" RAX %016llx RCX %016llx RDX %016llx RBX %016llx", Regs->RAX, Regs->RCX, Regs->RDX, Regs->RBX); - Log(" RSP %016x RBP %016x RSI %016x RDI %016x", + Log(" RSP %016llx RBP %016llx RSI %016llx RDI %016llx", Regs->RSP, Regs->RBP, Regs->RSP, Regs->RDI); - Log(" R8 %016x R9 %016x R10 %016x R11 %016x", + Log(" R8 %016llx R9 %016llx R10 %016llx R11 %016llx", Regs->R8, Regs->R9, Regs->R10, Regs->R11); - Log(" R12 %016x R13 %016x R14 %016x R15 %016x", + Log(" R12 %016llx R13 %016llx R14 %016llx R15 %016llx", Regs->R12, Regs->R13, Regs->R14, Regs->R15); Log(" FS %04x GS %04x", Regs->FS, Regs->GS); @@ -57,9 +57,9 @@ void Error_Handler(tRegs *Regs) __asm__ __volatile__ ("mov %%cr0, %0":"=r"(cr)); Warning(" CR0 0x%08x", cr); __asm__ __volatile__ ("mov %%cr2, %0":"=r"(cr)); - Warning(" CR2 0x%08x", cr); + Warning(" CR2 0x%016llx", cr); __asm__ __volatile__ ("mov %%cr3, %0":"=r"(cr)); - Warning(" CR3 0x%08x", cr); + Warning(" CR3 0x%016llx", cr); __asm__ __volatile__ ("mov %%cr4, %0":"=r"(cr)); Warning(" CR4 0x%08x", cr); diff --git a/Kernel/arch/x86_64/include/arch.h b/Kernel/arch/x86_64/include/arch.h index c353089a..0e5cb611 100644 --- a/Kernel/arch/x86_64/include/arch.h +++ b/Kernel/arch/x86_64/include/arch.h @@ -10,6 +10,9 @@ #define KERNEL_BASE 0xFFFFFFFF##80000000 #define BITS 64 +#define STACKED_LOCKS 0 +#define LOCK_DISABLE_INTS 1 + //#define INT_MAX 0x7FFFFFFF //#define UINT_MAX 0xFFFFFFFF diff --git a/Kernel/arch/x86_64/lib.c b/Kernel/arch/x86_64/lib.c index f7f38c8b..f20753bc 100644 --- a/Kernel/arch/x86_64/lib.c +++ b/Kernel/arch/x86_64/lib.c @@ -58,7 +58,7 @@ void SHORTLOCK(struct sShortSpinlock *Lock) #if LOCK_DISABLE_INTS // Save interrupt state and clear interrupts - __ASM__ ("pushf;\n\tpop %0\n\tcli" : "=a"(IF)); + __ASM__ ("pushf;\n\tpop %%rax\n\tcli" : "=a"(IF)); IF &= 0x200; // AND out all but the interrupt flag #endif diff --git a/Kernel/arch/x86_64/proc.c b/Kernel/arch/x86_64/proc.c index 1d1513be..9abcc633 100644 --- a/Kernel/arch/x86_64/proc.c +++ b/Kernel/arch/x86_64/proc.c @@ -736,6 +736,8 @@ void Proc_Scheduler(int CPU) // If the spinlock is set, let it complete if(IS_LOCKED(&glThreadListLock)) return; + //LogF("Scheduler: CPU = %i\n", CPU); + // Get current thread thread = gaCPUs[CPU].Current; @@ -761,12 +763,13 @@ void Proc_Scheduler(int CPU) // Error Check if(thread == NULL) { thread = gaCPUs[CPU].IdleThread; - Warning("Hmm... Threads_GetNextToRun returned NULL, I don't think this should happen.\n"); + //Warning("Hmm... Threads_GetNextToRun returned NULL, I don't think this should happen.\n"); + //LogF("Zzzzz.\n"); return; } #if DEBUG_TRACE_SWITCH - Log("Switching to task %i, CR3 = 0x%x, RIP = %p", + LogF("Switching to task %i, CR3 = 0x%x, RIP = %p", thread->TID, thread->MemState.CR3, thread->SavedState.RIP diff --git a/Kernel/lib.c b/Kernel/lib.c index b13d2e47..3a4f31f1 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -283,6 +283,14 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) GETVAL(); itoa(p, val, 10, minSize, pad); goto printString; + case 'X': + #if BITS == 64 + isLongLong = 1; // TODO: Handle non-x86 64-bit archs + #endif + GETVAL(); + itoa(p, val, 16, minSize, pad); + goto printString; + case 'x': GETVAL(); itoa(p, val, 16, minSize, pad); -- 2.20.1