debugsrv/runmodedebug/rmdriver/src/d_rmd_stepping.cpp
author hgs
Mon, 06 Sep 2010 15:00:47 +0300
changeset 51 98307c651589
parent 42 0ff24a8f6ca2
child 56 aa2539c91954
permissions -rw-r--r--
201035
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42
hgs
parents:
diff changeset
     1
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     2
// All rights reserved.
hgs
parents:
diff changeset
     3
// This component and the accompanying materials are made available
hgs
parents:
diff changeset
     4
// under the terms of the License "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     5
// which accompanies this distribution, and is available
hgs
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     7
//
hgs
parents:
diff changeset
     8
// Initial Contributors:
hgs
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    10
//
hgs
parents:
diff changeset
    11
// Contributors:
hgs
parents:
diff changeset
    12
//
hgs
parents:
diff changeset
    13
// Description:
hgs
parents:
diff changeset
    14
// This file contains stepping code refactored from rm_debug_kerneldriver.cpp/rm_debug_kerneldriver.h
hgs
parents:
diff changeset
    15
//
hgs
parents:
diff changeset
    16
hgs
parents:
diff changeset
    17
#include <e32def.h>
hgs
parents:
diff changeset
    18
#include <e32def_private.h>
hgs
parents:
diff changeset
    19
#include <e32cmn.h>
hgs
parents:
diff changeset
    20
#include <e32cmn_private.h>
hgs
parents:
diff changeset
    21
#include <kernel/kernel.h> 
hgs
parents:
diff changeset
    22
#include <kernel/kern_priv.h>
hgs
parents:
diff changeset
    23
#include <nk_trace.h>
hgs
parents:
diff changeset
    24
#include <arm.h>
hgs
parents:
diff changeset
    25
#include <rm_debug_api.h>
hgs
parents:
diff changeset
    26
hgs
parents:
diff changeset
    27
#include "d_rmd_stepping.h"
hgs
parents:
diff changeset
    28
#include "d_rmd_breakpoints.h"
hgs
parents:
diff changeset
    29
#include "rm_debug_kerneldriver.h"	// needed to access DRM_DebugChannel
hgs
parents:
diff changeset
    30
#include "rm_debug_driver.h"
hgs
parents:
diff changeset
    31
#include "debug_logging.h"
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
using namespace Debug;
hgs
parents:
diff changeset
    34
hgs
parents:
diff changeset
    35
//
hgs
parents:
diff changeset
    36
// DRMDStepping::DRMDStepping
hgs
parents:
diff changeset
    37
//
hgs
parents:
diff changeset
    38
DRMDStepping::DRMDStepping(DRM_DebugChannel* aChannel)
hgs
parents:
diff changeset
    39
:
hgs
parents:
diff changeset
    40
	iChannel(aChannel)
hgs
parents:
diff changeset
    41
	{
hgs
parents:
diff changeset
    42
	// to do
hgs
parents:
diff changeset
    43
	}
hgs
parents:
diff changeset
    44
hgs
parents:
diff changeset
    45
//
hgs
parents:
diff changeset
    46
// DRMDStepping::~DRM_DebugChannel
hgs
parents:
diff changeset
    47
//
hgs
parents:
diff changeset
    48
DRMDStepping::~DRMDStepping()
hgs
parents:
diff changeset
    49
	{
hgs
parents:
diff changeset
    50
	// to do
hgs
parents:
diff changeset
    51
	}
hgs
parents:
diff changeset
    52
hgs
parents:
diff changeset
    53
//
hgs
parents:
diff changeset
    54
// DRMDStepping::IsExecuted
hgs
parents:
diff changeset
    55
//
hgs
parents:
diff changeset
    56
TBool DRMDStepping::IsExecuted(TUint8 aCondition ,TUint32 aStatusRegister)
hgs
parents:
diff changeset
    57
	{
hgs
parents:
diff changeset
    58
	LOG_MSG("DRMDStepping::IsExecuted()");
hgs
parents:
diff changeset
    59
hgs
parents:
diff changeset
    60
	TBool N = ((aStatusRegister >> 28) & 0x0000000F) & 0x00000008;
hgs
parents:
diff changeset
    61
	TBool Z = ((aStatusRegister >> 28) & 0x0000000F) & 0x00000004;
hgs
parents:
diff changeset
    62
	TBool C = ((aStatusRegister >> 28) & 0x0000000F) & 0x00000002;
hgs
parents:
diff changeset
    63
	TBool V = ((aStatusRegister >> 28) & 0x0000000F) & 0x00000001;
hgs
parents:
diff changeset
    64
hgs
parents:
diff changeset
    65
	switch(aCondition)
hgs
parents:
diff changeset
    66
		{
hgs
parents:
diff changeset
    67
		case 0:
hgs
parents:
diff changeset
    68
			return Z;
hgs
parents:
diff changeset
    69
		case 1:
hgs
parents:
diff changeset
    70
			return !Z;
hgs
parents:
diff changeset
    71
		case 2:
hgs
parents:
diff changeset
    72
			return C;
hgs
parents:
diff changeset
    73
		case 3:
hgs
parents:
diff changeset
    74
			return !C;
hgs
parents:
diff changeset
    75
		case 4:
hgs
parents:
diff changeset
    76
			return N;
hgs
parents:
diff changeset
    77
		case 5:
hgs
parents:
diff changeset
    78
			return !N;
hgs
parents:
diff changeset
    79
		case 6:
hgs
parents:
diff changeset
    80
			return V;
hgs
parents:
diff changeset
    81
		case 7:
hgs
parents:
diff changeset
    82
			return !V;
hgs
parents:
diff changeset
    83
		case 8:
hgs
parents:
diff changeset
    84
			return (C && !Z);
hgs
parents:
diff changeset
    85
		case 9:
hgs
parents:
diff changeset
    86
			return (!C || Z);
hgs
parents:
diff changeset
    87
		case 10:
hgs
parents:
diff changeset
    88
			return (N == V);
hgs
parents:
diff changeset
    89
		case 11:
hgs
parents:
diff changeset
    90
			return (N != V);
hgs
parents:
diff changeset
    91
		case 12:
hgs
parents:
diff changeset
    92
			return ((N == V) && !Z);
hgs
parents:
diff changeset
    93
		case 13:
hgs
parents:
diff changeset
    94
			return (Z || (N != V));
hgs
parents:
diff changeset
    95
		case 14:
hgs
parents:
diff changeset
    96
		case 15:
hgs
parents:
diff changeset
    97
			return ETrue;
hgs
parents:
diff changeset
    98
		}
hgs
parents:
diff changeset
    99
	
hgs
parents:
diff changeset
   100
	return EFalse;
hgs
parents:
diff changeset
   101
	}
hgs
parents:
diff changeset
   102
hgs
parents:
diff changeset
   103
//
hgs
parents:
diff changeset
   104
// DRMDStepping::IsPreviousInstructionMovePCToLR
hgs
parents:
diff changeset
   105
//
hgs
parents:
diff changeset
   106
TBool DRMDStepping::IsPreviousInstructionMovePCToLR(DThread *aThread)
hgs
parents:
diff changeset
   107
	{
hgs
parents:
diff changeset
   108
	LOG_MSG("DRMDStepping::IsPreviousInstructionMovePCToLR()");
hgs
parents:
diff changeset
   109
hgs
parents:
diff changeset
   110
	TInt err = KErrNone;
hgs
parents:
diff changeset
   111
	
hgs
parents:
diff changeset
   112
	// there are several types of instructions that modify the PC that aren't
hgs
parents:
diff changeset
   113
	// designated as linked or non linked branches.  the way gcc generates the
hgs
parents:
diff changeset
   114
	// code can tell us whether or not these instructions are to be treated as
hgs
parents:
diff changeset
   115
	// linked branches.  the main cases are bx and any type of mov or load or
hgs
parents:
diff changeset
   116
	// arithmatic operation that changes the PC.  if these are really just
hgs
parents:
diff changeset
   117
	// function calls that will return, gcc will generate a mov	lr, pc
hgs
parents:
diff changeset
   118
	// instruction as the previous instruction.  note that this is just for arm
hgs
parents:
diff changeset
   119
	// and armi
hgs
parents:
diff changeset
   120
	
hgs
parents:
diff changeset
   121
	// get the address of the previous instruction
hgs
parents:
diff changeset
   122
	TUint32 address = 0;
hgs
parents:
diff changeset
   123
	err = iChannel->ReadKernelRegisterValue(aThread, PC_REGISTER, address);
hgs
parents:
diff changeset
   124
	if(err != KErrNone)
hgs
parents:
diff changeset
   125
		{
hgs
parents:
diff changeset
   126
		LOG_MSG2("Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
   127
		}
hgs
parents:
diff changeset
   128
	address -= 4;
hgs
parents:
diff changeset
   129
hgs
parents:
diff changeset
   130
	TBuf8<4> previousInstruction;
hgs
parents:
diff changeset
   131
	err = iChannel->DoReadMemory(aThread, address, 4, previousInstruction);
hgs
parents:
diff changeset
   132
	if (KErrNone != err)
hgs
parents:
diff changeset
   133
		{
hgs
parents:
diff changeset
   134
		LOG_MSG2("Error %d reading memory at address %x", address);
hgs
parents:
diff changeset
   135
		return EFalse;
hgs
parents:
diff changeset
   136
		}
hgs
parents:
diff changeset
   137
hgs
parents:
diff changeset
   138
	const TUint32 movePCToLRIgnoringCondition = 0x01A0E00F;
hgs
parents:
diff changeset
   139
hgs
parents:
diff changeset
   140
	TUint32 inst = *(TUint32 *)previousInstruction.Ptr();
hgs
parents:
diff changeset
   141
	
hgs
parents:
diff changeset
   142
	if ((inst & 0x0FFFFFFF) == movePCToLRIgnoringCondition)
hgs
parents:
diff changeset
   143
		{
hgs
parents:
diff changeset
   144
		return ETrue;
hgs
parents:
diff changeset
   145
		}
hgs
parents:
diff changeset
   146
		
hgs
parents:
diff changeset
   147
	return EFalse;
hgs
parents:
diff changeset
   148
	}
hgs
parents:
diff changeset
   149
hgs
parents:
diff changeset
   150
//
hgs
parents:
diff changeset
   151
// DRMDStepping::DecodeDataProcessingInstruction
hgs
parents:
diff changeset
   152
//
hgs
parents:
diff changeset
   153
void DRMDStepping::DecodeDataProcessingInstruction(TUint8 aOpcode, TUint32 aOp1, TUint32 aOp2, TUint32 aStatusRegister, TUint32 &aBreakAddress)
hgs
parents:
diff changeset
   154
	{
hgs
parents:
diff changeset
   155
	LOG_MSG("DRMDStepping::DecodeDataProcessingInstruction()");
hgs
parents:
diff changeset
   156
hgs
parents:
diff changeset
   157
	switch(aOpcode)
hgs
parents:
diff changeset
   158
		{
hgs
parents:
diff changeset
   159
		case 0:
hgs
parents:
diff changeset
   160
			{
hgs
parents:
diff changeset
   161
			// AND
hgs
parents:
diff changeset
   162
			aBreakAddress = aOp1 & aOp2;
hgs
parents:
diff changeset
   163
			break;
hgs
parents:
diff changeset
   164
			}
hgs
parents:
diff changeset
   165
		case 1:
hgs
parents:
diff changeset
   166
			{
hgs
parents:
diff changeset
   167
			// EOR
hgs
parents:
diff changeset
   168
			aBreakAddress = aOp1 ^ aOp2;
hgs
parents:
diff changeset
   169
			break;
hgs
parents:
diff changeset
   170
			}
hgs
parents:
diff changeset
   171
		case 2:
hgs
parents:
diff changeset
   172
			{
hgs
parents:
diff changeset
   173
			// SUB
hgs
parents:
diff changeset
   174
			aBreakAddress = aOp1 - aOp2;
hgs
parents:
diff changeset
   175
			break;
hgs
parents:
diff changeset
   176
			}
hgs
parents:
diff changeset
   177
		case 3:
hgs
parents:
diff changeset
   178
			{
hgs
parents:
diff changeset
   179
			// RSB
hgs
parents:
diff changeset
   180
			aBreakAddress = aOp2 - aOp1;
hgs
parents:
diff changeset
   181
			break;
hgs
parents:
diff changeset
   182
			}
hgs
parents:
diff changeset
   183
		case 4:
hgs
parents:
diff changeset
   184
			{
hgs
parents:
diff changeset
   185
			// ADD
hgs
parents:
diff changeset
   186
			aBreakAddress = aOp1 + aOp2;
hgs
parents:
diff changeset
   187
			break;
hgs
parents:
diff changeset
   188
			}
hgs
parents:
diff changeset
   189
		case 5:
hgs
parents:
diff changeset
   190
			{
hgs
parents:
diff changeset
   191
			// ADC
hgs
parents:
diff changeset
   192
			aBreakAddress = aOp1 + aOp2 + (aStatusRegister & arm_carry_bit()) ? 1 : 0;
hgs
parents:
diff changeset
   193
			break;
hgs
parents:
diff changeset
   194
			}
hgs
parents:
diff changeset
   195
		case 6:
hgs
parents:
diff changeset
   196
			{
hgs
parents:
diff changeset
   197
			// SBC
hgs
parents:
diff changeset
   198
			aBreakAddress = aOp1 - aOp2 - (aStatusRegister & arm_carry_bit()) ? 0 : 1;
hgs
parents:
diff changeset
   199
			break;
hgs
parents:
diff changeset
   200
			}
hgs
parents:
diff changeset
   201
		case 7:
hgs
parents:
diff changeset
   202
			{
hgs
parents:
diff changeset
   203
			// RSC
hgs
parents:
diff changeset
   204
			aBreakAddress = aOp2 - aOp1 - (aStatusRegister & arm_carry_bit()) ? 0 : 1;
hgs
parents:
diff changeset
   205
			break;
hgs
parents:
diff changeset
   206
			}
hgs
parents:
diff changeset
   207
		case 12:
hgs
parents:
diff changeset
   208
			{
hgs
parents:
diff changeset
   209
			// ORR
hgs
parents:
diff changeset
   210
			aBreakAddress = aOp1 | aOp2;
hgs
parents:
diff changeset
   211
			break;
hgs
parents:
diff changeset
   212
			}
hgs
parents:
diff changeset
   213
		case 13:
hgs
parents:
diff changeset
   214
			{
hgs
parents:
diff changeset
   215
			// MOV
hgs
parents:
diff changeset
   216
			aBreakAddress = aOp2;
hgs
parents:
diff changeset
   217
			break;
hgs
parents:
diff changeset
   218
			}
hgs
parents:
diff changeset
   219
		case 14:
hgs
parents:
diff changeset
   220
			{
hgs
parents:
diff changeset
   221
			// BIC
hgs
parents:
diff changeset
   222
			aBreakAddress = aOp1 & ~aOp2;
hgs
parents:
diff changeset
   223
			break;
hgs
parents:
diff changeset
   224
			}
hgs
parents:
diff changeset
   225
		case 15:
hgs
parents:
diff changeset
   226
			{
hgs
parents:
diff changeset
   227
			// MVN
hgs
parents:
diff changeset
   228
			aBreakAddress = ~aOp2;
hgs
parents:
diff changeset
   229
			break;
hgs
parents:
diff changeset
   230
			}
hgs
parents:
diff changeset
   231
		}
hgs
parents:
diff changeset
   232
	}
hgs
parents:
diff changeset
   233
hgs
parents:
diff changeset
   234
//
hgs
parents:
diff changeset
   235
// DRMDStepping::CurrentInstruction
hgs
parents:
diff changeset
   236
//
hgs
parents:
diff changeset
   237
// Returns the current instruction bitpattern (either 32-bits or 16-bits) if possible
hgs
parents:
diff changeset
   238
TInt DRMDStepping::CurrentInstruction(DThread* aThread, TUint32& aInstruction)
hgs
parents:
diff changeset
   239
	{
hgs
parents:
diff changeset
   240
	LOG_MSG("DRMDStepping::CurrentInstruction");
hgs
parents:
diff changeset
   241
hgs
parents:
diff changeset
   242
	// What is the current PC?
hgs
parents:
diff changeset
   243
	TUint32 pc;	
hgs
parents:
diff changeset
   244
	ReturnIfError(CurrentPC(aThread,pc));
hgs
parents:
diff changeset
   245
hgs
parents:
diff changeset
   246
	// Read it one byte at a time to ensure alignment doesn't matter
hgs
parents:
diff changeset
   247
	TUint32 inst = 0;
hgs
parents:
diff changeset
   248
	for(TInt i=3;i>=0;i--)
hgs
parents:
diff changeset
   249
		{
hgs
parents:
diff changeset
   250
hgs
parents:
diff changeset
   251
		TBuf8<1> instruction;
hgs
parents:
diff changeset
   252
		TInt err = iChannel->DoReadMemory(aThread, (pc+i), 1, instruction); 
hgs
parents:
diff changeset
   253
		if (KErrNone != err)
hgs
parents:
diff changeset
   254
			{
hgs
parents:
diff changeset
   255
			LOG_MSG2("DRMDStepping::CurrentInstruction : Failed to read memory at current PC: return 0x%08x",pc);
hgs
parents:
diff changeset
   256
			return err;
hgs
parents:
diff changeset
   257
			}
hgs
parents:
diff changeset
   258
hgs
parents:
diff changeset
   259
		inst = (inst << 8) | (*(TUint8 *)instruction.Ptr());
hgs
parents:
diff changeset
   260
		}
hgs
parents:
diff changeset
   261
hgs
parents:
diff changeset
   262
	aInstruction = inst;
hgs
parents:
diff changeset
   263
hgs
parents:
diff changeset
   264
	LOG_MSG2("DRMDStepping::CurrentInstruction 0x%08x", aInstruction);
hgs
parents:
diff changeset
   265
hgs
parents:
diff changeset
   266
	return KErrNone;
hgs
parents:
diff changeset
   267
	}
hgs
parents:
diff changeset
   268
hgs
parents:
diff changeset
   269
//
hgs
parents:
diff changeset
   270
// DRMDStepping::CurrentArchMode
hgs
parents:
diff changeset
   271
//
hgs
parents:
diff changeset
   272
// Determines architecture mode from the supplied cpsr
hgs
parents:
diff changeset
   273
TInt DRMDStepping::CurrentArchMode(const TUint32 aCpsr, Debug::TArchitectureMode& aMode)
hgs
parents:
diff changeset
   274
	{
hgs
parents:
diff changeset
   275
// Thumb2 work will depend on having a suitable cpu architecture to compile for...
hgs
parents:
diff changeset
   276
#ifdef ECpuJf
hgs
parents:
diff changeset
   277
	// State table as per ARM ARM DDI0406A, section A.2.5.1
hgs
parents:
diff changeset
   278
	if(aCpsr & ECpuJf)
hgs
parents:
diff changeset
   279
		{
hgs
parents:
diff changeset
   280
		if (aCpsr & ECpuThumb)
hgs
parents:
diff changeset
   281
			{
hgs
parents:
diff changeset
   282
			// ThumbEE (Thumb2)
hgs
parents:
diff changeset
   283
			aMode = Debug::EThumb2EEMode;
hgs
parents:
diff changeset
   284
			}
hgs
parents:
diff changeset
   285
		else
hgs
parents:
diff changeset
   286
			{
hgs
parents:
diff changeset
   287
			// Jazelle mode - not supported
hgs
parents:
diff changeset
   288
			return KErrNotSupported;
hgs
parents:
diff changeset
   289
			}
hgs
parents:
diff changeset
   290
		}
hgs
parents:
diff changeset
   291
	else
hgs
parents:
diff changeset
   292
#endif
hgs
parents:
diff changeset
   293
		{
hgs
parents:
diff changeset
   294
		if (aCpsr & ECpuThumb)
hgs
parents:
diff changeset
   295
			{
hgs
parents:
diff changeset
   296
			// Thumb mode
hgs
parents:
diff changeset
   297
			aMode = Debug::EThumbMode;
hgs
parents:
diff changeset
   298
			}
hgs
parents:
diff changeset
   299
		else
hgs
parents:
diff changeset
   300
			{
hgs
parents:
diff changeset
   301
			// ARM mode
hgs
parents:
diff changeset
   302
			aMode = Debug::EArmMode;
hgs
parents:
diff changeset
   303
			}
hgs
parents:
diff changeset
   304
		}
hgs
parents:
diff changeset
   305
hgs
parents:
diff changeset
   306
	return KErrNone;
hgs
parents:
diff changeset
   307
	}
hgs
parents:
diff changeset
   308
hgs
parents:
diff changeset
   309
//
hgs
parents:
diff changeset
   310
// DRMDStepping::PCAfterInstructionExecutes
hgs
parents:
diff changeset
   311
//
hgs
parents:
diff changeset
   312
// Note, this function pretty much ignores all the arguments except for aThread.
hgs
parents:
diff changeset
   313
// The arguments continue to exist so that the function has the same prototype as
hgs
parents:
diff changeset
   314
// the original from Nokia. In the long term this function will be re-factored
hgs
parents:
diff changeset
   315
// to remove obsolete parameters.
hgs
parents:
diff changeset
   316
//
hgs
parents:
diff changeset
   317
TUint32 DRMDStepping::PCAfterInstructionExecutes(DThread *aThread, TUint32 aCurrentPC, TUint32 aStatusRegister, TInt aInstSize, /*TBool aStepInto,*/ TUint32 &aNewRangeEnd, TBool &aChangingModes)
hgs
parents:
diff changeset
   318
	{
hgs
parents:
diff changeset
   319
	LOG_MSG("DRMDStepping::PCAfterInstructionExecutes()");
hgs
parents:
diff changeset
   320
hgs
parents:
diff changeset
   321
	// by default we will set the breakpoint at the next instruction
hgs
parents:
diff changeset
   322
	TUint32 breakAddress = aCurrentPC + aInstSize;
hgs
parents:
diff changeset
   323
hgs
parents:
diff changeset
   324
	TInt err = KErrNone;
hgs
parents:
diff changeset
   325
hgs
parents:
diff changeset
   326
	// determine the architecture
hgs
parents:
diff changeset
   327
	TUint32 cpuid;
hgs
parents:
diff changeset
   328
	asm("mrc p15, 0, cpuid, c0, c0, 0 ");
hgs
parents:
diff changeset
   329
	LOG_MSG2("DRMDStepping::PCAfterInstructionExecutes() - cpuid = 0x%08x\n",cpuid);
hgs
parents:
diff changeset
   330
hgs
parents:
diff changeset
   331
	cpuid >>= 8;
hgs
parents:
diff changeset
   332
	cpuid &= 0xFF;
hgs
parents:
diff changeset
   333
hgs
parents:
diff changeset
   334
	// determine the architecture mode for the current instruction
hgs
parents:
diff changeset
   335
	TArchitectureMode mode = EArmMode;	// Default assumption is ARM 
hgs
parents:
diff changeset
   336
hgs
parents:
diff changeset
   337
	// Now we must examine the CPSR to read the T and J bits. See ARM ARM DDI0406A, section B1.3.3
hgs
parents:
diff changeset
   338
	TUint32 cpsr;
hgs
parents:
diff changeset
   339
hgs
parents:
diff changeset
   340
	ReturnIfError(CurrentCPSR(aThread,cpsr));
hgs
parents:
diff changeset
   341
	LOG_MSG2("DRMDStepping::PCAfterInstructionExecutes() - cpsr = 0x%08x\n",cpsr);
hgs
parents:
diff changeset
   342
hgs
parents:
diff changeset
   343
	// Determine the mode
hgs
parents:
diff changeset
   344
	ReturnIfError(CurrentArchMode(cpsr,mode));
hgs
parents:
diff changeset
   345
hgs
parents:
diff changeset
   346
	// Decode instruction based on current CPU mode
hgs
parents:
diff changeset
   347
	switch(mode)
hgs
parents:
diff changeset
   348
		{
hgs
parents:
diff changeset
   349
		case Debug::EArmMode:
hgs
parents:
diff changeset
   350
			{
hgs
parents:
diff changeset
   351
			// Obtain the current instruction bit pattern
hgs
parents:
diff changeset
   352
			TUint32 inst;
hgs
parents:
diff changeset
   353
			ReturnIfError(CurrentInstruction(aThread,inst));
hgs
parents:
diff changeset
   354
			
hgs
parents:
diff changeset
   355
			LOG_MSG2("Current instruction: %x", inst);
hgs
parents:
diff changeset
   356
hgs
parents:
diff changeset
   357
			// check the conditions to see if this will actually get executed
hgs
parents:
diff changeset
   358
			if (IsExecuted(((inst>>28) & 0x0000000F), aStatusRegister)) 
hgs
parents:
diff changeset
   359
				{
hgs
parents:
diff changeset
   360
				switch(arm_opcode(inst)) // bits 27-25
hgs
parents:
diff changeset
   361
					{
hgs
parents:
diff changeset
   362
					case 0:
hgs
parents:
diff changeset
   363
						{
hgs
parents:
diff changeset
   364
						switch((inst & 0x00000010) >> 4) // bit 4
hgs
parents:
diff changeset
   365
							{
hgs
parents:
diff changeset
   366
							case 0:
hgs
parents:
diff changeset
   367
								{
hgs
parents:
diff changeset
   368
								switch((inst & 0x01800000) >> 23) // bits 24-23
hgs
parents:
diff changeset
   369
									{
hgs
parents:
diff changeset
   370
									case 2:
hgs
parents:
diff changeset
   371
										{
hgs
parents:
diff changeset
   372
										// move to/from status register.  pc updates not allowed
hgs
parents:
diff changeset
   373
										// or TST, TEQ, CMP, CMN which don't modify the PC
hgs
parents:
diff changeset
   374
										break;
hgs
parents:
diff changeset
   375
										}
hgs
parents:
diff changeset
   376
									default:
hgs
parents:
diff changeset
   377
										{
hgs
parents:
diff changeset
   378
										// Data processing immediate shift
hgs
parents:
diff changeset
   379
										if (arm_rd(inst) == PC_REGISTER)
hgs
parents:
diff changeset
   380
											{
hgs
parents:
diff changeset
   381
											TUint32 rn = aCurrentPC + 8;
hgs
parents:
diff changeset
   382
											if (arm_rn(inst) != PC_REGISTER) // bits 19-16
hgs
parents:
diff changeset
   383
												{
hgs
parents:
diff changeset
   384
												err = iChannel->ReadKernelRegisterValue(aThread, arm_rn(inst), rn);
hgs
parents:
diff changeset
   385
												if(err != KErrNone)
hgs
parents:
diff changeset
   386
													{
hgs
parents:
diff changeset
   387
													LOG_MSG2("Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
   388
													}
hgs
parents:
diff changeset
   389
												}
hgs
parents:
diff changeset
   390
hgs
parents:
diff changeset
   391
											TUint32 shifter = ShiftedRegValue(aThread, inst, aCurrentPC, aStatusRegister);
hgs
parents:
diff changeset
   392
hgs
parents:
diff changeset
   393
											DecodeDataProcessingInstruction(((inst & 0x01E00000) >> 21), rn, shifter, aStatusRegister, breakAddress);
hgs
parents:
diff changeset
   394
											}
hgs
parents:
diff changeset
   395
										break;
hgs
parents:
diff changeset
   396
										}
hgs
parents:
diff changeset
   397
									}
hgs
parents:
diff changeset
   398
								break;
hgs
parents:
diff changeset
   399
								}
hgs
parents:
diff changeset
   400
							case 1:
hgs
parents:
diff changeset
   401
								{
hgs
parents:
diff changeset
   402
								switch((inst & 0x00000080) >> 7) // bit 7
hgs
parents:
diff changeset
   403
									{
hgs
parents:
diff changeset
   404
									case 0:
hgs
parents:
diff changeset
   405
										{
hgs
parents:
diff changeset
   406
										switch((inst & 0x01900000) >> 20) // bits 24-23 and bit 20
hgs
parents:
diff changeset
   407
											{
hgs
parents:
diff changeset
   408
											case 0x10:
hgs
parents:
diff changeset
   409
												{
hgs
parents:
diff changeset
   410
												// from figure 3-3
hgs
parents:
diff changeset
   411
												switch((inst & 0x000000F0) >> 4) // bits 7-4
hgs
parents:
diff changeset
   412
													{
hgs
parents:
diff changeset
   413
													case 1:
hgs
parents:
diff changeset
   414
														{
hgs
parents:
diff changeset
   415
														if (((inst & 0x00400000) >> 22) == 0) // bit 22
hgs
parents:
diff changeset
   416
															{
hgs
parents:
diff changeset
   417
															// BX
hgs
parents:
diff changeset
   418
															// this is a strange case.  normally this is used in the epilogue to branch the the link
hgs
parents:
diff changeset
   419
															// register.  sometimes it is used to call a function, and the LR is stored in the previous
hgs
parents:
diff changeset
   420
															// instruction.  since what we want to do is different for the two cases when stepping over,
hgs
parents:
diff changeset
   421
															// we need to read the previous instruction to see what we should do
hgs
parents:
diff changeset
   422
															err = iChannel->ReadKernelRegisterValue(aThread, (inst & 0x0000000F), breakAddress);
hgs
parents:
diff changeset
   423
															if(err != KErrNone)
hgs
parents:
diff changeset
   424
																{
hgs
parents:
diff changeset
   425
																LOG_MSG2("Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
   426
																}
hgs
parents:
diff changeset
   427
hgs
parents:
diff changeset
   428
															if ((breakAddress & 0x00000001) == 1)
hgs
parents:
diff changeset
   429
																{
hgs
parents:
diff changeset
   430
																aChangingModes = ETrue;
hgs
parents:
diff changeset
   431
																}
hgs
parents:
diff changeset
   432
hgs
parents:
diff changeset
   433
															breakAddress &= 0xFFFFFFFE;
hgs
parents:
diff changeset
   434
															}
hgs
parents:
diff changeset
   435
														break;
hgs
parents:
diff changeset
   436
														}
hgs
parents:
diff changeset
   437
													case 3:
hgs
parents:
diff changeset
   438
														{
hgs
parents:
diff changeset
   439
														// BLX
hgs
parents:
diff changeset
   440
															{
hgs
parents:
diff changeset
   441
															err = iChannel->ReadKernelRegisterValue(aThread, (inst & 0x0000000F), breakAddress);
hgs
parents:
diff changeset
   442
															if(err != KErrNone)
hgs
parents:
diff changeset
   443
																{
hgs
parents:
diff changeset
   444
																LOG_MSG2("Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
   445
																}
hgs
parents:
diff changeset
   446
hgs
parents:
diff changeset
   447
															if ((breakAddress & 0x00000001) == 1)
hgs
parents:
diff changeset
   448
																{
hgs
parents:
diff changeset
   449
																aChangingModes = ETrue;
hgs
parents:
diff changeset
   450
																}
hgs
parents:
diff changeset
   451
															
hgs
parents:
diff changeset
   452
															breakAddress &= 0xFFFFFFFE;
hgs
parents:
diff changeset
   453
															}
hgs
parents:
diff changeset
   454
														break;
hgs
parents:
diff changeset
   455
														}
hgs
parents:
diff changeset
   456
													default:
hgs
parents:
diff changeset
   457
														{
hgs
parents:
diff changeset
   458
														// either doesn't modify the PC or it is illegal to
hgs
parents:
diff changeset
   459
														break;
hgs
parents:
diff changeset
   460
														}
hgs
parents:
diff changeset
   461
													}
hgs
parents:
diff changeset
   462
												break;
hgs
parents:
diff changeset
   463
												}
hgs
parents:
diff changeset
   464
											default:
hgs
parents:
diff changeset
   465
												{
hgs
parents:
diff changeset
   466
												// Data processing register shift
hgs
parents:
diff changeset
   467
												if (((inst & 0x01800000) >> 23) == 2) // bits 24-23
hgs
parents:
diff changeset
   468
													{
hgs
parents:
diff changeset
   469
													// TST, TEQ, CMP, CMN don't modify the PC
hgs
parents:
diff changeset
   470
													}
hgs
parents:
diff changeset
   471
												else if (arm_rd(inst) == PC_REGISTER)
hgs
parents:
diff changeset
   472
													{
hgs
parents:
diff changeset
   473
													// destination register is the PC
hgs
parents:
diff changeset
   474
													TUint32 rn = aCurrentPC + 8;
hgs
parents:
diff changeset
   475
													if (arm_rn(inst) != PC_REGISTER) // bits 19-16
hgs
parents:
diff changeset
   476
														{
hgs
parents:
diff changeset
   477
														err = iChannel->ReadKernelRegisterValue(aThread, arm_rn(inst), rn);
hgs
parents:
diff changeset
   478
														if(err != KErrNone)
hgs
parents:
diff changeset
   479
															{
hgs
parents:
diff changeset
   480
															LOG_MSG2("Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
   481
															}
hgs
parents:
diff changeset
   482
														}
hgs
parents:
diff changeset
   483
													
hgs
parents:
diff changeset
   484
													TUint32 shifter = ShiftedRegValue(aThread, inst, aCurrentPC, aStatusRegister);
hgs
parents:
diff changeset
   485
													
hgs
parents:
diff changeset
   486
													DecodeDataProcessingInstruction(((inst & 0x01E00000) >> 21), rn, shifter, aStatusRegister, breakAddress);
hgs
parents:
diff changeset
   487
													}
hgs
parents:
diff changeset
   488
												break;
hgs
parents:
diff changeset
   489
												}
hgs
parents:
diff changeset
   490
											}
hgs
parents:
diff changeset
   491
										break;
hgs
parents:
diff changeset
   492
										}
hgs
parents:
diff changeset
   493
									default:
hgs
parents:
diff changeset
   494
										{
hgs
parents:
diff changeset
   495
										// from figure 3-2, updates to the PC illegal
hgs
parents:
diff changeset
   496
										break;
hgs
parents:
diff changeset
   497
										}
hgs
parents:
diff changeset
   498
									}
hgs
parents:
diff changeset
   499
								break;
hgs
parents:
diff changeset
   500
								}
hgs
parents:
diff changeset
   501
							}
hgs
parents:
diff changeset
   502
						break;
hgs
parents:
diff changeset
   503
						}
hgs
parents:
diff changeset
   504
					case 1:
hgs
parents:
diff changeset
   505
						{
hgs
parents:
diff changeset
   506
						if (((inst & 0x01800000) >> 23) == 2) // bits 24-23
hgs
parents:
diff changeset
   507
							{
hgs
parents:
diff changeset
   508
							// cannot modify the PC
hgs
parents:
diff changeset
   509
							break;
hgs
parents:
diff changeset
   510
							}
hgs
parents:
diff changeset
   511
						else if (arm_rd(inst) == PC_REGISTER)
hgs
parents:
diff changeset
   512
							{
hgs
parents:
diff changeset
   513
							// destination register is the PC
hgs
parents:
diff changeset
   514
							TUint32 rn;
hgs
parents:
diff changeset
   515
							err = iChannel->ReadKernelRegisterValue(aThread, arm_rn(inst), rn); // bits 19-16
hgs
parents:
diff changeset
   516
							if(err != KErrNone)
hgs
parents:
diff changeset
   517
								{
hgs
parents:
diff changeset
   518
								LOG_MSG2("Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
   519
								}
hgs
parents:
diff changeset
   520
							TUint32 shifter = ((arm_data_imm(inst) >> arm_data_rot(inst)) | (arm_data_imm(inst) << (32 - arm_data_rot(inst)))) & 0xffffffff;
hgs
parents:
diff changeset
   521
hgs
parents:
diff changeset
   522
							DecodeDataProcessingInstruction(((inst & 0x01E00000) >> 21), rn, shifter, aStatusRegister, breakAddress);
hgs
parents:
diff changeset
   523
							}
hgs
parents:
diff changeset
   524
						break;
hgs
parents:
diff changeset
   525
						}
hgs
parents:
diff changeset
   526
					case 2:
hgs
parents:
diff changeset
   527
						{
hgs
parents:
diff changeset
   528
						// load/store immediate offset
hgs
parents:
diff changeset
   529
						if (arm_load(inst)) // bit 20
hgs
parents:
diff changeset
   530
							{
hgs
parents:
diff changeset
   531
							// loading a register from memory
hgs
parents:
diff changeset
   532
							if (arm_rd(inst) == PC_REGISTER)
hgs
parents:
diff changeset
   533
								{
hgs
parents:
diff changeset
   534
								// loading the PC register
hgs
parents:
diff changeset
   535
								TUint32 base;
hgs
parents:
diff changeset
   536
								err = iChannel->ReadKernelRegisterValue(aThread, arm_rn(inst), base);
hgs
parents:
diff changeset
   537
								if(err != KErrNone)
hgs
parents:
diff changeset
   538
									{
hgs
parents:
diff changeset
   539
									LOG_MSG2("Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
   540
									}
hgs
parents:
diff changeset
   541
hgs
parents:
diff changeset
   542
								/* Note: At runtime the PC would be 8 further on
hgs
parents:
diff changeset
   543
								 */
hgs
parents:
diff changeset
   544
								if (arm_rn(inst) == PC_REGISTER)
hgs
parents:
diff changeset
   545
									{
hgs
parents:
diff changeset
   546
									base = aCurrentPC + 8;
hgs
parents:
diff changeset
   547
									}
hgs
parents:
diff changeset
   548
hgs
parents:
diff changeset
   549
								TUint32 offset = 0;
hgs
parents:
diff changeset
   550
hgs
parents:
diff changeset
   551
								if (arm_single_pre(inst))
hgs
parents:
diff changeset
   552
									{
hgs
parents:
diff changeset
   553
									// Pre-indexing
hgs
parents:
diff changeset
   554
									offset = arm_single_imm(inst);
hgs
parents:
diff changeset
   555
hgs
parents:
diff changeset
   556
									if (arm_single_u(inst))
hgs
parents:
diff changeset
   557
										{
hgs
parents:
diff changeset
   558
										base += offset;
hgs
parents:
diff changeset
   559
										}
hgs
parents:
diff changeset
   560
									else
hgs
parents:
diff changeset
   561
										{
hgs
parents:
diff changeset
   562
										base -= offset;
hgs
parents:
diff changeset
   563
										}
hgs
parents:
diff changeset
   564
									}
hgs
parents:
diff changeset
   565
hgs
parents:
diff changeset
   566
								TBuf8<4> destination;
hgs
parents:
diff changeset
   567
								err = iChannel->DoReadMemory(aThread, base, 4, destination);
hgs
parents:
diff changeset
   568
								
hgs
parents:
diff changeset
   569
								if (KErrNone == err)
hgs
parents:
diff changeset
   570
									{
hgs
parents:
diff changeset
   571
									breakAddress = *(TUint32 *)destination.Ptr();
hgs
parents:
diff changeset
   572
hgs
parents:
diff changeset
   573
									if ((breakAddress & 0x00000001) == 1)
hgs
parents:
diff changeset
   574
										{
hgs
parents:
diff changeset
   575
										aChangingModes = ETrue;
hgs
parents:
diff changeset
   576
										}
hgs
parents:
diff changeset
   577
									breakAddress &= 0xFFFFFFFE;
hgs
parents:
diff changeset
   578
									}
hgs
parents:
diff changeset
   579
								else
hgs
parents:
diff changeset
   580
									{
hgs
parents:
diff changeset
   581
									LOG_MSG("Error reading memory in decoding step instruction");
hgs
parents:
diff changeset
   582
									}
hgs
parents:
diff changeset
   583
								}
hgs
parents:
diff changeset
   584
							}
hgs
parents:
diff changeset
   585
						break;
hgs
parents:
diff changeset
   586
						}
hgs
parents:
diff changeset
   587
					case 3:
hgs
parents:
diff changeset
   588
						{
hgs
parents:
diff changeset
   589
						if (((inst & 0xF0000000) != 0xF0000000) && ((inst & 0x00000010) == 0))
hgs
parents:
diff changeset
   590
							{
hgs
parents:
diff changeset
   591
							// load/store register offset
hgs
parents:
diff changeset
   592
							if (arm_load(inst)) // bit 20
hgs
parents:
diff changeset
   593
								{
hgs
parents:
diff changeset
   594
								// loading a register from memory
hgs
parents:
diff changeset
   595
								if (arm_rd(inst) == PC_REGISTER)
hgs
parents:
diff changeset
   596
									{
hgs
parents:
diff changeset
   597
									// loading the PC register
hgs
parents:
diff changeset
   598
									TUint32 base = 0;
hgs
parents:
diff changeset
   599
									if(arm_rn(inst) == PC_REGISTER)
hgs
parents:
diff changeset
   600
										{
hgs
parents:
diff changeset
   601
										base = aCurrentPC + 8;
hgs
parents:
diff changeset
   602
										}
hgs
parents:
diff changeset
   603
									else
hgs
parents:
diff changeset
   604
										{
hgs
parents:
diff changeset
   605
										err = iChannel->ReadKernelRegisterValue(aThread, arm_rn(inst), base);
hgs
parents:
diff changeset
   606
										if(err != KErrNone)
hgs
parents:
diff changeset
   607
											{
hgs
parents:
diff changeset
   608
											LOG_MSG2("Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
   609
											}
hgs
parents:
diff changeset
   610
										}
hgs
parents:
diff changeset
   611
hgs
parents:
diff changeset
   612
									TUint32 offset = 0;
hgs
parents:
diff changeset
   613
hgs
parents:
diff changeset
   614
									if (arm_single_pre(inst))
hgs
parents:
diff changeset
   615
										{
hgs
parents:
diff changeset
   616
										offset = ShiftedRegValue(aThread, inst, aCurrentPC, aStatusRegister);
hgs
parents:
diff changeset
   617
hgs
parents:
diff changeset
   618
										if (arm_single_u(inst))
hgs
parents:
diff changeset
   619
											{
hgs
parents:
diff changeset
   620
											base += offset;
hgs
parents:
diff changeset
   621
											}
hgs
parents:
diff changeset
   622
										else
hgs
parents:
diff changeset
   623
											{
hgs
parents:
diff changeset
   624
											base -= offset;
hgs
parents:
diff changeset
   625
											}
hgs
parents:
diff changeset
   626
										}
hgs
parents:
diff changeset
   627
hgs
parents:
diff changeset
   628
									TBuf8<4> destination;
hgs
parents:
diff changeset
   629
									err = iChannel->DoReadMemory(aThread, base, 4, destination);
hgs
parents:
diff changeset
   630
hgs
parents:
diff changeset
   631
									if (KErrNone == err)
hgs
parents:
diff changeset
   632
										{
hgs
parents:
diff changeset
   633
										breakAddress = *(TUint32 *)destination.Ptr();
hgs
parents:
diff changeset
   634
hgs
parents:
diff changeset
   635
										if ((breakAddress & 0x00000001) == 1)
hgs
parents:
diff changeset
   636
											{
hgs
parents:
diff changeset
   637
											aChangingModes = ETrue;
hgs
parents:
diff changeset
   638
											}
hgs
parents:
diff changeset
   639
										breakAddress &= 0xFFFFFFFE;
hgs
parents:
diff changeset
   640
										}
hgs
parents:
diff changeset
   641
									else
hgs
parents:
diff changeset
   642
										{
hgs
parents:
diff changeset
   643
										LOG_MSG("Error reading memory in decoding step instruction");
hgs
parents:
diff changeset
   644
										}
hgs
parents:
diff changeset
   645
									}
hgs
parents:
diff changeset
   646
								}
hgs
parents:
diff changeset
   647
							}
hgs
parents:
diff changeset
   648
						break;
hgs
parents:
diff changeset
   649
						}
hgs
parents:
diff changeset
   650
					case 4:
hgs
parents:
diff changeset
   651
						{
hgs
parents:
diff changeset
   652
						if ((inst & 0xF0000000) != 0xF0000000)
hgs
parents:
diff changeset
   653
							{
hgs
parents:
diff changeset
   654
							// load/store multiple
hgs
parents:
diff changeset
   655
							if (arm_load(inst)) // bit 20
hgs
parents:
diff changeset
   656
								{
hgs
parents:
diff changeset
   657
								// loading a register from memory
hgs
parents:
diff changeset
   658
								if (((inst & 0x00008000) >> 15))
hgs
parents:
diff changeset
   659
									{
hgs
parents:
diff changeset
   660
									// loading the PC register
hgs
parents:
diff changeset
   661
									TInt offset = 0;	
hgs
parents:
diff changeset
   662
									if (arm_block_u(inst))
hgs
parents:
diff changeset
   663
										{
hgs
parents:
diff changeset
   664
										TUint32 reglist = arm_block_reglist(inst);
hgs
parents:
diff changeset
   665
										offset = iChannel->Bitcount(reglist) * 4 - 4;
hgs
parents:
diff changeset
   666
										if (arm_block_pre(inst))
hgs
parents:
diff changeset
   667
											offset += 4;
hgs
parents:
diff changeset
   668
										}
hgs
parents:
diff changeset
   669
									else if (arm_block_pre(inst))
hgs
parents:
diff changeset
   670
										{
hgs
parents:
diff changeset
   671
										offset = -4;
hgs
parents:
diff changeset
   672
										}
hgs
parents:
diff changeset
   673
hgs
parents:
diff changeset
   674
									TUint32 temp = 0;
hgs
parents:
diff changeset
   675
									err = iChannel->ReadKernelRegisterValue(aThread, arm_rn(inst), temp);
hgs
parents:
diff changeset
   676
									if(err != KErrNone)
hgs
parents:
diff changeset
   677
										{
hgs
parents:
diff changeset
   678
										LOG_MSG2("Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
   679
										}
hgs
parents:
diff changeset
   680
hgs
parents:
diff changeset
   681
									temp += offset;
hgs
parents:
diff changeset
   682
hgs
parents:
diff changeset
   683
									TBuf8<4> destination;
hgs
parents:
diff changeset
   684
									err = iChannel->DoReadMemory(aThread, temp, 4, destination);
hgs
parents:
diff changeset
   685
hgs
parents:
diff changeset
   686
									if (KErrNone == err)
hgs
parents:
diff changeset
   687
										{
hgs
parents:
diff changeset
   688
										breakAddress = *(TUint32 *)destination.Ptr();
hgs
parents:
diff changeset
   689
										if ((breakAddress & 0x00000001) == 1)
hgs
parents:
diff changeset
   690
											{
hgs
parents:
diff changeset
   691
											aChangingModes = ETrue;
hgs
parents:
diff changeset
   692
											}
hgs
parents:
diff changeset
   693
										breakAddress &= 0xFFFFFFFE;
hgs
parents:
diff changeset
   694
										}
hgs
parents:
diff changeset
   695
									else
hgs
parents:
diff changeset
   696
										{
hgs
parents:
diff changeset
   697
										LOG_MSG("Error reading memory in decoding step instruction");
hgs
parents:
diff changeset
   698
										}
hgs
parents:
diff changeset
   699
									}
hgs
parents:
diff changeset
   700
								}
hgs
parents:
diff changeset
   701
							}
hgs
parents:
diff changeset
   702
						break;
hgs
parents:
diff changeset
   703
						}
hgs
parents:
diff changeset
   704
					case 5:
hgs
parents:
diff changeset
   705
						{
hgs
parents:
diff changeset
   706
						if ((inst & 0xF0000000) == 0xF0000000)
hgs
parents:
diff changeset
   707
							{
hgs
parents:
diff changeset
   708
							// BLX
hgs
parents:
diff changeset
   709
							breakAddress = (TUint32)arm_instr_b_dest(inst, aCurrentPC);
hgs
parents:
diff changeset
   710
hgs
parents:
diff changeset
   711
							// Unconditionally change into Thumb mode
hgs
parents:
diff changeset
   712
							aChangingModes = ETrue;
hgs
parents:
diff changeset
   713
							breakAddress &= 0xFFFFFFFE;
hgs
parents:
diff changeset
   714
							}
hgs
parents:
diff changeset
   715
						else
hgs
parents:
diff changeset
   716
							{
hgs
parents:
diff changeset
   717
							if ((inst & 0x01000000)) // bit 24
hgs
parents:
diff changeset
   718
								{
hgs
parents:
diff changeset
   719
								// BL
hgs
parents:
diff changeset
   720
									breakAddress = (TUint32)arm_instr_b_dest(inst, aCurrentPC);
hgs
parents:
diff changeset
   721
								}
hgs
parents:
diff changeset
   722
							else
hgs
parents:
diff changeset
   723
								{
hgs
parents:
diff changeset
   724
								// B
hgs
parents:
diff changeset
   725
								breakAddress = (TUint32)arm_instr_b_dest(inst, aCurrentPC);
hgs
parents:
diff changeset
   726
								}
hgs
parents:
diff changeset
   727
							}
hgs
parents:
diff changeset
   728
						break;
hgs
parents:
diff changeset
   729
						} // case 5
hgs
parents:
diff changeset
   730
					} //switch(arm_opcode(inst)) // bits 27-25
hgs
parents:
diff changeset
   731
				} // if (IsExecuted(((inst>>28) & 0x0000000F), aStatusRegister)) 
hgs
parents:
diff changeset
   732
			} // case Debug::EArmMode:
hgs
parents:
diff changeset
   733
		break;
hgs
parents:
diff changeset
   734
hgs
parents:
diff changeset
   735
		case Debug::EThumbMode:
hgs
parents:
diff changeset
   736
			{
hgs
parents:
diff changeset
   737
			// Thumb Mode
hgs
parents:
diff changeset
   738
			//
hgs
parents:
diff changeset
   739
			// Notes: This now includes the extra code
hgs
parents:
diff changeset
   740
			// required to decode V6T2 instructions
hgs
parents:
diff changeset
   741
			
hgs
parents:
diff changeset
   742
			LOG_MSG("DRMDStepping::PCAfterInstructionExecutes: Thumb Instruction");
hgs
parents:
diff changeset
   743
hgs
parents:
diff changeset
   744
			TUint16 inst;
hgs
parents:
diff changeset
   745
hgs
parents:
diff changeset
   746
			// Obtain the current instruction bit pattern
hgs
parents:
diff changeset
   747
			TUint32 inst32;
hgs
parents:
diff changeset
   748
			ReturnIfError(CurrentInstruction(aThread,inst32));
hgs
parents:
diff changeset
   749
hgs
parents:
diff changeset
   750
			inst = static_cast<TUint16>(inst32 & 0xFFFF);
hgs
parents:
diff changeset
   751
hgs
parents:
diff changeset
   752
			LOG_MSG2("Current Thumb instruction: 0x%x", inst);
hgs
parents:
diff changeset
   753
hgs
parents:
diff changeset
   754
			// v6T2 instructions
hgs
parents:
diff changeset
   755
hgs
parents:
diff changeset
   756
			// Note: v6T2 decoding is only enabled for DEBUG builds or if using an
hgs
parents:
diff changeset
   757
			// an ARM_V6T2 supporting build system. At the time of writing, no
hgs
parents:
diff changeset
   758
			// ARM_V6T2 supporting build system exists, so the stepping code cannot
hgs
parents:
diff changeset
   759
			// be said to be known to work. Hence it is not run for release builds
hgs
parents:
diff changeset
   760
hgs
parents:
diff changeset
   761
			TBool use_v6t2_decodings = EFalse;
hgs
parents:
diff changeset
   762
hgs
parents:
diff changeset
   763
#if defined(DEBUG) || defined(__ARMV6T2__)
hgs
parents:
diff changeset
   764
			use_v6t2_decodings = ETrue;
hgs
parents:
diff changeset
   765
#endif
hgs
parents:
diff changeset
   766
			// coverity[dead_error_line]
hgs
parents:
diff changeset
   767
			if (use_v6t2_decodings)
hgs
parents:
diff changeset
   768
				{
hgs
parents:
diff changeset
   769
				// 16-bit encodings
hgs
parents:
diff changeset
   770
hgs
parents:
diff changeset
   771
				// A6.2.5 Misc 16-bit instructions
hgs
parents:
diff changeset
   772
				// DONE Compare and branch on zero (page A8-66)
hgs
parents:
diff changeset
   773
				// If then hints
hgs
parents:
diff changeset
   774
hgs
parents:
diff changeset
   775
				// ARM ARM DDI0406A - section A8.6.27 CBNZ, CBZ
hgs
parents:
diff changeset
   776
				//
hgs
parents:
diff changeset
   777
				// Compare and branch on Nonzero and Compare and Branch on Zero.
hgs
parents:
diff changeset
   778
				if ((inst & 0xF500) == 0xB100)
hgs
parents:
diff changeset
   779
					{
hgs
parents:
diff changeset
   780
					LOG_MSG("ARM ARM DDI0406A - section A8.6.27 CBNZ, CBZ");
hgs
parents:
diff changeset
   781
hgs
parents:
diff changeset
   782
					// Decoding as per ARM ARM description
hgs
parents:
diff changeset
   783
					TUint32 op = (inst & 0x0800) >> 11;
hgs
parents:
diff changeset
   784
					TUint32 i = (inst & 0x0200) >> 9;
hgs
parents:
diff changeset
   785
					TUint32 imm5 = (inst & 0x00F8) >> 3;
hgs
parents:
diff changeset
   786
					TUint32 Rn = inst & 0x0007;
hgs
parents:
diff changeset
   787
hgs
parents:
diff changeset
   788
					TUint32 imm32 = (i << 6) | (imm5 << 1);
hgs
parents:
diff changeset
   789
hgs
parents:
diff changeset
   790
					// Obtain value for register Rn
hgs
parents:
diff changeset
   791
					TUint32 RnVal = 0;
hgs
parents:
diff changeset
   792
					ReturnIfError(RegisterValue(aThread,Rn,RnVal));
hgs
parents:
diff changeset
   793
hgs
parents:
diff changeset
   794
					if (op)
hgs
parents:
diff changeset
   795
						{
hgs
parents:
diff changeset
   796
						// nonzero
hgs
parents:
diff changeset
   797
						if (RnVal != 0x0)
hgs
parents:
diff changeset
   798
							{
hgs
parents:
diff changeset
   799
							// Branch
hgs
parents:
diff changeset
   800
							breakAddress = aCurrentPC + imm32;
hgs
parents:
diff changeset
   801
							}
hgs
parents:
diff changeset
   802
						}
hgs
parents:
diff changeset
   803
					else
hgs
parents:
diff changeset
   804
						{
hgs
parents:
diff changeset
   805
						// zero
hgs
parents:
diff changeset
   806
						if (RnVal == 0x0)
hgs
parents:
diff changeset
   807
							{
hgs
parents:
diff changeset
   808
							// Branch
hgs
parents:
diff changeset
   809
							breakAddress = aCurrentPC + imm32;
hgs
parents:
diff changeset
   810
							}
hgs
parents:
diff changeset
   811
						}
hgs
parents:
diff changeset
   812
				}
hgs
parents:
diff changeset
   813
hgs
parents:
diff changeset
   814
				// ARM ARM DDI0406A - section A8.6.50 IT
hgs
parents:
diff changeset
   815
				//
hgs
parents:
diff changeset
   816
				// If Then instruction
hgs
parents:
diff changeset
   817
				if ((inst & 0xFF00) == 0xBF00)
hgs
parents:
diff changeset
   818
					{
hgs
parents:
diff changeset
   819
					LOG_MSG("ARM ARM DDI0406A - section A8.6.50 IT");
hgs
parents:
diff changeset
   820
hgs
parents:
diff changeset
   821
					// Decoding as per ARM ARM description
hgs
parents:
diff changeset
   822
					TUint32 firstcond = inst & 0x00F0 >> 4;
hgs
parents:
diff changeset
   823
					TUint32 mask = inst & 0x000F;
hgs
parents:
diff changeset
   824
hgs
parents:
diff changeset
   825
					if (firstcond == 0xF)
hgs
parents:
diff changeset
   826
						{
hgs
parents:
diff changeset
   827
						// unpredictable
hgs
parents:
diff changeset
   828
						LOG_MSG("ARM ARM DDI0406A - section A8.6.50 IT - Unpredictable");
hgs
parents:
diff changeset
   829
						break;
hgs
parents:
diff changeset
   830
						}
hgs
parents:
diff changeset
   831
hgs
parents:
diff changeset
   832
					if ((firstcond == 0xE) && (BitCount(mask) != 1))
hgs
parents:
diff changeset
   833
						{
hgs
parents:
diff changeset
   834
						// unpredictable
hgs
parents:
diff changeset
   835
						LOG_MSG("ARM ARM DDI0406A - section A8.6.50 IT - Unpredictable");
hgs
parents:
diff changeset
   836
						break;
hgs
parents:
diff changeset
   837
						}
hgs
parents:
diff changeset
   838
hgs
parents:
diff changeset
   839
					// should check if 'in-it-block'
hgs
parents:
diff changeset
   840
					LOG_MSG("Cannot step IT instructions.");
hgs
parents:
diff changeset
   841
hgs
parents:
diff changeset
   842
					// all the conds are as per Table A8-1 (i.e. the usual 16 cases)
hgs
parents:
diff changeset
   843
					// no idea how to decode the it block 'after-the-fact'
hgs
parents:
diff changeset
   844
					// so probably need to treat instructions in the it block
hgs
parents:
diff changeset
   845
					// as 'may' be executed. So breakpoints at both possible locations
hgs
parents:
diff changeset
   846
					// depending on whether the instruction is executed or not.
hgs
parents:
diff changeset
   847
hgs
parents:
diff changeset
   848
					// also, how do we know if we have hit a breakpoint whilst 'in' an it block?
hgs
parents:
diff changeset
   849
					// can we check the status registers to find out?
hgs
parents:
diff changeset
   850
					//
hgs
parents:
diff changeset
   851
					// see arm arm page 390.
hgs
parents:
diff changeset
   852
					//
hgs
parents:
diff changeset
   853
					// seems to depend on the itstate field. this also says what the condition code
hgs
parents:
diff changeset
   854
					// actually is, and how many instructions are left in the itblock.
hgs
parents:
diff changeset
   855
					// perhaps we can just totally ignore this state, and always do the two-instruction
hgs
parents:
diff changeset
   856
					// breakpoint thing? Not if there is any possibility that the address target
hgs
parents:
diff changeset
   857
					// would be invalid for the non-taken branch address...
hgs
parents:
diff changeset
   858
					}
hgs
parents:
diff changeset
   859
hgs
parents:
diff changeset
   860
hgs
parents:
diff changeset
   861
				// 32-bit encodings.
hgs
parents:
diff changeset
   862
				//
hgs
parents:
diff changeset
   863
hgs
parents:
diff changeset
   864
				// Load word A6-23
hgs
parents:
diff changeset
   865
				// Data processing instructions a6-28
hgs
parents:
diff changeset
   866
				// 
hgs
parents:
diff changeset
   867
hgs
parents:
diff changeset
   868
				// ARM ARM DDI0406A - section A8.6.26
hgs
parents:
diff changeset
   869
				if (inst32 & 0xFFF0FFFF == 0xE3C08F00)
hgs
parents:
diff changeset
   870
					{
hgs
parents:
diff changeset
   871
					LOG_MSG("ARM ARM DDI0406A - section A8.6.26 - BXJ is not supported");
hgs
parents:
diff changeset
   872
hgs
parents:
diff changeset
   873
					// Decoding as per ARM ARM description
hgs
parents:
diff changeset
   874
					// TUint32 Rm = inst32 & 0x000F0000;	// not needed yet
hgs
parents:
diff changeset
   875
					}
hgs
parents:
diff changeset
   876
hgs
parents:
diff changeset
   877
				// return from exception... SUBS PC,LR. page b6-25
hgs
parents:
diff changeset
   878
				//
hgs
parents:
diff changeset
   879
				// ARM ARM DDi046A - section B6.1.13 - SUBS PC,LR
hgs
parents:
diff changeset
   880
				//
hgs
parents:
diff changeset
   881
				// Encoding T1
hgs
parents:
diff changeset
   882
				if (inst32 & 0xFFFFFF00 == 0xF3DE8F00)
hgs
parents:
diff changeset
   883
					{
hgs
parents:
diff changeset
   884
					LOG_MSG("ARM ARM DDI0406A - section B6.1.13 - SUBS PC,LR Encoding T1");
hgs
parents:
diff changeset
   885
hgs
parents:
diff changeset
   886
					// Decoding as per ARM ARM description
hgs
parents:
diff changeset
   887
					TUint32 imm8 = inst32 & 0x000000FF;
hgs
parents:
diff changeset
   888
					TUint32 imm32 = imm8;
hgs
parents:
diff changeset
   889
hgs
parents:
diff changeset
   890
					// TUint32 register_form = EFalse;	// not needed for this decoding
hgs
parents:
diff changeset
   891
					// TUint32 opcode = 0x2;	// SUB	// not needed for this decoding
hgs
parents:
diff changeset
   892
					TUint32 n = 14;
hgs
parents:
diff changeset
   893
hgs
parents:
diff changeset
   894
					// Obtain LR
hgs
parents:
diff changeset
   895
					TUint32 lrVal;
hgs
parents:
diff changeset
   896
					ReturnIfError(RegisterValue(aThread,n,lrVal));
hgs
parents:
diff changeset
   897
hgs
parents:
diff changeset
   898
					TUint32 operand2 = imm32;	// always for Encoding T1
hgs
parents:
diff changeset
   899
					
hgs
parents:
diff changeset
   900
					TUint32 result = lrVal - operand2;
hgs
parents:
diff changeset
   901
					
hgs
parents:
diff changeset
   902
					breakAddress = result;
hgs
parents:
diff changeset
   903
					}
hgs
parents:
diff changeset
   904
hgs
parents:
diff changeset
   905
				// ARM ARM DDI0406A - section A8.6.16 - B
hgs
parents:
diff changeset
   906
				//
hgs
parents:
diff changeset
   907
				// Branch Encoding T3
hgs
parents:
diff changeset
   908
				if (inst32 & 0xF800D000 == 0xF0008000)
hgs
parents:
diff changeset
   909
					{
hgs
parents:
diff changeset
   910
					LOG_MSG("ARM ARM DDI0406A - section A8.6.16 - B Encoding T3");
hgs
parents:
diff changeset
   911
hgs
parents:
diff changeset
   912
					// Decoding as per ARM ARM description
hgs
parents:
diff changeset
   913
					TUint32 S = inst32 & 0x04000000 >> 26;
hgs
parents:
diff changeset
   914
					// TUint32 cond = inst32 & 0x03C00000 >> 22;	// not needed for this decoding
hgs
parents:
diff changeset
   915
					TUint32 imm6 = inst32 & 0x003F0000 >> 16;
hgs
parents:
diff changeset
   916
					TUint32 J1 = inst32 & 0x00002000 >> 13;
hgs
parents:
diff changeset
   917
					TUint32 J2 = inst32 & 0x00000800 >> 11;
hgs
parents:
diff changeset
   918
					TUint32 imm11 = inst32 & 0x000007FF;
hgs
parents:
diff changeset
   919
hgs
parents:
diff changeset
   920
					TUint32 imm32 = S ? 0xFFFFFFFF : 0 ;
hgs
parents:
diff changeset
   921
					imm32 = (imm32 << 1) | J2;
hgs
parents:
diff changeset
   922
					imm32 = (imm32 << 1) | J1;
hgs
parents:
diff changeset
   923
					imm32 = (imm32 << 6) | imm6;
hgs
parents:
diff changeset
   924
					imm32 = (imm32 << 11) | imm11;
hgs
parents:
diff changeset
   925
					imm32 = (imm32 << 1) | 0;
hgs
parents:
diff changeset
   926
hgs
parents:
diff changeset
   927
					breakAddress = aCurrentPC + imm32;
hgs
parents:
diff changeset
   928
					}
hgs
parents:
diff changeset
   929
hgs
parents:
diff changeset
   930
				// ARM ARM DDI0406A - section A8.6.16 - B
hgs
parents:
diff changeset
   931
				//
hgs
parents:
diff changeset
   932
				// Branch Encoding T4
hgs
parents:
diff changeset
   933
				if (inst32 & 0xF800D000 == 0xF0009000)
hgs
parents:
diff changeset
   934
					{
hgs
parents:
diff changeset
   935
					LOG_MSG("ARM ARM DDI0406A - section A8.6.16 - B");
hgs
parents:
diff changeset
   936
hgs
parents:
diff changeset
   937
					// Decoding as per ARM ARM description
hgs
parents:
diff changeset
   938
					TUint32 S = inst32 & 0x04000000 >> 26;
hgs
parents:
diff changeset
   939
					TUint32 imm10 = inst32 & 0x03FF0000 >> 16;
hgs
parents:
diff changeset
   940
					TUint32 J1 = inst32 & 0x00002000 >> 12;
hgs
parents:
diff changeset
   941
					TUint32 J2 = inst32 & 0x00000800 >> 11;
hgs
parents:
diff changeset
   942
					TUint32 imm11 = inst32 & 0x000003FF;
hgs
parents:
diff changeset
   943
hgs
parents:
diff changeset
   944
					TUint32 I1 = !(J1 ^ S);
hgs
parents:
diff changeset
   945
					TUint32 I2 = !(J2 ^ S);
hgs
parents:
diff changeset
   946
hgs
parents:
diff changeset
   947
					TUint32 imm32 = S ? 0xFFFFFFFF : 0;
hgs
parents:
diff changeset
   948
					imm32 = (imm32 << 1) | S;
hgs
parents:
diff changeset
   949
					imm32 = (imm32 << 1) | I1;
hgs
parents:
diff changeset
   950
					imm32 = (imm32 << 1) | I2;
hgs
parents:
diff changeset
   951
					imm32 = (imm32 << 10) | imm10;
hgs
parents:
diff changeset
   952
					imm32 = (imm32 << 11) | imm11;
hgs
parents:
diff changeset
   953
					imm32 = (imm32 << 1) | 0;
hgs
parents:
diff changeset
   954
hgs
parents:
diff changeset
   955
					breakAddress = aCurrentPC + imm32;
hgs
parents:
diff changeset
   956
					}
hgs
parents:
diff changeset
   957
hgs
parents:
diff changeset
   958
hgs
parents:
diff changeset
   959
				// ARM ARM DDI0406A - section A8.6.225 - TBB, TBH
hgs
parents:
diff changeset
   960
				//
hgs
parents:
diff changeset
   961
				// Table Branch Byte, Table Branch Halfword
hgs
parents:
diff changeset
   962
				if (inst32 & 0xFFF0FFE0 == 0xE8D0F000)
hgs
parents:
diff changeset
   963
						{
hgs
parents:
diff changeset
   964
					LOG_MSG("ARM ARM DDI0406A - section A8.6.225 TBB,TBH Encoding T1");
hgs
parents:
diff changeset
   965
hgs
parents:
diff changeset
   966
					// Decoding as per ARM ARM description
hgs
parents:
diff changeset
   967
					TUint32 Rn = inst32 & 0x000F0000 >> 16;
hgs
parents:
diff changeset
   968
					TUint32 H = inst32 & 0x00000010 >> 4;
hgs
parents:
diff changeset
   969
					TUint32 Rm = inst32 & 0x0000000F;
hgs
parents:
diff changeset
   970
hgs
parents:
diff changeset
   971
					// Unpredictable?
hgs
parents:
diff changeset
   972
					if (Rm == 13 || Rm == 15)
hgs
parents:
diff changeset
   973
						{
hgs
parents:
diff changeset
   974
						LOG_MSG("ARM ARM DDI0406A - section A8.6.225 TBB,TBH Encoding T1 - Unpredictable");
hgs
parents:
diff changeset
   975
						break;
hgs
parents:
diff changeset
   976
						}
hgs
parents:
diff changeset
   977
hgs
parents:
diff changeset
   978
					TUint32 halfwords;
hgs
parents:
diff changeset
   979
					TUint32 address;
hgs
parents:
diff changeset
   980
					ReturnIfError(RegisterValue(aThread,Rn,address));
hgs
parents:
diff changeset
   981
hgs
parents:
diff changeset
   982
					TUint32 offset;
hgs
parents:
diff changeset
   983
					ReturnIfError(RegisterValue(aThread,Rm,offset));
hgs
parents:
diff changeset
   984
hgs
parents:
diff changeset
   985
					if (H)
hgs
parents:
diff changeset
   986
						{
hgs
parents:
diff changeset
   987
						address += offset << 1;
hgs
parents:
diff changeset
   988
						}
hgs
parents:
diff changeset
   989
					else
hgs
parents:
diff changeset
   990
						{
hgs
parents:
diff changeset
   991
						address += offset;
hgs
parents:
diff changeset
   992
						}
hgs
parents:
diff changeset
   993
hgs
parents:
diff changeset
   994
					ReturnIfError(ReadMem32(aThread,address,halfwords));
hgs
parents:
diff changeset
   995
hgs
parents:
diff changeset
   996
					breakAddress = aCurrentPC + 2*halfwords;
hgs
parents:
diff changeset
   997
					break;
hgs
parents:
diff changeset
   998
					}
hgs
parents:
diff changeset
   999
hgs
parents:
diff changeset
  1000
				// ARM ARM DDI0406A - section A8.6.55 - LDMDB, LDMEA
hgs
parents:
diff changeset
  1001
				//
hgs
parents:
diff changeset
  1002
				// LDMDB Encoding T1
hgs
parents:
diff changeset
  1003
				if (inst32 & 0xFFD02000 == 0xE9100000)
hgs
parents:
diff changeset
  1004
					{
hgs
parents:
diff changeset
  1005
					LOG_MSG("ARM ARM DDI0406 - section A8.6.55 LDMDB Encoding T1");
hgs
parents:
diff changeset
  1006
hgs
parents:
diff changeset
  1007
					// Decoding as per ARM ARM description
hgs
parents:
diff changeset
  1008
					// TUint32 W = inst32 & 0x00200000 >> 21;	// Not needed for this encoding
hgs
parents:
diff changeset
  1009
					TUint32 Rn = inst32 & 0x000F0000 >> 16;
hgs
parents:
diff changeset
  1010
					TUint32 P = inst32 & 0x00008000 >> 15;
hgs
parents:
diff changeset
  1011
					TUint32 M = inst32 & 0x00004000 >> 14;
hgs
parents:
diff changeset
  1012
					TUint32 registers = inst32 & 0x00001FFF;
hgs
parents:
diff changeset
  1013
hgs
parents:
diff changeset
  1014
					//TBool wback = (W == 1);	// not needed for this encoding
hgs
parents:
diff changeset
  1015
hgs
parents:
diff changeset
  1016
					// Unpredictable?
hgs
parents:
diff changeset
  1017
					if (Rn == 15 || BitCount(registers) < 2 || ((P == 1) && (M==1)))
hgs
parents:
diff changeset
  1018
						{
hgs
parents:
diff changeset
  1019
						LOG_MSG("ARM ARM DDI0406 - section A8.6.55 LDMDB Encoding T1 - Unpredictable");
hgs
parents:
diff changeset
  1020
						break;
hgs
parents:
diff changeset
  1021
						}
hgs
parents:
diff changeset
  1022
hgs
parents:
diff changeset
  1023
					TUint32 address;
hgs
parents:
diff changeset
  1024
					ReturnIfError(RegisterValue(aThread,Rn,address));
hgs
parents:
diff changeset
  1025
hgs
parents:
diff changeset
  1026
					address -= 4*BitCount(registers);
hgs
parents:
diff changeset
  1027
hgs
parents:
diff changeset
  1028
					for(TInt i=0; i<15; i++)
hgs
parents:
diff changeset
  1029
						{
hgs
parents:
diff changeset
  1030
						if (IsBitSet(registers,i))
hgs
parents:
diff changeset
  1031
							{
hgs
parents:
diff changeset
  1032
							address +=4;
hgs
parents:
diff changeset
  1033
							}
hgs
parents:
diff changeset
  1034
						}
hgs
parents:
diff changeset
  1035
hgs
parents:
diff changeset
  1036
					if (IsBitSet(registers,15))
hgs
parents:
diff changeset
  1037
						{
hgs
parents:
diff changeset
  1038
						TUint32 RnVal = 0;
hgs
parents:
diff changeset
  1039
						ReturnIfError(ReadMem32(aThread,address,RnVal));
hgs
parents:
diff changeset
  1040
hgs
parents:
diff changeset
  1041
						breakAddress = RnVal;
hgs
parents:
diff changeset
  1042
						}
hgs
parents:
diff changeset
  1043
					break;
hgs
parents:
diff changeset
  1044
					}
hgs
parents:
diff changeset
  1045
hgs
parents:
diff changeset
  1046
				// ARM ARM DDI0406A - section A8.6.121 POP
hgs
parents:
diff changeset
  1047
				//
hgs
parents:
diff changeset
  1048
				// POP.W Encoding T2
hgs
parents:
diff changeset
  1049
				if (inst32 & 0xFFFF2000 == 0xE8BD0000)
hgs
parents:
diff changeset
  1050
					{
hgs
parents:
diff changeset
  1051
					LOG_MSG("ARM ARM DDI0406A - section A8.6.121 POP Encoding T2");
hgs
parents:
diff changeset
  1052
hgs
parents:
diff changeset
  1053
					// Decoding as per ARM ARM description
hgs
parents:
diff changeset
  1054
					TUint32 registers = inst32 & 0x00001FFF;
hgs
parents:
diff changeset
  1055
					TUint32 P = inst32 & 0x00008000;
hgs
parents:
diff changeset
  1056
					TUint32 M = inst32 & 0x00004000;
hgs
parents:
diff changeset
  1057
hgs
parents:
diff changeset
  1058
					// Unpredictable?
hgs
parents:
diff changeset
  1059
					if ( (BitCount(registers)<2) || ((P == 1)&&(M == 1)) )
hgs
parents:
diff changeset
  1060
						{
hgs
parents:
diff changeset
  1061
						LOG_MSG("ARM ARM DDI0406A - section A8.6.121 POP Encoding T2 - Unpredictable");
hgs
parents:
diff changeset
  1062
						break;
hgs
parents:
diff changeset
  1063
						}
hgs
parents:
diff changeset
  1064
hgs
parents:
diff changeset
  1065
					TUint32 address;
hgs
parents:
diff changeset
  1066
					ReturnIfError(RegisterValue(aThread,13,address));
hgs
parents:
diff changeset
  1067
					
hgs
parents:
diff changeset
  1068
					for(TInt i=0; i< 15; i++)
hgs
parents:
diff changeset
  1069
						{
hgs
parents:
diff changeset
  1070
						if (IsBitSet(registers,i))
hgs
parents:
diff changeset
  1071
							{
hgs
parents:
diff changeset
  1072
							address += 4;
hgs
parents:
diff changeset
  1073
							}
hgs
parents:
diff changeset
  1074
						}
hgs
parents:
diff changeset
  1075
hgs
parents:
diff changeset
  1076
					// Is the PC written?
hgs
parents:
diff changeset
  1077
					if (IsBitSet(registers,15))
hgs
parents:
diff changeset
  1078
						{
hgs
parents:
diff changeset
  1079
						// Yes
hgs
parents:
diff changeset
  1080
						ReturnIfError(ReadMem32(aThread,address,breakAddress));
hgs
parents:
diff changeset
  1081
						}
hgs
parents:
diff changeset
  1082
					}
hgs
parents:
diff changeset
  1083
hgs
parents:
diff changeset
  1084
				// POP Encoding T3
hgs
parents:
diff changeset
  1085
				if (inst32 & 0xFFFF0FFFF == 0xF85D0B04)
hgs
parents:
diff changeset
  1086
					{
hgs
parents:
diff changeset
  1087
					LOG_MSG("ARM ARM DDI0406A - section A8.6.121 POP Encoding T3");
hgs
parents:
diff changeset
  1088
hgs
parents:
diff changeset
  1089
					// Decoding as per ARM ARM description
hgs
parents:
diff changeset
  1090
					TUint32 Rt = inst32 & 0x0000F000 >> 12;
hgs
parents:
diff changeset
  1091
					TUint32 registers = 1 << Rt;
hgs
parents:
diff changeset
  1092
hgs
parents:
diff changeset
  1093
					// Unpredictable?
hgs
parents:
diff changeset
  1094
					if (Rt == 13 || Rt == 15)
hgs
parents:
diff changeset
  1095
						{
hgs
parents:
diff changeset
  1096
						LOG_MSG("ARM ARM DDI0406A - section A8.6.121 POP Encoding T3 - Unpredictable");
hgs
parents:
diff changeset
  1097
						break;
hgs
parents:
diff changeset
  1098
						}
hgs
parents:
diff changeset
  1099
					
hgs
parents:
diff changeset
  1100
					TUint32 address;
hgs
parents:
diff changeset
  1101
					ReturnIfError(RegisterValue(aThread,13,address));
hgs
parents:
diff changeset
  1102
					
hgs
parents:
diff changeset
  1103
					for(TInt i=0; i< 15; i++)
hgs
parents:
diff changeset
  1104
						{
hgs
parents:
diff changeset
  1105
						if (IsBitSet(registers,i))
hgs
parents:
diff changeset
  1106
							{
hgs
parents:
diff changeset
  1107
							address += 4;
hgs
parents:
diff changeset
  1108
							}
hgs
parents:
diff changeset
  1109
						}
hgs
parents:
diff changeset
  1110
hgs
parents:
diff changeset
  1111
					// Is the PC written?
hgs
parents:
diff changeset
  1112
					if (IsBitSet(registers,15))
hgs
parents:
diff changeset
  1113
						{
hgs
parents:
diff changeset
  1114
						// Yes
hgs
parents:
diff changeset
  1115
						ReturnIfError(ReadMem32(aThread,address,breakAddress));
hgs
parents:
diff changeset
  1116
						}
hgs
parents:
diff changeset
  1117
hgs
parents:
diff changeset
  1118
					break;
hgs
parents:
diff changeset
  1119
					}
hgs
parents:
diff changeset
  1120
hgs
parents:
diff changeset
  1121
				// ARM ARM DDI0406A - section A8.6.53 LDM
hgs
parents:
diff changeset
  1122
				//
hgs
parents:
diff changeset
  1123
				// Load Multiple Encoding T2 
hgs
parents:
diff changeset
  1124
				if ((inst32 & 0xFFD02000) == 0xE8900000)
hgs
parents:
diff changeset
  1125
					{
hgs
parents:
diff changeset
  1126
					LOG_MSG("ARM ARM DDI0406A - section A8.6.53 LDM Encoding T2");
hgs
parents:
diff changeset
  1127
hgs
parents:
diff changeset
  1128
					// Decoding as per ARM ARM description
hgs
parents:
diff changeset
  1129
					TUint32 W = inst32 & 0x0020000 >> 21;
hgs
parents:
diff changeset
  1130
					TUint32 Rn = inst32 & 0x000F0000 >> 16;
hgs
parents:
diff changeset
  1131
					TUint32 P = inst32 & 0x00008000 >> 15;
hgs
parents:
diff changeset
  1132
					TUint32 M = inst32 & 0x00004000 >> 14;
hgs
parents:
diff changeset
  1133
					TUint32 registers = inst32 & 0x0000FFFF;
hgs
parents:
diff changeset
  1134
					TUint32 register_list = inst32 & 0x00001FFF;
hgs
parents:
diff changeset
  1135
				
hgs
parents:
diff changeset
  1136
					// POP?
hgs
parents:
diff changeset
  1137
					if ( (W == 1) && (Rn == 13) )
hgs
parents:
diff changeset
  1138
						{
hgs
parents:
diff changeset
  1139
						// POP instruction
hgs
parents:
diff changeset
  1140
						LOG_MSG("ARM ARM DDI0406A - section A8.6.53 LDM Encoding T2 - POP");
hgs
parents:
diff changeset
  1141
						}
hgs
parents:
diff changeset
  1142
hgs
parents:
diff changeset
  1143
					// Unpredictable?
hgs
parents:
diff changeset
  1144
					if (Rn == 15 || BitCount(register_list) < 2 || ((P == 1) && (M == 1)) )
hgs
parents:
diff changeset
  1145
						{
hgs
parents:
diff changeset
  1146
						LOG_MSG("ARM ARM DDI0406A - section A8.6.53 LDM Encoding T2 - Unpredictable");
hgs
parents:
diff changeset
  1147
						break;
hgs
parents:
diff changeset
  1148
						}
hgs
parents:
diff changeset
  1149
					
hgs
parents:
diff changeset
  1150
					TUint32 RnVal;
hgs
parents:
diff changeset
  1151
					ReturnIfError(RegisterValue(aThread,Rn,RnVal));
hgs
parents:
diff changeset
  1152
hgs
parents:
diff changeset
  1153
					TUint32 address = RnVal;
hgs
parents:
diff changeset
  1154
hgs
parents:
diff changeset
  1155
					// Calculate offset of address
hgs
parents:
diff changeset
  1156
					for(TInt i = 0; i < 15; i++)
hgs
parents:
diff changeset
  1157
						{
hgs
parents:
diff changeset
  1158
						if (IsBitSet(registers,i))
hgs
parents:
diff changeset
  1159
						{
hgs
parents:
diff changeset
  1160
							address += 4;
hgs
parents:
diff changeset
  1161
						}
hgs
parents:
diff changeset
  1162
						}
hgs
parents:
diff changeset
  1163
hgs
parents:
diff changeset
  1164
					// Does it load the PC?
hgs
parents:
diff changeset
  1165
					if (IsBitSet(registers,15))
hgs
parents:
diff changeset
  1166
						{
hgs
parents:
diff changeset
  1167
						// Obtain the value loaded into the PC
hgs
parents:
diff changeset
  1168
						ReturnIfError(ReadMem32(aThread,address,breakAddress));
hgs
parents:
diff changeset
  1169
						}
hgs
parents:
diff changeset
  1170
					break;
hgs
parents:
diff changeset
  1171
hgs
parents:
diff changeset
  1172
					}
hgs
parents:
diff changeset
  1173
hgs
parents:
diff changeset
  1174
				// ARM ARM DDI0406A - section B6.1.8 RFE
hgs
parents:
diff changeset
  1175
				//
hgs
parents:
diff changeset
  1176
				// Return From Exception Encoding T1 RFEDB
hgs
parents:
diff changeset
  1177
				if ((inst32 & 0xFFD0FFFF) == 0xE810C000)
hgs
parents:
diff changeset
  1178
					{
hgs
parents:
diff changeset
  1179
					LOG_MSG("ARM ARM DDI0406A - section B6.1.8 RFE Encoding T1");
hgs
parents:
diff changeset
  1180
hgs
parents:
diff changeset
  1181
					// Decoding as per ARM ARM description
hgs
parents:
diff changeset
  1182
					// TUint32 W = (inst32 & 0x00200000) >> 21;	// not needed for this encoding
hgs
parents:
diff changeset
  1183
					TUint32 Rn = (inst32 & 0x000F0000) >> 16;
hgs
parents:
diff changeset
  1184
					
hgs
parents:
diff changeset
  1185
					// TBool wback = (W == 1);	// not needed for this encoding
hgs
parents:
diff changeset
  1186
					TBool increment = EFalse;
hgs
parents:
diff changeset
  1187
					TBool wordhigher = EFalse;
hgs
parents:
diff changeset
  1188
hgs
parents:
diff changeset
  1189
					// Do calculation
hgs
parents:
diff changeset
  1190
					if (Rn == 15)
hgs
parents:
diff changeset
  1191
						{
hgs
parents:
diff changeset
  1192
						// Unpredictable 
hgs
parents:
diff changeset
  1193
						LOG_MSG("ARM ARM DDI0406A - section B6.1.8 RFE Encoding T1 - Unpredictable");
hgs
parents:
diff changeset
  1194
						break;
hgs
parents:
diff changeset
  1195
						}
hgs
parents:
diff changeset
  1196
hgs
parents:
diff changeset
  1197
					TUint32 RnVal = 0;
hgs
parents:
diff changeset
  1198
					ReturnIfError(RegisterValue(aThread,Rn,RnVal));
hgs
parents:
diff changeset
  1199
hgs
parents:
diff changeset
  1200
					TUint32 address = 0;
hgs
parents:
diff changeset
  1201
					ReturnIfError(ReadMem32(aThread,RnVal,address));
hgs
parents:
diff changeset
  1202
hgs
parents:
diff changeset
  1203
					if (increment)
hgs
parents:
diff changeset
  1204
						{
hgs
parents:
diff changeset
  1205
						address -= 8;
hgs
parents:
diff changeset
  1206
						}
hgs
parents:
diff changeset
  1207
hgs
parents:
diff changeset
  1208
					if (wordhigher)
hgs
parents:
diff changeset
  1209
						{
hgs
parents:
diff changeset
  1210
						address += 4;
hgs
parents:
diff changeset
  1211
						}
hgs
parents:
diff changeset
  1212
hgs
parents:
diff changeset
  1213
					breakAddress = address;
hgs
parents:
diff changeset
  1214
					break;
hgs
parents:
diff changeset
  1215
					}
hgs
parents:
diff changeset
  1216
hgs
parents:
diff changeset
  1217
				// Return From Exception Encoding T2 RFEIA
hgs
parents:
diff changeset
  1218
				if ((inst32 & 0xFFD0FFFF) == 0xE990C000)
hgs
parents:
diff changeset
  1219
					{
hgs
parents:
diff changeset
  1220
					LOG_MSG("ARM ARM DDI0406A - section B6.1.8 RFE Encoding T2");
hgs
parents:
diff changeset
  1221
hgs
parents:
diff changeset
  1222
					// Decoding as per ARM ARM description
hgs
parents:
diff changeset
  1223
					// TUint32 W = (inst32 & 0x00200000) >> 21;	// not needed for this encoding
hgs
parents:
diff changeset
  1224
					TUint32 Rn = (inst32 & 0x000F0000) >> 16;
hgs
parents:
diff changeset
  1225
					
hgs
parents:
diff changeset
  1226
					// TBool wback = (W == 1);	// not needed for this encoding
hgs
parents:
diff changeset
  1227
					TBool increment = ETrue;
hgs
parents:
diff changeset
  1228
					TBool wordhigher = EFalse;
hgs
parents:
diff changeset
  1229
hgs
parents:
diff changeset
  1230
					// Do calculation
hgs
parents:
diff changeset
  1231
					if (Rn == 15)
hgs
parents:
diff changeset
  1232
						{
hgs
parents:
diff changeset
  1233
						// Unpredictable 
hgs
parents:
diff changeset
  1234
						LOG_MSG("ARM ARM DDI0406A - section B6.1.8 RFE Encoding T2 - Unpredictable");
hgs
parents:
diff changeset
  1235
						break;
hgs
parents:
diff changeset
  1236
						}
hgs
parents:
diff changeset
  1237
hgs
parents:
diff changeset
  1238
					TUint32 RnVal = 0;
hgs
parents:
diff changeset
  1239
					ReturnIfError(RegisterValue(aThread,Rn,RnVal));
hgs
parents:
diff changeset
  1240
hgs
parents:
diff changeset
  1241
					TUint32 address = 0;
hgs
parents:
diff changeset
  1242
					ReturnIfError(ReadMem32(aThread,RnVal,address));
hgs
parents:
diff changeset
  1243
hgs
parents:
diff changeset
  1244
					if (increment)
hgs
parents:
diff changeset
  1245
						{
hgs
parents:
diff changeset
  1246
						address -= 8;
hgs
parents:
diff changeset
  1247
						}
hgs
parents:
diff changeset
  1248
hgs
parents:
diff changeset
  1249
					if (wordhigher)
hgs
parents:
diff changeset
  1250
						{
hgs
parents:
diff changeset
  1251
						address += 4;
hgs
parents:
diff changeset
  1252
						}
hgs
parents:
diff changeset
  1253
hgs
parents:
diff changeset
  1254
					breakAddress = RnVal;
hgs
parents:
diff changeset
  1255
					break;
hgs
parents:
diff changeset
  1256
					}
hgs
parents:
diff changeset
  1257
hgs
parents:
diff changeset
  1258
				// Return From Exception Encoding A1 RFE<amode>
hgs
parents:
diff changeset
  1259
				if ((inst32 & 0xFE50FFFF) == 0xF8100A00)
hgs
parents:
diff changeset
  1260
					{
hgs
parents:
diff changeset
  1261
					LOG_MSG("ARM ARM DDI0406A - section B6.1.8 RFE Encoding A1");
hgs
parents:
diff changeset
  1262
hgs
parents:
diff changeset
  1263
					// Decoding as per ARM ARM description
hgs
parents:
diff changeset
  1264
					TUint32 P = (inst32 & 0x01000000) >> 24;
hgs
parents:
diff changeset
  1265
					TUint32 U = (inst32 & 0x00800000) >> 23;
hgs
parents:
diff changeset
  1266
					// TUint32 W = (inst32 & 0x00200000) >> 21; // not needed for this encoding
hgs
parents:
diff changeset
  1267
					TUint32 Rn = (inst32 & 0x000F0000) >> 16;	
hgs
parents:
diff changeset
  1268
					
hgs
parents:
diff changeset
  1269
					// TBool wback = (W == 1);	// not needed for this encoding
hgs
parents:
diff changeset
  1270
					TBool increment = (U == 1);
hgs
parents:
diff changeset
  1271
					TBool wordhigher = (P == U);
hgs
parents:
diff changeset
  1272
hgs
parents:
diff changeset
  1273
					// Do calculation
hgs
parents:
diff changeset
  1274
					if (Rn == 15)
hgs
parents:
diff changeset
  1275
						{
hgs
parents:
diff changeset
  1276
						// Unpredictable 
hgs
parents:
diff changeset
  1277
						LOG_MSG("ARM ARM DDI0406A - section B6.1.8 RFE Encoding A1 - Unpredictable");
hgs
parents:
diff changeset
  1278
						break;
hgs
parents:
diff changeset
  1279
						}
hgs
parents:
diff changeset
  1280
hgs
parents:
diff changeset
  1281
					TUint32 RnVal = 0;
hgs
parents:
diff changeset
  1282
					ReturnIfError(RegisterValue(aThread,Rn,RnVal));
hgs
parents:
diff changeset
  1283
hgs
parents:
diff changeset
  1284
					TUint32 address = 0;
hgs
parents:
diff changeset
  1285
					ReturnIfError(ReadMem32(aThread,RnVal,address));
hgs
parents:
diff changeset
  1286
hgs
parents:
diff changeset
  1287
					if (increment)
hgs
parents:
diff changeset
  1288
						{
hgs
parents:
diff changeset
  1289
						address -= 8;
hgs
parents:
diff changeset
  1290
						}
hgs
parents:
diff changeset
  1291
hgs
parents:
diff changeset
  1292
					if (wordhigher)
hgs
parents:
diff changeset
  1293
						{
hgs
parents:
diff changeset
  1294
						address += 4;
hgs
parents:
diff changeset
  1295
						}
hgs
parents:
diff changeset
  1296
hgs
parents:
diff changeset
  1297
					breakAddress = address;
hgs
parents:
diff changeset
  1298
					break;
hgs
parents:
diff changeset
  1299
					}
hgs
parents:
diff changeset
  1300
				}
hgs
parents:
diff changeset
  1301
hgs
parents:
diff changeset
  1302
			// v4T/v5T/v6T instructions
hgs
parents:
diff changeset
  1303
			switch(thumb_opcode(inst))
hgs
parents:
diff changeset
  1304
				{
hgs
parents:
diff changeset
  1305
				case 0x08:
hgs
parents:
diff changeset
  1306
					{
hgs
parents:
diff changeset
  1307
					// Data-processing. See ARM ARM DDI0406A, section A6-8, A6.2.2.
hgs
parents:
diff changeset
  1308
hgs
parents:
diff changeset
  1309
					if ((thumb_inst_7_15(inst) == 0x08F))
hgs
parents:
diff changeset
  1310
						{
hgs
parents:
diff changeset
  1311
						// BLX(2)
hgs
parents:
diff changeset
  1312
						err = iChannel->ReadKernelRegisterValue(aThread, ((inst & 0x0078) >> 3), breakAddress);
hgs
parents:
diff changeset
  1313
						if(err != KErrNone)
hgs
parents:
diff changeset
  1314
							{
hgs
parents:
diff changeset
  1315
							LOG_MSG2("Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
  1316
							}
hgs
parents:
diff changeset
  1317
hgs
parents:
diff changeset
  1318
						if ((breakAddress & 0x00000001) == 0)
hgs
parents:
diff changeset
  1319
							{
hgs
parents:
diff changeset
  1320
							aChangingModes = ETrue;
hgs
parents:
diff changeset
  1321
							}
hgs
parents:
diff changeset
  1322
hgs
parents:
diff changeset
  1323
						breakAddress &= 0xFFFFFFFE;
hgs
parents:
diff changeset
  1324
hgs
parents:
diff changeset
  1325
						// Report how we decoded this instruction
hgs
parents:
diff changeset
  1326
						LOG_MSG("DRMDStepping::PCAfterInstructionExecutes: Decoded as BLX (2)");
hgs
parents:
diff changeset
  1327
						}
hgs
parents:
diff changeset
  1328
					else if (thumb_inst_7_15(inst) == 0x08E)
hgs
parents:
diff changeset
  1329
						{
hgs
parents:
diff changeset
  1330
						// BX
hgs
parents:
diff changeset
  1331
						err = iChannel->ReadKernelRegisterValue(aThread, ((inst & 0x0078) >> 3), breakAddress);
hgs
parents:
diff changeset
  1332
						if(err != KErrNone)
hgs
parents:
diff changeset
  1333
							{
hgs
parents:
diff changeset
  1334
							LOG_MSG2("Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
  1335
							}
hgs
parents:
diff changeset
  1336
hgs
parents:
diff changeset
  1337
						if ((breakAddress & 0x00000001) == 0)
hgs
parents:
diff changeset
  1338
							{
hgs
parents:
diff changeset
  1339
							aChangingModes = ETrue;
hgs
parents:
diff changeset
  1340
							}
hgs
parents:
diff changeset
  1341
						
hgs
parents:
diff changeset
  1342
						breakAddress &= 0xFFFFFFFE;
hgs
parents:
diff changeset
  1343
hgs
parents:
diff changeset
  1344
						// Report how we decoded this instruction
hgs
parents:
diff changeset
  1345
						LOG_MSG("DRMDStepping::PCAfterInstructionExecutes: Decoded as BX");
hgs
parents:
diff changeset
  1346
						}
hgs
parents:
diff changeset
  1347
					else if ((thumb_inst_8_15(inst) == 0x46) && ((inst & 0x87) == 0x87))
hgs
parents:
diff changeset
  1348
						{
hgs
parents:
diff changeset
  1349
						// MOV with PC as the destination
hgs
parents:
diff changeset
  1350
						err = iChannel->ReadKernelRegisterValue(aThread, ((inst & 0x0078) >> 3), breakAddress);
hgs
parents:
diff changeset
  1351
						if(err != KErrNone)
hgs
parents:
diff changeset
  1352
							{
hgs
parents:
diff changeset
  1353
							LOG_MSG2("Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
  1354
							}
hgs
parents:
diff changeset
  1355
hgs
parents:
diff changeset
  1356
						// Report how we decoded this instruction
hgs
parents:
diff changeset
  1357
						LOG_MSG("DRMDStepping::PCAfterInstructionExecutes: Decoded as MOV with PC as the destination");
hgs
parents:
diff changeset
  1358
						}
hgs
parents:
diff changeset
  1359
					else if ((thumb_inst_8_15(inst) == 0x44) && ((inst & 0x87) == 0x87))
hgs
parents:
diff changeset
  1360
						{
hgs
parents:
diff changeset
  1361
						// ADD with PC as the destination
hgs
parents:
diff changeset
  1362
						err = iChannel->ReadKernelRegisterValue(aThread, ((inst & 0x0078) >> 3), breakAddress);
hgs
parents:
diff changeset
  1363
						if(err != KErrNone)
hgs
parents:
diff changeset
  1364
							{
hgs
parents:
diff changeset
  1365
							LOG_MSG2("Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
  1366
							}
hgs
parents:
diff changeset
  1367
						breakAddress += aCurrentPC + 4; // +4 because we need to use the PC+4 according to ARM ARM DDI0406A, section A6.1.2.
hgs
parents:
diff changeset
  1368
hgs
parents:
diff changeset
  1369
						// Report how we decoded this instruction
hgs
parents:
diff changeset
  1370
						LOG_MSG("DRMDStepping::PCAfterInstructionExecutes: Decoded as ADD with PC as the destination");
hgs
parents:
diff changeset
  1371
						}
hgs
parents:
diff changeset
  1372
					break;
hgs
parents:
diff changeset
  1373
					}
hgs
parents:
diff changeset
  1374
				case 0x13:
hgs
parents:
diff changeset
  1375
					{
hgs
parents:
diff changeset
  1376
					// Load/Store single data item. See ARM ARM DDI0406A, section A6-10
hgs
parents:
diff changeset
  1377
hgs
parents:
diff changeset
  1378
					//This instruction doesn't modify the PC.
hgs
parents:
diff changeset
  1379
hgs
parents:
diff changeset
  1380
					//if (thumb_inst_8_15(inst) == 0x9F)
hgs
parents:
diff changeset
  1381
					//{
hgs
parents:
diff changeset
  1382
						// LDR(4) with the PC as the destination
hgs
parents:
diff changeset
  1383
					//	breakAddress = ReadRegister(aThread, SP_REGISTER) + (4 * (inst & 0x00FF));
hgs
parents:
diff changeset
  1384
					//}
hgs
parents:
diff changeset
  1385
hgs
parents:
diff changeset
  1386
					// Report how we decoded this instruction
hgs
parents:
diff changeset
  1387
					LOG_MSG("DRMDStepping::PCAfterInstructionExecutes: Decoded as This instruction doesn't modify the PC.");
hgs
parents:
diff changeset
  1388
					break;
hgs
parents:
diff changeset
  1389
					}
hgs
parents:
diff changeset
  1390
				case 0x17:
hgs
parents:
diff changeset
  1391
					{
hgs
parents:
diff changeset
  1392
					// Misc 16-bit instruction. See ARM ARM DDI0406A, section A6-11
hgs
parents:
diff changeset
  1393
hgs
parents:
diff changeset
  1394
					if (thumb_inst_8_15(inst) == 0xBD)
hgs
parents:
diff changeset
  1395
						{
hgs
parents:
diff changeset
  1396
						// POP with the PC in the list
hgs
parents:
diff changeset
  1397
						TUint32 regList = (inst & 0x00FF);
hgs
parents:
diff changeset
  1398
						TInt offset = 0;
hgs
parents:
diff changeset
  1399
						err = iChannel->ReadKernelRegisterValue(aThread,  SP_REGISTER, (T4ByteRegisterValue&)offset);
hgs
parents:
diff changeset
  1400
						if(err != KErrNone)
hgs
parents:
diff changeset
  1401
							{
hgs
parents:
diff changeset
  1402
							LOG_MSG2("Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
  1403
							}
hgs
parents:
diff changeset
  1404
						offset += (iChannel->Bitcount(regList) * 4);
hgs
parents:
diff changeset
  1405
hgs
parents:
diff changeset
  1406
						TBuf8<4> destination;
hgs
parents:
diff changeset
  1407
						err = iChannel->DoReadMemory(aThread, offset, 4, destination);
hgs
parents:
diff changeset
  1408
						
hgs
parents:
diff changeset
  1409
						if (KErrNone == err)
hgs
parents:
diff changeset
  1410
							{
hgs
parents:
diff changeset
  1411
							breakAddress = *(TUint32 *)destination.Ptr();
hgs
parents:
diff changeset
  1412
hgs
parents:
diff changeset
  1413
							if ((breakAddress & 0x00000001) == 0)
hgs
parents:
diff changeset
  1414
								{
hgs
parents:
diff changeset
  1415
								aChangingModes = ETrue;
hgs
parents:
diff changeset
  1416
								}
hgs
parents:
diff changeset
  1417
hgs
parents:
diff changeset
  1418
							breakAddress &= 0xFFFFFFFE;
hgs
parents:
diff changeset
  1419
							}
hgs
parents:
diff changeset
  1420
						else
hgs
parents:
diff changeset
  1421
							{
hgs
parents:
diff changeset
  1422
							LOG_MSG("Error reading memory in decoding step instruction");
hgs
parents:
diff changeset
  1423
							}
hgs
parents:
diff changeset
  1424
hgs
parents:
diff changeset
  1425
						// Report how we decoded this instruction
hgs
parents:
diff changeset
  1426
						LOG_MSG("DRMDStepping::PCAfterInstructionExecutes: Decoded as POP with the PC in the list");
hgs
parents:
diff changeset
  1427
						}
hgs
parents:
diff changeset
  1428
					break;
hgs
parents:
diff changeset
  1429
					}
hgs
parents:
diff changeset
  1430
				case 0x1A:
hgs
parents:
diff changeset
  1431
				case 0x1B:
hgs
parents:
diff changeset
  1432
					{
hgs
parents:
diff changeset
  1433
					// Conditional branch, and supervisor call. See ARM ARM DDI0406A, section A6-13
hgs
parents:
diff changeset
  1434
hgs
parents:
diff changeset
  1435
					if (thumb_inst_8_15(inst) < 0xDE)
hgs
parents:
diff changeset
  1436
						{
hgs
parents:
diff changeset
  1437
						// B(1) conditional branch
hgs
parents:
diff changeset
  1438
						if (IsExecuted(((inst & 0x0F00) >> 8), aStatusRegister))
hgs
parents:
diff changeset
  1439
							{
hgs
parents:
diff changeset
  1440
							TUint32 offset = ((inst & 0x000000FF) << 1);
hgs
parents:
diff changeset
  1441
							if (offset & 0x00000100)
hgs
parents:
diff changeset
  1442
								{
hgs
parents:
diff changeset
  1443
								offset |= 0xFFFFFF00;
hgs
parents:
diff changeset
  1444
								}
hgs
parents:
diff changeset
  1445
							
hgs
parents:
diff changeset
  1446
							breakAddress = aCurrentPC + 4 + offset;
hgs
parents:
diff changeset
  1447
hgs
parents:
diff changeset
  1448
							// Report how we decoded this instruction
hgs
parents:
diff changeset
  1449
							LOG_MSG("DRMDStepping::PCAfterInstructionExecutes: Decoded as B(1) conditional branch");
hgs
parents:
diff changeset
  1450
							}
hgs
parents:
diff changeset
  1451
						}
hgs
parents:
diff changeset
  1452
					break;
hgs
parents:
diff changeset
  1453
					}
hgs
parents:
diff changeset
  1454
				case 0x1C:
hgs
parents:
diff changeset
  1455
					{
hgs
parents:
diff changeset
  1456
					// Unconditional branch, See ARM ARM DDI0406A, section A8-44.
hgs
parents:
diff changeset
  1457
hgs
parents:
diff changeset
  1458
					// B(2) unconditional branch
hgs
parents:
diff changeset
  1459
					TUint32 offset = (inst & 0x000007FF) << 1;
hgs
parents:
diff changeset
  1460
					if (offset & 0x00000800)
hgs
parents:
diff changeset
  1461
						{
hgs
parents:
diff changeset
  1462
						offset |= 0xFFFFF800;
hgs
parents:
diff changeset
  1463
						}
hgs
parents:
diff changeset
  1464
					
hgs
parents:
diff changeset
  1465
					breakAddress = aCurrentPC + 4 + offset;
hgs
parents:
diff changeset
  1466
hgs
parents:
diff changeset
  1467
					// Report how we decoded this instruction
hgs
parents:
diff changeset
  1468
					LOG_MSG("DRMDStepping::PCAfterInstructionExecutes: Decoded as B(2) unconditional branch");
hgs
parents:
diff changeset
  1469
hgs
parents:
diff changeset
  1470
					break;
hgs
parents:
diff changeset
  1471
					}
hgs
parents:
diff changeset
  1472
				case 0x1D:
hgs
parents:
diff changeset
  1473
					{
hgs
parents:
diff changeset
  1474
					if (!(inst & 0x0001))
hgs
parents:
diff changeset
  1475
						{
hgs
parents:
diff changeset
  1476
						// BLX(1)
hgs
parents:
diff changeset
  1477
						err = iChannel->ReadKernelRegisterValue(aThread, LINK_REGISTER, breakAddress);
hgs
parents:
diff changeset
  1478
						if(err != KErrNone)
hgs
parents:
diff changeset
  1479
							{
hgs
parents:
diff changeset
  1480
							LOG_MSG2("Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
  1481
							}
hgs
parents:
diff changeset
  1482
						breakAddress +=  ((inst & 0x07FF) << 1);
hgs
parents:
diff changeset
  1483
						if ((breakAddress & 0x00000001) == 0)
hgs
parents:
diff changeset
  1484
							{
hgs
parents:
diff changeset
  1485
							aChangingModes = ETrue;
hgs
parents:
diff changeset
  1486
							}
hgs
parents:
diff changeset
  1487
hgs
parents:
diff changeset
  1488
						breakAddress &= 0xFFFFFFFC;
hgs
parents:
diff changeset
  1489
hgs
parents:
diff changeset
  1490
						// Report how we decoded this instruction
hgs
parents:
diff changeset
  1491
						LOG_MSG("DRMDStepping::PCAfterInstructionExecutes: Decoded as BLX(1)");
hgs
parents:
diff changeset
  1492
hgs
parents:
diff changeset
  1493
						}
hgs
parents:
diff changeset
  1494
					break;
hgs
parents:
diff changeset
  1495
					}
hgs
parents:
diff changeset
  1496
				case 0x1E:
hgs
parents:
diff changeset
  1497
					{
hgs
parents:
diff changeset
  1498
					// Check for ARMv7 CPU
hgs
parents:
diff changeset
  1499
					if(cpuid == 0xC0)
hgs
parents:
diff changeset
  1500
						{
hgs
parents:
diff changeset
  1501
						// BL/BLX 32-bit instruction
hgs
parents:
diff changeset
  1502
						aNewRangeEnd += 4;
hgs
parents:
diff changeset
  1503
hgs
parents:
diff changeset
  1504
						breakAddress = (TUint32)thumb_instr_b_dest(inst32, aCurrentPC);
hgs
parents:
diff changeset
  1505
hgs
parents:
diff changeset
  1506
						if((inst32 >> 27) == 0x1D)
hgs
parents:
diff changeset
  1507
							{
hgs
parents:
diff changeset
  1508
							// BLX(1)
hgs
parents:
diff changeset
  1509
							if ((breakAddress & 0x00000001) == 0)
hgs
parents:
diff changeset
  1510
								{
hgs
parents:
diff changeset
  1511
								aChangingModes = ETrue;
hgs
parents:
diff changeset
  1512
								}
hgs
parents:
diff changeset
  1513
hgs
parents:
diff changeset
  1514
							breakAddress &= 0xFFFFFFFC;
hgs
parents:
diff changeset
  1515
hgs
parents:
diff changeset
  1516
							// Report how we decoded this instruction
hgs
parents:
diff changeset
  1517
							LOG_MSG("DRMDStepping::PCAfterInstructionExecutes: Decoded as 32-bit BLX(1)");
hgs
parents:
diff changeset
  1518
							}
hgs
parents:
diff changeset
  1519
						else
hgs
parents:
diff changeset
  1520
							{
hgs
parents:
diff changeset
  1521
							// Report how we decoded this instruction
hgs
parents:
diff changeset
  1522
							LOG_MSG("DRMDStepping::PCAfterInstructionExecutes: 32-bit BL instruction");
hgs
parents:
diff changeset
  1523
							}
hgs
parents:
diff changeset
  1524
						LOG_MSG2(" 32-bit BL/BLX instruction: breakAddress = 0x%X", breakAddress);
hgs
parents:
diff changeset
  1525
						} // if(cpuid == 0xC0)
hgs
parents:
diff changeset
  1526
					else
hgs
parents:
diff changeset
  1527
						{
hgs
parents:
diff changeset
  1528
						// BL/BLX prefix - destination is encoded in this and the next instruction
hgs
parents:
diff changeset
  1529
						aNewRangeEnd += 2;
hgs
parents:
diff changeset
  1530
hgs
parents:
diff changeset
  1531
						// Report how we decoded this instruction
hgs
parents:
diff changeset
  1532
						LOG_MSG("DRMDStepping::PCAfterInstructionExecutes: BL/BLX prefix - destination is encoded in this and the next instruction");
hgs
parents:
diff changeset
  1533
						}
hgs
parents:
diff changeset
  1534
hgs
parents:
diff changeset
  1535
					break;
hgs
parents:
diff changeset
  1536
					}
hgs
parents:
diff changeset
  1537
				case 0x1F:
hgs
parents:
diff changeset
  1538
					{
hgs
parents:
diff changeset
  1539
					// BL
hgs
parents:
diff changeset
  1540
					err = iChannel->ReadKernelRegisterValue(aThread, LINK_REGISTER, breakAddress);
hgs
parents:
diff changeset
  1541
					if(err != KErrNone)
hgs
parents:
diff changeset
  1542
						{
hgs
parents:
diff changeset
  1543
						LOG_MSG2("Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
  1544
						}
hgs
parents:
diff changeset
  1545
					breakAddress += ((inst & 0x07FF) << 1);
hgs
parents:
diff changeset
  1546
hgs
parents:
diff changeset
  1547
					// Report how we decoded this instruction
hgs
parents:
diff changeset
  1548
					LOG_MSG("DRMDStepping::PCAfterInstructionExecutes: Decoded as BL");
hgs
parents:
diff changeset
  1549
					break;
hgs
parents:
diff changeset
  1550
					}
hgs
parents:
diff changeset
  1551
				default:
hgs
parents:
diff changeset
  1552
					{
hgs
parents:
diff changeset
  1553
					// Don't know any better at this point!
hgs
parents:
diff changeset
  1554
					LOG_MSG("DRMDStepping::PCAfterInstructionExecutes:- default to next instruction");
hgs
parents:
diff changeset
  1555
					}
hgs
parents:
diff changeset
  1556
					break;
hgs
parents:
diff changeset
  1557
				} // switch(thumb_opcode(inst))
hgs
parents:
diff changeset
  1558
			} // case Debug::EThumbMode:
hgs
parents:
diff changeset
  1559
		break;
hgs
parents:
diff changeset
  1560
hgs
parents:
diff changeset
  1561
		case Debug::EThumb2EEMode:
hgs
parents:
diff changeset
  1562
			{
hgs
parents:
diff changeset
  1563
			// Not yet supported
hgs
parents:
diff changeset
  1564
			LOG_MSG("DRMDStepping::PCAfterInstructionExecutes - Debug::EThumb2Mode is not supported");
hgs
parents:
diff changeset
  1565
hgs
parents:
diff changeset
  1566
			}
hgs
parents:
diff changeset
  1567
			break;
hgs
parents:
diff changeset
  1568
hgs
parents:
diff changeset
  1569
		default:
hgs
parents:
diff changeset
  1570
			LOG_MSG("DRMDStepping::PCAfterInstructionExecutes - Cannot determine CPU mode architecture");
hgs
parents:
diff changeset
  1571
		} // switch(mode)
hgs
parents:
diff changeset
  1572
hgs
parents:
diff changeset
  1573
	LOG_MSG2("DRMDStepping::PCAfterInstructionExecutes : return 0x%08x",breakAddress);
hgs
parents:
diff changeset
  1574
	return breakAddress;
hgs
parents:
diff changeset
  1575
	}
hgs
parents:
diff changeset
  1576
hgs
parents:
diff changeset
  1577
// Obtain a 32-bit memory value with minimum fuss
hgs
parents:
diff changeset
  1578
TInt DRMDStepping::ReadMem32(DThread* aThread, const TUint32 aAddress, TUint32& aValue)
hgs
parents:
diff changeset
  1579
	{
hgs
parents:
diff changeset
  1580
	TBuf8<4> valBuf;
hgs
parents:
diff changeset
  1581
	TInt err = iChannel->DoReadMemory(aThread, aAddress, 4, valBuf);
hgs
parents:
diff changeset
  1582
	if (err != KErrNone)
hgs
parents:
diff changeset
  1583
		{
hgs
parents:
diff changeset
  1584
		LOG_MSG2("DRMDStepping::ReadMem32 failed to read memory at 0x%08x", aAddress);
hgs
parents:
diff changeset
  1585
		return err;
hgs
parents:
diff changeset
  1586
		}
hgs
parents:
diff changeset
  1587
hgs
parents:
diff changeset
  1588
	aValue = *(TUint32 *)valBuf.Ptr();
hgs
parents:
diff changeset
  1589
hgs
parents:
diff changeset
  1590
	return KErrNone;
hgs
parents:
diff changeset
  1591
	}
hgs
parents:
diff changeset
  1592
hgs
parents:
diff changeset
  1593
// Obtain a 16-bit memory value with minimum fuss
hgs
parents:
diff changeset
  1594
TInt DRMDStepping::ReadMem16(DThread* aThread, const TUint32 aAddress, TUint16& aValue)
hgs
parents:
diff changeset
  1595
	{
hgs
parents:
diff changeset
  1596
	TBuf8<2> valBuf;
hgs
parents:
diff changeset
  1597
	TInt err = iChannel->DoReadMemory(aThread, aAddress, 2, valBuf);
hgs
parents:
diff changeset
  1598
	if (err != KErrNone)
hgs
parents:
diff changeset
  1599
		{
hgs
parents:
diff changeset
  1600
		LOG_MSG2("DRMDStepping::ReadMem16 failed to read memory at 0x%08x", aAddress);
hgs
parents:
diff changeset
  1601
		return err;
hgs
parents:
diff changeset
  1602
		}
hgs
parents:
diff changeset
  1603
hgs
parents:
diff changeset
  1604
	aValue = *(TUint16 *)valBuf.Ptr();
hgs
parents:
diff changeset
  1605
hgs
parents:
diff changeset
  1606
	return KErrNone;
hgs
parents:
diff changeset
  1607
	}
hgs
parents:
diff changeset
  1608
hgs
parents:
diff changeset
  1609
// Obtain a 16-bit memory value with minimum fuss
hgs
parents:
diff changeset
  1610
TInt DRMDStepping::ReadMem8(DThread* aThread, const TUint32 aAddress, TUint8& aValue)
hgs
parents:
diff changeset
  1611
	{
hgs
parents:
diff changeset
  1612
	TBuf8<1> valBuf;
hgs
parents:
diff changeset
  1613
	TInt err = iChannel->DoReadMemory(aThread, aAddress, 1, valBuf);
hgs
parents:
diff changeset
  1614
	if (err != KErrNone)
hgs
parents:
diff changeset
  1615
		{
hgs
parents:
diff changeset
  1616
		LOG_MSG2("DRMDStepping::ReadMem8 failed to read memory at 0x%08x", aAddress);
hgs
parents:
diff changeset
  1617
		return err;
hgs
parents:
diff changeset
  1618
		}
hgs
parents:
diff changeset
  1619
hgs
parents:
diff changeset
  1620
	aValue = *(TUint8 *)valBuf.Ptr();
hgs
parents:
diff changeset
  1621
hgs
parents:
diff changeset
  1622
	return KErrNone;
hgs
parents:
diff changeset
  1623
	}
hgs
parents:
diff changeset
  1624
hgs
parents:
diff changeset
  1625
// Obtain a core register value with minimum fuss
hgs
parents:
diff changeset
  1626
TInt DRMDStepping::RegisterValue(DThread *aThread, const TUint32 aKernelRegisterId, TUint32 &aValue)
hgs
parents:
diff changeset
  1627
	{
hgs
parents:
diff changeset
  1628
	TInt err = iChannel->ReadKernelRegisterValue(aThread, aKernelRegisterId, aValue);
hgs
parents:
diff changeset
  1629
	if(err != KErrNone)
hgs
parents:
diff changeset
  1630
		{
hgs
parents:
diff changeset
  1631
		LOG_MSG3("DRMDStepping::RegisterValue failed to read register %d err = %d", aKernelRegisterId, err);
hgs
parents:
diff changeset
  1632
		}
hgs
parents:
diff changeset
  1633
		return err;
hgs
parents:
diff changeset
  1634
	}
hgs
parents:
diff changeset
  1635
hgs
parents:
diff changeset
  1636
hgs
parents:
diff changeset
  1637
// Encodings from ARM ARM DDI0406A, section 9.2.1
hgs
parents:
diff changeset
  1638
enum TThumb2EEOpcode
hgs
parents:
diff changeset
  1639
	{
hgs
parents:
diff changeset
  1640
	EThumb2HDP,		// Handler Branch with Parameter
hgs
parents:
diff changeset
  1641
	EThumb2UNDEF,	// UNDEFINED
hgs
parents:
diff changeset
  1642
	EThumb2HB,		// Handler Branch, Handler Branch with Link
hgs
parents:
diff changeset
  1643
	EThumb2HBLP,	// Handle Branch with Link and Parameter
hgs
parents:
diff changeset
  1644
	EThumb2LDRF,	// Load Register from a frame
hgs
parents:
diff changeset
  1645
	EThumb2CHKA,	// Check Array
hgs
parents:
diff changeset
  1646
	EThumb2LDRL,	// Load Register from a literal pool
hgs
parents:
diff changeset
  1647
	EThumb2LDRA,	// Load Register (array operations)
hgs
parents:
diff changeset
  1648
	EThumb2STR		// Store Register to a frame
hgs
parents:
diff changeset
  1649
	};
hgs
parents:
diff changeset
  1650
hgs
parents:
diff changeset
  1651
//
hgs
parents:
diff changeset
  1652
// DRMDStepping::ShiftedRegValue
hgs
parents:
diff changeset
  1653
//
hgs
parents:
diff changeset
  1654
TUint32 DRMDStepping::ShiftedRegValue(DThread *aThread, TUint32 aInstruction, TUint32 aCurrentPC, TUint32 aStatusRegister)
hgs
parents:
diff changeset
  1655
	{
hgs
parents:
diff changeset
  1656
	LOG_MSG("DRMDStepping::ShiftedRegValue()");
hgs
parents:
diff changeset
  1657
hgs
parents:
diff changeset
  1658
	TUint32 shift = 0;
hgs
parents:
diff changeset
  1659
	if (aInstruction & 0x10)	// bit 4
hgs
parents:
diff changeset
  1660
		{
hgs
parents:
diff changeset
  1661
		shift = (arm_rs(aInstruction) == PC_REGISTER ? aCurrentPC + 8 : aStatusRegister) & 0xFF;
hgs
parents:
diff changeset
  1662
		}
hgs
parents:
diff changeset
  1663
	else
hgs
parents:
diff changeset
  1664
		{
hgs
parents:
diff changeset
  1665
		shift = arm_data_c(aInstruction);
hgs
parents:
diff changeset
  1666
		}
hgs
parents:
diff changeset
  1667
	
hgs
parents:
diff changeset
  1668
	TInt rm = arm_rm(aInstruction);
hgs
parents:
diff changeset
  1669
	
hgs
parents:
diff changeset
  1670
	TUint32 res = 0;
hgs
parents:
diff changeset
  1671
	if(rm == PC_REGISTER)
hgs
parents:
diff changeset
  1672
		{
hgs
parents:
diff changeset
  1673
		res = aCurrentPC + ((aInstruction & 0x10) ? 12 : 8);
hgs
parents:
diff changeset
  1674
		}
hgs
parents:
diff changeset
  1675
	else
hgs
parents:
diff changeset
  1676
		{
hgs
parents:
diff changeset
  1677
		TInt err = iChannel->ReadKernelRegisterValue(aThread, rm, res);
hgs
parents:
diff changeset
  1678
		if(err != KErrNone)
hgs
parents:
diff changeset
  1679
			{
hgs
parents:
diff changeset
  1680
			LOG_MSG2("DRMDStepping::ShiftedRegValue - Non-zero error code discarded: %d", err);
hgs
parents:
diff changeset
  1681
			}
hgs
parents:
diff changeset
  1682
		}
hgs
parents:
diff changeset
  1683
hgs
parents:
diff changeset
  1684
	switch(arm_data_shift(aInstruction))
hgs
parents:
diff changeset
  1685
		{
hgs
parents:
diff changeset
  1686
		case 0:			// LSL
hgs
parents:
diff changeset
  1687
			{
hgs
parents:
diff changeset
  1688
			res = shift >= 32 ? 0 : res << shift;
hgs
parents:
diff changeset
  1689
			break;
hgs
parents:
diff changeset
  1690
			}
hgs
parents:
diff changeset
  1691
		case 1:			// LSR
hgs
parents:
diff changeset
  1692
			{
hgs
parents:
diff changeset
  1693
			res = shift >= 32 ? 0 : res >> shift;
hgs
parents:
diff changeset
  1694
			break;
hgs
parents:
diff changeset
  1695
			}
hgs
parents:
diff changeset
  1696
		case 2:			// ASR
hgs
parents:
diff changeset
  1697
			{
hgs
parents:
diff changeset
  1698
			if (shift >= 32)
hgs
parents:
diff changeset
  1699
			shift = 31;
hgs
parents:
diff changeset
  1700
			res = ((res & 0x80000000L) ? ~((~res) >> shift) : res >> shift);
hgs
parents:
diff changeset
  1701
			break;
hgs
parents:
diff changeset
  1702
			}
hgs
parents:
diff changeset
  1703
		case 3:			// ROR/RRX
hgs
parents:
diff changeset
  1704
			{
hgs
parents:
diff changeset
  1705
			shift &= 31;
hgs
parents:
diff changeset
  1706
			if (shift == 0)
hgs
parents:
diff changeset
  1707
				{
hgs
parents:
diff changeset
  1708
				res = (res >> 1) | ((aStatusRegister & arm_carry_bit()) ? 0x80000000L : 0);
hgs
parents:
diff changeset
  1709
				}
hgs
parents:
diff changeset
  1710
			else
hgs
parents:
diff changeset
  1711
				{
hgs
parents:
diff changeset
  1712
				res = (res >> shift) | (res << (32 - shift));
hgs
parents:
diff changeset
  1713
				}
hgs
parents:
diff changeset
  1714
			break;
hgs
parents:
diff changeset
  1715
			}
hgs
parents:
diff changeset
  1716
		}
hgs
parents:
diff changeset
  1717
hgs
parents:
diff changeset
  1718
	return res & 0xFFFFFFFF;
hgs
parents:
diff changeset
  1719
}
hgs
parents:
diff changeset
  1720
hgs
parents:
diff changeset
  1721
//
hgs
parents:
diff changeset
  1722
// DRMDStepping::CurrentPC
hgs
parents:
diff changeset
  1723
//
hgs
parents:
diff changeset
  1724
// 
hgs
parents:
diff changeset
  1725
//
hgs
parents:
diff changeset
  1726
TInt DRMDStepping::CurrentPC(DThread* aThread, TUint32& aPC)
hgs
parents:
diff changeset
  1727
	{
hgs
parents:
diff changeset
  1728
	LOG_MSG("DRMDStepping::CurrentPC");
hgs
parents:
diff changeset
  1729
hgs
parents:
diff changeset
  1730
	TInt err = iChannel->ReadKernelRegisterValue(aThread, PC_REGISTER, aPC);
hgs
parents:
diff changeset
  1731
	if(err != KErrNone)
hgs
parents:
diff changeset
  1732
		{
hgs
parents:
diff changeset
  1733
		// We don't know the current PC for this thread!
hgs
parents:
diff changeset
  1734
		LOG_MSG("DRMDStepping::CurrentPC - Failed to read the current PC");
hgs
parents:
diff changeset
  1735
		
hgs
parents:
diff changeset
  1736
		return KErrGeneral;
hgs
parents:
diff changeset
  1737
		}
hgs
parents:
diff changeset
  1738
hgs
parents:
diff changeset
  1739
	LOG_MSG2("DRMDStepping::CurrentPC 0x%08x", aPC);
hgs
parents:
diff changeset
  1740
hgs
parents:
diff changeset
  1741
	return KErrNone;
hgs
parents:
diff changeset
  1742
	}
hgs
parents:
diff changeset
  1743
hgs
parents:
diff changeset
  1744
//
hgs
parents:
diff changeset
  1745
// DRMDStepping::CurrentCPSR
hgs
parents:
diff changeset
  1746
//
hgs
parents:
diff changeset
  1747
// 
hgs
parents:
diff changeset
  1748
//
hgs
parents:
diff changeset
  1749
TInt DRMDStepping::CurrentCPSR(DThread* aThread, TUint32& aCPSR)
hgs
parents:
diff changeset
  1750
	{
hgs
parents:
diff changeset
  1751
	LOG_MSG("DRMDStepping::CurrentCPSR");
hgs
parents:
diff changeset
  1752
hgs
parents:
diff changeset
  1753
	TInt err = iChannel->ReadKernelRegisterValue(aThread, STATUS_REGISTER, aCPSR);
hgs
parents:
diff changeset
  1754
	if(err != KErrNone)
hgs
parents:
diff changeset
  1755
		{
hgs
parents:
diff changeset
  1756
		// We don't know the current PC for this thread!
hgs
parents:
diff changeset
  1757
		LOG_MSG("DRMDStepping::CurrentPC - Failed to read the current CPSR");
hgs
parents:
diff changeset
  1758
		
hgs
parents:
diff changeset
  1759
		return KErrGeneral;
hgs
parents:
diff changeset
  1760
		}
hgs
parents:
diff changeset
  1761
hgs
parents:
diff changeset
  1762
	LOG_MSG2("DRMDStepping::CurrentCPSR 0x%08x", aCPSR);
hgs
parents:
diff changeset
  1763
	
hgs
parents:
diff changeset
  1764
	return KErrNone;
hgs
parents:
diff changeset
  1765
	}
hgs
parents:
diff changeset
  1766
hgs
parents:
diff changeset
  1767
//
hgs
parents:
diff changeset
  1768
// DRMDStepping::ModifyBreaksForStep
hgs
parents:
diff changeset
  1769
//
hgs
parents:
diff changeset
  1770
// Set a temporary breakpoint at the next instruction to be executed after the one at the current PC
hgs
parents:
diff changeset
  1771
// Disable the breakpoint at the current PC if one exists
hgs
parents:
diff changeset
  1772
//
hgs
parents:
diff changeset
  1773
TInt DRMDStepping::ModifyBreaksForStep(DThread *aThread, TUint32 aRangeStart, TUint32 aRangeEnd, /*TBool aStepInto,*/ TBool aResumeOnceOutOfRange, TBool aCheckForStubs, const TUint32 aNumSteps)
hgs
parents:
diff changeset
  1774
	{
hgs
parents:
diff changeset
  1775
	LOG_MSG2("DRMDStepping::ModifyBreaksForStep() Numsteps 0x%d",aNumSteps);
hgs
parents:
diff changeset
  1776
hgs
parents:
diff changeset
  1777
	// Validate arguments
hgs
parents:
diff changeset
  1778
	if (!aThread)
hgs
parents:
diff changeset
  1779
		{
hgs
parents:
diff changeset
  1780
		LOG_MSG("DRMDStepping::ModifyBreaksForStep() - No aThread specified to step");
hgs
parents:
diff changeset
  1781
		return KErrArgument;
hgs
parents:
diff changeset
  1782
		}
hgs
parents:
diff changeset
  1783
hgs
parents:
diff changeset
  1784
	// Current PC
hgs
parents:
diff changeset
  1785
	TUint32 currentPC;
hgs
parents:
diff changeset
  1786
hgs
parents:
diff changeset
  1787
	ReturnIfError(CurrentPC(aThread,currentPC));
hgs
parents:
diff changeset
  1788
	LOG_MSG2("Current PC: 0x%x", currentPC);
hgs
parents:
diff changeset
  1789
hgs
parents:
diff changeset
  1790
	// disable breakpoint at the current PC if necessary
hgs
parents:
diff changeset
  1791
	ReturnIfError(iChannel->iBreakManager->DisableBreakAtAddress(currentPC));
hgs
parents:
diff changeset
  1792
hgs
parents:
diff changeset
  1793
	// Current CPSR
hgs
parents:
diff changeset
  1794
	TUint32 statusRegister;
hgs
parents:
diff changeset
  1795
hgs
parents:
diff changeset
  1796
	ReturnIfError(CurrentCPSR(aThread,statusRegister));
hgs
parents:
diff changeset
  1797
	LOG_MSG2("Current CPSR: %x", statusRegister);
hgs
parents:
diff changeset
  1798
hgs
parents:
diff changeset
  1799
	TBool thumbMode = (statusRegister & ECpuThumb);
hgs
parents:
diff changeset
  1800
	if (thumbMode)
hgs
parents:
diff changeset
  1801
		LOG_MSG("Thumb Mode");
hgs
parents:
diff changeset
  1802
hgs
parents:
diff changeset
  1803
	TInt instSize = thumbMode ? 2 : 4;
hgs
parents:
diff changeset
  1804
hgs
parents:
diff changeset
  1805
	TBool changingModes = EFalse;
hgs
parents:
diff changeset
  1806
hgs
parents:
diff changeset
  1807
	TUint32 breakAddress = 0;
hgs
parents:
diff changeset
  1808
hgs
parents:
diff changeset
  1809
	TUint32 newRangeEnd = aRangeEnd;
hgs
parents:
diff changeset
  1810
hgs
parents:
diff changeset
  1811
	breakAddress = PCAfterInstructionExecutes(aThread, currentPC, statusRegister, instSize, /* aStepInto, */ newRangeEnd, changingModes);
hgs
parents:
diff changeset
  1812
hgs
parents:
diff changeset
  1813
	/*
hgs
parents:
diff changeset
  1814
	If there is already a user breakpoint at this address, we do not need to set a temp breakpoint. The program
hgs
parents:
diff changeset
  1815
	should simply stop at that address.	
hgs
parents:
diff changeset
  1816
	*/
hgs
parents:
diff changeset
  1817
	TBreakEntry* breakEntry = NULL;
hgs
parents:
diff changeset
  1818
	do
hgs
parents:
diff changeset
  1819
		{
hgs
parents:
diff changeset
  1820
		breakEntry = iChannel->iBreakManager->GetNextBreak(breakEntry);
hgs
parents:
diff changeset
  1821
		if(breakEntry && !iChannel->iBreakManager->IsTemporaryBreak(*breakEntry))
hgs
parents:
diff changeset
  1822
			{
hgs
parents:
diff changeset
  1823
			if ((breakEntry->iAddress == breakAddress) && ((breakEntry->iThreadSpecific && breakEntry->iId == aThread->iId) || (!breakEntry->iThreadSpecific && breakEntry->iId == aThread->iOwningProcess->iId)))
hgs
parents:
diff changeset
  1824
				{
hgs
parents:
diff changeset
  1825
				LOG_MSG("DRMDStepping::ModifyBreaksForStep - Breakpoint already exists at the step target address\n");
hgs
parents:
diff changeset
  1826
hgs
parents:
diff changeset
  1827
				// note also that if this is the case, we will not keep stepping if we hit a real breakpoint, so may as well set
hgs
parents:
diff changeset
  1828
				// the step count = 0.
hgs
parents:
diff changeset
  1829
				breakEntry->iNumSteps = 0;
hgs
parents:
diff changeset
  1830
hgs
parents:
diff changeset
  1831
				return KErrNone;
hgs
parents:
diff changeset
  1832
				}
hgs
parents:
diff changeset
  1833
			}
hgs
parents:
diff changeset
  1834
		} while(breakEntry);
hgs
parents:
diff changeset
  1835
hgs
parents:
diff changeset
  1836
	breakEntry = NULL;
hgs
parents:
diff changeset
  1837
	do
hgs
parents:
diff changeset
  1838
		{
hgs
parents:
diff changeset
  1839
		breakEntry = iChannel->iBreakManager->GetNextBreak(breakEntry);
hgs
parents:
diff changeset
  1840
		if(breakEntry && iChannel->iBreakManager->IsTemporaryBreak(*breakEntry))
hgs
parents:
diff changeset
  1841
			{
hgs
parents:
diff changeset
  1842
			if (breakEntry->iAddress == 0)
hgs
parents:
diff changeset
  1843
				{
hgs
parents:
diff changeset
  1844
				breakEntry->iId = aThread->iId;
hgs
parents:
diff changeset
  1845
				breakEntry->iAddress = breakAddress;
hgs
parents:
diff changeset
  1846
				breakEntry->iThreadSpecific = ETrue;
hgs
parents:
diff changeset
  1847
hgs
parents:
diff changeset
  1848
				TBool realThumbMode = (thumbMode && !changingModes) || (!thumbMode && changingModes);
hgs
parents:
diff changeset
  1849
hgs
parents:
diff changeset
  1850
				// Need to set the correct type of breakpoint for the mode we are in
hgs
parents:
diff changeset
  1851
				// and the the one we are changing into
hgs
parents:
diff changeset
  1852
				if(realThumbMode)
hgs
parents:
diff changeset
  1853
					{
hgs
parents:
diff changeset
  1854
					// We are remaining in Thumb mode
hgs
parents:
diff changeset
  1855
					breakEntry->iMode = EThumbMode;
hgs
parents:
diff changeset
  1856
					}
hgs
parents:
diff changeset
  1857
				else
hgs
parents:
diff changeset
  1858
					{
hgs
parents:
diff changeset
  1859
					// We are switching to ARM mode
hgs
parents:
diff changeset
  1860
					breakEntry->iMode = EArmMode;
hgs
parents:
diff changeset
  1861
					}
hgs
parents:
diff changeset
  1862
hgs
parents:
diff changeset
  1863
				breakEntry->iResumeOnceOutOfRange = aResumeOnceOutOfRange;
hgs
parents:
diff changeset
  1864
				breakEntry->iSteppingInto = ETrue /* aStepInto */;
hgs
parents:
diff changeset
  1865
				breakEntry->iRangeStart = 0;	// no longer used
hgs
parents:
diff changeset
  1866
				breakEntry->iRangeEnd = 0;		// no longer used
hgs
parents:
diff changeset
  1867
hgs
parents:
diff changeset
  1868
				LOG_MSG2("Adding temp breakpoint with id: %d", breakEntry->iBreakId);
hgs
parents:
diff changeset
  1869
				LOG_MSG2("Adding temp breakpoint with thread id: %d", aThread->iId);
hgs
parents:
diff changeset
  1870
hgs
parents:
diff changeset
  1871
				// Record how many more steps to go after we hit this one
hgs
parents:
diff changeset
  1872
				breakEntry->iNumSteps = aNumSteps;
hgs
parents:
diff changeset
  1873
hgs
parents:
diff changeset
  1874
				LOG_MSG3("Setting temp breakpoint id %d with %d steps to go\n", breakEntry->iBreakId, aNumSteps);
hgs
parents:
diff changeset
  1875
hgs
parents:
diff changeset
  1876
				return iChannel->iBreakManager->DoEnableBreak(*breakEntry, ETrue);			
hgs
parents:
diff changeset
  1877
				}
hgs
parents:
diff changeset
  1878
			}
hgs
parents:
diff changeset
  1879
		} while(breakEntry);
hgs
parents:
diff changeset
  1880
	LOG_MSG("ModifyBreaksForStep : Failed to set suitable breakpoint for stepping");
hgs
parents:
diff changeset
  1881
	return KErrNoMemory;	// should never get here
hgs
parents:
diff changeset
  1882
}
hgs
parents:
diff changeset
  1883
hgs
parents:
diff changeset
  1884
// End of file - d-rmd-stepping.cpp