1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/nkernsmp/x86/ncmonitor.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,224 @@
1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32\nkernsmp\x86\ncmonitor.cpp
1.18 +// Kernel crash debugger - NKERN X86 specific portion
1.19 +//
1.20 +//
1.21 +
1.22 +#define __INCLUDE_NTHREADBASE_DEFINES__
1.23 +
1.24 +#include "nk_priv.h"
1.25 +#include <x86.h>
1.26 +#include <kernel/monitor.h>
1.27 +
1.28 +
1.29 +void Monitor::DisplaySpinLock(const char* aTitle, TSpinLock* aLock)
1.30 + {
1.31 + volatile TUint32* p = (volatile TUint32*)aLock;
1.32 + Printf("%s %08x %08x\r\n", aTitle, p[0], p[1]);
1.33 + }
1.34 +
1.35 +EXPORT_C void Monitor::DisplayNThreadInfo(NThread* aT)
1.36 + {
1.37 + DisplayNSchedulableInfo(aT);
1.38 + }
1.39 +
1.40 +void Monitor::DisplayNSchedulableInfo(NSchedulable* aS)
1.41 + {
1.42 + NThread* t = aS->iParent ? (NThread*)aS : 0;
1.43 + NThreadGroup* g = aS->iParent ? 0 : (NThreadGroup*)aS;
1.44 +
1.45 + if (t && aS->iParent==aS)
1.46 + Printf("NThread @%08x Pri %d\r\n",aS,aS->iPriority);
1.47 + else if (t)
1.48 + Printf("NThread @%08x (G:%08x) Pri %d\r\n",aS,aS->iParent,aS->iPriority);
1.49 + else
1.50 + Printf("NThreadGroup @%08x Pri %d\r\n",aS,aS->iPriority);
1.51 + Printf("Rdy=%02x Curr=%02x LastCpu=%d CpuChg=%02x FrzCpu=%d\r\n", aS->iReady, aS->iCurrent, aS->iLastCpu, aS->iCpuChange, aS->iFreezeCpu);
1.52 + Printf("Next=%08x Prev=%08x Parent=%08x CPUaff=%08x\r\n", aS->iNext, aS->iPrev, aS->iParent, aS->iCpuAffinity);
1.53 + Printf("PauseCount %02x Susp %1x\r\n", aS->iPauseCount, aS->iSuspended);
1.54 + DisplaySpinLock("SpinLock", &aS->iSSpinLock);
1.55 + Printf("Stopping %02x Events %08x %08x EventState %08x\r\n", aS->iStopping, aS->iEvents.iA.iNext, aS->iEvents.iA.iPrev, aS->iEventState);
1.56 + Printf("TotalCpuTime %08x %08x RunCount %08x %08x\r\n", aS->iTotalCpuTime32[1], aS->iTotalCpuTime32[0], aS->iRunCount32[1], aS->iRunCount32[0]);
1.57 +
1.58 + if (g)
1.59 + {
1.60 + // Thread group
1.61 + return;
1.62 + }
1.63 +
1.64 + Printf("WaitState %02x %02x [%02x %02x] (%08x)\r\n", t->iWaitState.iWtC.iWtStFlags, t->iWaitState.iWtC.iWtObjType,
1.65 + t->iWaitState.iWtC.iWtStSpare1, t->iWaitState.iWtC.iWtStSpare2, t->iWaitState.iWtC.iWtObj);
1.66 + Printf("BasePri %d MutexPri %d Att=%02x\r\n", t->iBasePri, t->iMutexPri, t->i_ThrdAttr);
1.67 + Printf("HeldFM=%08x FMDef=%02x AddrSp=%08x\r\n", t->iHeldFastMutex, t->iFastMutexDefer, t->iAddressSpace);
1.68 + Printf("Time=%d Timeslice=%d ReqCount=%08x\r\n", t->iTime, t->iTimeslice, t->iRequestSemaphore.iCount);
1.69 + Printf("SuspendCount=%d CsCount=%d CsFunction=%08x\r\n", t->iSuspendCount, t->iCsCount, t->iCsFunction);
1.70 + Printf("LinkedObjType %02x LinkedObj %08x\r\n", t->iLinkedObjType, t->iLinkedObj);
1.71 + Printf("SavedSP=%08x WaitLink:%08x %08x %d\r\n", t->iSavedSP, t->iWaitLink.iNext, t->iWaitLink.iPrev, t->iWaitLink.iPriority);
1.72 + Printf("iNewParent=%08x iExtraContext=%08x, iExtraContextSize=%08x\r\n", t->iNewParent, t->iExtraContext, t->iExtraContextSize);
1.73 + Printf("iUserModeCallbacks=%08x iNThreadBaseSpare6=%08x\r\n", t->iUserModeCallbacks, t->iNThreadBaseSpare6);
1.74 + Printf("iNThreadBaseSpare7=%08x iNThreadBaseSpare8=%08x iNThreadBaseSpare9=%08x\r\n", t->iNThreadBaseSpare7, t->iNThreadBaseSpare8, t->iNThreadBaseSpare9);
1.75 + if (!aS->iCurrent)
1.76 + {
1.77 + TUint32* pS=(TUint32*)t->iSavedSP;
1.78 + SThreadReschedStack reg;
1.79 + MTRAPD(r,wordmove(®,pS,sizeof(SThreadReschedStack)));
1.80 + if (r==KErrNone)
1.81 + {
1.82 + Printf("CR0 %08x RsF %08x EIP %08x RSN %08x\r\n", reg.iCR0, reg.iReschedFlag, reg.iEip, reg.iReason);
1.83 + }
1.84 + }
1.85 + NewLine();
1.86 + }
1.87 +
1.88 +void Monitor::DisplayNFastSemInfo(NFastSemaphore* pS)
1.89 + {
1.90 + if (pS->iCount >= 0)
1.91 + Printf("NFastSemaphore @ %08x Count %d OwningThread %08x\r\n",pS,pS->iCount,pS->iOwningThread);
1.92 + else
1.93 + Printf("NFastSemaphore @ %08x Count %08x (%08x) OwningThread %08x\r\n",pS,pS->iCount,pS->iCount<<2,pS->iOwningThread);
1.94 + }
1.95 +
1.96 +void Monitor::DisplayNFastMutexInfo(NFastMutex* aM)
1.97 + {
1.98 + Printf("NFastMutex @ %08x HoldingThread %08x iWaitQ Pri Mask %08x %08x\r\n", aM, aM->iHoldingThread, aM->iWaitQ.iPresent[1], aM->iWaitQ.iPresent[0]);
1.99 + DisplaySpinLock("SpinLock", &aM->iMutexLock);
1.100 + }
1.101 +
1.102 +void DisplaySubSchedulerInfo(Monitor& m, TSubScheduler& ss)
1.103 + {
1.104 + m.Printf("\r\nSUBSCHEDULER %d @%08x:\r\n",ss.iCpuNum,&ss);
1.105 + m.Printf("CurrentThread=%08x\r\n", ss.iCurrentThread);
1.106 + m.Printf("DFCS %08x %08x CPU# %08x CPUmask %08x\r\n", ss.iDfcs.iA.iNext, ss.iDfcs.iA.iPrev, ss.iCpuNum, ss.iCpuMask);
1.107 + m.Printf("KLCount %d DFCPending %02x ReschedNeeded %02x InIDFC %02x\r\n", ss.iKernLockCount, ss.iDfcPendingFlag, ss.iRescheduleNeededFlag, ss.iInIDFC);
1.108 + m.Printf("AddressSpace=%08x ReschedIPIs=%08x iNextIPI %08x\r\n", ss.iAddressSpace, ss.iReschedIPIs, ss.iNextIPI);
1.109 + volatile TUint32* pL = (volatile TUint32*)&ss.iReadyListLock;
1.110 + m.Printf("SpinLock %08x %08x %08x %08x\r\n", pL[0], pL[1], pL[2], pL[3]);
1.111 + m.Printf("Extras[ 0] %08x Extras[ 1] %08x Extras[ 2] %08x Extras[ 3] %08x\r\n", ss.iExtras[0], ss.iExtras[1], ss.iExtras[2], ss.iExtras[3]);
1.112 + m.Printf("Extras[ 4] %08x Extras[ 5] %08x Extras[ 6] %08x Extras[ 7] %08x\r\n", ss.iExtras[4], ss.iExtras[5], ss.iExtras[6], ss.iExtras[7]);
1.113 + m.Printf("Extras[ 8] %08x i_IrqCount %08x i_ExcInfo %08x i_CrashSt %08x\r\n", ss.iExtras[8], ss.i_IrqCount, ss.i_ExcInfo, ss.i_CrashState);
1.114 + m.Printf("i_APICID %08x i_IrqNestC %08x i_IrqStkTp %08x i_Tss %08x\r\n", ss.i_APICID, ss.i_IrqNestCount, ss.i_IrqStackTop, ss.i_Tss);
1.115 + m.Printf("i_TmrMultF %08x i_TmrMultI %08x i_CpuMult %08x Extras[13] %08x\r\n", ss.i_TimerMultF, ss.i_TimerMultI, ss.i_CpuMult, ss.iExtras[19]);
1.116 + m.Printf("i_TmOffL %08x i_TmOffH %08x Extras[16] %08x Extras[17] %08x\r\n", ss.iExtras[20], ss.iExtras[21], ss.iExtras[22], ss.iExtras[23]);
1.117 + m.Printf("iLastTimestamp %08x %08x iReschedCount %08x %08x\r\n", ss.iLastTimestamp32[1], ss.iLastTimestamp32[0], ss.iReschedCount32[1], ss.iReschedCount32[0]);
1.118 + }
1.119 +
1.120 +void Monitor::DisplaySchedulerInfo()
1.121 + {
1.122 + TScheduler* pS=TScheduler::Ptr();
1.123 + Printf("SCHEDULER @%08x:\r\n",pS);
1.124 + Printf("ProcessHandler=%08x MonitorExceptionHandler=%08x RescheduleHook=%08x\r\n",pS->iProcessHandler,pS->iMonitorExceptionHandler,pS->iRescheduleHook);
1.125 + Printf("iActiveCpus1=%08x, iActiveCpus2=%08x, iNumCpus=%d\r\n",pS->iActiveCpus1,pS->iActiveCpus2,pS->iNumCpus);
1.126 + Printf("SYSLOCK @ %08x\r\n",&pS->iLock);
1.127 + DisplayNFastMutexInfo(&pS->iLock);
1.128 + DisplaySpinLock("IdleSpinLock", &pS->iIdleSpinLock);
1.129 + Printf("IdleDfcs %08x %08x CpusNotIdle %08x IdleGeneration %02x IdleSpillCpu %02x\r\n",
1.130 + pS->iIdleDfcs.iA.iNext, pS->iIdleDfcs.iA.iPrev, pS->iCpusNotIdle, pS->iIdleGeneration, pS->iIdleSpillCpu);
1.131 + Printf("Extras 0: %08x 1: %08x 2: %08x 3: %08x\r\n",pS->iExtras[0],pS->iExtras[1],pS->iExtras[2],pS->iExtras[3]);
1.132 + Printf("Extras 4: %08x 5: %08x 6: %08x 7: %08x\r\n",pS->iExtras[4],pS->iExtras[5],pS->iExtras[6],pS->iExtras[7]);
1.133 + Printf("Extras 8: %08x 9: %08x A: %08x B: %08x\r\n",pS->iExtras[8],pS->iExtras[9],pS->iExtras[10],pS->iExtras[11]);
1.134 + Printf("Extras C: %08x D: %08x E: %08x F: %08x\r\n",pS->iExtras[12],pS->iExtras[13],pS->iExtras[14],pS->iExtras[15]);
1.135 + Printf("Extras 10: %08x 11: %08x 12: %08x 13: %08x\r\n",pS->iExtras[16],pS->iExtras[17],pS->iExtras[18],pS->iExtras[19]);
1.136 + Printf("Extras 14: %08x 15: %08x 16: %08x 17: %08x\r\n",pS->iExtras[20],pS->iExtras[21],pS->iExtras[22],pS->iExtras[23]);
1.137 +
1.138 + TInt i;
1.139 + for (i=0; i<KMaxCpus; ++i)
1.140 + {
1.141 + TSubScheduler& ss = *pS->iSub[i];
1.142 + DisplaySubSchedulerInfo(*this,ss);
1.143 + }
1.144 + }
1.145 +
1.146 +SFullX86RegSet& RegSet(TInt aCpu)
1.147 + {
1.148 + TScheduler* pS=TScheduler::Ptr();
1.149 + TSubScheduler& ss = *pS->iSub[aCpu];
1.150 + SCpuData* cpudata = (SCpuData*)ss.i_Tss;
1.151 + return cpudata->iRegs;
1.152 + }
1.153 +
1.154 +TX86Tss& TSS(TInt aCpu)
1.155 + {
1.156 + TScheduler* pS=TScheduler::Ptr();
1.157 + TSubScheduler& ss = *pS->iSub[aCpu];
1.158 + return *(TX86Tss*)ss.i_Tss;
1.159 + }
1.160 +
1.161 +void Monitor::DumpCpuRegisters()
1.162 + {
1.163 + TInt i;
1.164 + for (i=0; i<KMaxCpus; ++i)
1.165 + {
1.166 + SFullX86RegSet& r = RegSet(i);
1.167 + Printf("CPU %d:\r\n", i);
1.168 + Printf("EAX=%08x EBX=%08x ECX=%08x EDX=%08x\r\n",r.iEax,r.iEbx,r.iEcx,r.iEdx);
1.169 + Printf("ESP=%08x EBP=%08x ESI=%08x EDI=%08x\r\n",r.iEsp,r.iEbp,r.iEsi,r.iEdi);
1.170 + Printf(" CS=%08x EIP=%08x EFL=%08x SS=%08x\r\n",r.iCs,r.iEip,r.iEflags,r.iSs);
1.171 + Printf(" DS=%08x ES=%08x FS=%08x GS=%08x\r\n",r.iDs,r.iEs,r.iFs,r.iGs);
1.172 + Printf("IrqNest=%08x\r\n",r.iIrqNestCount);
1.173 + NewLine();
1.174 + }
1.175 + }
1.176 +
1.177 +void Monitor::DisplayCpuFaultInfo()
1.178 + {
1.179 + TScheduler* pS=TScheduler::Ptr();
1.180 + TInt i;
1.181 + for (i=0; i<KMaxCpus; ++i)
1.182 + {
1.183 + Printf("CPU %d:\r\n", i);
1.184 + TSubScheduler& ss = *pS->iSub[i];
1.185 + if (!ss.i_ExcInfo)
1.186 + continue;
1.187 + TX86ExcInfo& a = *(TX86ExcInfo*)ss.i_ExcInfo;
1.188 + Printf("Exc %02x EFLAGS=%08x FAR=%08x ErrCode=%08x\r\n",a.iExcId,a.iEflags,a.iFaultAddress,a.iExcErrorCode);
1.189 + Printf("EAX=%08x EBX=%08x ECX=%08x EDX=%08x\r\n",a.iEax,a.iEbx,a.iEcx,a.iEdx);
1.190 + Printf("ESP=%08x EBP=%08x ESI=%08x EDI=%08x\r\n",a.iEsp,a.iEbp,a.iEsi,a.iEdi);
1.191 + Printf(" CS=%08x EIP=%08x DS=%08x SS=%08x\r\n",a.iCs,a.iEip,a.iDs,a.iSs);
1.192 + Printf(" ES=%08x FS=%08x GS=%08x\r\n",a.iEs,a.iFs,a.iGs);
1.193 + if (a.iCs&3)
1.194 + {
1.195 + Printf("SS3=%08x ESP3=%08x\r\n",a.iSs3,a.iEsp3);
1.196 + }
1.197 + NewLine();
1.198 + }
1.199 + }
1.200 +
1.201 +EXPORT_C void Monitor::GetStackPointers(NThread* aThread, TUint& aSupSP, TUint& aUsrSP)
1.202 + {
1.203 + TScheduler* pS = TScheduler::Ptr();
1.204 + TBool user_done = FALSE;
1.205 + if (aThread->iCurrent)
1.206 + {
1.207 + TInt i = aThread->iLastCpu;
1.208 + if (RegSet(i).iCs & 3)
1.209 + aSupSP = RegSet(i).iEsp;
1.210 + else
1.211 + {
1.212 + aUsrSP = RegSet(i).iEsp;
1.213 + aSupSP = TSS(i).iEsp0;
1.214 + user_done = TRUE;
1.215 + }
1.216 + }
1.217 + else
1.218 + aSupSP = (TUint)aThread->iSavedSP;
1.219 +
1.220 + if (!user_done)
1.221 + {
1.222 + // User SP is in the exception info on the top of the supervisor stack
1.223 + TUint stackTop = (TUint)aThread->iStackBase + aThread->iStackSize;
1.224 + TX86ExcInfo* excRegs = (TX86ExcInfo*)(stackTop - sizeof(TX86ExcInfo));
1.225 + aUsrSP = excRegs->iEsp3;
1.226 + }
1.227 + }