author | hgs |
Wed, 12 May 2010 10:34:10 +0100 | |
changeset 133 | 2a0ada0a1bf8 |
parent 90 | 947f0dc9f7a8 |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32/include/nkernsmp/arm/entry.h |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include <arm_gic.h> |
|
19 |
#include <arm_tmr.h> |
|
20 |
||
21 |
||
22 |
extern "C" { |
|
23 |
||
24 |
extern void __ArmVectorReset(); |
|
25 |
extern void __ArmVectorUndef(); |
|
26 |
extern void __ArmVectorSwi(); |
|
27 |
extern void __ArmVectorAbortPrefetch(); |
|
28 |
extern void __ArmVectorAbortData(); |
|
29 |
extern void __ArmVectorReserved(); |
|
30 |
extern void __ArmVectorIrq(); |
|
31 |
extern void __ArmVectorFiq(); |
|
32 |
||
33 |
#define __DECLARE_UNDEFINED_INSTRUCTION_HANDLER asm(".word __ArmVectorUndef ") |
|
34 |
#define __DECLARE_PREFETCH_ABORT_HANDLER asm(".word __ArmVectorAbortPrefetch ") |
|
35 |
#define __DECLARE_DATA_ABORT_HANDLER asm(".word __ArmVectorAbortData ") |
|
36 |
||
37 |
#ifdef BTRACE_CPU_USAGE |
|
38 |
extern void btrace_irq_entry(TInt); |
|
39 |
extern void btrace_fiq_entry(); |
|
40 |
#endif |
|
41 |
||
42 |
extern void handle_crash_ipi(); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
43 |
extern void handle_indirect_powerdown_ipi(); |
0 | 44 |
|
45 |
#ifdef _DEBUG |
|
46 |
extern void __DebugMsgIrq(TUint aIrqNumber); |
|
47 |
#endif |
|
48 |
||
49 |
/* NOTE: We must ensure that this code goes at the beginning of the kernel image. |
|
50 |
*/ |
|
51 |
__NAKED__ void __this_must_go_at_the_beginning_of_the_kernel_image() |
|
52 |
{ |
|
53 |
asm("ldr pc, __reset_vector "); // 00 = Reset vector |
|
54 |
asm("ldr pc, __undef_vector "); // 04 = Undefined instruction vector |
|
55 |
asm("ldr pc, __swi_vector "); // 08 = SWI vector |
|
56 |
asm("ldr pc, __pabt_vector "); // 0C = Prefetch abort vector |
|
57 |
asm("ldr pc, __dabt_vector "); // 10 = Data abort vector |
|
58 |
asm("ldr pc, __unused_vector "); // 14 = unused |
|
59 |
asm("b HandleIrq "); // 18 = IRQ vector |
|
60 |
// 1C = FIQ vector, code in situ |
|
61 |
/*** FIQ entry point ******************************************************/ |
|
62 |
asm("ldr r12, __ArmInterrupt "); |
|
63 |
#ifdef BTRACE_CPU_USAGE |
|
64 |
asm("ldr r11, __BTraceCpuUsageFilter "); |
|
65 |
#endif |
|
66 |
asm("sub lr, lr, #4 "); |
|
67 |
asm("ldr r10, [r12,#%a0]" : : "i" _FOFF(SArmInterruptInfo,iFiqHandler)); // r10 points to FIQ handler |
|
68 |
asm("str lr, [sp, #-4]! "); |
|
69 |
// we assume FIQ handler preserves r0-r7 but not r8-r12 |
|
70 |
// hence must be assembler, so stack misalignment OK |
|
71 |
#if defined(__CPU_ARM_HAS_WORKING_CLREX) |
|
72 |
CLREX |
|
73 |
#elif defined(__CPU_ARM_HAS_LDREX_STREX) |
|
74 |
STREX(8,14,13); // dummy STREX to reset exclusivity monitor |
|
75 |
#endif |
|
76 |
#ifdef __USER_MEMORY_GUARDS_ENABLED__ |
|
77 |
USER_MEMORY_GUARD_ON(,lr,r8); |
|
78 |
asm("str lr, [sp, #-4]! "); |
|
79 |
#endif |
|
80 |
#ifdef BTRACE_CPU_USAGE |
|
81 |
asm("ldrb r8, [r11] "); |
|
82 |
asm("ldr lr, _ArmVectorFiq "); |
|
83 |
asm("cmp r8, #0 "); |
|
84 |
asm("bne btrace_fiq"); |
|
85 |
__JUMP(, r10); // jump to FIQ handler |
|
86 |
||
87 |
asm("btrace_fiq: "); // call trace handler before fiq handler... |
|
88 |
asm("stmfd sp!, {r0-r3,r12,lr} "); |
|
89 |
asm("adr lr, btrace_fiq_return "); |
|
90 |
asm("ldr pc, __btrace_fiq_entry "); |
|
91 |
asm("btrace_fiq_return: "); |
|
92 |
asm("ldmfd sp!, {r0-r3,r12,lr} "); |
|
93 |
__JUMP(, r10); // jump to FIQ handler |
|
94 |
#endif |
|
95 |
asm("ldr lr, _ArmVectorFiq "); |
|
96 |
__JUMP(,r10); // jump to FIQ handler |
|
97 |
||
98 |
||
99 |
/*** Nested IRQ register save *********************************************/ |
|
100 |
asm("nested_irq: "); |
|
101 |
SRSDBW(MODE_SYS); // save return address and return CPSR to interrupt stack |
|
102 |
CPSCHM(MODE_SYS); // mode_sys, IRQs off |
|
103 |
asm("stmfd sp!, {r0-r12,lr} "); // save R0-R12,R14 from system mode |
|
104 |
GET_RWNO_TID(,r4); |
|
105 |
asm("b nested_irq_rejoin "); |
|
106 |
||
107 |
/*** IRQ entry point ******************************************************/ |
|
108 |
asm("HandleIrq: "); |
|
109 |
asm("mrs r13, spsr "); |
|
110 |
asm("sub lr, lr, #4 "); |
|
111 |
asm("and r13, r13, #0x1f "); |
|
112 |
asm("cmp r13, #0x1f "); // interrupted mode_sys? |
|
113 |
asm("beq nested_irq "); // yes -> nested interrupt |
|
114 |
SRSDBW(MODE_SVC); // save return address and return CPSR to supervisor stack |
|
115 |
__ASM_CLI_MODE(MODE_SVC); // mode_svc, IRQs and FIQs off |
|
116 |
asm("sub sp, sp, #%a0" : : "i" _FOFF(SThreadExcStack,iR15)); |
|
117 |
asm("stmia sp, {r0-r14}^ "); // save R0-R12, R13_usr, R14_usr |
|
118 |
asm("mov r1, #%a0" : : "i" ((TInt)SThreadExcStack::EIrq)); |
|
119 |
#if defined(__CPU_ARM_HAS_WORKING_CLREX) |
|
120 |
CLREX |
|
121 |
#elif defined(__CPU_ARM_HAS_LDREX_STREX) |
|
122 |
STREX(12, 0, 13); // dummy STREX to reset exclusivity monitor |
|
123 |
#endif |
|
124 |
GET_RWNO_TID(,r4); |
|
125 |
asm("mov r5, sp "); |
|
126 |
asm("str r1, [sp, #%a0]" : : "i" _FOFF(SThreadExcStack,iExcCode)); // word describing exception type |
|
127 |
__ASM_STI2_MODE(MODE_SYS); // mode_sys, IRQs off, FIQs on |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
128 |
asm("ldr sp, [r4, #%a0]" : : "i" _FOFF(TSubScheduler, iSSX.iIrqStackTop)); |
0 | 129 |
USER_MEMORY_GUARD_ON(,r8,r0); // r8 = original DACR if user memory guards in use |
130 |
||
131 |
asm("nested_irq_rejoin: "); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
132 |
asm("ldr r0, [r4, #%a0]" : : "i" _FOFF(TSubScheduler, iSSX.iIrqCount)); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
133 |
asm("ldr r7, [r4, #%a0]" : : "i" _FOFF(TSubScheduler, iSSX.iIrqNestCount)); |
0 | 134 |
asm("ldr r12, __ArmInterrupt "); |
135 |
asm("ldr r10, _ArmVectorIrq "); |
|
136 |
asm("add r0, r0, #1 "); |
|
137 |
asm("add r7, r7, #1 "); |
|
138 |
__DATA_MEMORY_BARRIER_Z__(r2); // ensure memory accesses in interrupted code are observed before |
|
139 |
// the writes to i_IrqCount, i_IrqNestCount |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
140 |
asm("str r0, [r4, #%a0]" : : "i" _FOFF(TSubScheduler, iSSX.iIrqCount)); // increment i_IrqCount |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
141 |
asm("ldr r11, [r12,#%a0]" : : "i" _FOFF(SArmInterruptInfo,iIrqHandler)); // address if IRQ handler |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
142 |
asm("ldr r6, [r4, #%a0]" : : "i" _FOFF(TSubScheduler, iSSX.iGicCpuIfcAddr)); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
143 |
asm("str r7, [r4, #%a0]" : : "i" _FOFF(TSubScheduler, iSSX.iIrqNestCount)); // increment i_IrqNestCount |
0 | 144 |
|
145 |
asm("1: "); |
|
146 |
#ifdef BTRACE_CPU_USAGE |
|
147 |
asm("ldr r2, __BTraceCpuUsageFilter "); |
|
148 |
#endif |
|
149 |
asm("mov r1, #%a0" : : "i" ((TInt)E_GicIntId_Spurious+1)); |
|
150 |
asm("ldr r0, [r6, #%a0]" : : "i" _FOFF(GicCpuIfc, iAck)); // r0 = number of interrupt to service |
|
151 |
#ifdef BTRACE_CPU_USAGE |
|
152 |
asm("ldrb r2, [r2] "); |
|
153 |
#endif |
|
154 |
asm("sub r1, r1, #1 "); |
|
155 |
asm("cmp r0, r1 "); // any more interrupts pending? |
|
156 |
asm("beq 2f "); // if not, branch out |
|
157 |
#ifdef BTRACE_CPU_USAGE |
|
158 |
asm("cmp r2, #0 "); |
|
159 |
asm("beq 9f "); |
|
160 |
asm("stmfd sp!, {r0-r3} "); |
|
161 |
asm("adr lr, btrace_irq_return "); |
|
162 |
asm("ldr pc, __btrace_irq_entry "); |
|
163 |
asm("btrace_irq_return: "); |
|
164 |
asm("ldmfd sp!, {r0-r3} "); |
|
165 |
asm("9: "); |
|
166 |
#endif // BTRACE_CPU_USAGE |
|
167 |
ASM_DEBUG1(_longjump_Irq,r0); |
|
168 |
asm("adr lr, 1b "); |
|
169 |
asm("tst r0, #0x3e0 "); // check for interrupt numbers 0-31 |
|
170 |
asm("beq 3f "); // branch out if so |
|
171 |
__JUMP(,r11); // jump to dispatcher, R0 = interrupt number, return to 1: |
|
172 |
// dispatcher acknowledges interrupt |
|
173 |
||
174 |
// No more interrupts pending - jump to postamble in the kernel |
|
175 |
// R4->TSubScheduler at this point, R5->saved registers on SVC stack if not nested IRQ |
|
176 |
// R6->GIC CPU interface |
|
177 |
asm("2: "); |
|
178 |
__JUMP(,r10); |
|
179 |
||
180 |
// Kernel IPI |
|
181 |
asm("3: "); |
|
182 |
asm("and r2, r0, #31 "); // r2 = interrupt number 0...31 |
|
183 |
asm("cmp r2, #%a0" : : "i" ((TInt)TIMESLICE_VECTOR)); |
|
184 |
asm("beq do_timeslice_irq "); |
|
185 |
asm("cmp r2, #%a0" : : "i" ((TInt)RESCHED_IPI_VECTOR)); |
|
186 |
asm("beq do_resched_ipi "); |
|
187 |
asm("cmp r2, #%a0" : : "i" ((TInt)GENERIC_IPI_VECTOR)); |
|
188 |
asm("beq do_generic_ipi "); |
|
189 |
asm("cmp r2, #%a0" : : "i" ((TInt)TRANSFERRED_IRQ_VECTOR)); |
|
190 |
asm("beq do_transferred_ipi "); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
191 |
asm("cmp r2, #%a0" : : "i" ((TInt)INDIRECT_POWERDOWN_IPI_VECTOR)); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
192 |
asm("beq do_indirect_powerdown_ipi "); |
0 | 193 |
asm("cmp r2, #15 "); |
194 |
__JUMP(hi, r11); // if >15 but not TIMESLICE_VECTOR, call dispatcher |
|
195 |
||
196 |
// else assume CRASH_IPI |
|
197 |
asm("str r0, [r6, #%a0]" : : "i" _FOFF(GicCpuIfc, iEoi)); // acknowledge interrupt |
|
198 |
__DATA_SYNC_BARRIER_Z__(r1); |
|
199 |
asm("ldr r1, __HandleCrashIPI "); |
|
200 |
__JUMP(, r1); // CRASH IPI, so crash |
|
201 |
||
202 |
// TIMESLICE, RESCHED or TRANSFERRED |
|
203 |
asm("do_timeslice_irq: "); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
204 |
asm("ldr r2, [r4, #%a0]" : : "i" _FOFF(TSubScheduler, iSSX.iLocalTimerAddr)); |
0 | 205 |
asm("mov r1, #1 "); |
206 |
asm("str r1, [r2, #%a0]" : : "i" _FOFF(ArmLocalTimer, iTimerIntStatus)); // clear timer event flag |
|
207 |
asm("do_resched_ipi: "); |
|
208 |
asm("mov r1, #1 "); |
|
209 |
asm("strb r1, [r4, #%a0]" : : "i" _FOFF(TSubScheduler, iRescheduleNeededFlag)); |
|
210 |
asm("do_transferred_ipi: "); |
|
211 |
asm("str r0, [r6, #%a0]" : : "i" _FOFF(GicCpuIfc, iEoi)); // acknowledge interrupt |
|
212 |
__DATA_SYNC_BARRIER_Z__(r1); // ensure writes to i_IrqCount, i_IrqNestCount, iRescheduleNeededFlag complete before SEV |
|
213 |
// also ensure EOI is written before we return from the interrupt |
|
214 |
ARM_SEV; // kick any CPUs waiting for us to enter the ISR |
|
215 |
asm("b 1b "); |
|
216 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
217 |
asm("do_indirect_powerdown_ipi: "); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
218 |
asm("str r0, [r6, #%a0]" : : "i" _FOFF(GicCpuIfc, iEoi)); // acknowledge interrupt |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
219 |
__DATA_SYNC_BARRIER_Z__(r1); // ensure writes to i_IrqCount, i_IrqNestCount, iRescheduleNeededFlag complete before SEV |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
220 |
// also ensure EOI is written before we return from the interrupt |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
221 |
ARM_SEV; // kick any CPUs waiting for us to enter the ISR |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
222 |
asm("stmfd sp!, {r0-r3,r12,lr} "); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
223 |
asm("bl call_ipd_handler "); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
224 |
asm("ldmfd sp!, {r0-r3,r12,lr} "); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
225 |
asm("b 1b "); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
226 |
|
0 | 227 |
// GENERIC_IPI |
228 |
asm("do_generic_ipi: "); |
|
229 |
asm("ldr r2, _GenericIPIIsr "); |
|
230 |
asm("str r0, [r6, #%a0]" : : "i" _FOFF(GicCpuIfc, iEoi)); // acknowledge interrupt |
|
231 |
asm("mov r0, r4 "); // r0->SubScheduler |
|
232 |
__DATA_SYNC_BARRIER_Z__(r1); |
|
233 |
__JUMP(, r2); |
|
234 |
||
235 |
asm("__DebugMsg_longjump_Irq: "); |
|
236 |
asm("ldr pc, _dmIrq "); |
|
237 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
238 |
asm("call_ipd_handler: "); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
239 |
asm("ldr pc, __handle_ipd_ipi "); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
240 |
|
0 | 241 |
asm("__reset_vector:"); |
242 |
asm(".word __ArmVectorReset "); |
|
243 |
asm("__undef_vector:"); |
|
244 |
__DECLARE_UNDEFINED_INSTRUCTION_HANDLER; |
|
245 |
asm("__swi_vector:"); |
|
246 |
asm(".word __ArmVectorSwi "); |
|
247 |
asm("__pabt_vector:"); |
|
248 |
__DECLARE_PREFETCH_ABORT_HANDLER; |
|
249 |
asm("__dabt_vector:"); |
|
250 |
__DECLARE_DATA_ABORT_HANDLER; |
|
251 |
asm("__unused_vector:"); |
|
252 |
asm(".word __ArmVectorReserved "); |
|
253 |
||
254 |
asm("__ArmInterrupt: "); |
|
255 |
asm(".word ArmInterruptInfo "); |
|
256 |
asm("_ArmVectorIrq: "); |
|
257 |
asm(".word __ArmVectorIrq "); |
|
258 |
asm("_GenericIPIIsr: "); |
|
259 |
asm(".word generic_ipi_isr "); |
|
260 |
asm("_ArmVectorFiq: "); |
|
261 |
asm(".word __ArmVectorFiq "); |
|
262 |
asm("__HandleCrashIPI: "); |
|
263 |
asm(".word handle_crash_ipi "); |
|
264 |
#ifdef BTRACE_CPU_USAGE |
|
265 |
asm("__BTraceCpuUsageFilter: "); |
|
266 |
asm(".word %a0" : : "i" ((TInt)&BTraceData.iFilter[BTrace::ECpuUsage])); |
|
267 |
asm("__btrace_irq_entry: "); |
|
268 |
asm(".word btrace_irq_entry "); |
|
269 |
asm("__btrace_fiq_entry: "); |
|
270 |
asm(".word btrace_fiq_entry "); |
|
271 |
#endif |
|
272 |
asm("_dmIrq: "); |
|
273 |
asm(".word __DebugMsgIrq "); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
274 |
asm("__handle_ipd_ipi: "); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
275 |
asm(".word handle_indirect_powerdown_ipi "); |
0 | 276 |
} |
277 |
} |
|
278 |