os/kernelhwsrv/kerneltest/e32utils/profiler/sampler.cia
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32utils/profiler/sampler.cia	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,82 @@
     1.4 +// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32utils\profiler\sampler.cia
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <platform.h>
    1.22 +
    1.23 +#include "sampler.h"
    1.24 +#include <kernel/kern_priv.h>		//temporary
    1.25 +
    1.26 +
    1.27 +#if defined(__GCC32__)
    1.28 +// CIA symbol macros for Gcc98r2
    1.29 +#define CSM__ZN5NKern14CurrentContextEv " CurrentContext__5NKern"
    1.30 +#elif defined(__ARMCC__)
    1.31 +// CIA symbol macros for RVCT
    1.32 +#define CSM__ZN5NKern14CurrentContextEv " __cpp(NKern::CurrentContext)"
    1.33 +#else
    1.34 +// CIA symbol macros for EABI assemblers
    1.35 +#define CSM__ZN5NKern14CurrentContextEv " _ZN5NKern14CurrentContextEv"
    1.36 +#endif
    1.37 +
    1.38 +
    1.39 +__NAKED__ TUint IntStackPtr()
    1.40 +	{
    1.41 +	asm("mrs r1, cpsr ");
    1.42 +	asm("bic r3, r1, #0x1f ");
    1.43 +//#ifdef __MISA__
    1.44 +//	asm("orr r3, r3, #0xd1 ");		// mode_fiq, all interrupts off
    1.45 +//#else
    1.46 +	asm("orr r3, r3, #0xd2 ");		// mode_irq, all interrupts off
    1.47 +//#endif
    1.48 +	asm("msr cpsr, r3 ");
    1.49 +	asm("mov r0, sp ");				// r0=sp_irq or sp_fiq
    1.50 +	asm("msr cpsr, r1 ");			// restore interrupts
    1.51 +	__JUMP(,lr);
    1.52 +	}
    1.53 +
    1.54 +__NAKED__ TUint32 SPSR()
    1.55 +	{
    1.56 +	asm("mrs r0, spsr ");
    1.57 +	__JUMP(,lr);
    1.58 +	}
    1.59 +
    1.60 +
    1.61 +// This will return 1 if it was iDFC interrupted (0 otherwise).
    1.62 +// As there is no Kernel interface for that, we have to 'fake' Kernel by
    1.63 +// setting SVC mode before calling NKern::CurrentContext.
    1.64 +// Without that, CurrentContext would always return EInterrupt.
    1.65 +__NAKED__ TUint IDFCRunning()
    1.66 +	{
    1.67 +	asm("stmfd sp!, {r4-r5} ");	
    1.68 +
    1.69 +	asm("mrs r5, cpsr");							// r5 = cpsr_irq
    1.70 +	asm("bic r4, r5, #0xdf ");						// clear interrupt mask & CPU mode
    1.71 +	asm("orr r4, r4, #0xd3 ");						// disable all interrupts and set SVC mode
    1.72 +
    1.73 +	asm("msr CPSR_cf, r4");   						// switch to SVC, (dissable FIQ, IRQ)
    1.74 +	
    1.75 +	// NKern::CurrentContext does not use sp (only r0,r1,r2)
    1.76 +	// It is just lr in svc mode we need to preserve.
    1.77 +	asm("mov r4, lr");             					// r4 = lr_svc
    1.78 +	asm("bl " CSM__ZN5NKern14CurrentContextEv ); 	// r0 = 1 if iDFC was running, 0 if a thread was running
    1.79 +	asm("mov lr, r4");								// lr_svc is back to original state
    1.80 +
    1.81 +	asm("msr CPSR_cf, r5");							// return to IRQ mode
    1.82 +	
    1.83 +	asm("ldmfd sp!, {r4-r5} ");
    1.84 +	__JUMP(,lr);
    1.85 +	}