1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/debug/crashMonitor/src/arm/cscmdatasave.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,152 @@
1.4 +// Copyright (c) 2008-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\kernel\arm\cscmdatasave.cpp
1.18 +// SCM - Arm portion
1.19 +//
1.20 +//
1.21 +
1.22 +#define __INCLUDE_REG_OFFSETS__ // for SP_R13U in nk_plat.h
1.23 +
1.24 +
1.25 +#include "arm_mem.h"
1.26 +#include "nk_plat.h"
1.27 +#include <scmdatatypes.h>
1.28 +#include <scmdatasave.h>
1.29 +
1.30 +
1.31 +/**
1.32 + * Reads the CPU registers at the time of the crash
1.33 + * @param aRegs struct to store the resulting CPU registers
1.34 + */
1.35 +void SCMDataSave::ReadCPURegisters(SFullArmRegSet& aRegs)
1.36 + {
1.37 + aRegs =*(SFullArmRegSet*)iMonitor->iRegs;
1.38 + }
1.39 +
1.40 +/**
1.41 + * Reads the user registers for a given thread - may not be the current thread
1.42 + * @param aThread thread whose registers we want to read
1.43 + * @param aRegs registers will be written here if available
1.44 + * @return KErrArgument if aThread is the current thread or any of the system wide error codes
1.45 + */
1.46 +TInt SCMDataSave::ReadUserRegisters(DThread* aThread, TArmRegSet& aRegs, TUint32& aAvailableRegs)
1.47 + {
1.48 + TFileName filename;
1.49 + aThread->TraceAppendFullName(filename, EFalse);
1.50 +
1.51 + //we retrieve the registers differently for the current thread
1.52 + if(aThread == &Kern::CurrentThread())
1.53 + {
1.54 + return KErrArgument;
1.55 + }
1.56 +
1.57 + TUint32* stackPointer = (TUint32*)aThread->iNThread.iSavedSP; //Still need to check pointer somehow
1.58 + TUint32* stackTop = (TUint32*)((TUint32)aThread->iNThread.iStackBase +(TUint32)aThread->iNThread.iStackSize);
1.59 + TArmReg* out = (TArmReg*)(&aRegs);
1.60 +
1.61 + //Get a pointer to this threads context table
1.62 + NThread::TUserContextType type = aThread->iNThread.UserContextType();
1.63 + const TArmContextElement* table = aThread->iNThread.UserContextTables()[type];
1.64 +
1.65 + aAvailableRegs = 0;
1.66 + for(TInt i = 0; i<KArmRegisterCount; ++i)
1.67 + {
1.68 + TInt value = table[i].iValue;
1.69 + TInt type = table[i].iType;
1.70 +
1.71 + if(type == TArmContextElement::EOffsetFromSp)
1.72 + {
1.73 + value = stackPointer[value];
1.74 + aAvailableRegs |= (1<<i);
1.75 + }
1.76 + else if(type == TArmContextElement::EOffsetFromStackTop)
1.77 + {
1.78 + value = stackTop[-value];
1.79 + aAvailableRegs |= (1<<i);
1.80 + }
1.81 + else if(type == TArmContextElement::ESpPlusOffset)
1.82 + {
1.83 + value = (TInt)(stackPointer + value);
1.84 + aAvailableRegs |= (1<<i);
1.85 + }
1.86 +
1.87 + out[i] = value;
1.88 + }
1.89 +
1.90 + return KErrNone;
1.91 + }
1.92 +
1.93 +/**
1.94 + * Reads the system registers for a given thread
1.95 + * Can not be used on the current thread
1.96 + * @param aThread
1.97 + * @param aRegs
1.98 + * @param aAvailableRegs
1.99 + * @return KErrArgument if aThread is the current thread or any of the system wide error codes
1.100 + */
1.101 +TInt SCMDataSave::ReadSystemRegisters(DThread* aThread, TArmRegSet& aRegs, TUint32& aAvailableRegs)
1.102 + {
1.103 + if(aThread == &Kern::CurrentThread())
1.104 + {
1.105 + return KErrArgument;
1.106 + }
1.107 +
1.108 + TFileName filename;
1.109 + aThread->TraceAppendFullName(filename, EFalse);
1.110 +
1.111 + TUint32* stackPointer = (TUint32*)aThread->iNThread.iSavedSP;
1.112 + TUint32* stackTop = (TUint32*)((TUint32)aThread->iNThread.iStackBase +(TUint32)aThread->iNThread.iStackSize);
1.113 + TArmReg* out = (TArmReg*)(&aRegs);
1.114 +
1.115 + //Get a pointer to this threads context table
1.116 + const TArmContextElement* table = aThread->iNThread.UserContextTables()[NThread::EContextKernel];
1.117 +
1.118 + aAvailableRegs = 0;
1.119 + for(TInt i = 0; i<KArmRegisterCount; ++i)
1.120 + {
1.121 + TInt value = table[i].iValue;
1.122 + TInt type = table[i].iType;
1.123 +
1.124 + if(type == TArmContextElement::EOffsetFromSp)
1.125 + {
1.126 + //ensure we are still on the stack
1.127 + if(stackPointer + value >= stackTop)
1.128 + continue;
1.129 +
1.130 + value = stackPointer[value];
1.131 + aAvailableRegs |= (1<<i);
1.132 + }
1.133 + else if(type == TArmContextElement::EOffsetFromStackTop)
1.134 + {
1.135 + //ensure we are still on the stack
1.136 + if(stackTop - value < (TUint32*)aThread->iNThread.iStackBase)
1.137 + continue;
1.138 +
1.139 + value = stackTop[-value];
1.140 + aAvailableRegs |= (1<<i);
1.141 + }
1.142 + else if(type == TArmContextElement::ESpPlusOffset)
1.143 + {
1.144 + value = (TInt)(stackPointer + value);
1.145 + aAvailableRegs |= (1<<i);
1.146 + }
1.147 +
1.148 + out[i] = value;
1.149 + }
1.150 +
1.151 + return KErrNone;
1.152 + }
1.153 +
1.154 +//EOF
1.155 +