kernel/eka/debug/crashMonitor/src/arm/cscmdatasave.cpp
changeset 296 94f2adf59133
parent 293 0659d0e1a03c
child 297 b2826f67641f
equal deleted inserted replaced
293:0659d0e1a03c 296:94f2adf59133
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32\kernel\arm\cscmdatasave.cpp
       
    15 // SCM - Arm portion
       
    16 // 
       
    17 //
       
    18 
       
    19 #define __INCLUDE_REG_OFFSETS__  // for SP_R13U in nk_plat.h
       
    20 
       
    21 
       
    22 #include "arm_mem.h"
       
    23 #include "nk_plat.h"
       
    24 #include <scmdatatypes.h>
       
    25 #include <scmdatasave.h>
       
    26 
       
    27 
       
    28 /**
       
    29  * Reads the CPU registers at the time of the crash
       
    30  * @param aRegs struct to store the resulting CPU registers
       
    31  */
       
    32 void SCMDataSave::ReadCPURegisters(SFullArmRegSet& aRegs)
       
    33 	{
       
    34 	aRegs =*(SFullArmRegSet*)iMonitor->iRegs;
       
    35 	}
       
    36 
       
    37 /**
       
    38  * Reads the user registers for a given thread - may not be the current thread
       
    39  * @param aThread thread whose registers we want to read
       
    40  * @param aRegs registers will be written here if available
       
    41  * @return KErrArgument if aThread is the current thread or any of the system wide error codes
       
    42  */
       
    43 TInt SCMDataSave::ReadUserRegisters(DThread* aThread, TArmRegSet& aRegs, TUint32& aAvailableRegs)
       
    44 	{
       
    45 	TFileName filename;
       
    46 	aThread->TraceAppendFullName(filename, EFalse);	
       
    47 	
       
    48 	//we retrieve the registers differently for the current thread
       
    49 	if(aThread == &Kern::CurrentThread())
       
    50 		{
       
    51 		return KErrArgument;
       
    52 		}
       
    53 	
       
    54 	TUint32* stackPointer = (TUint32*)aThread->iNThread.iSavedSP; //Still need to check pointer somehow
       
    55 	TUint32* stackTop = (TUint32*)((TUint32)aThread->iNThread.iStackBase +(TUint32)aThread->iNThread.iStackSize);
       
    56 	TArmReg* out = (TArmReg*)(&aRegs);		
       
    57 	
       
    58 	//Get a pointer to this threads context table
       
    59 	NThread::TUserContextType type = aThread->iNThread.UserContextType();
       
    60 	const TArmContextElement* table = aThread->iNThread.UserContextTables()[type];
       
    61 	
       
    62 	aAvailableRegs = 0;
       
    63 	for(TInt i = 0; i<KArmRegisterCount; ++i)
       
    64 		{
       
    65 		TInt value = table[i].iValue;
       
    66 		TInt type = table[i].iType;
       
    67 		
       
    68 		if(type == TArmContextElement::EOffsetFromSp)
       
    69 			{
       
    70 			value = stackPointer[value];	
       
    71 			aAvailableRegs |= (1<<i);
       
    72 			}
       
    73 		else if(type == TArmContextElement::EOffsetFromStackTop)
       
    74 			{
       
    75 			value = stackTop[-value];
       
    76 			aAvailableRegs |= (1<<i);
       
    77 			}
       
    78 		else if(type == TArmContextElement::ESpPlusOffset)
       
    79 			{
       
    80 			value = (TInt)(stackPointer + value);
       
    81 			aAvailableRegs |= (1<<i);
       
    82 			}
       
    83 		
       
    84 		out[i] = value;
       
    85 		}
       
    86 	
       
    87 	return KErrNone;
       
    88 	}
       
    89 
       
    90 /**
       
    91  * Reads the system registers for a given thread
       
    92  * Can not be used on the current thread
       
    93  * @param aThread
       
    94  * @param aRegs
       
    95  * @param aAvailableRegs
       
    96  * @return KErrArgument if aThread is the current thread or any of the system wide error codes
       
    97  */
       
    98 TInt SCMDataSave::ReadSystemRegisters(DThread* aThread, TArmRegSet& aRegs, TUint32& aAvailableRegs)
       
    99 	{	
       
   100 	if(aThread == &Kern::CurrentThread())
       
   101 		{
       
   102 		return KErrArgument;
       
   103 		}
       
   104 	
       
   105 	TFileName filename;
       
   106 	aThread->TraceAppendFullName(filename, EFalse);
       
   107 	
       
   108 	TUint32* stackPointer = (TUint32*)aThread->iNThread.iSavedSP;
       
   109 	TUint32* stackTop = (TUint32*)((TUint32)aThread->iNThread.iStackBase +(TUint32)aThread->iNThread.iStackSize);
       
   110 	TArmReg* out = (TArmReg*)(&aRegs);		
       
   111 	
       
   112 	//Get a pointer to this threads context table
       
   113 	const TArmContextElement* table = aThread->iNThread.UserContextTables()[NThread::EContextKernel];
       
   114 	
       
   115 	aAvailableRegs = 0;
       
   116 	for(TInt i = 0; i<KArmRegisterCount; ++i)
       
   117 		{
       
   118 		TInt value = table[i].iValue;
       
   119 		TInt type = table[i].iType;
       
   120 		
       
   121 		if(type == TArmContextElement::EOffsetFromSp)
       
   122 			{
       
   123 			//ensure we are still on the stack
       
   124 			if(stackPointer + value >= stackTop)
       
   125 				continue;
       
   126 				
       
   127 			value = stackPointer[value];	
       
   128 			aAvailableRegs |= (1<<i);
       
   129 			}
       
   130 		else if(type == TArmContextElement::EOffsetFromStackTop)
       
   131 			{
       
   132 			//ensure we are still on the stack
       
   133 			if(stackTop - value < (TUint32*)aThread->iNThread.iStackBase)
       
   134 				continue;
       
   135 			
       
   136 			value = stackTop[-value];
       
   137 			aAvailableRegs |= (1<<i);
       
   138 			}
       
   139 		else if(type == TArmContextElement::ESpPlusOffset)
       
   140 			{
       
   141 			value = (TInt)(stackPointer + value);
       
   142 			aAvailableRegs |= (1<<i);
       
   143 			}
       
   144 		
       
   145 		out[i] = value;
       
   146 		}	
       
   147 	
       
   148 	return KErrNone;
       
   149 	}
       
   150 
       
   151 //EOF
       
   152