os/kernelhwsrv/kerneltest/e32utils/profiler/sampler.cia
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32utils\profiler\sampler.cia
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <platform.h>
sl@0
    19
sl@0
    20
#include "sampler.h"
sl@0
    21
#include <kernel/kern_priv.h>		//temporary
sl@0
    22
sl@0
    23
sl@0
    24
#if defined(__GCC32__)
sl@0
    25
// CIA symbol macros for Gcc98r2
sl@0
    26
#define CSM__ZN5NKern14CurrentContextEv " CurrentContext__5NKern"
sl@0
    27
#elif defined(__ARMCC__)
sl@0
    28
// CIA symbol macros for RVCT
sl@0
    29
#define CSM__ZN5NKern14CurrentContextEv " __cpp(NKern::CurrentContext)"
sl@0
    30
#else
sl@0
    31
// CIA symbol macros for EABI assemblers
sl@0
    32
#define CSM__ZN5NKern14CurrentContextEv " _ZN5NKern14CurrentContextEv"
sl@0
    33
#endif
sl@0
    34
sl@0
    35
sl@0
    36
__NAKED__ TUint IntStackPtr()
sl@0
    37
	{
sl@0
    38
	asm("mrs r1, cpsr ");
sl@0
    39
	asm("bic r3, r1, #0x1f ");
sl@0
    40
//#ifdef __MISA__
sl@0
    41
//	asm("orr r3, r3, #0xd1 ");		// mode_fiq, all interrupts off
sl@0
    42
//#else
sl@0
    43
	asm("orr r3, r3, #0xd2 ");		// mode_irq, all interrupts off
sl@0
    44
//#endif
sl@0
    45
	asm("msr cpsr, r3 ");
sl@0
    46
	asm("mov r0, sp ");				// r0=sp_irq or sp_fiq
sl@0
    47
	asm("msr cpsr, r1 ");			// restore interrupts
sl@0
    48
	__JUMP(,lr);
sl@0
    49
	}
sl@0
    50
sl@0
    51
__NAKED__ TUint32 SPSR()
sl@0
    52
	{
sl@0
    53
	asm("mrs r0, spsr ");
sl@0
    54
	__JUMP(,lr);
sl@0
    55
	}
sl@0
    56
sl@0
    57
sl@0
    58
// This will return 1 if it was iDFC interrupted (0 otherwise).
sl@0
    59
// As there is no Kernel interface for that, we have to 'fake' Kernel by
sl@0
    60
// setting SVC mode before calling NKern::CurrentContext.
sl@0
    61
// Without that, CurrentContext would always return EInterrupt.
sl@0
    62
__NAKED__ TUint IDFCRunning()
sl@0
    63
	{
sl@0
    64
	asm("stmfd sp!, {r4-r5} ");	
sl@0
    65
sl@0
    66
	asm("mrs r5, cpsr");							// r5 = cpsr_irq
sl@0
    67
	asm("bic r4, r5, #0xdf ");						// clear interrupt mask & CPU mode
sl@0
    68
	asm("orr r4, r4, #0xd3 ");						// disable all interrupts and set SVC mode
sl@0
    69
sl@0
    70
	asm("msr CPSR_cf, r4");   						// switch to SVC, (dissable FIQ, IRQ)
sl@0
    71
	
sl@0
    72
	// NKern::CurrentContext does not use sp (only r0,r1,r2)
sl@0
    73
	// It is just lr in svc mode we need to preserve.
sl@0
    74
	asm("mov r4, lr");             					// r4 = lr_svc
sl@0
    75
	asm("bl " CSM__ZN5NKern14CurrentContextEv ); 	// r0 = 1 if iDFC was running, 0 if a thread was running
sl@0
    76
	asm("mov lr, r4");								// lr_svc is back to original state
sl@0
    77
sl@0
    78
	asm("msr CPSR_cf, r5");							// return to IRQ mode
sl@0
    79
	
sl@0
    80
	asm("ldmfd sp!, {r4-r5} ");
sl@0
    81
	__JUMP(,lr);
sl@0
    82
	}