20
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "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 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <platform.h>
|
|
20 |
|
|
21 |
#include "GeneralsDriver.h"
|
|
22 |
#include <kern_priv.h> //temporary
|
|
23 |
|
|
24 |
#ifdef __SMP__
|
|
25 |
#include <e32cia.h>
|
|
26 |
#include <arm.h>
|
|
27 |
#include <arm_gic.h>
|
|
28 |
#include <arm_tmr.h>
|
|
29 |
#endif
|
|
30 |
|
|
31 |
#if defined(__GCC32__)
|
|
32 |
// CIA symbol macros for Gcc98r2
|
|
33 |
#define CSM__ZN5NKern14CurrentContextEv " CurrentContext__5NKern"
|
|
34 |
#elif defined(__ARMCC__)
|
|
35 |
// CIA symbol macros for RVCT
|
|
36 |
#define CSM__ZN5NKern14CurrentContextEv " __cpp(NKern::CurrentContext)"
|
|
37 |
#else
|
|
38 |
// CIA symbol macros for EABI assemblers
|
|
39 |
#define CSM__ZN5NKern14CurrentContextEv " _ZN5NKern14CurrentContextEv"
|
|
40 |
#endif
|
|
41 |
|
|
42 |
#ifdef __WINS__
|
|
43 |
__NAKED__ TUint* IntStackPtr()
|
|
44 |
{
|
|
45 |
return 0;
|
|
46 |
}
|
|
47 |
|
|
48 |
__NAKED__ TUint32 SPSR()
|
|
49 |
{
|
|
50 |
return 0;
|
|
51 |
}
|
|
52 |
__NAKED__ void UsrModLr(TUint32* a)
|
|
53 |
{
|
|
54 |
*a = 0;
|
|
55 |
}
|
|
56 |
#else
|
|
57 |
|
|
58 |
__NAKED__ TUint* IntStackPtr()
|
|
59 |
{
|
|
60 |
#ifdef __SMP__
|
|
61 |
asm("stmfd sp!, {r0-r12,lr} ");
|
|
62 |
#endif
|
|
63 |
asm("mrs r1, cpsr "); // copy current program status register (cpsr) to R1
|
|
64 |
asm("bic r3, r1, #0x1f "); // compare to 0x1f, i.e. make sure that spsr is available?
|
|
65 |
#ifdef __SMP__
|
|
66 |
__ASM_CLI_MODE(MODE_IRQ); // disable all interrupts and set to irq mode (we are in NTimer interrupt)
|
|
67 |
#else
|
|
68 |
asm("orr r3, r3, #0xd2 "); // mode_irq, all interrupts off
|
|
69 |
asm("msr cpsr, r3 "); // write result on R3 back to cpsr, irqs disabled
|
|
70 |
#endif
|
|
71 |
asm("mov r0, sp "); // read stack pointer to R0, mode r0=sp_irq
|
|
72 |
asm("msr cpsr, r1 "); // restore interrupts
|
|
73 |
#ifdef __SMP__
|
|
74 |
asm("ldmfd sp!, {r0-r12,pc} ");
|
|
75 |
#endif
|
|
76 |
__JUMP(,lr);
|
|
77 |
}
|
|
78 |
|
|
79 |
__NAKED__ TUint32 SPSR()
|
|
80 |
{
|
|
81 |
asm("mrs r0, spsr ");
|
|
82 |
__JUMP(,lr);
|
|
83 |
}
|
|
84 |
__NAKED__ void UsrModLr(TUint32*)
|
|
85 |
{
|
|
86 |
// r0 = address to store
|
|
87 |
asm ("stmia r0,{lr}^");
|
|
88 |
__JUMP(,lr);
|
|
89 |
}
|
|
90 |
|
62
|
91 |
// This will return 1 if it was iDFC interrupted (0 otherwise).
|
|
92 |
// As there is no Kernel interface for that, we have to 'fake' Kernel by
|
|
93 |
// setting SVC mode before calling NKern::CurrentContext.
|
|
94 |
// Without that, CurrentContext would always return EInterrupt.
|
|
95 |
__NAKED__ TUint IDFCRunning()
|
|
96 |
{
|
|
97 |
asm("stmfd sp!, {r4-r5} ");
|
|
98 |
|
|
99 |
asm("mrs r5, cpsr"); // r5 = cpsr_irq
|
|
100 |
asm("bic r4, r5, #0xdf "); // clear interrupt mask & CPU mode
|
|
101 |
asm("orr r4, r4, #0xd3 "); // disable all interrupts and set SVC mode
|
|
102 |
|
|
103 |
asm("msr CPSR_cf, r4"); // switch to SVC, (dissable FIQ, IRQ)
|
|
104 |
|
|
105 |
// NKern::CurrentContext does not use sp (only r0,r1,r2)
|
|
106 |
// It is just lr in svc mode we need to preserve.
|
|
107 |
asm("mov r4, lr"); // r4 = lr_svc
|
|
108 |
asm("bl " CSM__ZN5NKern14CurrentContextEv ); // r0 = 1 if iDFC was running, 0 if a thread was running
|
|
109 |
asm("mov lr, r4"); // lr_svc is back to original state
|
|
110 |
|
|
111 |
asm("msr CPSR_cf, r5"); // return to IRQ mode
|
|
112 |
|
|
113 |
asm("ldmfd sp!, {r4-r5} ");
|
|
114 |
__JUMP(,lr);
|
|
115 |
}
|
20
|
116 |
#endif
|