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