os/kernelhwsrv/kernel/eka/drivers/hcr/hcr_debug.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Helper functions for HCR debug
    15 
    16 #include <e32err.h>
    17 #include <e32const.h>
    18 #include <e32def.h>
    19 #include <e32cmn.h>
    20 #include <e32des8.h>
    21 #include <kernel/kernel.h>
    22 
    23 
    24 #include "hcr_debug.h"
    25 
    26 #ifdef HCR_TRACE
    27 /**
    28 Make a classic hexadecimal dump of the content of an memory region. Do not
    29 call directly but used the macros: HCR_HEX_DUMP_ABS(), HCR_HEX_DUMP_REL()
    30 
    31 @param 	aStartAddress	Pointer of the first byte of the region
    32 		aLength			Size of the region
    33 		aAbsolute		If it is TRUE then it displays absolute address where the aStartAddress points
    34 						If it is FALSE then it displays reltive address from aStartAddress
    35 
    36 @pre    Call from thread context (neither NULL, DFC0, DFC1 threads)
    37 */    
    38 
    39 void HexDump(TUint8* aStartAddress, TUint32 aLength, TBool aAbsolute)
    40 	{
    41 	TUint32 nIndex;
    42 	TBuf<128> printBuf;	// Buffer for address and values
    43 	TBuf<32> printBuf2; // Buffer for character representation
    44 	
    45 	TUint32 extLength = ((aLength & 0xf) == 0 ? aLength :(aLength & 0xfffffff0)+0x10);
    46 	
    47 	for(nIndex = 0; nIndex != extLength ; ++nIndex )
    48 		{
    49 		if(nIndex % 16 == 0)	
    50 			{
    51 			// A line is ready compose two buffers and print the line out
    52 			printBuf.Append(_L("    "));
    53 			printBuf.Append(printBuf2);
    54 			Kern::Printf("%S", &printBuf);
    55 			
    56 			// Start a new line
    57 			printBuf.Zero();
    58 			printBuf.Append(_L("0x"));
    59 			if(aAbsolute)
    60 				{
    61 				printBuf.AppendNumFixedWidth((TUint)(aStartAddress + nIndex), EHex,8);	
    62 				}
    63 			else
    64 				{
    65 				printBuf.AppendNumFixedWidth((TUint)(nIndex), EHex,8);	
    66 				}
    67 			
    68 			printBuf.Append(_L(": "));
    69 			printBuf2.Zero();
    70 			}
    71 			
    72 		if( nIndex < aLength )
    73 			{
    74 			// Active content
    75 			// Put the value into buffer
    76 			printBuf.AppendNumFixedWidth(*(aStartAddress + nIndex), EHex,2 );
    77 			printBuf.Append(TChar(' '));
    78 			
    79 			// Put the chracter representation into a second buffer
    80 			if( *(aStartAddress + nIndex) < ' ' )
    81 				{
    82 				printBuf2.Append(TChar('.'));	// Control character
    83 				}
    84 			else
    85 				{
    86 				printBuf2.Append(TChar(*(aStartAddress + nIndex)));	
    87 				}	
    88 			}
    89 		else
    90 			{
    91 			// Fill up content
    92 			printBuf.Append(_L("   "));		// Fill value place with spaces
    93 			printBuf2.Append(TChar(' '));	// Fill char representation place with space
    94 			}
    95 		}
    96 	// Print out the rest of the buffer
    97 	printBuf.Append(_L("    "));
    98 	printBuf.Append(printBuf2);
    99 	Kern::Printf("%S\n", &printBuf);		
   100 	}
   101 	
   102 #endif // HCR_TRACE