os/kernelhwsrv/kernel/eka/euser/epoc/arm/uc_trp.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) 1995-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
// e32\euser\epoc\arm\uc_trp.cia
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32cia.h>
sl@0
    19
#include <u32std.h>
sl@0
    20
#include <e32panic.h>
sl@0
    21
#include <u32exec.h>
sl@0
    22
#include "uc_std.h"
sl@0
    23
sl@0
    24
//  With -fvtable-thunks
sl@0
    25
const TInt KVTableTrapOffset=8;
sl@0
    26
const TInt KVTableLeaveOffset=16;
sl@0
    27
sl@0
    28
//  Without -fvtable-thunks
sl@0
    29
//  const TInt KVTableTrapOffset=12;
sl@0
    30
//  const TInt KVTableLeaveOffset=28;
sl@0
    31
sl@0
    32
sl@0
    33
#ifndef __LEAVE_EQUALS_THROW__
sl@0
    34
sl@0
    35
EXPORT_C __NAKED__ TInt TTrap::Trap(TInt & /*aResult*/)
sl@0
    36
//
sl@0
    37
// Save the enter frame state and return 0.
sl@0
    38
//
sl@0
    39
	{
sl@0
    40
sl@0
    41
	asm("mov r2, #0 ");						// aResult==KErrNone
sl@0
    42
	asm("str r2, [r1, #0] ");				// iResult=(&aResult)
sl@0
    43
	asm("str r1, [r0, #%a0]" : : "i" _FOFF(TTrap,iResult));
sl@0
    44
	asm("stmia r0, {r4-r11, sp, lr} ");		// Save the context
sl@0
    45
	asm("stmfd sp!, {r4,lr} ");
sl@0
    46
	asm("bl  " CSM_ZN4Exec13PushTrapFrameEP5TTrap);
sl@0
    47
	asm("cmp r0, #0 ");						// == NULL
sl@0
    48
	asm("ldrne r3, [r0, #%a0]" : : "i" (_TTRAPHANDLER_VPTR_OFFSET_));
sl@0
    49
	asm("beq ttrap_trap_no_trap_handler ");
sl@0
    50
#ifdef __SUPPORT_THUMB_INTERWORKING
sl@0
    51
	asm("ldr r3, [r3, #%a0]" : : "i" (_TTRAPHANDLER_TRAP_OFFSET_));
sl@0
    52
	asm("adr lr, __ttrap_trap_return ");	// iHandler->Trap()
sl@0
    53
	asm("bx r3 ");
sl@0
    54
#else
sl@0
    55
	asm("adr lr, __ttrap_trap_return ");	// iHandler->Trap()
sl@0
    56
	asm("ldr pc, [r3, #%a0]" : : "i" (_TTRAPHANDLER_TRAP_OFFSET_));
sl@0
    57
#endif
sl@0
    58
	asm("__ttrap_trap_return: ");
sl@0
    59
	asm("mov r0, #0							");
sl@0
    60
	asm("ttrap_trap_no_trap_handler: ");
sl@0
    61
	__POPRET("r4,");
sl@0
    62
	}
sl@0
    63
sl@0
    64
extern void PanicNoTrapFrame();
sl@0
    65
sl@0
    66
sl@0
    67
sl@0
    68
EXPORT_C __NAKED__ void User::Leave(TInt /*aReason*/)
sl@0
    69
/**
sl@0
    70
Leaves the currently executing function, unwinds the call stack, and returns
sl@0
    71
from the most recently entered trap harness.
sl@0
    72
sl@0
    73
@param aReason The value returned from the most recent call to TRAP or TRAPD.
sl@0
    74
               This is known as the reason code and, typically, it gives the
sl@0
    75
               reason for the environment or user error causing this leave
sl@0
    76
               to occur.
sl@0
    77
              
sl@0
    78
@see TRAP
sl@0
    79
@see TRAPD              
sl@0
    80
*/
sl@0
    81
	{
sl@0
    82
sl@0
    83
	asm("mov r4, r0 ");						// Save aReason
sl@0
    84
	asm("bl  " CSM_ZN4Exec12PopTrapFrameEv);			// Returns the current TTrap
sl@0
    85
    asm("cmp r0, #0 ");
sl@0
    86
    asm("bleq  " CSM_Z16PanicNoTrapFramev);
sl@0
    87
	asm("ldr r1, [r0, #%a0]" : : "i" _FOFF(TTrap,iResult));
sl@0
    88
	asm("mov r5, r0 ");						// Save it for later
sl@0
    89
	asm("ldr r0, [r0, #%a0]" : : "i" _FOFF(TTrap,iHandler));
sl@0
    90
	asm("str r4, [r1, #0] ");				// *(pT->iResult)=aReason
sl@0
    91
	asm("cmp r0, #0 ");
sl@0
    92
	asm("ldrne r2, [r0, #%a0]" : : "i" (_TTRAPHANDLER_VPTR_OFFSET_));
sl@0
    93
	asm("beq user_leave_no_trap_handler ");	// No trap handler
sl@0
    94
	asm("mov r1, r4 ");						// Pass aReason
sl@0
    95
#ifdef __SUPPORT_THUMB_INTERWORKING
sl@0
    96
	asm("ldr r3, [r2, #%a0]" : : "i" (_TTRAPHANDLER_LEAVE_OFFSET_));
sl@0
    97
	asm("adr lr, user_leave_no_trap_handler ");	// iHandler->Leave(aReason)
sl@0
    98
	asm("bx r3 ");
sl@0
    99
#else
sl@0
   100
	asm("adr lr, user_leave_no_trap_handler ");	// iHandler->Leave(aReason)
sl@0
   101
	asm("ldr pc, [r2, #%a0]" : : "i" (_TTRAPHANDLER_LEAVE_OFFSET_));
sl@0
   102
#endif
sl@0
   103
	asm("user_leave_no_trap_handler: ");
sl@0
   104
	asm("ldmia	r5, {r4-r11, sp, lr} ");	// Restore the context
sl@0
   105
	asm("mov	r0, #1 ");					// return(1)
sl@0
   106
	__JUMP(,lr);							// return
sl@0
   107
	}
sl@0
   108
sl@0
   109
#endif // !__LEAVE_EQUALS_THROW__